Work around table API inconsistencies to handle table schema updates
This commit is contained in:
parent
f86c0ec36e
commit
84a5739c53
|
@ -140,8 +140,15 @@ export function createTablesStore() {
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function has to merge state as there discrepancies with the table
|
||||||
|
// API endpoints. The table list endpoint and get table endpoint use the
|
||||||
|
// "type" property to mean different things.
|
||||||
store.update(state => {
|
store.update(state => {
|
||||||
state.list[index] = table
|
state.list[index] = {
|
||||||
|
...table,
|
||||||
|
type: state.list[index].type,
|
||||||
|
}
|
||||||
return state
|
return state
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,9 +18,7 @@
|
||||||
dispatch,
|
dispatch,
|
||||||
config,
|
config,
|
||||||
ui,
|
ui,
|
||||||
table,
|
columns,
|
||||||
rows,
|
|
||||||
API,
|
|
||||||
} = getContext("sheet")
|
} = getContext("sheet")
|
||||||
|
|
||||||
let anchor
|
let anchor
|
||||||
|
@ -83,15 +81,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
const makeDisplayColumn = async () => {
|
const makeDisplayColumn = async () => {
|
||||||
const tableDefinition = $table
|
await columns.actions.changePrimaryDisplay(column.name)
|
||||||
if (!tableDefinition) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
await API.saveTable({
|
|
||||||
...tableDefinition,
|
|
||||||
primaryDisplay: column.name,
|
|
||||||
})
|
|
||||||
await rows.actions.refreshTableDefinition()
|
|
||||||
open = false
|
open = false
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -126,6 +126,14 @@ export const deriveStores = context => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Updates the tables primary display column
|
||||||
|
const changePrimaryDisplay = async column => {
|
||||||
|
return await saveTable({
|
||||||
|
...get(table),
|
||||||
|
primaryDisplay: column,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
// Persists column changes by saving metadata against table schema
|
// Persists column changes by saving metadata against table schema
|
||||||
const saveChanges = async () => {
|
const saveChanges = async () => {
|
||||||
const $columns = get(columns)
|
const $columns = get(columns)
|
||||||
|
@ -153,8 +161,11 @@ export const deriveStores = context => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
await saveTable({ ...$table, schema: newSchema })
|
||||||
|
}
|
||||||
|
|
||||||
|
const saveTable = async newTable => {
|
||||||
// Update local state
|
// Update local state
|
||||||
const newTable = { ...$table, schema: newSchema }
|
|
||||||
table.set(newTable)
|
table.set(newTable)
|
||||||
|
|
||||||
// Broadcast event so that we can keep sync with external state
|
// Broadcast event so that we can keep sync with external state
|
||||||
|
@ -170,6 +181,7 @@ export const deriveStores = context => {
|
||||||
...columns,
|
...columns,
|
||||||
actions: {
|
actions: {
|
||||||
saveChanges,
|
saveChanges,
|
||||||
|
changePrimaryDisplay,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue