diff --git a/packages/frontend-core/src/components/grid/stores/datasources/index.ts b/packages/frontend-core/src/components/grid/stores/datasources/index.ts index 4c3ffc7a74..8127a9fecf 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/index.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/index.ts @@ -3,10 +3,13 @@ import { SaveRowRequest, SaveTableRequest, UIDatasource, + UITable, + UIView, UpdateViewRequest, } from "@budibase/types" -export interface DatasourceActions< +interface DatasourceActions< + TDatasource = UITable | UIView, TSaveDefinitionRequest = UpdateViewRequest | SaveTableRequest > { saveDefinition: (newDefinition: TSaveDefinitionRequest) => Promise @@ -14,6 +17,15 @@ export interface DatasourceActions< updateRow: (row: SaveRowRequest) => Promise deleteRows: (rows: Row[]) => Promise getRow: (id: string) => Promise - isDatasourceValid: (datasource: UIDatasource) => boolean | void + isDatasourceValid: (datasource: TDatasource) => boolean | void canUseColumn: (name: string) => boolean | void } + +export interface DatasourceTableActions + extends DatasourceActions {} + +export interface DatasourceViewActions + extends DatasourceActions {} + +export interface DatasourceNonPlusActions + extends DatasourceActions {} 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 65fc6d8696..46b224730b 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts @@ -1,11 +1,11 @@ -import { SortOrder, UIDatasource } from "@budibase/types" +import { SortOrder, UIDatasource, UITable, UIView } from "@budibase/types" import { get } from "svelte/store" import { Store as StoreContext } from ".." -import { DatasourceActions } from "." +import { DatasourceNonPlusActions } from "." interface NonPlusActions { nonPlus: { - actions: DatasourceActions + actions: DatasourceNonPlusActions } } @@ -34,8 +34,8 @@ export const createActions = (context: StoreContext): NonPlusActions => { // There are many different types and shapes of datasource, so we only // check that we aren't null return ( - !table.actions.isDatasourceValid(datasource) && - !viewV2.actions.isDatasourceValid(datasource) && + !table.actions.isDatasourceValid(datasource as UITable) && + !viewV2.actions.isDatasourceValid(datasource as UIView) && datasource?.type != null ) } 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 5f3d27159e..5c8b3e1a1a 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/table.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/table.ts @@ -4,16 +4,17 @@ import { SaveTableRequest, SortOrder, UIDatasource, + UITable, } from "@budibase/types" import { get } from "svelte/store" import { Store as StoreContext } from ".." -import { DatasourceActions } from "." +import { DatasourceTableActions } from "." const SuppressErrors = true interface TableActions { table: { - actions: DatasourceActions + actions: DatasourceTableActions } } @@ -97,7 +98,7 @@ export const initialise = (context: StoreContext) => { // Clear previous subscriptions unsubscribers?.forEach(unsubscribe => unsubscribe()) unsubscribers = [] - if (!table.actions.isDatasourceValid($datasource)) { + if (!table.actions.isDatasourceValid($datasource as UITable)) { return } 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 edafd94d6f..f70059e016 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts @@ -3,17 +3,17 @@ import { Row, SaveRowRequest, SortOrder, - UIDatasource, + UIView, UpdateViewRequest, } from "@budibase/types" import { Store as StoreContext } from ".." -import { DatasourceActions } from "." +import { DatasourceViewActions } from "." const SuppressErrors = true interface ViewActions { viewV2: { - actions: DatasourceActions + actions: DatasourceViewActions } } @@ -56,7 +56,7 @@ export const createActions = (context: StoreContext): ViewActions => { return res?.rows?.[0] } - const isDatasourceValid = (datasource: UIDatasource) => { + const isDatasourceValid = (datasource: UIView) => { return ( datasource?.type === "viewV2" && !!datasource?.id && !!datasource?.tableId ) @@ -108,7 +108,7 @@ export const initialise = (context: StoreContext) => { // Clear previous subscriptions unsubscribers?.forEach(unsubscribe => unsubscribe()) unsubscribers = [] - if (!viewV2.actions.isDatasourceValid($datasource)) { + if (!viewV2.actions.isDatasourceValid($datasource as UIView)) { return } @@ -147,7 +147,7 @@ export const initialise = (context: StoreContext) => { unsubscribers.push( sort.subscribe(async $sort => { // Ensure we're updating the correct view - const $view = get(definition) + const $view = get(definition) as UIView if ($view?.id !== $datasource.id) { return } diff --git a/packages/types/src/ui/stores/grid/datasource.ts b/packages/types/src/ui/stores/grid/datasource.ts index 818b4f00da..5d27183806 100644 --- a/packages/types/src/ui/stores/grid/datasource.ts +++ b/packages/types/src/ui/stores/grid/datasource.ts @@ -1,6 +1,8 @@ import { SortOrder, UIFieldSchema, UISearchFilter } from "@budibase/types" -export interface UIDatasource { +export type UIDatasource = UITable | UIView + +export interface UITable { type: string name: string id: string @@ -14,6 +16,18 @@ export interface UIDatasource { schema: Record } +export interface UIView { + type: string + version: 2 + id: string + tableId: string + sort?: { + field: string + order: SortOrder + } + queryUI: UISearchFilter +} + export interface UIFieldMutation { visible: boolean readonly?: boolean