Type viewV2
This commit is contained in:
parent
02578e2f0d
commit
b0ef785e7a
|
@ -49,7 +49,7 @@ export const createActions = (context: StoreContext): TableActions => {
|
|||
return datasource?.type === "table" && !!datasource?.tableId
|
||||
}
|
||||
|
||||
const getRow = async (id: string) => {
|
||||
const getRow = async (id: any) => {
|
||||
const res = await API.searchTable(get(datasource).tableId, {
|
||||
limit: 1,
|
||||
query: {
|
||||
|
|
|
@ -1,16 +1,42 @@
|
|||
import { get } from "svelte/store"
|
||||
import { SortOrder } from "@budibase/types"
|
||||
import {
|
||||
Row,
|
||||
SaveRowRequest,
|
||||
SortOrder,
|
||||
UpdateViewRequest,
|
||||
} from "@budibase/types"
|
||||
import { Store as StoreContext } from ".."
|
||||
|
||||
const SuppressErrors = true
|
||||
|
||||
export const createActions = context => {
|
||||
interface ViewActions {
|
||||
viewV2: {
|
||||
actions: {
|
||||
saveDefinition: (newDefinition: UpdateViewRequest) => Promise<void>
|
||||
addRow: (row: SaveRowRequest) => Promise<Row>
|
||||
updateRow: (row: SaveRowRequest) => Promise<Row>
|
||||
deleteRows: (rows: (string | Row)[]) => Promise<void>
|
||||
getRow: (id: string) => Promise<Row>
|
||||
isDatasourceValid: (datasource: {
|
||||
type: string
|
||||
id: string
|
||||
tableId: string
|
||||
}) => boolean
|
||||
canUseColumn: (name: string) => boolean
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export type Store = ViewActions
|
||||
|
||||
export const createActions = (context: StoreContext): ViewActions => {
|
||||
const { API, datasource, columns } = context
|
||||
|
||||
const saveDefinition = async newDefinition => {
|
||||
const saveDefinition = async (newDefinition: UpdateViewRequest) => {
|
||||
await API.viewV2.update(newDefinition)
|
||||
}
|
||||
|
||||
const saveRow = async row => {
|
||||
const saveRow = async (row: SaveRowRequest) => {
|
||||
const $datasource = get(datasource)
|
||||
row = {
|
||||
...row,
|
||||
|
@ -23,11 +49,11 @@ export const createActions = context => {
|
|||
}
|
||||
}
|
||||
|
||||
const deleteRows = async rows => {
|
||||
const deleteRows = async (rows: (string | Row)[]) => {
|
||||
await API.deleteRows(get(datasource).id, rows)
|
||||
}
|
||||
|
||||
const getRow = async id => {
|
||||
const getRow = async (id: string) => {
|
||||
const res = await API.viewV2.fetch(get(datasource).id, {
|
||||
limit: 1,
|
||||
query: {
|
||||
|
@ -40,13 +66,17 @@ export const createActions = context => {
|
|||
return res?.rows?.[0]
|
||||
}
|
||||
|
||||
const isDatasourceValid = datasource => {
|
||||
const isDatasourceValid = (datasource: {
|
||||
type: string
|
||||
id: string
|
||||
tableId: string
|
||||
}) => {
|
||||
return (
|
||||
datasource?.type === "viewV2" && datasource?.id && datasource?.tableId
|
||||
datasource?.type === "viewV2" && !!datasource?.id && !!datasource?.tableId
|
||||
)
|
||||
}
|
||||
|
||||
const canUseColumn = name => {
|
||||
const canUseColumn = (name: string) => {
|
||||
return get(columns).some(col => col.name === name && col.visible)
|
||||
}
|
||||
|
||||
|
@ -65,7 +95,7 @@ export const createActions = context => {
|
|||
}
|
||||
}
|
||||
|
||||
export const initialise = context => {
|
||||
export const initialise = (context: StoreContext) => {
|
||||
const {
|
||||
definition,
|
||||
datasource,
|
|
@ -57,7 +57,8 @@ export interface BaseStore {
|
|||
|
||||
export type Store = BaseStore &
|
||||
Columns.Store &
|
||||
Table.Store & {
|
||||
Table.Store &
|
||||
ViewV2.Store & {
|
||||
// TODO while typing the rest of stores
|
||||
datasource: Writable<any> & { actions: any }
|
||||
definition: Writable<any>
|
||||
|
@ -70,6 +71,9 @@ export type Store = BaseStore &
|
|||
initialFilter: Writable<any>
|
||||
initialSortColumn: Writable<any>
|
||||
initialSortOrder: Writable<any>
|
||||
rows: Writable<any> & { actions: any }
|
||||
subscribe: any
|
||||
config: Writable<any>
|
||||
}
|
||||
|
||||
export const attachStores = (context: Store): Store => {
|
||||
|
|
Loading…
Reference in New Issue