From 6d1f2c9200ddc897f172a2bf9c5b6dccbae24c55 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 30 Dec 2024 12:39:52 +0100 Subject: [PATCH] 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 }