From 90b663912585f11f02a2394c1e4b7f28c1b09cde Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 23 Dec 2024 09:33:55 +0100 Subject: [PATCH] Extract action interface --- .../grid/stores/datasources/index.ts | 19 +++++++++++++++++++ .../grid/stores/datasources/nonPlus.ts | 11 ++--------- .../grid/stores/datasources/table.ts | 12 ++---------- .../grid/stores/datasources/viewV2.ts | 11 ++--------- 4 files changed, 25 insertions(+), 28 deletions(-) create mode 100644 packages/frontend-core/src/components/grid/stores/datasources/index.ts diff --git a/packages/frontend-core/src/components/grid/stores/datasources/index.ts b/packages/frontend-core/src/components/grid/stores/datasources/index.ts new file mode 100644 index 0000000000..1d1a2103b1 --- /dev/null +++ b/packages/frontend-core/src/components/grid/stores/datasources/index.ts @@ -0,0 +1,19 @@ +import { + Row, + SaveRowRequest, + SaveTableRequest, + UIDatasource, + UpdateViewRequest, +} from "@budibase/types" + +export interface DatasourceActions< + TSaveDefinitionRequest = UpdateViewRequest | SaveTableRequest +> { + saveDefinition: (newDefinition: TSaveDefinitionRequest) => Promise + addRow: (row: SaveRowRequest) => Promise + updateRow: (row: SaveRowRequest) => Promise + deleteRows: (rows: (string | Row)[]) => Promise + getRow: (id: string) => Promise + isDatasourceValid: (datasource: UIDatasource) => boolean + canUseColumn: (name: string) => boolean +} 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 dcc4d47076..2ea5a05a0e 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts @@ -1,18 +1,11 @@ import { SortOrder, UIDatasource } from "@budibase/types" import { get } from "svelte/store" import { Store as StoreContext } from ".." +import { DatasourceActions } from "." interface NonPlusActions { nonPlus: { - actions: { - saveDefinition: () => Promise - addRow: () => Promise - updateRow: () => Promise - deleteRows: () => Promise - getRow: () => Promise - isDatasourceValid: (datasource: UIDatasource) => boolean - canUseColumn: (name: string) => boolean - } + actions: DatasourceActions } } 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 e905c89e44..9f1a490306 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/table.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/table.ts @@ -1,27 +1,19 @@ import { Row, SaveRowRequest, - SaveRowResponse, SaveTableRequest, SortOrder, UIDatasource, } from "@budibase/types" import { get } from "svelte/store" import { Store as StoreContext } from ".." +import { DatasourceActions } from "." const SuppressErrors = true 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: UIDatasource) => boolean - canUseColumn: (name: string) => boolean - } + actions: DatasourceActions } } 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 677a85312f..70a83b4594 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts @@ -7,20 +7,13 @@ import { UpdateViewRequest, } from "@budibase/types" import { Store as StoreContext } from ".." +import { DatasourceActions } from "." const SuppressErrors = true interface ViewActions { viewV2: { - actions: { - saveDefinition: (newDefinition: UpdateViewRequest) => Promise - addRow: (row: SaveRowRequest) => Promise - updateRow: (row: SaveRowRequest) => Promise - deleteRows: (rows: (string | Row)[]) => Promise - getRow: (id: string) => Promise - isDatasourceValid: (datasource: UIDatasource) => boolean - canUseColumn: (name: string) => boolean - } + actions: DatasourceActions } }