Fix types
This commit is contained in:
parent
d101a89003
commit
02578e2f0d
|
@ -1,6 +1,7 @@
|
||||||
import {
|
import {
|
||||||
Row,
|
Row,
|
||||||
SaveRowRequest,
|
SaveRowRequest,
|
||||||
|
SaveRowResponse,
|
||||||
SaveTableRequest,
|
SaveTableRequest,
|
||||||
SortOrder,
|
SortOrder,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
@ -9,7 +10,23 @@ import { Store as StoreContext } from ".."
|
||||||
|
|
||||||
const SuppressErrors = true
|
const SuppressErrors = true
|
||||||
|
|
||||||
export const createActions = (context: StoreContext) => {
|
interface TableActions {
|
||||||
|
table: {
|
||||||
|
actions: {
|
||||||
|
saveDefinition: (newDefinition: SaveTableRequest) => Promise<void>
|
||||||
|
addRow: (row: SaveRowRequest) => Promise<SaveRowResponse>
|
||||||
|
updateRow: (row: SaveRowRequest) => Promise<SaveRowResponse>
|
||||||
|
deleteRows: (rows: (string | Row)[]) => Promise<void>
|
||||||
|
getRow: (id: string) => Promise<Row>
|
||||||
|
isDatasourceValid: (datasource: { type: string; tableId: any }) => boolean
|
||||||
|
canUseColumn: (name: string) => boolean
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Store = TableActions
|
||||||
|
|
||||||
|
export const createActions = (context: StoreContext): TableActions => {
|
||||||
const { API, datasource, columns } = context
|
const { API, datasource, columns } = context
|
||||||
|
|
||||||
const saveDefinition = async (newDefinition: SaveTableRequest) => {
|
const saveDefinition = async (newDefinition: SaveTableRequest) => {
|
||||||
|
@ -29,7 +46,7 @@ export const createActions = (context: StoreContext) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const isDatasourceValid = (datasource: { type: string; tableId: any }) => {
|
const isDatasourceValid = (datasource: { type: string; tableId: any }) => {
|
||||||
return datasource?.type === "table" && datasource?.tableId
|
return datasource?.type === "table" && !!datasource?.tableId
|
||||||
}
|
}
|
||||||
|
|
||||||
const getRow = async (id: string) => {
|
const getRow = async (id: string) => {
|
||||||
|
@ -80,7 +97,7 @@ export const initialise = (context: StoreContext) => {
|
||||||
|
|
||||||
// Keep a list of subscriptions so that we can clear them when the datasource
|
// Keep a list of subscriptions so that we can clear them when the datasource
|
||||||
// config changes
|
// config changes
|
||||||
let unsubscribers = []
|
let unsubscribers: any[] = []
|
||||||
|
|
||||||
// Observe datasource changes and apply logic for table datasources
|
// Observe datasource changes and apply logic for table datasources
|
||||||
datasource.subscribe($datasource => {
|
datasource.subscribe($datasource => {
|
||||||
|
|
|
@ -45,7 +45,7 @@ const DependencyOrderedStores = [
|
||||||
Users,
|
Users,
|
||||||
Menu,
|
Menu,
|
||||||
Pagination,
|
Pagination,
|
||||||
Config,
|
Config as any,
|
||||||
Clipboard,
|
Clipboard,
|
||||||
Notifications,
|
Notifications,
|
||||||
Cache,
|
Cache,
|
||||||
|
@ -56,17 +56,17 @@ export interface BaseStore {
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Store = BaseStore &
|
export type Store = BaseStore &
|
||||||
Columns.Store & {
|
Columns.Store &
|
||||||
|
Table.Store & {
|
||||||
// TODO while typing the rest of stores
|
// TODO while typing the rest of stores
|
||||||
datasource: Writable<any>
|
datasource: Writable<any> & { actions: any }
|
||||||
definition: Writable<any>
|
definition: Writable<any>
|
||||||
enrichedSchema: Writable<any>
|
enrichedSchema: any
|
||||||
fetch: Writable<any>
|
fetch: Writable<any>
|
||||||
filter: Writable<any>
|
filter: Writable<any>
|
||||||
inlineFilters: Writable<any>
|
inlineFilters: Writable<any>
|
||||||
allFilters: Writable<any>
|
allFilters: Writable<any>
|
||||||
sort: Writable<any>
|
sort: Writable<any>
|
||||||
table: Writable<any> & { actions: any }
|
|
||||||
initialFilter: Writable<any>
|
initialFilter: Writable<any>
|
||||||
initialSortColumn: Writable<any>
|
initialSortColumn: Writable<any>
|
||||||
initialSortOrder: Writable<any>
|
initialSortOrder: Writable<any>
|
||||||
|
|
Loading…
Reference in New Issue