Fix "type" conflicts

This commit is contained in:
Adria Navarro 2024-12-24 13:01:26 +01:00
parent 78dd802d3a
commit fc51b4e132
8 changed files with 24 additions and 31 deletions

View File

@ -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

View File

@ -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<void>
@ -17,18 +14,18 @@ interface DatasourceBaseActions<
updateRow: (row: SaveRowRequest) => Promise<Row | void>
deleteRows: (rows: Row[]) => Promise<void>
getRow: (id: string) => Promise<Row | void>
isDatasourceValid: (datasource: TDatasource) => boolean | void
isDatasourceValid: (datasource: UIDatasource) => boolean | void
canUseColumn: (name: string) => boolean | void
}
export interface DatasourceTableActions
extends DatasourceBaseActions<UITable, SaveTableRequest> {}
extends DatasourceBaseActions<SaveTableRequest> {}
export interface DatasourceViewActions
extends DatasourceBaseActions<UIView, UpdateViewRequest> {}
extends DatasourceBaseActions<UpdateViewRequest> {}
export interface DatasourceNonPlusActions
extends DatasourceBaseActions<UIDatasource, never> {}
extends DatasourceBaseActions<never> {}
export type DatasourceActions =
| DatasourceTableActions & DatasourceViewActions & DatasourceNonPlusActions

View File

@ -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
)
}

View File

@ -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
}

View File

@ -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.

View File

@ -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

View File

@ -8,7 +8,6 @@ import {
} from "@budibase/types"
export interface UITable {
type: string
name: string
id: string
tableId: string

View File

@ -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<string, UIFieldSchema>
sort?: {
field: string
order: SortOrder
}
queryUI: UISearchFilter
}