From 332fdc5f38a98022e80155a969e6167ff80bf959 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 20:58:35 +0100 Subject: [PATCH] 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