From fc51b4e132a8807481c4fcbfbca04f0f646bff05 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Tue, 24 Dec 2024 13:01:26 +0100 Subject: [PATCH] Fix "type" conflicts --- .../src/components/grid/stores/datasource.ts | 9 +++++++-- .../components/grid/stores/datasources/index.ts | 11 ++++------- .../components/grid/stores/datasources/nonPlus.ts | 6 +++--- .../components/grid/stores/datasources/table.ts | 3 +-- .../components/grid/stores/datasources/viewV2.ts | 7 ++++--- packages/types/src/ui/stores/grid/datasource.ts | 4 +++- packages/types/src/ui/stores/grid/table.ts | 1 - packages/types/src/ui/stores/grid/view.ts | 14 ++------------ 8 files changed, 24 insertions(+), 31 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index 6a3bced620..b60e488db2 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -133,7 +133,11 @@ export const deriveStores = (context: StoreContext): DerivedDatasourceStore => { type = ($datasource as any).value?.datasource?.type } // Handle calculation views - if (type === "viewV2" && $definition?.type === ViewV2Type.CALCULATION) { + if ( + type === "viewV2" && + "type" in $definition && + $definition?.type === ViewV2Type.CALCULATION + ) { return false } return ["table", "viewV2", "link"].includes(type) @@ -167,6 +171,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { const getAPI = () => { const $datasource = get(datasource) const type = $datasource?.type + console.error({ type }) if (!type) { return null } @@ -338,7 +343,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { // Checks if a certain datasource config is valid const isDatasourceValid = (datasource: UIDatasource) => { - return getAPI()?.actions.isDatasourceValid(datasource as any) + return getAPI()?.actions.isDatasourceValid(datasource) } // Checks if this datasource can use a specific column by name 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 a03d85e74f..c58aef37e9 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/index.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/index.ts @@ -3,13 +3,10 @@ import { SaveRowRequest, SaveTableRequest, UIDatasource, - UITable, - UIView, UpdateViewRequest, } from "@budibase/types" interface DatasourceBaseActions< - TDatasource = UITable | UIView, TSaveDefinitionRequest = UpdateViewRequest | SaveTableRequest > { saveDefinition: (newDefinition: TSaveDefinitionRequest) => Promise @@ -17,18 +14,18 @@ interface DatasourceBaseActions< updateRow: (row: SaveRowRequest) => Promise deleteRows: (rows: Row[]) => Promise getRow: (id: string) => Promise - isDatasourceValid: (datasource: TDatasource) => boolean | void + isDatasourceValid: (datasource: UIDatasource) => boolean | void canUseColumn: (name: string) => boolean | void } export interface DatasourceTableActions - extends DatasourceBaseActions {} + extends DatasourceBaseActions {} export interface DatasourceViewActions - extends DatasourceBaseActions {} + extends DatasourceBaseActions {} export interface DatasourceNonPlusActions - extends DatasourceBaseActions {} + extends DatasourceBaseActions {} export type DatasourceActions = | DatasourceTableActions & DatasourceViewActions & DatasourceNonPlusActions 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 46b224730b..17e5e8b8d9 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, UIDatasource, UITable, UIView } from "@budibase/types" +import { SortOrder, UIDatasource } from "@budibase/types" import { get } from "svelte/store" import { Store as StoreContext } from ".." import { DatasourceNonPlusActions } from "." @@ -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 as UITable) && - !viewV2.actions.isDatasourceValid(datasource as UIView) && + !table.actions.isDatasourceValid(datasource) && + !viewV2.actions.isDatasourceValid(datasource) && 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 5c8b3e1a1a..894a65ba4c 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/table.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/table.ts @@ -4,7 +4,6 @@ import { SaveTableRequest, SortOrder, UIDatasource, - UITable, } from "@budibase/types" import { get } from "svelte/store" import { Store as StoreContext } from ".." @@ -98,7 +97,7 @@ export const initialise = (context: StoreContext) => { // Clear previous subscriptions unsubscribers?.forEach(unsubscribe => unsubscribe()) unsubscribers = [] - if (!table.actions.isDatasourceValid($datasource as UITable)) { + if (!table.actions.isDatasourceValid($datasource)) { 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 e83d866455..d9cac5397d 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, UIView, UpdateViewRequest, } from "@budibase/types" @@ -56,7 +57,7 @@ export const createActions = (context: StoreContext): ViewActions => { return res?.rows?.[0] } - const isDatasourceValid = (datasource: UIView) => { + const isDatasourceValid = (datasource: UIDatasource) => { return ( datasource?.type === "viewV2" && !!datasource?.id && !!datasource?.tableId ) @@ -108,7 +109,7 @@ export const initialise = (context: StoreContext) => { // Clear previous subscriptions unsubscribers?.forEach(unsubscribe => unsubscribe()) unsubscribers = [] - if (!viewV2.actions.isDatasourceValid($datasource as UIView)) { + if (!viewV2.actions.isDatasourceValid($datasource)) { return } @@ -168,7 +169,7 @@ export const initialise = (context: StoreContext) => { field: $sort.column, order: $sort.order || SortOrder.ASCENDING, }, - } as never as UpdateViewRequest) + }) } // Also update the fetch to ensure the new sort is respected. diff --git a/packages/types/src/ui/stores/grid/datasource.ts b/packages/types/src/ui/stores/grid/datasource.ts index c8a6a6fc83..1d9b6740a4 100644 --- a/packages/types/src/ui/stores/grid/datasource.ts +++ b/packages/types/src/ui/stores/grid/datasource.ts @@ -1,6 +1,8 @@ import { UITable, UIView } from "@budibase/types" -export type UIDatasource = UITable | UIView +export type UIDatasource = (UITable | UIView) & { + type: string +} export interface UIFieldMutation { visible?: boolean diff --git a/packages/types/src/ui/stores/grid/table.ts b/packages/types/src/ui/stores/grid/table.ts index 4c19cbf882..6fae1e908a 100644 --- a/packages/types/src/ui/stores/grid/table.ts +++ b/packages/types/src/ui/stores/grid/table.ts @@ -8,7 +8,6 @@ import { } from "@budibase/types" export interface UITable { - type: string name: string id: string tableId: string diff --git a/packages/types/src/ui/stores/grid/view.ts b/packages/types/src/ui/stores/grid/view.ts index af214e7d82..f81cc34aaf 100644 --- a/packages/types/src/ui/stores/grid/view.ts +++ b/packages/types/src/ui/stores/grid/view.ts @@ -1,16 +1,6 @@ -import { SortOrder, UISearchFilter } from "@budibase/types" +import { ViewV2 } from "@budibase/types" import { UIFieldSchema } from "./table" -export interface UIView { - type: string - version: 2 - id: string - tableId: string - primaryDisplay?: string +export interface UIView extends ViewV2 { schema: Record - sort?: { - field: string - order: SortOrder - } - queryUI: UISearchFilter }