1
0
Fork 0
mirror of synced 2024-08-05 13:21:26 +12:00

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)
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")
}

View file

@ -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,

View file

@ -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.

View file

@ -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()
}