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 4796f5d071..dcc4d47076 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts @@ -1,4 +1,4 @@ -import { SortOrder } from "@budibase/types" +import { SortOrder, UIDatasource } from "@budibase/types" import { get } from "svelte/store" import { Store as StoreContext } from ".." @@ -10,11 +10,7 @@ interface NonPlusActions { updateRow: () => Promise deleteRows: () => Promise getRow: () => Promise - isDatasourceValid: (datasource: { - type: string - id: string - tableId: string - }) => boolean + isDatasourceValid: (datasource: UIDatasource) => boolean canUseColumn: (name: string) => boolean } } @@ -41,11 +37,7 @@ export const createActions = (context: StoreContext): NonPlusActions => { throw "This datasource does not support fetching individual rows" } - const isDatasourceValid = (datasource: { - type: string - id: string - tableId: string - }) => { + const isDatasourceValid = (datasource: UIDatasource) => { // There are many different types and shapes of datasource, so we only // check that we aren't null return ( 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 2e947c586e..e905c89e44 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/table.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/table.ts @@ -4,6 +4,7 @@ import { SaveRowResponse, SaveTableRequest, SortOrder, + UIDatasource, } from "@budibase/types" import { get } from "svelte/store" import { Store as StoreContext } from ".." @@ -18,7 +19,7 @@ interface TableActions { updateRow: (row: SaveRowRequest) => Promise deleteRows: (rows: (string | Row)[]) => Promise getRow: (id: string) => Promise - isDatasourceValid: (datasource: { type: string; tableId: any }) => boolean + isDatasourceValid: (datasource: UIDatasource) => boolean canUseColumn: (name: string) => boolean } } @@ -45,7 +46,7 @@ export const createActions = (context: StoreContext): TableActions => { await API.deleteRows(get(datasource).tableId, rows) } - const isDatasourceValid = (datasource: { type: string; tableId: any }) => { + const isDatasourceValid = (datasource: UIDatasource) => { return datasource?.type === "table" && !!datasource?.tableId } 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 304a25efb3..677a85312f 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts @@ -3,6 +3,7 @@ import { Row, SaveRowRequest, SortOrder, + UIDatasource, UpdateViewRequest, } from "@budibase/types" import { Store as StoreContext } from ".." @@ -17,11 +18,7 @@ interface ViewActions { updateRow: (row: SaveRowRequest) => Promise deleteRows: (rows: (string | Row)[]) => Promise getRow: (id: string) => Promise - isDatasourceValid: (datasource: { - type: string - id: string - tableId: string - }) => boolean + isDatasourceValid: (datasource: UIDatasource) => boolean canUseColumn: (name: string) => boolean } } @@ -66,11 +63,7 @@ export const createActions = (context: StoreContext): ViewActions => { return res?.rows?.[0] } - const isDatasourceValid = (datasource: { - type: string - id: string - tableId: string - }) => { + const isDatasourceValid = (datasource: UIDatasource) => { return ( datasource?.type === "viewV2" && !!datasource?.id && !!datasource?.tableId ) diff --git a/packages/types/src/ui/stores/grid/datasource.ts b/packages/types/src/ui/stores/grid/datasource.ts new file mode 100644 index 0000000000..d7367352d5 --- /dev/null +++ b/packages/types/src/ui/stores/grid/datasource.ts @@ -0,0 +1,5 @@ +export interface UIDatasource { + type: string + id: string + tableId: string +} diff --git a/packages/types/src/ui/stores/grid/index.ts b/packages/types/src/ui/stores/grid/index.ts index 81f23bae69..f6c3472aaa 100644 --- a/packages/types/src/ui/stores/grid/index.ts +++ b/packages/types/src/ui/stores/grid/index.ts @@ -1 +1,2 @@ export * from "./columns" +export * from "./datasource"