From 332fdc5f38a98022e80155a969e6167ff80bf959 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 20:58:35 +0100 Subject: [PATCH 01/13] Initial typing config store --- .../grid/stores/{config.js => config.ts} | 30 +++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) rename packages/frontend-core/src/components/grid/stores/{config.js => config.ts} (73%) diff --git a/packages/frontend-core/src/components/grid/stores/config.js b/packages/frontend-core/src/components/grid/stores/config.ts similarity index 73% rename from packages/frontend-core/src/components/grid/stores/config.js rename to packages/frontend-core/src/components/grid/stores/config.ts index 4a60370690..c4c56cbe1c 100644 --- a/packages/frontend-core/src/components/grid/stores/config.js +++ b/packages/frontend-core/src/components/grid/stores/config.ts @@ -1,10 +1,30 @@ import { derivedMemo } from "../../../utils" -import { derived } from "svelte/store" -import { ViewV2Type } from "@budibase/types" +import { derived, Readable } from "svelte/store" +import { UIDatasource, ViewV2Type } from "@budibase/types" +import { Store as StoreContext } from "." -export const createStores = context => { +interface ConfigStore { + datasource: UIDatasource + initialSortColumn: any + initialSortOrder: any + initialFilter: any + fixedRowHeight: any + schemaOverrides: any + notifySuccess: any + notifyError: any + rowConditions: any +} + +interface PropsContext { + props: Readable +} + +export type Store = ConfigStore + +export const createStores = (context: PropsContext): ConfigStore => { const { props } = context - const getProp = prop => derivedMemo(props, $props => $props[prop]) + const getProp = (prop: T): ConfigStore[T] => + derivedMemo(props, ($props: ConfigStore) => $props[prop]) // Derive and memoize some props so that we can react to them in isolation const datasource = getProp("datasource") @@ -30,7 +50,7 @@ export const createStores = context => { } } -export const deriveStores = context => { +export const deriveStores = (context: StoreContext) => { const { props, definition, hasNonAutoColumn } = context // Derive features From 81ed65b0996b60e4441dd055d19328ad233aeb6b Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Sun, 29 Dec 2024 12:42:31 +0100 Subject: [PATCH 02/13] Type anys --- .../frontend-core/src/components/grid/stores/config.ts | 4 ++-- .../frontend-core/src/components/grid/stores/index.ts | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/config.ts b/packages/frontend-core/src/components/grid/stores/config.ts index c4c56cbe1c..b7b044b095 100644 --- a/packages/frontend-core/src/components/grid/stores/config.ts +++ b/packages/frontend-core/src/components/grid/stores/config.ts @@ -5,10 +5,10 @@ import { Store as StoreContext } from "." interface ConfigStore { datasource: UIDatasource - initialSortColumn: any + initialSortColumn: Readable initialSortOrder: any initialFilter: any - fixedRowHeight: any + fixedRowHeight: Readable schemaOverrides: any notifySuccess: any notifyError: any diff --git a/packages/frontend-core/src/components/grid/stores/index.ts b/packages/frontend-core/src/components/grid/stores/index.ts index 1706865981..57a730c4c0 100644 --- a/packages/frontend-core/src/components/grid/stores/index.ts +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -70,23 +70,19 @@ export type Store = BaseStore & Scroll.Store & { // TODO while typing the rest of stores sort: Writable - initialFilter: Writable - initialSortColumn: Writable - initialSortOrder: Writable subscribe: any config: Writable dispatch: (event: string, data: any) => any notifications: Writable - schemaOverrides: Writable gridID: string props: Writable width: Writable - fixedRowHeight: Writable bounds: Readable height: Readable } & Rows.Store & Reorder.Store & - Resize.Store + Resize.Store & + Config.Store export const attachStores = (context: Store): Store => { // Atomic store creation From 1714a3cc1d858546599cd2d1832e9c0c19ce7125 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 30 Dec 2024 09:42:55 +0100 Subject: [PATCH 03/13] Fix relatedcolumns return type --- .../GridColumnConfiguration.svelte | 10 ++++++---- packages/frontend-core/src/utils/relatedColumns.ts | 5 +---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/GridColumnConfiguration.svelte b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/GridColumnConfiguration.svelte index 5b3d1ec5a2..46aea2a6c4 100644 --- a/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/GridColumnConfiguration.svelte +++ b/packages/builder/src/components/design/settings/controls/GridColumnConfiguration/GridColumnConfiguration.svelte @@ -26,12 +26,14 @@ const getSchema = (asset, datasource) => { const schema = getSchemaForDatasource(asset, datasource).schema - // Don't show ID and rev in tables - if (schema) { - delete schema._id - delete schema._rev + if (!schema) { + return } + // Don't show ID and rev in tables + delete schema._id + delete schema._rev + const result = enrichSchemaWithRelColumns(schema) return result } diff --git a/packages/frontend-core/src/utils/relatedColumns.ts b/packages/frontend-core/src/utils/relatedColumns.ts index e7bd3662d3..7bec526605 100644 --- a/packages/frontend-core/src/utils/relatedColumns.ts +++ b/packages/frontend-core/src/utils/relatedColumns.ts @@ -46,10 +46,7 @@ const columnTypeManyParser = { export function enrichSchemaWithRelColumns( schema: Record -): Record | undefined { - if (!schema) { - return - } +): Record { const result = Object.keys(schema).reduce>( (result, fieldName) => { const field = schema[fieldName] From 421cefaa9bce2869cb1099eb760a11dde2f2ce0e Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 30 Dec 2024 09:48:34 +0100 Subject: [PATCH 04/13] Type schemaOverrides --- .../frontend-core/src/components/grid/stores/config.ts | 10 +++++++++- packages/types/src/ui/stores/grid/table.ts | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/frontend-core/src/components/grid/stores/config.ts b/packages/frontend-core/src/components/grid/stores/config.ts index b7b044b095..d6050d1a14 100644 --- a/packages/frontend-core/src/components/grid/stores/config.ts +++ b/packages/frontend-core/src/components/grid/stores/config.ts @@ -9,7 +9,15 @@ interface ConfigStore { initialSortOrder: any initialFilter: any fixedRowHeight: Readable - schemaOverrides: any + schemaOverrides: Readable< + Record< + string, + { + displayName?: string + disabled?: boolean + } + > + > notifySuccess: any notifyError: any rowConditions: any diff --git a/packages/types/src/ui/stores/grid/table.ts b/packages/types/src/ui/stores/grid/table.ts index a5a13d5fa2..e69f9fd38f 100644 --- a/packages/types/src/ui/stores/grid/table.ts +++ b/packages/types/src/ui/stores/grid/table.ts @@ -27,6 +27,7 @@ export type UIFieldSchema = FieldSchema & related?: { field: string; subField: string } columns?: Record cellRenderType?: string + disabled?: boolean } interface UIRelationSchemaField extends RelationSchemaField { From 68f29560bd483a56e074ebfef7434efcaa00b747 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 30 Dec 2024 09:50:40 +0100 Subject: [PATCH 05/13] Remove rowConditions --- .../frontend-core/src/components/grid/layout/Grid.svelte | 2 -- .../frontend-core/src/components/grid/stores/config.ts | 7 ++----- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/packages/frontend-core/src/components/grid/layout/Grid.svelte b/packages/frontend-core/src/components/grid/layout/Grid.svelte index fcaf9724c3..c0ad5810b7 100644 --- a/packages/frontend-core/src/components/grid/layout/Grid.svelte +++ b/packages/frontend-core/src/components/grid/layout/Grid.svelte @@ -47,7 +47,6 @@ export let buttonsCollapsedText = null export let darkMode = false export let isCloud = null - export let rowConditions = null export let aiEnabled = false // Unique identifier for DOM nodes inside this instance @@ -106,7 +105,6 @@ darkMode, isCloud, aiEnabled, - rowConditions, }) // Derive min height and make available in context diff --git a/packages/frontend-core/src/components/grid/stores/config.ts b/packages/frontend-core/src/components/grid/stores/config.ts index d6050d1a14..dcc1d34200 100644 --- a/packages/frontend-core/src/components/grid/stores/config.ts +++ b/packages/frontend-core/src/components/grid/stores/config.ts @@ -18,9 +18,8 @@ interface ConfigStore { } > > - notifySuccess: any - notifyError: any - rowConditions: any + notifySuccess: (message: string) => void + notifyError: (message: string) => void } interface PropsContext { @@ -43,7 +42,6 @@ export const createStores = (context: PropsContext): ConfigStore => { const schemaOverrides = getProp("schemaOverrides") const notifySuccess = getProp("notifySuccess") const notifyError = getProp("notifyError") - const rowConditions = getProp("rowConditions") return { datasource, @@ -54,7 +52,6 @@ export const createStores = (context: PropsContext): ConfigStore => { schemaOverrides, notifySuccess, notifyError, - rowConditions, } } From a643f31857e877ebd3d4d13f928309bd03e0d749 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 30 Dec 2024 10:07:18 +0100 Subject: [PATCH 06/13] Fix types --- packages/frontend-core/src/components/grid/stores/config.ts | 6 +++--- .../frontend-core/src/components/grid/stores/datasource.ts | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/config.ts b/packages/frontend-core/src/components/grid/stores/config.ts index dcc1d34200..a020aaa149 100644 --- a/packages/frontend-core/src/components/grid/stores/config.ts +++ b/packages/frontend-core/src/components/grid/stores/config.ts @@ -1,10 +1,10 @@ import { derivedMemo } from "../../../utils" -import { derived, Readable } from "svelte/store" +import { derived, Readable, Writable } from "svelte/store" import { UIDatasource, ViewV2Type } from "@budibase/types" import { Store as StoreContext } from "." -interface ConfigStore { - datasource: UIDatasource +export interface ConfigStore { + datasource: Writable initialSortColumn: Readable initialSortOrder: any initialFilter: any diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index 9e86cb5364..d9dd2fb279 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -14,6 +14,7 @@ import { } from "@budibase/types" import { Store as StoreContext } from "." import { DatasourceActions } from "./datasources" +import { ConfigStore } from "./config" interface DatasourceStore { definition: Writable @@ -28,7 +29,7 @@ interface DerivedDatasourceStore { } interface ActionDatasourceStore { - datasource: DatasourceStore["definition"] & { + datasource: ConfigStore["datasource"] & { actions: DatasourceActions & { refreshDefinition: () => Promise changePrimaryDisplay: (column: string) => Promise From 9977c26ab400bb08e24aaa9f39c0021625deac4c Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 30 Dec 2024 10:52:06 +0100 Subject: [PATCH 07/13] Type memo --- .../src/components/grid/stores/config.ts | 37 ++++++++++--------- packages/frontend-core/src/utils/memo.d.ts | 10 +++++ 2 files changed, 30 insertions(+), 17 deletions(-) create mode 100644 packages/frontend-core/src/utils/memo.d.ts diff --git a/packages/frontend-core/src/components/grid/stores/config.ts b/packages/frontend-core/src/components/grid/stores/config.ts index a020aaa149..ee328a1c18 100644 --- a/packages/frontend-core/src/components/grid/stores/config.ts +++ b/packages/frontend-core/src/components/grid/stores/config.ts @@ -1,23 +1,26 @@ import { derivedMemo } from "../../../utils" -import { derived, Readable, Writable } from "svelte/store" -import { UIDatasource, ViewV2Type } from "@budibase/types" +import { derived, Readable } from "svelte/store" +import { + SortOrder, + UIDatasource, + UISearchFilter, + ViewV2Type, +} from "@budibase/types" import { Store as StoreContext } from "." export interface ConfigStore { - datasource: Writable - initialSortColumn: Readable - initialSortOrder: any - initialFilter: any - fixedRowHeight: Readable - schemaOverrides: Readable< - Record< - string, - { - displayName?: string - disabled?: boolean - } - > - > + datasource: Readable + initialSortColumn: Readable + initialSortOrder: Readable + initialFilter: Readable + fixedRowHeight: Readable + schemaOverrides: Readable | null> notifySuccess: (message: string) => void notifyError: (message: string) => void } @@ -30,7 +33,7 @@ export type Store = ConfigStore export const createStores = (context: PropsContext): ConfigStore => { const { props } = context - const getProp = (prop: T): ConfigStore[T] => + const getProp = (prop: T) => derivedMemo(props, ($props: ConfigStore) => $props[prop]) // Derive and memoize some props so that we can react to them in isolation diff --git a/packages/frontend-core/src/utils/memo.d.ts b/packages/frontend-core/src/utils/memo.d.ts new file mode 100644 index 0000000000..de5074f784 --- /dev/null +++ b/packages/frontend-core/src/utils/memo.d.ts @@ -0,0 +1,10 @@ +import { Readable, Writable } from "svelte/store" + +declare module "./memo" { + export function memo(value: T): Writable + + export function derivedMemo( + store: Readable, + derivation: (store: TStore) => TResult + ): TResult +} From fafa0472d74b851793778adaa1adb14a0510bd41 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 30 Dec 2024 10:58:07 +0100 Subject: [PATCH 08/13] Fix definition types --- packages/frontend-core/src/components/grid/stores/columns.ts | 4 ++-- .../frontend-core/src/components/grid/stores/datasource.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/columns.ts b/packages/frontend-core/src/components/grid/stores/columns.ts index 8073988323..70b93d93e6 100644 --- a/packages/frontend-core/src/components/grid/stores/columns.ts +++ b/packages/frontend-core/src/components/grid/stores/columns.ts @@ -156,11 +156,11 @@ export const initialise = (context: StoreContext) => { // Merge new schema fields with existing schema in order to preserve widths const processColumns = ($enrichedSchema: any) => { - if (!$enrichedSchema) { + const $definition = get(definition) + if (!$enrichedSchema || !$definition) { columns.set([]) return } - const $definition = get(definition) const $columns = get(columns) const $displayColumn = get(displayColumn) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index d9dd2fb279..55af9c016a 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -17,7 +17,7 @@ import { DatasourceActions } from "./datasources" import { ConfigStore } from "./config" interface DatasourceStore { - definition: Writable + definition: Writable schemaMutations: Writable> subSchemaMutations: Writable>> } @@ -219,7 +219,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { // Updates the datasources primary display column const changePrimaryDisplay = async (column: string) => { - let newDefinition = cloneDeep(get(definition)) + let newDefinition = cloneDeep(get(definition)!) // Update primary display newDefinition.primaryDisplay = column From d21e25f72dbaaed2ebeac80257a45b6916560419 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 30 Dec 2024 11:02:40 +0100 Subject: [PATCH 09/13] Fix nullish types --- .../src/components/grid/stores/datasources/nonPlus.ts | 2 +- .../src/components/grid/stores/datasources/table.ts | 2 +- .../src/components/grid/stores/datasources/viewV2.ts | 2 +- packages/frontend-core/src/components/grid/stores/filter.ts | 4 +++- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts b/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts index 15bbc9b396..ae8f187278 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts @@ -91,7 +91,7 @@ export const initialise = (context: StoreContext) => { } // Wipe state - filter.set(get(initialFilter)) + filter.set(get(initialFilter) ?? undefined) inlineFilters.set([]) sort.set({ column: get(initialSortColumn), diff --git a/packages/frontend-core/src/components/grid/stores/datasources/table.ts b/packages/frontend-core/src/components/grid/stores/datasources/table.ts index 65d68a7d5d..e52faef5cc 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/table.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/table.ts @@ -108,7 +108,7 @@ export const initialise = (context: StoreContext) => { } // Wipe state - filter.set(get(initialFilter)) + filter.set(get(initialFilter) ?? undefined) inlineFilters.set([]) sort.set({ column: get(initialSortColumn), diff --git a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts index e18b9f71c0..71c22e6866 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts @@ -121,7 +121,7 @@ export const initialise = (context: StoreContext) => { } // Reset state for new view - filter.set(get(initialFilter)) + filter.set(get(initialFilter) ?? undefined) inlineFilters.set([]) sort.set({ column: get(initialSortColumn), diff --git a/packages/frontend-core/src/components/grid/stores/filter.ts b/packages/frontend-core/src/components/grid/stores/filter.ts index 36f6cd9483..459b5ca652 100644 --- a/packages/frontend-core/src/components/grid/stores/filter.ts +++ b/packages/frontend-core/src/components/grid/stores/filter.ts @@ -120,5 +120,7 @@ export const initialise = (context: StoreContext) => { const { filter, initialFilter } = context // Reset filter when initial filter prop changes - initialFilter.subscribe(filter.set) + initialFilter.subscribe($initialFilter => + filter.set($initialFilter ?? undefined) + ) } From 2d36eab278edcb376588c76cd890a92640f2350c Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 30 Dec 2024 12:21:39 +0100 Subject: [PATCH 10/13] Type initial props --- .../src/components/grid/stores/index.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/index.ts b/packages/frontend-core/src/components/grid/stores/index.ts index 57a730c4c0..56d2e4f6c9 100644 --- a/packages/frontend-core/src/components/grid/stores/index.ts +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -24,6 +24,7 @@ import * as ViewV2 from "./datasources/viewV2" import * as NonPlus from "./datasources/nonPlus" import * as Cache from "./cache" import * as Conditions from "./conditions" +import { UIDatasource } from "@budibase/types" const DependencyOrderedStores = [ Sort, @@ -53,6 +54,16 @@ const DependencyOrderedStores = [ export interface BaseStore { API: APIClient + gridID: string + props: Writable<{ + datasource: UIDatasource + canAddRows: boolean + canEditRows: boolean + canDeleteRows: boolean + canEditColumns: boolean + canExpandRows: boolean + canSaveSchema: boolean + }> } export type Store = BaseStore & @@ -74,8 +85,6 @@ export type Store = BaseStore & config: Writable dispatch: (event: string, data: any) => any notifications: Writable - gridID: string - props: Writable width: Writable bounds: Readable height: Readable From 6d1f2c9200ddc897f172a2bf9c5b6dccbae24c55 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 30 Dec 2024 12:39:52 +0100 Subject: [PATCH 11/13] Remove anys and fix types --- .../src/components/grid/stores/config.ts | 53 +++++++++---------- .../src/components/grid/stores/datasource.ts | 5 +- .../src/components/grid/stores/index.ts | 36 +++++++++---- packages/frontend-core/src/utils/memo.d.ts | 2 +- 4 files changed, 52 insertions(+), 44 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/config.ts b/packages/frontend-core/src/components/grid/stores/config.ts index ee328a1c18..c6a3f86386 100644 --- a/packages/frontend-core/src/components/grid/stores/config.ts +++ b/packages/frontend-core/src/components/grid/stores/config.ts @@ -1,40 +1,35 @@ import { derivedMemo } from "../../../utils" import { derived, Readable } from "svelte/store" -import { - SortOrder, - UIDatasource, - UISearchFilter, - ViewV2Type, -} from "@budibase/types" -import { Store as StoreContext } from "." +import { ViewV2Type } from "@budibase/types" +import { BaseStoreProps, Store as StoreContext } from "." -export interface ConfigStore { - datasource: Readable - initialSortColumn: Readable - initialSortOrder: Readable - initialFilter: Readable - fixedRowHeight: Readable - schemaOverrides: Readable | null> - notifySuccess: (message: string) => void - notifyError: (message: string) => void +interface ConfigStore { + datasource: Readable + initialSortColumn: Readable + initialSortOrder: Readable + initialFilter: Readable + fixedRowHeight: Readable + schemaOverrides: Readable + notifySuccess: Readable + notifyError: Readable + canAddRows?: Readable + canEditRows?: Readable + canDeleteRows?: Readable + canEditColumns?: Readable + canExpandRows?: Readable + canSaveSchema?: Readable } -interface PropsContext { - props: Readable +interface ConfigDerivedStore { + config: Readable } -export type Store = ConfigStore +export type Store = ConfigStore & ConfigDerivedStore -export const createStores = (context: PropsContext): ConfigStore => { +export const createStores = (context: StoreContext): ConfigStore => { const { props } = context - const getProp = (prop: T) => - derivedMemo(props, ($props: ConfigStore) => $props[prop]) + const getProp = (prop: T) => + derivedMemo(props, $props => $props[prop]) // Derive and memoize some props so that we can react to them in isolation const datasource = getProp("datasource") @@ -58,7 +53,7 @@ export const createStores = (context: PropsContext): ConfigStore => { } } -export const deriveStores = (context: StoreContext) => { +export const deriveStores = (context: StoreContext): ConfigDerivedStore => { const { props, definition, hasNonAutoColumn } = context // Derive features diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index 55af9c016a..74101701ed 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -12,9 +12,8 @@ import { UpdateViewRequest, ViewV2Type, } from "@budibase/types" -import { Store as StoreContext } from "." +import { Store as StoreContext, BaseStoreProps } from "." import { DatasourceActions } from "./datasources" -import { ConfigStore } from "./config" interface DatasourceStore { definition: Writable @@ -29,7 +28,7 @@ interface DerivedDatasourceStore { } interface ActionDatasourceStore { - datasource: ConfigStore["datasource"] & { + datasource: BaseStoreProps["datasource"] & { actions: DatasourceActions & { refreshDefinition: () => Promise changePrimaryDisplay: (column: string) => Promise diff --git a/packages/frontend-core/src/components/grid/stores/index.ts b/packages/frontend-core/src/components/grid/stores/index.ts index 56d2e4f6c9..d4c589fcf7 100644 --- a/packages/frontend-core/src/components/grid/stores/index.ts +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -24,7 +24,7 @@ import * as ViewV2 from "./datasources/viewV2" import * as NonPlus from "./datasources/nonPlus" import * as Cache from "./cache" import * as Conditions from "./conditions" -import { UIDatasource } from "@budibase/types" +import { SortOrder, UIDatasource, UISearchFilter } from "@budibase/types" const DependencyOrderedStores = [ Sort, @@ -52,18 +52,33 @@ const DependencyOrderedStores = [ Cache, ] +export interface BaseStoreProps { + datasource: UIDatasource + initialSortColumn: string | null + initialSortOrder: SortOrder | null + initialFilter: UISearchFilter | null + fixedRowHeight: number | null + schemaOverrides: Record< + string, + { + displayName?: string + disabled?: boolean + } + > | null + notifySuccess: (message: string) => void + notifyError: (message: string) => void + canAddRows: boolean + canEditRows: boolean + canDeleteRows: boolean + canEditColumns: boolean + canExpandRows: boolean + canSaveSchema: boolean +} + export interface BaseStore { API: APIClient gridID: string - props: Writable<{ - datasource: UIDatasource - canAddRows: boolean - canEditRows: boolean - canDeleteRows: boolean - canEditColumns: boolean - canExpandRows: boolean - canSaveSchema: boolean - }> + props: Writable } export type Store = BaseStore & @@ -82,7 +97,6 @@ export type Store = BaseStore & // TODO while typing the rest of stores sort: Writable subscribe: any - config: Writable dispatch: (event: string, data: any) => any notifications: Writable width: Writable diff --git a/packages/frontend-core/src/utils/memo.d.ts b/packages/frontend-core/src/utils/memo.d.ts index de5074f784..04d3416e49 100644 --- a/packages/frontend-core/src/utils/memo.d.ts +++ b/packages/frontend-core/src/utils/memo.d.ts @@ -6,5 +6,5 @@ declare module "./memo" { export function derivedMemo( store: Readable, derivation: (store: TStore) => TResult - ): TResult + ): Readable } From 9d1d4d0abf06699658538b80b2eb731c8f5ef192 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 30 Dec 2024 12:47:09 +0100 Subject: [PATCH 12/13] Cleanup types --- .../src/components/grid/stores/config.ts | 17 ++--------------- .../src/components/grid/stores/index.ts | 12 ++++++------ 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/config.ts b/packages/frontend-core/src/components/grid/stores/config.ts index c6a3f86386..e334b58495 100644 --- a/packages/frontend-core/src/components/grid/stores/config.ts +++ b/packages/frontend-core/src/components/grid/stores/config.ts @@ -3,21 +3,8 @@ import { derived, Readable } from "svelte/store" import { ViewV2Type } from "@budibase/types" import { BaseStoreProps, Store as StoreContext } from "." -interface ConfigStore { - datasource: Readable - initialSortColumn: Readable - initialSortOrder: Readable - initialFilter: Readable - fixedRowHeight: Readable - schemaOverrides: Readable - notifySuccess: Readable - notifyError: Readable - canAddRows?: Readable - canEditRows?: Readable - canDeleteRows?: Readable - canEditColumns?: Readable - canExpandRows?: Readable - canSaveSchema?: Readable +type ConfigStore = { + [key in keyof BaseStoreProps]: Readable } interface ConfigDerivedStore { diff --git a/packages/frontend-core/src/components/grid/stores/index.ts b/packages/frontend-core/src/components/grid/stores/index.ts index d4c589fcf7..30a1a923f2 100644 --- a/packages/frontend-core/src/components/grid/stores/index.ts +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -67,12 +67,12 @@ export interface BaseStoreProps { > | null notifySuccess: (message: string) => void notifyError: (message: string) => void - canAddRows: boolean - canEditRows: boolean - canDeleteRows: boolean - canEditColumns: boolean - canExpandRows: boolean - canSaveSchema: boolean + canAddRows?: boolean + canEditRows?: boolean + canDeleteRows?: boolean + canEditColumns?: boolean + canExpandRows?: boolean + canSaveSchema?: boolean } export interface BaseStore { From d2d19291ef9e639a9f1f8beccbfdce79e5f608e4 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 30 Dec 2024 12:47:18 +0100 Subject: [PATCH 13/13] Fix nullish --- packages/frontend-core/src/components/grid/stores/filter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/frontend-core/src/components/grid/stores/filter.ts b/packages/frontend-core/src/components/grid/stores/filter.ts index 459b5ca652..b0a204d42c 100644 --- a/packages/frontend-core/src/components/grid/stores/filter.ts +++ b/packages/frontend-core/src/components/grid/stores/filter.ts @@ -26,7 +26,7 @@ export const createStores = (context: StoreContext): FilterStore => { const { props } = context // Initialise to default props - const filter = memo(get(props).initialFilter) + const filter = memo(get(props).initialFilter ?? undefined) const inlineFilters = memo([]) return {