Improve types
This commit is contained in:
parent
812d19b9b0
commit
a318290518
|
@ -3,10 +3,13 @@ import {
|
||||||
SaveRowRequest,
|
SaveRowRequest,
|
||||||
SaveTableRequest,
|
SaveTableRequest,
|
||||||
UIDatasource,
|
UIDatasource,
|
||||||
|
UITable,
|
||||||
|
UIView,
|
||||||
UpdateViewRequest,
|
UpdateViewRequest,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
export interface DatasourceActions<
|
interface DatasourceActions<
|
||||||
|
TDatasource = UITable | UIView,
|
||||||
TSaveDefinitionRequest = UpdateViewRequest | SaveTableRequest
|
TSaveDefinitionRequest = UpdateViewRequest | SaveTableRequest
|
||||||
> {
|
> {
|
||||||
saveDefinition: (newDefinition: TSaveDefinitionRequest) => Promise<void>
|
saveDefinition: (newDefinition: TSaveDefinitionRequest) => Promise<void>
|
||||||
|
@ -14,6 +17,15 @@ export interface DatasourceActions<
|
||||||
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: UIDatasource) => boolean | void
|
isDatasourceValid: (datasource: TDatasource) => boolean | void
|
||||||
canUseColumn: (name: string) => 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 { get } from "svelte/store"
|
||||||
import { Store as StoreContext } from ".."
|
import { Store as StoreContext } from ".."
|
||||||
import { DatasourceActions } from "."
|
import { DatasourceNonPlusActions } from "."
|
||||||
|
|
||||||
interface NonPlusActions {
|
interface NonPlusActions {
|
||||||
nonPlus: {
|
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
|
// 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) &&
|
!table.actions.isDatasourceValid(datasource as UITable) &&
|
||||||
!viewV2.actions.isDatasourceValid(datasource) &&
|
!viewV2.actions.isDatasourceValid(datasource as UIView) &&
|
||||||
datasource?.type != null
|
datasource?.type != null
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,16 +4,17 @@ 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 ".."
|
||||||
import { DatasourceActions } from "."
|
import { DatasourceTableActions } from "."
|
||||||
|
|
||||||
const SuppressErrors = true
|
const SuppressErrors = true
|
||||||
|
|
||||||
interface TableActions {
|
interface TableActions {
|
||||||
table: {
|
table: {
|
||||||
actions: DatasourceActions<SaveTableRequest>
|
actions: DatasourceTableActions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +98,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)) {
|
if (!table.actions.isDatasourceValid($datasource as UITable)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,17 +3,17 @@ import {
|
||||||
Row,
|
Row,
|
||||||
SaveRowRequest,
|
SaveRowRequest,
|
||||||
SortOrder,
|
SortOrder,
|
||||||
UIDatasource,
|
UIView,
|
||||||
UpdateViewRequest,
|
UpdateViewRequest,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { Store as StoreContext } from ".."
|
import { Store as StoreContext } from ".."
|
||||||
import { DatasourceActions } from "."
|
import { DatasourceViewActions } from "."
|
||||||
|
|
||||||
const SuppressErrors = true
|
const SuppressErrors = true
|
||||||
|
|
||||||
interface ViewActions {
|
interface ViewActions {
|
||||||
viewV2: {
|
viewV2: {
|
||||||
actions: DatasourceActions<UpdateViewRequest>
|
actions: DatasourceViewActions
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ export const createActions = (context: StoreContext): ViewActions => {
|
||||||
return res?.rows?.[0]
|
return res?.rows?.[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
const isDatasourceValid = (datasource: UIDatasource) => {
|
const isDatasourceValid = (datasource: UIView) => {
|
||||||
return (
|
return (
|
||||||
datasource?.type === "viewV2" && !!datasource?.id && !!datasource?.tableId
|
datasource?.type === "viewV2" && !!datasource?.id && !!datasource?.tableId
|
||||||
)
|
)
|
||||||
|
@ -108,7 +108,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)) {
|
if (!viewV2.actions.isDatasourceValid($datasource as UIView)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ export const initialise = (context: StoreContext) => {
|
||||||
unsubscribers.push(
|
unsubscribers.push(
|
||||||
sort.subscribe(async $sort => {
|
sort.subscribe(async $sort => {
|
||||||
// Ensure we're updating the correct view
|
// Ensure we're updating the correct view
|
||||||
const $view = get(definition)
|
const $view = get(definition) as UIView
|
||||||
if ($view?.id !== $datasource.id) {
|
if ($view?.id !== $datasource.id) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
import { SortOrder, UIFieldSchema, UISearchFilter } from "@budibase/types"
|
import { SortOrder, UIFieldSchema, UISearchFilter } from "@budibase/types"
|
||||||
|
|
||||||
export interface UIDatasource {
|
export type UIDatasource = UITable | UIView
|
||||||
|
|
||||||
|
export interface UITable {
|
||||||
type: string
|
type: string
|
||||||
name: string
|
name: string
|
||||||
id: string
|
id: string
|
||||||
|
@ -14,6 +16,18 @@ export interface UIDatasource {
|
||||||
schema: Record<string, UIFieldSchema>
|
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 {
|
export interface UIFieldMutation {
|
||||||
visible: boolean
|
visible: boolean
|
||||||
readonly?: boolean
|
readonly?: boolean
|
||||||
|
|
Loading…
Reference in New Issue