Fix a few edge cases and bugs

This commit is contained in:
Andrew Kingston 2024-05-17 15:12:39 +01:00
parent 4b693088fa
commit 594b2eb04c
4 changed files with 38 additions and 40 deletions

View File

@ -12,7 +12,7 @@
$: text = getText($columns) $: text = getText($columns)
const toggleVisibility = async (column, visible) => { const toggleVisibility = async (column, visible) => {
datasource.actions.addSchemaMutation(column, { visible }) datasource.actions.addSchemaMutation(column.name, { visible })
await datasource.actions.saveSchemaMutations() await datasource.actions.saveSchemaMutations()
dispatch(visible ? "show-column" : "hide-column") dispatch(visible ? "show-column" : "hide-column")
} }

View File

@ -6,8 +6,6 @@ export const createStores = () => {
const definition = memo(null) const definition = memo(null)
const schemaMutations = memo({}) const schemaMutations = memo({})
definition.subscribe(console.log)
return { return {
definition, definition,
schemaMutations, schemaMutations,
@ -61,7 +59,7 @@ export const deriveStores = context => {
} }
enrichedSchema[field] = { enrichedSchema[field] = {
...$schema[field], ...$schema[field],
...$schemaOverrides[field], ...$schemaOverrides?.[field],
...schemaMutations[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 // Adds a schema mutation for a single field
const addSchemaMutation = (field, mutation) => { const addSchemaMutation = (field, mutation) => {
if (!field || !mutation) { if (!field || !mutation) {
@ -239,6 +207,36 @@ export const createActions = context => {
schemaMutations.set({}) 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 { return {
datasource: { datasource: {
...datasource, ...datasource,

View File

@ -174,14 +174,12 @@ export const createActions = context => {
document.removeEventListener("touchend", stopReordering) document.removeEventListener("touchend", stopReordering)
document.removeEventListener("touchcancel", stopReordering) document.removeEventListener("touchcancel", stopReordering)
// Ensure there's actually a change // Ensure there's actually a change before saving
let { sourceColumn, targetColumn } = get(reorder) const { sourceColumn, targetColumn } = get(reorder)
reorder.set(reorderInitialState)
if (sourceColumn !== targetColumn) { if (sourceColumn !== targetColumn) {
await moveColumn(sourceColumn, targetColumn) await moveColumn(sourceColumn, targetColumn)
} }
// Reset state
reorder.set(reorderInitialState)
} }
// Moves a column after another columns. // Moves a column after another columns.

View File

@ -89,7 +89,9 @@ export const createActions = context => {
// Resets a column size back to default // Resets a column size back to default
const resetSize = async column => { const resetSize = async column => {
datasource.actions.addSchemaMutation(column, { width: DefaultColumnWidth }) datasource.actions.addSchemaMutation(column.name, {
width: DefaultColumnWidth,
})
await datasource.actions.saveSchemaMutations() await datasource.actions.saveSchemaMutations()
} }