Change column config layout

This commit is contained in:
Adria Navarro 2023-09-19 09:50:29 +02:00
parent 1c76a77682
commit 847e17e04a
1 changed files with 31 additions and 51 deletions

View File

@ -346,53 +346,32 @@
} }
function getRelationshipOptions(field) { function getRelationshipOptions(field) {
if (!field) { if (!field || !field.tableId) {
return null return null
} }
const linkTable = tableOptions?.find(table => table._id === field.tableId)
if (field.type === FieldType.LINK) { if (!linkTable) {
if (!field.tableId) {
return null
}
const linkTable = tableOptions?.find(table => table._id === field.tableId)
if (!linkTable) {
return null
}
const thisName = truncate(table.name, { length: 14 }),
linkName = truncate(linkTable.name, { length: 14 })
return [
{
name: `Many ${thisName} rows → many ${linkName} rows`,
alt: `Many ${table.name} rows → many ${linkTable.name} rows`,
value: RelationshipType.MANY_TO_MANY,
},
{
name: `One ${linkName} row → many ${thisName} rows`,
alt: `One ${linkTable.name} rows → many ${table.name} rows`,
value: RelationshipType.ONE_TO_MANY,
},
{
name: `One ${thisName} row → many ${linkName} rows`,
alt: `One ${table.name} rows → many ${linkTable.name} rows`,
value: RelationshipType.MANY_TO_ONE,
},
]
} else if (field.type === BB_USER_REFERENCE_TYPE) {
return [
{
name: `Single user`,
alt: `Single user`,
value: RelationshipType.ONE_TO_MANY,
},
{
name: `Multiple users`,
alt: `Multiple users`,
value: RelationshipType.MANY_TO_ONE,
},
]
} else {
return null return null
} }
const thisName = truncate(table.name, { length: 14 }),
linkName = truncate(linkTable.name, { length: 14 })
return [
{
name: `Many ${thisName} rows → many ${linkName} rows`,
alt: `Many ${table.name} rows → many ${linkTable.name} rows`,
value: RelationshipType.MANY_TO_MANY,
},
{
name: `One ${linkName} row → many ${thisName} rows`,
alt: `One ${linkTable.name} rows → many ${table.name} rows`,
value: RelationshipType.ONE_TO_MANY,
},
{
name: `One ${thisName} row → many ${linkName} rows`,
alt: `One ${table.name} rows → many ${linkTable.name} rows`,
value: RelationshipType.MANY_TO_ONE,
},
]
} }
function getAllowedTypes() { function getAllowedTypes() {
@ -700,14 +679,15 @@
>Open schema editor</Button >Open schema editor</Button
> >
{:else if isBBReference} {:else if isBBReference}
<RadioGroup <Toggle
disabled={linkEditDisabled} value={editableColumn.relationshipType === RelationshipType.MANY_TO_MANY}
label="Define the relationship" on:change={e =>
bind:value={editableColumn.relationshipType} (editableColumn.relationshipType = e.detail
options={relationshipOptions} ? RelationshipType.MANY_TO_MANY
getOptionLabel={option => option.name} : RelationshipType.ONE_TO_MANY)}
getOptionValue={option => option.value} disabled={!isCreating}
getOptionTitle={option => option.alt} thin
text="Allow multiple users"
/> />
{/if} {/if}
{#if editableColumn.type === AUTO_TYPE || editableColumn.autocolumn} {#if editableColumn.type === AUTO_TYPE || editableColumn.autocolumn}