Add support for new relationship objects in client apps
This commit is contained in:
parent
73d19f53d1
commit
6d9c5cdf46
|
@ -35,7 +35,7 @@
|
||||||
|
|
||||||
// Form API contains functions to control the form
|
// Form API contains functions to control the form
|
||||||
const formApi = {
|
const formApi = {
|
||||||
registerField: (field, defaultValue = null, fieldDisabled = false) => {
|
registerField: (field, defaultValue = undefined, fieldDisabled = false) => {
|
||||||
if (!field) {
|
if (!field) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@
|
||||||
role="option"
|
role="option"
|
||||||
aria-selected="true"
|
aria-selected="true"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
on:click={() => onSelectOption(null)}>
|
on:click={() => onSelectOption(undefined)}>
|
||||||
<span class="spectrum-Menu-itemLabel">{placeholderOption}</span>
|
<span class="spectrum-Menu-itemLabel">{placeholderOption}</span>
|
||||||
<svg
|
<svg
|
||||||
class="spectrum-Icon spectrum-UIIcon-Checkmark100 spectrum-Menu-checkmark spectrum-Menu-itemIcon"
|
class="spectrum-Icon spectrum-UIIcon-Checkmark100 spectrum-Menu-checkmark spectrum-Menu-itemIcon"
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
const setFieldText = value => {
|
const setFieldText = value => {
|
||||||
if (fieldSchema?.relationshipType === "one-to-many") {
|
if (fieldSchema?.relationshipType === "one-to-many") {
|
||||||
if (value?.length && options?.length) {
|
if (value?.length && options?.length) {
|
||||||
const row = options.find(row => row._id === value[0])
|
const row = options.find(row => row._id === value[0]?._id)
|
||||||
return getDisplayName(row)
|
return getDisplayName(row)
|
||||||
} else {
|
} else {
|
||||||
return placeholder || "Choose an option"
|
return placeholder || "Choose an option"
|
||||||
|
@ -60,27 +60,30 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const getDisplayName = row => {
|
const getDisplayName = row => {
|
||||||
return row[tableDefinition?.primaryDisplay || "_id"]
|
return row?.[tableDefinition?.primaryDisplay || "_id"] || "-"
|
||||||
}
|
}
|
||||||
|
|
||||||
const getValueLookupMap = value => {
|
const getValueLookupMap = value => {
|
||||||
let map = {}
|
let map = {}
|
||||||
if (value?.length) {
|
if (value?.length) {
|
||||||
value.forEach(option => {
|
value.forEach(option => {
|
||||||
map[option] = true
|
if (option?._id) {
|
||||||
|
map[option._id] = true
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return map
|
return map
|
||||||
}
|
}
|
||||||
|
|
||||||
const toggleOption = option => {
|
const toggleOption = id => {
|
||||||
if (fieldSchema.type === "one-to-many") {
|
if (fieldSchema.relationshipType === "one-to-many") {
|
||||||
fieldApi.setValue([option])
|
fieldApi.setValue([{ _id: id }])
|
||||||
} else {
|
} else {
|
||||||
if ($fieldState.value.includes(option)) {
|
if ($fieldState.value.find(option => option?._id === id)) {
|
||||||
fieldApi.setValue($fieldState.value.filter(x => x !== option))
|
const filtered = $fieldState.value.filter(option => option?._id !== id)
|
||||||
|
fieldApi.setValue(filtered)
|
||||||
} else {
|
} else {
|
||||||
fieldApi.setValue([...$fieldState.value, option])
|
fieldApi.setValue([...$fieldState.value, { _id: id }])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
<div class="container">
|
<div class="container">
|
||||||
{#each items as item}
|
{#each items as item}
|
||||||
<div class="item">{item?.primaryDisplay}</div>
|
<div class="item">{item?.primaryDisplay ?? ''}</div>
|
||||||
{/each}
|
{/each}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ import AttachmentCell from "./AttachmentCell/Button.svelte"
|
||||||
import ViewDetails from "./ViewDetails/Cell.svelte"
|
import ViewDetails from "./ViewDetails/Cell.svelte"
|
||||||
import Select from "./Select/Wrapper.svelte"
|
import Select from "./Select/Wrapper.svelte"
|
||||||
import DatePicker from "./DateTime/Wrapper.svelte"
|
import DatePicker from "./DateTime/Wrapper.svelte"
|
||||||
import RelationshipCount from "./Relationship/RelationshipCount.svelte"
|
import RelationshipLabel from "./Relationship/RelationshipLabel.svelte"
|
||||||
|
|
||||||
const renderers = new Map([
|
const renderers = new Map([
|
||||||
["boolean", booleanRenderer],
|
["boolean", booleanRenderer],
|
||||||
|
@ -127,7 +127,7 @@ function linkedRowRenderer(options, constraints, editable, SDK) {
|
||||||
container.style.placeItems = "center"
|
container.style.placeItems = "center"
|
||||||
container.style.height = "100%"
|
container.style.height = "100%"
|
||||||
|
|
||||||
new RelationshipCount({
|
new RelationshipLabel({
|
||||||
target: container,
|
target: container,
|
||||||
props: {
|
props: {
|
||||||
row: params.data,
|
row: params.data,
|
||||||
|
|
Loading…
Reference in New Issue