diff --git a/packages/frontend-core/src/components/grid/controls/HideColumnsButton.svelte b/packages/frontend-core/src/components/grid/controls/HideColumnsButton.svelte index 9d2c580f76..f1c46d97f2 100644 --- a/packages/frontend-core/src/components/grid/controls/HideColumnsButton.svelte +++ b/packages/frontend-core/src/components/grid/controls/HideColumnsButton.svelte @@ -12,7 +12,7 @@ $: text = getText($columns) const toggleVisibility = async (column, visible) => { - datasource.actions.addSchemaMutation(column, { visible }) + datasource.actions.addSchemaMutation(column.name, { visible }) await datasource.actions.saveSchemaMutations() dispatch(visible ? "show-column" : "hide-column") } diff --git a/packages/frontend-core/src/components/grid/stores/datasource.js b/packages/frontend-core/src/components/grid/stores/datasource.js index 03b14eda20..8c5142bd10 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.js +++ b/packages/frontend-core/src/components/grid/stores/datasource.js @@ -6,8 +6,6 @@ export const createStores = () => { const definition = memo(null) const schemaMutations = memo({}) - definition.subscribe(console.log) - return { definition, schemaMutations, @@ -61,7 +59,7 @@ export const deriveStores = context => { } enrichedSchema[field] = { ...$schema[field], - ...$schemaOverrides[field], + ...$schemaOverrides?.[field], ...schemaMutations[field], } }) @@ -148,36 +146,6 @@ export const createActions = context => { }) } - // Adds a row to the datasource - const addRow = async row => { - return await getAPI()?.actions.addRow(row) - } - - // Updates an existing row in the datasource - const updateRow = async row => { - return await getAPI()?.actions.updateRow(row) - } - - // Deletes rows from the datasource - const deleteRows = async rows => { - return await getAPI()?.actions.deleteRows(rows) - } - - // Gets a single row from a datasource - const getRow = async id => { - return await getAPI()?.actions.getRow(id) - } - - // Checks if a certain datasource config is valid - const isDatasourceValid = datasource => { - return getAPI()?.actions.isDatasourceValid(datasource) - } - - // Checks if this datasource can use a specific column by name - const canUseColumn = name => { - return getAPI()?.actions.canUseColumn(name) - } - // Adds a schema mutation for a single field const addSchemaMutation = (field, mutation) => { if (!field || !mutation) { @@ -239,6 +207,36 @@ export const createActions = context => { schemaMutations.set({}) } + // Adds a row to the datasource + const addRow = async row => { + return await getAPI()?.actions.addRow(row) + } + + // Updates an existing row in the datasource + const updateRow = async row => { + return await getAPI()?.actions.updateRow(row) + } + + // Deletes rows from the datasource + const deleteRows = async rows => { + return await getAPI()?.actions.deleteRows(rows) + } + + // Gets a single row from a datasource + const getRow = async id => { + return await getAPI()?.actions.getRow(id) + } + + // Checks if a certain datasource config is valid + const isDatasourceValid = datasource => { + return getAPI()?.actions.isDatasourceValid(datasource) + } + + // Checks if this datasource can use a specific column by name + const canUseColumn = name => { + return getAPI()?.actions.canUseColumn(name) + } + return { datasource: { ...datasource, diff --git a/packages/frontend-core/src/components/grid/stores/reorder.js b/packages/frontend-core/src/components/grid/stores/reorder.js index 687ebdcf80..8557be0bb6 100644 --- a/packages/frontend-core/src/components/grid/stores/reorder.js +++ b/packages/frontend-core/src/components/grid/stores/reorder.js @@ -174,14 +174,12 @@ export const createActions = context => { document.removeEventListener("touchend", stopReordering) document.removeEventListener("touchcancel", stopReordering) - // Ensure there's actually a change - let { sourceColumn, targetColumn } = get(reorder) + // Ensure there's actually a change before saving + const { sourceColumn, targetColumn } = get(reorder) + reorder.set(reorderInitialState) if (sourceColumn !== targetColumn) { await moveColumn(sourceColumn, targetColumn) } - - // Reset state - reorder.set(reorderInitialState) } // Moves a column after another columns. diff --git a/packages/frontend-core/src/components/grid/stores/resize.js b/packages/frontend-core/src/components/grid/stores/resize.js index b9e1cc4df4..21d1f66001 100644 --- a/packages/frontend-core/src/components/grid/stores/resize.js +++ b/packages/frontend-core/src/components/grid/stores/resize.js @@ -89,7 +89,9 @@ export const createActions = context => { // Resets a column size back to default const resetSize = async column => { - datasource.actions.addSchemaMutation(column, { width: DefaultColumnWidth }) + datasource.actions.addSchemaMutation(column.name, { + width: DefaultColumnWidth, + }) await datasource.actions.saveSchemaMutations() }