Merge pull request #10672 from Budibase/fix/grid-schema-updates
Fix issue with schema mutation in grids
This commit is contained in:
commit
0c2ffd0030
|
@ -16,11 +16,11 @@
|
||||||
import GridEditColumnModal from "components/backend/DataTable/modals/grid/GridEditColumnModal.svelte"
|
import GridEditColumnModal from "components/backend/DataTable/modals/grid/GridEditColumnModal.svelte"
|
||||||
|
|
||||||
const userSchemaOverrides = {
|
const userSchemaOverrides = {
|
||||||
firstName: { name: "First name", disabled: true },
|
firstName: { displayName: "First name", disabled: true },
|
||||||
lastName: { name: "Last name", disabled: true },
|
lastName: { displayName: "Last name", disabled: true },
|
||||||
email: { name: "Email", disabled: true },
|
email: { displayName: "Email", disabled: true },
|
||||||
roleId: { name: "Role", disabled: true },
|
roleId: { displayName: "Role", disabled: true },
|
||||||
status: { name: "Status", disabled: true },
|
status: { displayName: "Status", disabled: true },
|
||||||
}
|
}
|
||||||
|
|
||||||
$: id = $tables.selected?._id
|
$: id = $tables.selected?._id
|
||||||
|
|
|
@ -52,7 +52,7 @@
|
||||||
{:else}
|
{:else}
|
||||||
<div class="text-cell" class:number={type === "number"}>
|
<div class="text-cell" class:number={type === "number"}>
|
||||||
<div class="value">
|
<div class="value">
|
||||||
{value || ""}
|
{value ?? ""}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -116,10 +116,24 @@ export const initialise = context => {
|
||||||
const schema = derived(
|
const schema = derived(
|
||||||
[table, schemaOverrides],
|
[table, schemaOverrides],
|
||||||
([$table, $schemaOverrides]) => {
|
([$table, $schemaOverrides]) => {
|
||||||
let newSchema = $table?.schema
|
if (!$table?.schema) {
|
||||||
if (!newSchema) {
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
let newSchema = { ...$table?.schema }
|
||||||
|
|
||||||
|
// Edge case to temporarily allow deletion of duplicated user
|
||||||
|
// fields that were saved with the "disabled" flag set.
|
||||||
|
// By overriding the saved schema we ensure only overrides can
|
||||||
|
// set the disabled flag.
|
||||||
|
// TODO: remove in future
|
||||||
|
Object.keys(newSchema).forEach(field => {
|
||||||
|
newSchema[field] = {
|
||||||
|
...newSchema[field],
|
||||||
|
disabled: false,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// Apply schema overrides
|
||||||
Object.keys($schemaOverrides || {}).forEach(field => {
|
Object.keys($schemaOverrides || {}).forEach(field => {
|
||||||
if (newSchema[field]) {
|
if (newSchema[field]) {
|
||||||
newSchema[field] = {
|
newSchema[field] = {
|
||||||
|
@ -160,7 +174,7 @@ export const initialise = context => {
|
||||||
fields
|
fields
|
||||||
.map(field => ({
|
.map(field => ({
|
||||||
name: field,
|
name: field,
|
||||||
label: $schema[field].name || field,
|
label: $schema[field].displayName || field,
|
||||||
schema: $schema[field],
|
schema: $schema[field],
|
||||||
width: $schema[field].width || DefaultColumnWidth,
|
width: $schema[field].width || DefaultColumnWidth,
|
||||||
visible: $schema[field].visible ?? true,
|
visible: $schema[field].visible ?? true,
|
||||||
|
|
Loading…
Reference in New Issue