Skip table order if defined on view

This commit is contained in:
Adria Navarro 2023-07-24 15:11:23 +02:00
parent 8e904cea13
commit dceb51a08d
2 changed files with 60 additions and 2 deletions

View File

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

View File

@ -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",
},
},
},
},
},
})
)
})
})
})
})