Fix grid config store so that schema overrides work

This commit is contained in:
Andrew Kingston 2023-08-22 11:31:25 +01:00
parent c7d1010ce3
commit c936304410
4 changed files with 21 additions and 23 deletions

View File

@ -57,8 +57,8 @@
<Grid
{API}
datasource={gridDatasource}
allowAddRows={!isUsersTable}
allowDeleteRows={!isUsersTable}
canAddRows={!isUsersTable}
canDeleteRows={!isUsersTable}
schemaOverrides={isUsersTable ? userSchemaOverrides : null}
showAvatars={false}
on:updatedatasource={handleGridTableUpdate}

View File

@ -196,7 +196,6 @@
icon="Label"
on:click={makeDisplayColumn}
disabled={idx === "sticky" ||
!$config.canEditPrimaryDisplay ||
bannedDisplayColumnTypes.includes(column.schema.type)}
>
Use as display column

View File

@ -80,9 +80,6 @@ export const createActions = context => {
// Updates the datasources primary display column
const changePrimaryDisplay = async column => {
if (!get(config).canEditPrimaryDisplay) {
return
}
return await datasource.actions.saveDefinition({
...get(definition),
primaryDisplay: column,

View File

@ -1,8 +1,8 @@
import { derivedMemo } from "../../../utils"
import { derived } from "svelte/store"
export const deriveStores = context => {
const { props, hasNonAutoColumn } = context
export const createStores = context => {
const { props } = context
const getProp = prop => derivedMemo(props, $props => $props[prop])
// Derive and memoize some props so that we can react to them in isolation
@ -16,16 +16,27 @@ export const deriveStores = context => {
const notifySuccess = getProp("notifySuccess")
const notifyError = getProp("notifyError")
return {
datasource,
initialSortColumn,
initialSortOrder,
initialFilter,
fixedRowHeight,
schemaOverrides,
columnWhitelist,
notifySuccess,
notifyError,
}
}
export const deriveStores = context => {
const { props, hasNonAutoColumn } = context
// Derive features
const config = derived(
[props, hasNonAutoColumn],
([$props, $hasNonAutoColumn]) => {
let config = {
...$props,
// Additional granular features which we don't expose as props
canEditPrimaryDisplay: $props.canEditColumns,
}
let config = { ...$props }
// Disable some features if we're editing a view
if ($props.datasource?.type === "viewV2") {
@ -43,14 +54,5 @@ export const deriveStores = context => {
return {
config,
datasource,
initialSortColumn,
initialSortOrder,
initialFilter,
fixedRowHeight,
schemaOverrides,
columnWhitelist,
notifySuccess,
notifyError,
}
}