From 02578e2f0d96eed03d47e4e249a7a2a40a3572d9 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 20 Dec 2024 14:38:23 +0100 Subject: [PATCH] Fix types --- .../grid/stores/datasources/table.ts | 23 ++++++++++++++++--- .../src/components/grid/stores/index.ts | 10 ++++---- 2 files changed, 25 insertions(+), 8 deletions(-) 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 dc485dc58e..8a2dea1a70 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/table.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/table.ts @@ -1,6 +1,7 @@ import { Row, SaveRowRequest, + SaveRowResponse, SaveTableRequest, SortOrder, } from "@budibase/types" @@ -9,7 +10,23 @@ import { Store as StoreContext } from ".." const SuppressErrors = true -export const createActions = (context: StoreContext) => { +interface TableActions { + table: { + actions: { + saveDefinition: (newDefinition: SaveTableRequest) => Promise + addRow: (row: SaveRowRequest) => Promise + updateRow: (row: SaveRowRequest) => Promise + deleteRows: (rows: (string | Row)[]) => Promise + getRow: (id: string) => Promise + isDatasourceValid: (datasource: { type: string; tableId: any }) => boolean + canUseColumn: (name: string) => boolean + } + } +} + +export type Store = TableActions + +export const createActions = (context: StoreContext): TableActions => { const { API, datasource, columns } = context const saveDefinition = async (newDefinition: SaveTableRequest) => { @@ -29,7 +46,7 @@ export const createActions = (context: StoreContext) => { } const isDatasourceValid = (datasource: { type: string; tableId: any }) => { - return datasource?.type === "table" && datasource?.tableId + return datasource?.type === "table" && !!datasource?.tableId } const getRow = async (id: string) => { @@ -80,7 +97,7 @@ export const initialise = (context: StoreContext) => { // Keep a list of subscriptions so that we can clear them when the datasource // config changes - let unsubscribers = [] + let unsubscribers: any[] = [] // Observe datasource changes and apply logic for table datasources datasource.subscribe($datasource => { diff --git a/packages/frontend-core/src/components/grid/stores/index.ts b/packages/frontend-core/src/components/grid/stores/index.ts index 123a61383a..677d8d3f83 100644 --- a/packages/frontend-core/src/components/grid/stores/index.ts +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -45,7 +45,7 @@ const DependencyOrderedStores = [ Users, Menu, Pagination, - Config, + Config as any, Clipboard, Notifications, Cache, @@ -56,17 +56,17 @@ export interface BaseStore { } export type Store = BaseStore & - Columns.Store & { + Columns.Store & + Table.Store & { // TODO while typing the rest of stores - datasource: Writable + datasource: Writable & { actions: any } definition: Writable - enrichedSchema: Writable + enrichedSchema: any fetch: Writable filter: Writable inlineFilters: Writable allFilters: Writable sort: Writable - table: Writable & { actions: any } initialFilter: Writable initialSortColumn: Writable initialSortOrder: Writable