Revert to use schema as source of truth for width, and use new technique to handle width overrides while still allowing customisation by users
This commit is contained in:
parent
0387e226fa
commit
eec8a4d289
|
@ -2749,7 +2749,7 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "number",
|
"type": "number",
|
||||||
"label": "Width",
|
"label": "Initial width",
|
||||||
"key": "width",
|
"key": "width",
|
||||||
"placeholder": "Auto"
|
"placeholder": "Auto"
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,13 +36,14 @@
|
||||||
} = getContext("sdk")
|
} = getContext("sdk")
|
||||||
|
|
||||||
let grid
|
let grid
|
||||||
|
let resizedColumns = {}
|
||||||
|
|
||||||
$: columnWhitelist = parsedColumns
|
$: columnWhitelist = parsedColumns
|
||||||
?.filter(col => col.active)
|
?.filter(col => col.active)
|
||||||
?.map(col => col.field)
|
?.map(col => col.field)
|
||||||
$: schemaOverrides = getSchemaOverrides(parsedColumns)
|
|
||||||
$: enrichedButtons = enrichButtons(buttons)
|
$: enrichedButtons = enrichButtons(buttons)
|
||||||
$: parsedColumns = getParsedColumns(columns)
|
$: parsedColumns = getParsedColumns(columns)
|
||||||
|
$: schemaOverrides = getSchemaOverrides(parsedColumns, resizedColumns)
|
||||||
$: actions = [
|
$: actions = [
|
||||||
{
|
{
|
||||||
type: ActionTypes.RefreshDatasource,
|
type: ActionTypes.RefreshDatasource,
|
||||||
|
@ -72,7 +73,6 @@
|
||||||
if (columns?.length && columns[0]?.active !== undefined) {
|
if (columns?.length && columns[0]?.active !== undefined) {
|
||||||
return columns
|
return columns
|
||||||
}
|
}
|
||||||
|
|
||||||
return columns?.map(column => ({
|
return columns?.map(column => ({
|
||||||
label: column.displayName || column.name,
|
label: column.displayName || column.name,
|
||||||
field: column.name,
|
field: column.name,
|
||||||
|
@ -80,12 +80,17 @@
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
const getSchemaOverrides = columns => {
|
const getSchemaOverrides = (columns, resizedColumns) => {
|
||||||
let overrides = {}
|
let overrides = {}
|
||||||
columns?.forEach(column => {
|
columns?.forEach(column => {
|
||||||
overrides[column.field] = {
|
overrides[column.field] = {
|
||||||
displayName: column.label,
|
displayName: column.label,
|
||||||
width: column.width,
|
}
|
||||||
|
|
||||||
|
// Only use the specified width until we resize the column, at which point
|
||||||
|
// we no longer want to override it
|
||||||
|
if (!resizedColumns[column.field]) {
|
||||||
|
overrides[column.field].width = column.width
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return overrides
|
return overrides
|
||||||
|
@ -119,6 +124,13 @@
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const onColumnResize = e => {
|
||||||
|
// Mark that we've resized this column so we can remove this width from
|
||||||
|
// schema overrides if present
|
||||||
|
const { column } = e.detail
|
||||||
|
resizedColumns = { ...resizedColumns, [column]: true }
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div use:styleable={styles} class:in-builder={$builderStore.inBuilder}>
|
<div use:styleable={styles} class:in-builder={$builderStore.inBuilder}>
|
||||||
|
@ -148,6 +160,7 @@
|
||||||
notifyError={notificationStore.actions.error}
|
notifyError={notificationStore.actions.error}
|
||||||
buttons={enrichedButtons}
|
buttons={enrichedButtons}
|
||||||
on:rowclick={e => onRowClick?.({ row: e.detail })}
|
on:rowclick={e => onRowClick?.({ row: e.detail })}
|
||||||
|
on:columnresize={onColumnResize}
|
||||||
/>
|
/>
|
||||||
</Provider>
|
</Provider>
|
||||||
</span>
|
</span>
|
||||||
|
|
|
@ -194,7 +194,7 @@ export const initialise = context => {
|
||||||
name: field,
|
name: field,
|
||||||
label: fieldSchema.displayName || field,
|
label: fieldSchema.displayName || field,
|
||||||
schema: fieldSchema,
|
schema: fieldSchema,
|
||||||
width: oldColumn?.width || fieldSchema.width || DefaultColumnWidth,
|
width: fieldSchema.width || oldColumn?.width || DefaultColumnWidth,
|
||||||
visible: fieldSchema.visible ?? true,
|
visible: fieldSchema.visible ?? true,
|
||||||
order: fieldSchema.order ?? oldColumn?.order,
|
order: fieldSchema.order ?? oldColumn?.order,
|
||||||
primaryDisplay: field === primaryDisplay,
|
primaryDisplay: field === primaryDisplay,
|
||||||
|
|
|
@ -21,7 +21,7 @@ export const createStores = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createActions = context => {
|
export const createActions = context => {
|
||||||
const { resize, columns, stickyColumn, ui } = context
|
const { resize, columns, stickyColumn, ui, dispatch } = context
|
||||||
|
|
||||||
// Starts resizing a certain column
|
// Starts resizing a certain column
|
||||||
const startResizing = (column, e) => {
|
const startResizing = (column, e) => {
|
||||||
|
@ -102,6 +102,8 @@ export const createActions = context => {
|
||||||
// Persist width if it changed
|
// Persist width if it changed
|
||||||
if ($resize.width !== $resize.initialWidth) {
|
if ($resize.width !== $resize.initialWidth) {
|
||||||
await columns.actions.saveChanges()
|
await columns.actions.saveChanges()
|
||||||
|
const { column, width } = $resize
|
||||||
|
dispatch("columnresize", { column, width })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue