Skip to content

Commit

Permalink
Type createActions
Browse files Browse the repository at this point in the history
  • Loading branch information
adrinr committed Dec 20, 2024
1 parent 7ebcbe3 commit fafe91e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { SortOrder } from "@budibase/types"
import {
Row,
SaveRowRequest,
SaveTableRequest,
SortOrder,
} from "@budibase/types"
import { get } from "svelte/store"
import { Store as StoreContext } from ".."

Expand All @@ -7,27 +12,27 @@ const SuppressErrors = true
export const createActions = (context: StoreContext) => {
const { API, datasource, columns } = context

const saveDefinition = async newDefinition => {
const saveDefinition = async (newDefinition: SaveTableRequest) => {
await API.saveTable(newDefinition)
}

const saveRow = async row => {
const saveRow = async (row: SaveRowRequest) => {
row = {
...row,
tableId: get(datasource)?.tableId,
}
return await API.saveRow(row, SuppressErrors)
}

const deleteRows = async rows => {
const deleteRows = async (rows: (string | Row)[]) => {
await API.deleteRows(get(datasource).tableId, rows)
}

const isDatasourceValid = datasource => {
const isDatasourceValid = (datasource: { type: string; tableId: any }) => {
return datasource?.type === "table" && datasource?.tableId
}

const getRow = async id => {
const getRow = async (id: string) => {
const res = await API.searchTable(get(datasource).tableId, {
limit: 1,
query: {
Expand All @@ -40,7 +45,7 @@ export const createActions = (context: StoreContext) => {
return res?.rows?.[0]
}

const canUseColumn = name => {
const canUseColumn = (name: string) => {
return get(columns).some(col => col.name === name)
}

Expand Down
3 changes: 2 additions & 1 deletion packages/frontend-core/src/components/grid/stores/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Writable } from "svelte/store"
import type { APIClient } from "../../../api/types"

import * as Bounds from "./bounds"
import * as Columns from "./columns"
Expand Down Expand Up @@ -51,7 +52,7 @@ const DependencyOrderedStores = [
]

export interface BaseStore {
API: any
API: APIClient
}

export type Store = BaseStore &
Expand Down

0 comments on commit fafe91e

Please sign in to comment.