Centralise readonly column logic

This commit is contained in:
Andrew Kingston 2024-06-24 08:12:46 +01:00
parent e2df7ae6db
commit bf77537792
No known key found for this signature in database
2 changed files with 17 additions and 6 deletions

View File

@ -6,6 +6,7 @@
const { const {
rows, rows,
columns,
focusedCellId, focusedCellId,
focusedCellAPI, focusedCellAPI,
menu, menu,
@ -40,13 +41,10 @@
// Determine if the cell is editable // Determine if the cell is editable
$: readonly = $: readonly =
column.schema.autocolumn || columns.actions.isReadonly(column) ||
column.schema.disabled || (!$config.canEditRows && !row._isNewRow)
column.schema.type === "formula" ||
(!$config.canEditRows && !row._isNewRow) ||
column.schema.readonly
// Register this cell API if the row is focused // Register this cell API if this cell is focused
$: { $: {
if (focused) { if (focused) {
focusedCellAPI.set(cellAPI) focusedCellAPI.set(cellAPI)

View File

@ -110,11 +110,24 @@ export const createActions = context => {
await datasource.actions.saveSchemaMutations() await datasource.actions.saveSchemaMutations()
} }
const isReadonly = column => {
if (!column?.schema) {
return false
}
return (
column.schema.autocolumn ||
column.schema.disabled ||
column.schema.type === "formula" ||
column.schema.readonly
)
}
return { return {
columns: { columns: {
...columns, ...columns,
actions: { actions: {
changeAllColumnWidths, changeAllColumnWidths,
isReadonly,
}, },
}, },
} }