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 type = ($datasource as any).value?.datasource?.type
} }
// Handle calculation views // Handle calculation views
if (type === "viewV2" && $definition?.type === ViewV2Type.CALCULATION) { if (
type === "viewV2" &&
"type" in $definition &&
$definition?.type === ViewV2Type.CALCULATION
) {
return false return false
} }
return ["table", "viewV2", "link"].includes(type) return ["table", "viewV2", "link"].includes(type)
@ -167,6 +171,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => {
const getAPI = () => { const getAPI = () => {
const $datasource = get(datasource) const $datasource = get(datasource)
const type = $datasource?.type const type = $datasource?.type
console.error({ type })
if (!type) { if (!type) {
return null return null
} }
@ -338,7 +343,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => {
// Checks if a certain datasource config is valid // Checks if a certain datasource config is valid
const isDatasourceValid = (datasource: UIDatasource) => { 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 // Checks if this datasource can use a specific column by name

View File

@ -3,13 +3,10 @@ import {
SaveRowRequest, SaveRowRequest,
SaveTableRequest, SaveTableRequest,
UIDatasource, UIDatasource,
UITable,
UIView,
UpdateViewRequest, UpdateViewRequest,
} from "@budibase/types" } from "@budibase/types"
interface DatasourceBaseActions< interface DatasourceBaseActions<
TDatasource = UITable | UIView,
TSaveDefinitionRequest = UpdateViewRequest | SaveTableRequest TSaveDefinitionRequest = UpdateViewRequest | SaveTableRequest
> { > {
saveDefinition: (newDefinition: TSaveDefinitionRequest) => Promise<void> saveDefinition: (newDefinition: TSaveDefinitionRequest) => Promise<void>
@ -17,18 +14,18 @@ interface DatasourceBaseActions<
updateRow: (row: SaveRowRequest) => Promise<Row | void> updateRow: (row: SaveRowRequest) => Promise<Row | void>
deleteRows: (rows: Row[]) => Promise<void> deleteRows: (rows: Row[]) => Promise<void>
getRow: (id: string) => Promise<Row | void> getRow: (id: string) => Promise<Row | void>
isDatasourceValid: (datasource: TDatasource) => boolean | void isDatasourceValid: (datasource: UIDatasource) => boolean | void
canUseColumn: (name: string) => boolean | void canUseColumn: (name: string) => boolean | void
} }
export interface DatasourceTableActions export interface DatasourceTableActions
extends DatasourceBaseActions<UITable, SaveTableRequest> {} extends DatasourceBaseActions<SaveTableRequest> {}
export interface DatasourceViewActions export interface DatasourceViewActions
extends DatasourceBaseActions<UIView, UpdateViewRequest> {} extends DatasourceBaseActions<UpdateViewRequest> {}
export interface DatasourceNonPlusActions export interface DatasourceNonPlusActions
extends DatasourceBaseActions<UIDatasource, never> {} extends DatasourceBaseActions<never> {}
export type DatasourceActions = export type DatasourceActions =
| DatasourceTableActions & DatasourceViewActions & DatasourceNonPlusActions | 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 { get } from "svelte/store"
import { Store as StoreContext } from ".." import { Store as StoreContext } from ".."
import { DatasourceNonPlusActions } 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 // There are many different types and shapes of datasource, so we only
// check that we aren't null // check that we aren't null
return ( return (
!table.actions.isDatasourceValid(datasource as UITable) && !table.actions.isDatasourceValid(datasource) &&
!viewV2.actions.isDatasourceValid(datasource as UIView) && !viewV2.actions.isDatasourceValid(datasource) &&
datasource?.type != null datasource?.type != null
) )
} }

View File

@ -4,7 +4,6 @@ import {
SaveTableRequest, SaveTableRequest,
SortOrder, SortOrder,
UIDatasource, UIDatasource,
UITable,
} from "@budibase/types" } from "@budibase/types"
import { get } from "svelte/store" import { get } from "svelte/store"
import { Store as StoreContext } from ".." import { Store as StoreContext } from ".."
@ -98,7 +97,7 @@ export const initialise = (context: StoreContext) => {
// Clear previous subscriptions // Clear previous subscriptions
unsubscribers?.forEach(unsubscribe => unsubscribe()) unsubscribers?.forEach(unsubscribe => unsubscribe())
unsubscribers = [] unsubscribers = []
if (!table.actions.isDatasourceValid($datasource as UITable)) { if (!table.actions.isDatasourceValid($datasource)) {
return return
} }

View File

@ -3,6 +3,7 @@ import {
Row, Row,
SaveRowRequest, SaveRowRequest,
SortOrder, SortOrder,
UIDatasource,
UIView, UIView,
UpdateViewRequest, UpdateViewRequest,
} from "@budibase/types" } from "@budibase/types"
@ -56,7 +57,7 @@ export const createActions = (context: StoreContext): ViewActions => {
return res?.rows?.[0] return res?.rows?.[0]
} }
const isDatasourceValid = (datasource: UIView) => { const isDatasourceValid = (datasource: UIDatasource) => {
return ( return (
datasource?.type === "viewV2" && !!datasource?.id && !!datasource?.tableId datasource?.type === "viewV2" && !!datasource?.id && !!datasource?.tableId
) )
@ -108,7 +109,7 @@ export const initialise = (context: StoreContext) => {
// Clear previous subscriptions // Clear previous subscriptions
unsubscribers?.forEach(unsubscribe => unsubscribe()) unsubscribers?.forEach(unsubscribe => unsubscribe())
unsubscribers = [] unsubscribers = []
if (!viewV2.actions.isDatasourceValid($datasource as UIView)) { if (!viewV2.actions.isDatasourceValid($datasource)) {
return return
} }
@ -168,7 +169,7 @@ export const initialise = (context: StoreContext) => {
field: $sort.column, field: $sort.column,
order: $sort.order || SortOrder.ASCENDING, order: $sort.order || SortOrder.ASCENDING,
}, },
} as never as UpdateViewRequest) })
} }
// Also update the fetch to ensure the new sort is respected. // Also update the fetch to ensure the new sort is respected.

View File

@ -1,6 +1,8 @@
import { UITable, UIView } from "@budibase/types" import { UITable, UIView } from "@budibase/types"
export type UIDatasource = UITable | UIView export type UIDatasource = (UITable | UIView) & {
type: string
}
export interface UIFieldMutation { export interface UIFieldMutation {
visible?: boolean visible?: boolean

View File

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

View File

@ -1,16 +1,6 @@
import { SortOrder, UISearchFilter } from "@budibase/types" import { ViewV2 } from "@budibase/types"
import { UIFieldSchema } from "./table" import { UIFieldSchema } from "./table"
export interface UIView { export interface UIView extends ViewV2 {
type: string
version: 2
id: string
tableId: string
primaryDisplay?: string
schema: Record<string, UIFieldSchema> schema: Record<string, UIFieldSchema>
sort?: {
field: string
order: SortOrder
}
queryUI: UISearchFilter
} }