Improve types
This commit is contained in:
parent
812d19b9b0
commit
a318290518
|
@ -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<void>
|
||||
|
@ -14,6 +17,15 @@ export interface DatasourceActions<
|
|||
updateRow: (row: SaveRowRequest) => Promise<Row | void>
|
||||
deleteRows: (rows: Row[]) => Promise<void>
|
||||
getRow: (id: string) => Promise<Row | void>
|
||||
isDatasourceValid: (datasource: UIDatasource) => boolean | void
|
||||
isDatasourceValid: (datasource: TDatasource) => boolean | void
|
||||
canUseColumn: (name: string) => boolean | void
|
||||
}
|
||||
|
||||
export interface DatasourceTableActions
|
||||
extends DatasourceActions<UITable, SaveTableRequest> {}
|
||||
|
||||
export interface DatasourceViewActions
|
||||
extends DatasourceActions<UIView, UpdateViewRequest> {}
|
||||
|
||||
export interface DatasourceNonPlusActions
|
||||
extends DatasourceActions<UIDatasource, never> {}
|
||||
|
|
|
@ -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
|
||||
)
|
||||
}
|
||||
|
|
|
@ -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<SaveTableRequest>
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -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<UpdateViewRequest>
|
||||
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
|
||||
}
|
||||
|
|
|
@ -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<string, UIFieldSchema>
|
||||
}
|
||||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue