diff --git a/packages/frontend-core/src/components/sheet/cells/HeaderCell.svelte b/packages/frontend-core/src/components/sheet/cells/HeaderCell.svelte
index 6913300dc6..68543ce052 100644
--- a/packages/frontend-core/src/components/sheet/cells/HeaderCell.svelte
+++ b/packages/frontend-core/src/components/sheet/cells/HeaderCell.svelte
@@ -91,7 +91,7 @@
...tableDefinition,
primaryDisplay: column.name,
})
- await rows.actions.refreshSchema()
+ await rows.actions.refreshTableDefinition()
open = false
}
@@ -164,9 +164,13 @@
-
+ Use as display column
+
diff --git a/packages/frontend-core/src/components/sheet/stores/columns.js b/packages/frontend-core/src/components/sheet/stores/columns.js
index cb689c8457..ffebe58f63 100644
--- a/packages/frontend-core/src/components/sheet/stores/columns.js
+++ b/packages/frontend-core/src/components/sheet/stores/columns.js
@@ -3,7 +3,7 @@ import { derived, get, writable } from "svelte/store"
export const DefaultColumnWidth = 200
export const createColumnsStores = context => {
- const { schema } = context
+ const { table } = context
const columns = writable([])
const stickyColumn = writable(null)
@@ -37,8 +37,9 @@ export const createColumnsStores = context => {
)
// Merge new schema fields with existing schema in order to preserve widths
- schema.subscribe($schema => {
- if (!$schema) {
+ table.subscribe($table => {
+ const schema = $table?.schema
+ if (!schema) {
columns.set([])
stickyColumn.set(null)
return
@@ -46,10 +47,16 @@ export const createColumnsStores = context => {
const currentColumns = get(columns)
const currentStickyColumn = get(stickyColumn)
+ // Find primary display
+ let primaryDisplay
+ if ($table.primaryDisplay && schema[$table.primaryDisplay]) {
+ primaryDisplay = $table.primaryDisplay
+ }
+
// Get field list
let fields = []
- Object.entries($schema || {}).forEach(([field, fieldSchema]) => {
- if (!fieldSchema.primaryDisplay) {
+ Object.keys(schema).forEach(field => {
+ if (field !== primaryDisplay) {
fields.push(field)
}
})
@@ -66,31 +73,28 @@ export const createColumnsStores = context => {
return {
name: field,
width: existing?.width || DefaultColumnWidth,
- schema: $schema[field],
+ schema: schema[field],
visible: existing?.visible ?? true,
}
})
)
// Update sticky column
- const primaryDisplay = Object.entries($schema).find(entry => {
- return entry[1].primaryDisplay
- })
if (!primaryDisplay) {
return
}
// Check if there is an existing column with this name so we can keep
// the width setting
- let existing = currentColumns.find(x => x.name === primaryDisplay[0])
- if (!existing && currentStickyColumn?.name === primaryDisplay[0]) {
+ let existing = currentColumns.find(x => x.name === primaryDisplay)
+ if (!existing && currentStickyColumn?.name === primaryDisplay) {
existing = currentStickyColumn
}
stickyColumn.set({
- name: primaryDisplay[0],
+ name: primaryDisplay,
width: existing?.width || DefaultColumnWidth,
left: 40,
- schema: primaryDisplay[1],
+ schema: schema[primaryDisplay],
idx: "sticky",
})
})
diff --git a/packages/frontend-core/src/components/sheet/stores/rows.js b/packages/frontend-core/src/components/sheet/stores/rows.js
index 91a3ad5f4f..ee1acb57fa 100644
--- a/packages/frontend-core/src/components/sheet/stores/rows.js
+++ b/packages/frontend-core/src/components/sheet/stores/rows.js
@@ -6,7 +6,6 @@ export const createRowsStore = context => {
const { config, API, scroll } = context
const tableId = derived(config, $config => $config.tableId)
const rows = writable([])
- const schema = writable({})
const table = writable(null)
const filter = writable([])
const loaded = writable(false)
@@ -89,13 +88,7 @@ export const createRowsStore = context => {
scroll.update(state => ({ ...state, top: 0 }))
}
- // Update schema and enrich primary display into schema
- let newSchema = $fetch.schema
- const primaryDisplay = $fetch.definition?.primaryDisplay
- if (primaryDisplay && newSchema[primaryDisplay]) {
- newSchema[primaryDisplay].primaryDisplay = true
- }
- schema.set(newSchema)
+ // Update table definition
table.set($fetch.definition)
// Process new rows
@@ -267,7 +260,7 @@ export const createRowsStore = context => {
}
// Refreshes the schema of the data fetch subscription
- const refreshSchema = async () => {
+ const refreshTableDefinition = async () => {
return await get(fetch)?.refreshDefinition()
}
@@ -288,12 +281,11 @@ export const createRowsStore = context => {
loadNextPage,
refreshRow,
refreshData,
- refreshSchema,
+ refreshTableDefinition,
},
},
rowLookupMap,
table,
- schema,
sort,
filter,
loaded,