Skip table order if defined on view
This commit is contained in:
parent
8e904cea13
commit
dceb51a08d
|
@ -69,7 +69,9 @@ function enrichSchema(
|
|||
viewOverrides: Record<string, UIFieldMetadata>
|
||||
) {
|
||||
const result: TableSchema = {}
|
||||
for (const [columnName, columnUIMetadata] of Object.entries(viewOverrides)) {
|
||||
const viewOverridesEntries = Object.entries(viewOverrides)
|
||||
const viewSetsOrder = viewOverridesEntries.some(([_, v]) => v.order)
|
||||
for (const [columnName, columnUIMetadata] of viewOverridesEntries) {
|
||||
if (!columnUIMetadata.visible) {
|
||||
continue
|
||||
}
|
||||
|
@ -78,7 +80,12 @@ function enrichSchema(
|
|||
continue
|
||||
}
|
||||
|
||||
result[columnName] = _.merge(tableSchema[columnName], columnUIMetadata)
|
||||
const tableFieldSchema = tableSchema[columnName]
|
||||
if (viewSetsOrder) {
|
||||
delete tableFieldSchema.order
|
||||
}
|
||||
|
||||
result[columnName] = _.merge(tableFieldSchema, columnUIMetadata)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
|
@ -252,6 +252,57 @@ describe("table sdk", () => {
|
|||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("if view defines order, the table schema order should be ignored", async () => {
|
||||
const tableId = basicTable._id!
|
||||
const view: ViewV2 = {
|
||||
version: 2,
|
||||
id: generator.guid(),
|
||||
name: generator.guid(),
|
||||
tableId,
|
||||
columns: {
|
||||
name: { visible: true, order: 1 },
|
||||
id: { visible: true },
|
||||
description: { visible: false, order: 2 },
|
||||
},
|
||||
}
|
||||
|
||||
const res = sdk.tables.enrichViewSchemas({
|
||||
...basicTable,
|
||||
views: { [view.name]: view },
|
||||
})
|
||||
|
||||
expect(res).toEqual(
|
||||
expect.objectContaining({
|
||||
...basicTable,
|
||||
views: {
|
||||
[view.name]: {
|
||||
...view,
|
||||
schema: {
|
||||
name: {
|
||||
type: "string",
|
||||
name: "name",
|
||||
order: 1,
|
||||
visible: true,
|
||||
width: 80,
|
||||
constraints: {
|
||||
type: "string",
|
||||
},
|
||||
},
|
||||
id: {
|
||||
type: "number",
|
||||
name: "id",
|
||||
visible: true,
|
||||
constraints: {
|
||||
type: "number",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue