1
0
Fork 0
mirror of synced 2024-10-03 02:27:06 +13:00

Add support for new relationship objects in client apps

This commit is contained in:
Andrew Kingston 2021-02-25 11:06:16 +00:00
parent bf384697d3
commit aab74cce1a
5 changed files with 17 additions and 14 deletions

View file

@ -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
} }

View file

@ -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"

View file

@ -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 }])
} }
} }
} }

View file

@ -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>

View file

@ -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,