Update/fetch nested settings
This commit is contained in:
parent
97a44a8162
commit
643210f3aa
|
@ -14,6 +14,12 @@
|
||||||
export let fromRelationshipField
|
export let fromRelationshipField
|
||||||
|
|
||||||
const { datasource, dispatch } = getContext("grid")
|
const { datasource, dispatch } = getContext("grid")
|
||||||
|
|
||||||
|
let relationshipPanelAnchor
|
||||||
|
let relationshipPanelColumns = []
|
||||||
|
let relationshipFieldName
|
||||||
|
|
||||||
|
$: relationshipField = columns.find(c => c.name === relationshipFieldName)
|
||||||
$: permissionsObj = permissions.reduce(
|
$: permissionsObj = permissions.reduce(
|
||||||
(acc, c) => ({
|
(acc, c) => ({
|
||||||
...acc,
|
...acc,
|
||||||
|
@ -25,33 +31,6 @@
|
||||||
)
|
)
|
||||||
|
|
||||||
$: allowRelationshipSchemas = true // TODO
|
$: allowRelationshipSchemas = true // TODO
|
||||||
let relationshipPanelOpen = false
|
|
||||||
let relationshipPanelAnchor
|
|
||||||
let relationshipPanelColumns = []
|
|
||||||
let relationshipField
|
|
||||||
|
|
||||||
const toggleColumn = async (column, permission) => {
|
|
||||||
const visible = permission !== FieldPermissions.HIDDEN
|
|
||||||
const readonly = permission === FieldPermissions.READONLY
|
|
||||||
|
|
||||||
await datasource.actions.addSchemaMutation(
|
|
||||||
column.name,
|
|
||||||
{
|
|
||||||
visible,
|
|
||||||
readonly,
|
|
||||||
},
|
|
||||||
fromRelationshipField?.name
|
|
||||||
)
|
|
||||||
try {
|
|
||||||
await datasource.actions.saveSchemaMutations()
|
|
||||||
} catch (e) {
|
|
||||||
notifications.error(e.message)
|
|
||||||
} finally {
|
|
||||||
await datasource.actions.resetSchemaMutations()
|
|
||||||
await datasource.actions.refreshDefinition()
|
|
||||||
}
|
|
||||||
dispatch(visible ? "show-column" : "hide-column")
|
|
||||||
}
|
|
||||||
|
|
||||||
$: displayColumns = columns.map(c => {
|
$: displayColumns = columns.map(c => {
|
||||||
const isRequired =
|
const isRequired =
|
||||||
|
@ -135,6 +114,29 @@
|
||||||
return { ...c, options }
|
return { ...c, options }
|
||||||
})
|
})
|
||||||
|
|
||||||
|
async function toggleColumn(column, permission) {
|
||||||
|
const visible = permission !== FieldPermissions.HIDDEN
|
||||||
|
const readonly = permission === FieldPermissions.READONLY
|
||||||
|
|
||||||
|
await datasource.actions.addSchemaMutation(
|
||||||
|
column.name,
|
||||||
|
{
|
||||||
|
visible,
|
||||||
|
readonly,
|
||||||
|
},
|
||||||
|
fromRelationshipField?.name
|
||||||
|
)
|
||||||
|
try {
|
||||||
|
await datasource.actions.saveSchemaMutations()
|
||||||
|
} catch (e) {
|
||||||
|
notifications.error(e.message)
|
||||||
|
} finally {
|
||||||
|
await datasource.actions.resetSchemaMutations()
|
||||||
|
await datasource.actions.refreshDefinition()
|
||||||
|
}
|
||||||
|
dispatch(visible ? "show-column" : "hide-column")
|
||||||
|
}
|
||||||
|
|
||||||
function columnToPermissionOptions(column) {
|
function columnToPermissionOptions(column) {
|
||||||
if (column.schema.visible === false) {
|
if (column.schema.visible === false) {
|
||||||
return FieldPermissions.HIDDEN
|
return FieldPermissions.HIDDEN
|
||||||
|
@ -147,34 +149,43 @@
|
||||||
return FieldPermissions.WRITABLE
|
return FieldPermissions.WRITABLE
|
||||||
}
|
}
|
||||||
|
|
||||||
function onRelationshipOpen(column, domElement) {
|
$: {
|
||||||
const relTable = $tables.list.find(
|
if (relationshipField) {
|
||||||
table => table._id === column.schema.tableId
|
cache.actions
|
||||||
)
|
.getTable(relationshipField.schema.tableId)
|
||||||
|
.then(relTable => {
|
||||||
relationshipPanelColumns = Object.values(relTable?.schema || {})
|
relationshipPanelColumns = Object.values(relTable?.schema || {})
|
||||||
.filter(
|
.filter(
|
||||||
schema => ![FieldType.LINK, FieldType.FORMULA].includes(schema.type)
|
schema =>
|
||||||
|
![FieldType.LINK, FieldType.FORMULA].includes(schema.type)
|
||||||
)
|
)
|
||||||
.map(column => {
|
.map(column => {
|
||||||
const isPrimaryDisplay = relTable.primaryDisplay === column.name
|
const isPrimaryDisplay = relTable.primaryDisplay === column.name
|
||||||
|
const isReadonly = !!(
|
||||||
|
isPrimaryDisplay ||
|
||||||
|
column.readonly ||
|
||||||
|
(relationshipField.schema?.schema || {})[column.name]?.readonly
|
||||||
|
)
|
||||||
return {
|
return {
|
||||||
name: column.name,
|
name: column.name,
|
||||||
label: column.name,
|
label: column.name,
|
||||||
primaryDisplay: isPrimaryDisplay,
|
primaryDisplay: isPrimaryDisplay,
|
||||||
schema: {
|
schema: {
|
||||||
...column,
|
...column,
|
||||||
visible: !!isPrimaryDisplay,
|
visible: isReadonly,
|
||||||
readonly: isPrimaryDisplay || column.readonly,
|
readonly: isReadonly,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.sort((a, b) =>
|
.sort((a, b) =>
|
||||||
a.primaryDisplay === b.primaryDisplay ? 0 : a.primaryDisplay ? -1 : 1
|
a.primaryDisplay === b.primaryDisplay
|
||||||
|
? 0
|
||||||
|
: a.primaryDisplay
|
||||||
|
? -1
|
||||||
|
: 1
|
||||||
)
|
)
|
||||||
|
})
|
||||||
relationshipPanelAnchor = domElement
|
}
|
||||||
relationshipPanelOpen = !relationshipPanelOpen
|
|
||||||
relationshipField = column
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -196,7 +207,10 @@
|
||||||
{#if allowRelationshipSchemas && column.schema.type === FieldType.LINK}
|
{#if allowRelationshipSchemas && column.schema.type === FieldType.LINK}
|
||||||
<div class="relationship-columns">
|
<div class="relationship-columns">
|
||||||
<ActionButton
|
<ActionButton
|
||||||
on:click={e => onRelationshipOpen(column, e.currentTarget)}
|
on:click={e => {
|
||||||
|
relationshipFieldName = column.name
|
||||||
|
relationshipPanelAnchor = e.currentTarget
|
||||||
|
}}
|
||||||
size="S"
|
size="S"
|
||||||
icon="ChevronRight"
|
icon="ChevronRight"
|
||||||
quiet
|
quiet
|
||||||
|
@ -210,7 +224,7 @@
|
||||||
|
|
||||||
{#if allowRelationshipSchemas}
|
{#if allowRelationshipSchemas}
|
||||||
<Popover
|
<Popover
|
||||||
bind:open={relationshipPanelOpen}
|
open={!!relationshipField}
|
||||||
anchor={relationshipPanelAnchor}
|
anchor={relationshipPanelAnchor}
|
||||||
align="right-outside"
|
align="right-outside"
|
||||||
>
|
>
|
||||||
|
|
Loading…
Reference in New Issue