Skip to content

Commit

Permalink
Type nonPlus
Browse files Browse the repository at this point in the history
  • Loading branch information
adrinr committed Dec 20, 2024
1 parent a11859c commit 09b1dea
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
import { SortOrder } from "@budibase/types"
import { get } from "svelte/store"
import { Store as StoreContext } from ".."

export const createActions = context => {
interface NonPlusActions {
nonPlus: {
actions: {
saveDefinition: () => Promise<void>
addRow: () => Promise<void>
updateRow: () => Promise<void>
deleteRows: () => Promise<void>
getRow: () => Promise<void>
isDatasourceValid: (datasource: {
type: string
id: string
tableId: string
}) => boolean
canUseColumn: (name: string) => boolean
}
}
}

export type Store = NonPlusActions

export const createActions = (context: StoreContext): NonPlusActions => {
const { columns, table, viewV2 } = context

const saveDefinition = async () => {
Expand All @@ -20,7 +41,11 @@ export const createActions = context => {
throw "This datasource does not support fetching individual rows"
}

const isDatasourceValid = datasource => {
const isDatasourceValid = (datasource: {
type: string
id: string
tableId: string
}) => {
// There are many different types and shapes of datasource, so we only
// check that we aren't null
return (
Expand All @@ -30,7 +55,7 @@ export const createActions = context => {
)
}

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

Expand All @@ -50,11 +75,11 @@ export const createActions = context => {
}

// Small util to compare datasource definitions
const isSameDatasource = (a, b) => {
const isSameDatasource = (a: any, b: any) => {
return JSON.stringify(a) === JSON.stringify(b)
}

export const initialise = context => {
export const initialise = (context: StoreContext) => {
const {
datasource,
sort,
Expand All @@ -69,7 +94,7 @@ export const initialise = context => {
} = context
// Keep a list of subscriptions so that we can clear them when the datasource
// config changes
let unsubscribers = []
let unsubscribers: any[] = []

// Observe datasource changes and apply logic for view V2 datasources
datasource.subscribe($datasource => {
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
Expand Up @@ -58,7 +58,8 @@ export interface BaseStore {
export type Store = BaseStore &
Columns.Store &
Table.Store &
ViewV2.Store & {
ViewV2.Store &
NonPlus.Store & {
// TODO while typing the rest of stores
datasource: Writable<any> & { actions: any }
definition: Writable<any>
Expand Down

0 comments on commit 09b1dea

Please sign in to comment.