Improve retention of grid metadata when updating datasources to avoid resetting state
This commit is contained in:
parent
3564fd5621
commit
c2acac36a8
|
@ -152,14 +152,20 @@ export const initialise = context => {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const $definition = get(definition)
|
const $definition = get(definition)
|
||||||
|
const $columns = get(columns)
|
||||||
|
const $stickyColumn = get(stickyColumn)
|
||||||
|
|
||||||
|
// Generate array of all columns to easily find pre-existing columns
|
||||||
|
let allColumns = $columns || []
|
||||||
|
if ($stickyColumn) {
|
||||||
|
allColumns.push($stickyColumn)
|
||||||
|
}
|
||||||
|
|
||||||
// Find primary display
|
// Find primary display
|
||||||
let primaryDisplay
|
let primaryDisplay
|
||||||
if (
|
const candidatePD = $definition.primaryDisplay || $stickyColumn?.name
|
||||||
$definition.primaryDisplay &&
|
if (candidatePD && $enrichedSchema[candidatePD]) {
|
||||||
$enrichedSchema[$definition.primaryDisplay]
|
primaryDisplay = candidatePD
|
||||||
) {
|
|
||||||
primaryDisplay = $definition.primaryDisplay
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get field list
|
// Get field list
|
||||||
|
@ -173,14 +179,18 @@ export const initialise = context => {
|
||||||
// Update columns, removing extraneous columns and adding missing ones
|
// Update columns, removing extraneous columns and adding missing ones
|
||||||
columns.set(
|
columns.set(
|
||||||
fields
|
fields
|
||||||
.map(field => ({
|
.map(field => {
|
||||||
|
const fieldSchema = $enrichedSchema[field]
|
||||||
|
const oldColumn = allColumns?.find(x => x.name === field)
|
||||||
|
return {
|
||||||
name: field,
|
name: field,
|
||||||
label: $enrichedSchema[field].displayName || field,
|
label: fieldSchema.displayName || field,
|
||||||
schema: $enrichedSchema[field],
|
schema: fieldSchema,
|
||||||
width: $enrichedSchema[field].width || DefaultColumnWidth,
|
width: fieldSchema.width || oldColumn?.width || DefaultColumnWidth,
|
||||||
visible: $enrichedSchema[field].visible ?? true,
|
visible: fieldSchema.visible ?? true,
|
||||||
order: $enrichedSchema[field].order,
|
order: fieldSchema.order ?? oldColumn?.order,
|
||||||
}))
|
}
|
||||||
|
})
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
// Sort by order first
|
// Sort by order first
|
||||||
const orderA = a.order
|
const orderA = a.order
|
||||||
|
@ -208,11 +218,13 @@ export const initialise = context => {
|
||||||
stickyColumn.set(null)
|
stickyColumn.set(null)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const stickySchema = $enrichedSchema[primaryDisplay]
|
||||||
|
const oldStickyColumn = allColumns?.find(x => x.name === primaryDisplay)
|
||||||
stickyColumn.set({
|
stickyColumn.set({
|
||||||
name: primaryDisplay,
|
name: primaryDisplay,
|
||||||
label: $enrichedSchema[primaryDisplay].displayName || primaryDisplay,
|
label: stickySchema.displayName || primaryDisplay,
|
||||||
schema: $enrichedSchema[primaryDisplay],
|
schema: stickySchema,
|
||||||
width: $enrichedSchema[primaryDisplay].width || DefaultColumnWidth,
|
width: stickySchema.width || oldStickyColumn?.width || DefaultColumnWidth,
|
||||||
visible: true,
|
visible: true,
|
||||||
order: 0,
|
order: 0,
|
||||||
left: GutterWidth,
|
left: GutterWidth,
|
||||||
|
|
Loading…
Reference in New Issue