From 8958b8d14c924b9d3884e41d41f7e06f2c38413a Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 10:26:09 +0100 Subject: [PATCH 01/21] Type UIRow --- .../src/components/grid/stores/datasource.ts | 4 ++-- .../src/components/grid/stores/datasources/index.ts | 10 +++++----- packages/types/src/ui/stores/grid/index.ts | 1 + packages/types/src/ui/stores/grid/rows.ts | 3 +++ 4 files changed, 11 insertions(+), 7 deletions(-) create mode 100644 packages/types/src/ui/stores/grid/rows.ts diff --git a/packages/frontend-core/src/components/grid/stores/datasource.ts b/packages/frontend-core/src/components/grid/stores/datasource.ts index ce9f2837bb..b532a4cf8b 100644 --- a/packages/frontend-core/src/components/grid/stores/datasource.ts +++ b/packages/frontend-core/src/components/grid/stores/datasource.ts @@ -3,12 +3,12 @@ import { getDatasourceDefinition, getDatasourceSchema } from "../../../fetch" import { enrichSchemaWithRelColumns, memo } from "../../../utils" import { cloneDeep } from "lodash" import { - Row, SaveRowRequest, SaveTableRequest, UIDatasource, UIFieldMutation, UIFieldSchema, + UIRow, UpdateViewRequest, ViewV2Type, } from "@budibase/types" @@ -331,7 +331,7 @@ export const createActions = (context: StoreContext): ActionDatasourceStore => { } // Deletes rows from the datasource - const deleteRows = async (rows: Row[]) => { + const deleteRows = async (rows: UIRow[]) => { return await getAPI()?.actions.deleteRows(rows) } diff --git a/packages/frontend-core/src/components/grid/stores/datasources/index.ts b/packages/frontend-core/src/components/grid/stores/datasources/index.ts index c58aef37e9..05e2bd0188 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/index.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/index.ts @@ -1,8 +1,8 @@ import { - Row, SaveRowRequest, SaveTableRequest, UIDatasource, + UIRow, UpdateViewRequest, } from "@budibase/types" @@ -10,10 +10,10 @@ interface DatasourceBaseActions< TSaveDefinitionRequest = UpdateViewRequest | SaveTableRequest > { saveDefinition: (newDefinition: TSaveDefinitionRequest) => Promise - addRow: (row: SaveRowRequest) => Promise - updateRow: (row: SaveRowRequest) => Promise - deleteRows: (rows: Row[]) => Promise - getRow: (id: string) => Promise + addRow: (row: SaveRowRequest) => Promise + updateRow: (row: SaveRowRequest) => Promise + deleteRows: (rows: UIRow[]) => Promise + getRow: (id: string) => Promise isDatasourceValid: (datasource: UIDatasource) => boolean | void canUseColumn: (name: string) => boolean | void } diff --git a/packages/types/src/ui/stores/grid/index.ts b/packages/types/src/ui/stores/grid/index.ts index aa68c3f207..880c3834c1 100644 --- a/packages/types/src/ui/stores/grid/index.ts +++ b/packages/types/src/ui/stores/grid/index.ts @@ -4,3 +4,4 @@ export * from "./table" export * from "./view" export * from "./user" export * from "./filters" +export * from "./rows" diff --git a/packages/types/src/ui/stores/grid/rows.ts b/packages/types/src/ui/stores/grid/rows.ts new file mode 100644 index 0000000000..82065675d0 --- /dev/null +++ b/packages/types/src/ui/stores/grid/rows.ts @@ -0,0 +1,3 @@ +import { Row } from "@budibase/types" + +export type UIRow = Row & { _id: string } From 88026798dbc0869bd00f0ad923b24c80fbc2e4a2 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 10:29:19 +0100 Subject: [PATCH 02/21] Type validation actions --- .../src/components/grid/stores/validation.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/validation.ts b/packages/frontend-core/src/components/grid/stores/validation.ts index f118020b16..9db432d1a5 100644 --- a/packages/frontend-core/src/components/grid/stores/validation.ts +++ b/packages/frontend-core/src/components/grid/stores/validation.ts @@ -10,7 +10,17 @@ interface DerivedValidationStore { validationRowLookupMap: Readable> } -export type Store = ValidationStore & DerivedValidationStore +interface ValidationActions { + validation: ValidationStore["validation"] & { + actions: { + setError: (cellId: string | undefined, error: string) => void + rowHasErrors: (rowId: string) => boolean + focusFirstRowError: (rowId: string) => void + } + } +} + +export type Store = ValidationStore & DerivedValidationStore & ValidationActions // Normally we would break out actions into the explicit "createActions" // function, but for validation all these actions are pure so can go into @@ -49,7 +59,7 @@ export const deriveStores = (context: StoreContext): DerivedValidationStore => { } } -export const createActions = (context: StoreContext) => { +export const createActions = (context: StoreContext): ValidationActions => { const { validation, focusedCellId, validationRowLookupMap } = context const setError = (cellId: string | undefined, error: string) => { From f92eb73e11c7a49d43c63a21e010983817d32a15 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 10:34:54 +0100 Subject: [PATCH 03/21] Type column actions --- .../src/components/grid/stores/columns.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/columns.ts b/packages/frontend-core/src/components/grid/stores/columns.ts index 01cbf3af22..be525e2835 100644 --- a/packages/frontend-core/src/components/grid/stores/columns.ts +++ b/packages/frontend-core/src/components/grid/stores/columns.ts @@ -16,7 +16,16 @@ interface DerivedColumnStore { hasNonAutoColumn: Readable } -export type Store = ColumnStore & DerivedColumnStore +interface ColumnActions { + columns: ColumnStore["columns"] & { + actions: { + changeAllColumnWidths: (width: number) => Promise + isReadonly: (column: UIColumn) => boolean + } + } +} + +export type Store = ColumnStore & DerivedColumnStore & ColumnActions export const createStores = (): ColumnStore => { const columns = writable([]) @@ -95,7 +104,7 @@ export const deriveStores = (context: StoreContext): DerivedColumnStore => { } } -export const createActions = (context: StoreContext) => { +export const createActions = (context: StoreContext): ColumnActions => { const { columns, datasource } = context // Updates the width of all columns From 0c536102313db3c6a76d1df3364ccda745aec14f Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 17:38:43 +0100 Subject: [PATCH 04/21] Initial row conversion --- .../grid/stores/datasources/index.ts | 4 +- .../src/components/grid/stores/index.ts | 6 +- .../grid/stores/{rows.js => rows.ts} | 147 +++++++++++++----- 3 files changed, 113 insertions(+), 44 deletions(-) rename packages/frontend-core/src/components/grid/stores/{rows.js => rows.ts} (85%) diff --git a/packages/frontend-core/src/components/grid/stores/datasources/index.ts b/packages/frontend-core/src/components/grid/stores/datasources/index.ts index 05e2bd0188..4b04095c8e 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/index.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/index.ts @@ -10,8 +10,8 @@ interface DatasourceBaseActions< TSaveDefinitionRequest = UpdateViewRequest | SaveTableRequest > { saveDefinition: (newDefinition: TSaveDefinitionRequest) => Promise - addRow: (row: SaveRowRequest) => Promise - updateRow: (row: SaveRowRequest) => Promise + addRow: (row: SaveRowRequest) => Promise + updateRow: (row: SaveRowRequest) => Promise deleteRows: (rows: UIRow[]) => Promise getRow: (id: string) => Promise isDatasourceValid: (datasource: UIDatasource) => boolean | void diff --git a/packages/frontend-core/src/components/grid/stores/index.ts b/packages/frontend-core/src/components/grid/stores/index.ts index 2a68e30d25..ec11ed1da8 100644 --- a/packages/frontend-core/src/components/grid/stores/index.ts +++ b/packages/frontend-core/src/components/grid/stores/index.ts @@ -69,12 +69,10 @@ export type Store = BaseStore & Clipboard.Store & Scroll.Store & { // TODO while typing the rest of stores - fetch: Writable sort: Writable initialFilter: Writable initialSortColumn: Writable initialSortOrder: Writable - rows: Writable & { actions: any } subscribe: any config: Writable dispatch: (event: string, data: any) => any @@ -82,13 +80,11 @@ export type Store = BaseStore & schemaOverrides: Writable gridID: string props: Writable - rowLookupMap: Writable width: Writable fixedRowHeight: Writable - rowChangeCache: Readable bounds: Readable height: Readable - } + } & Rows.Store export const attachStores = (context: Store): Store => { // Atomic store creation diff --git a/packages/frontend-core/src/components/grid/stores/rows.js b/packages/frontend-core/src/components/grid/stores/rows.ts similarity index 85% rename from packages/frontend-core/src/components/grid/stores/rows.js rename to packages/frontend-core/src/components/grid/stores/rows.ts index 122bbc295a..7082b9fd03 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.js +++ b/packages/frontend-core/src/components/grid/stores/rows.ts @@ -1,4 +1,4 @@ -import { writable, derived, get } from "svelte/store" +import { writable, derived, get, Writable, Readable } from "svelte/store" import { fetchData } from "../../../fetch" import { NewRowID, RowPageSize } from "../lib/constants" import { @@ -10,10 +10,49 @@ import { import { tick } from "svelte" import { Helpers } from "@budibase/bbui" import { sleep } from "../../../utils/utils" -import { FieldType } from "@budibase/types" +import { FieldType, Row, UIRow } from "@budibase/types" import { getRelatedTableValues } from "../../../utils" +import { Store as StoreContext } from "." -export const createStores = () => { +interface RowStore { + rows: Writable + fetch: Writable + loaded: Writable + refreshing: Writable + loading: Writable + rowChangeCache: Writable + inProgressChanges: Writable + hasNextPage: Writable + error: Writable +} + +interface RowDerivedStore { + rows: RowStore["rows"] + rowLookupMap: Readable +} + +interface RowActionStore { + rows: RowStore["rows"] & { + actions: { + addRow: any + duplicateRow: any + bulkDuplicate: any + updateValue: any + applyRowChanges: any + deleteRows: any + loadNextPage: any + refreshRow: any + replaceRow: any + refreshData: any + cleanRow: any + bulkUpdate: any + } + } +} + +export type Store = RowStore & RowDerivedStore & RowActionStore + +export const createStores = (): RowStore => { const rows = writable([]) const loading = writable(false) const loaded = writable(false) @@ -47,7 +86,7 @@ export const createStores = () => { } } -export const deriveStores = context => { +export const deriveStores = (context: StoreContext): RowDerivedStore => { const { rows, enrichedSchema } = context // Enrich rows with an index property and any pending changes @@ -60,8 +99,8 @@ export const deriveStores = context => { return $rows.map((row, idx) => ({ ...row, __idx: idx, - ...customColumns.reduce((map, column) => { - const fromField = $enrichedSchema[column.related.field] + ...customColumns.reduce((map: any, column: any) => { + const fromField = $enrichedSchema![column.related!.field] map[column.name] = getRelatedTableValues(row, column, fromField) return map }, {}), @@ -71,7 +110,7 @@ export const deriveStores = context => { // Generate a lookup map to quick find a row by ID const rowLookupMap = derived(enrichedRows, $enrichedRows => { - let map = {} + let map: Record = {} for (let i = 0; i < $enrichedRows.length; i++) { map[$enrichedRows[i]._id] = $enrichedRows[i] } @@ -87,7 +126,7 @@ export const deriveStores = context => { } } -export const createActions = context => { +export const createActions = (context: StoreContext): RowActionStore => { const { rows, rowLookupMap, @@ -114,11 +153,11 @@ export const createActions = context => { const instanceLoaded = writable(false) // Local cache of row IDs to speed up checking if a row exists - let rowCacheMap = {} + let rowCacheMap: Record = {} // Reset everything when datasource changes - let unsubscribe = null - let lastResetKey = null + let unsubscribe: (() => void) | null = null + let lastResetKey: string | null = null datasource.subscribe(async $datasource => { // Unsub from previous fetch if one exists unsubscribe?.() @@ -157,7 +196,7 @@ export const createActions = context => { }) // Subscribe to changes of this fetch model - unsubscribe = newFetch.subscribe(async $fetch => { + unsubscribe = newFetch.subscribe(async ($fetch: any) => { if ($fetch.error) { // Present a helpful error to the user let message = "An unknown error occurred" @@ -214,7 +253,7 @@ export const createActions = context => { // Handles validation errors from the rows API and updates local validation // state, storing error messages against relevant cells - const handleValidationError = (rowId, error) => { + const handleValidationError = (rowId: string, error: any) => { let errorString if (typeof error === "string") { errorString = error @@ -287,9 +326,19 @@ export const createActions = context => { } // Adds a new row - const addRow = async ({ row, idx, bubble = false, notify = true }) => { + const addRow = async ({ + row, + idx, + bubble = false, + notify = true, + }: { + row: Row + idx: number + bubble: boolean + notify: boolean + }) => { try { - const newRow = await datasource.actions.addRow(row) + const newRow = (await datasource.actions.addRow(row))! // Update state if (idx != null) { @@ -317,7 +366,7 @@ export const createActions = context => { } // Duplicates a row, inserting the duplicate row after the existing one - const duplicateRow = async row => { + const duplicateRow = async (row: UIRow) => { let clone = cleanRow(row) delete clone._id delete clone._rev @@ -337,10 +386,13 @@ export const createActions = context => { } // Duplicates multiple rows, inserting them after the last source row - const bulkDuplicate = async (rowsToDupe, progressCallback) => { + const bulkDuplicate = async ( + rowsToDupe: UIRow[], + progressCallback: (any: number) => void + ) => { // Find index of last row const $rowLookupMap = get(rowLookupMap) - const indices = rowsToDupe.map(row => $rowLookupMap[row._id]?.__idx) + const indices = rowsToDupe.map(row => $rowLookupMap[row._id!]?.__idx) const index = Math.max(...indices) const count = rowsToDupe.length @@ -357,8 +409,9 @@ export const createActions = context => { let failed = 0 for (let i = 0; i < count; i++) { try { - saved.push(await datasource.actions.addRow(clones[i])) - rowCacheMap[saved._id] = true + const newRow = (await datasource.actions.addRow(clones[i]))! + saved.push(newRow) + rowCacheMap[newRow._id] = true await sleep(50) // Small sleep to ensure we avoid rate limiting } catch (error) { failed++ @@ -370,7 +423,7 @@ export const createActions = context => { // Add to state if (saved.length) { rows.update(state => { - return state.toSpliced(index + 1, 0, ...saved) + return state.splice(index + 1, 0, ...saved) }) } @@ -385,7 +438,7 @@ export const createActions = context => { // Replaces a row in state with the newly defined row, handling updates, // addition and deletion - const replaceRow = (id, row) => { + const replaceRow = (id: string, row: UIRow | undefined) => { // Get index of row to check if it exists const $rows = get(rows) const $rowLookupMap = get(rowLookupMap) @@ -410,10 +463,10 @@ export const createActions = context => { } // Refreshes a specific row - const refreshRow = async id => { + const refreshRow = async (id: string) => { try { const row = await datasource.actions.getRow(id) - replaceRow(id, row) + replaceRow(id, row!) } catch { // Do nothing - we probably just don't support refreshing individual rows } @@ -425,7 +478,7 @@ export const createActions = context => { } // Checks if a changeset for a row actually mutates the row or not - const changesAreValid = (row, changes) => { + const changesAreValid = (row: UIRow, changes: Record) => { const columns = Object.keys(changes || {}) if (!row || !columns.length) { return false @@ -437,7 +490,7 @@ export const createActions = context => { // Patches a row with some changes in local state, and returns whether a // valid pending change was made or not - const stashRowChanges = (rowId, changes) => { + const stashRowChanges = (rowId: string, changes: Record) => { const $rowLookupMap = get(rowLookupMap) const $columnLookupMap = get(columnLookupMap) const row = $rowLookupMap[rowId] @@ -477,13 +530,18 @@ export const createActions = context => { changes = null, updateState = true, handleErrors = true, + }: { + rowId: string + changes?: any + updateState?: boolean + handleErrors?: boolean }) => { const $rowLookupMap = get(rowLookupMap) const row = $rowLookupMap[rowId] if (row == null) { return } - let savedRow + let savedRow: UIRow | undefined = undefined // Save change try { @@ -496,7 +554,7 @@ export const createActions = context => { // Update row const stashedChanges = get(rowChangeCache)[rowId] const newRow = { ...cleanRow(row), ...stashedChanges, ...changes } - savedRow = await datasource.actions.updateRow(newRow) + savedRow = (await datasource.actions.updateRow(newRow))! // Update row state after a successful change if (savedRow?._id) { @@ -537,14 +595,27 @@ export const createActions = context => { } // Updates a value of a row - const updateValue = async ({ rowId, column, value, apply = true }) => { + const updateValue = async ({ + rowId, + column, + value, + apply = true, + }: { + rowId: string + column: any + value: any + apply: boolean + }) => { const success = stashRowChanges(rowId, { [column]: value }) if (success && apply) { await applyRowChanges({ rowId }) } } - const bulkUpdate = async (changeMap, progressCallback) => { + const bulkUpdate = async ( + changeMap: Record, + progressCallback: (any: number) => void + ) => { const rowIds = Object.keys(changeMap || {}) const count = rowIds.length if (!count) { @@ -613,7 +684,7 @@ export const createActions = context => { } // Deletes an array of rows - const deleteRows = async rowsToDelete => { + const deleteRows = async (rowsToDelete: UIRow[]) => { if (!rowsToDelete?.length) { return } @@ -628,7 +699,7 @@ export const createActions = context => { // Local handler to process new rows inside the fetch, and append any new // rows to state that we haven't encountered before - const handleNewRows = (newRows, resetRows) => { + const handleNewRows = (newRows: UIRow[], resetRows?: boolean) => { if (resetRows) { rowCacheMap = {} } @@ -658,7 +729,7 @@ export const createActions = context => { } // Local handler to remove rows from state - const handleRemoveRows = rowsToRemove => { + const handleRemoveRows = (rowsToRemove: UIRow[]) => { const deletedIds = rowsToRemove.map(row => row._id) // We deliberately do not remove IDs from the cache map as the data may @@ -675,11 +746,11 @@ export const createActions = context => { // Cleans a row by removing any internal grid metadata from it. // Call this before passing a row to any sort of external flow. - const cleanRow = row => { + const cleanRow = (row: Row) => { let clone = { ...row } delete clone.__idx delete clone.__metadata - if (!get(hasBudibaseIdentifiers) && isGeneratedRowID(clone._id)) { + if (!get(hasBudibaseIdentifiers) && isGeneratedRowID(clone._id!)) { delete clone._id } return clone @@ -706,7 +777,7 @@ export const createActions = context => { } } -export const initialise = context => { +export const initialise = (context: StoreContext) => { const { rowChangeCache, inProgressChanges, @@ -733,7 +804,9 @@ export const initialise = context => { if (!id) { return } - const { rowId, field } = parseCellID(id) + let { rowId, field } = parseCellID(id) + rowId = rowId! + field = field! const hasChanges = field in (get(rowChangeCache)[rowId] || {}) const hasErrors = validation.actions.rowHasErrors(rowId) const isSavingChanges = get(inProgressChanges)[rowId] From e9826f7efd671021fb3802077361c5674e4a23d3 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 17:42:33 +0100 Subject: [PATCH 05/21] Revert toSpliced to splice --- packages/frontend-core/src/components/grid/stores/rows.ts | 2 +- packages/frontend-core/tsconfig.json | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/frontend-core/src/components/grid/stores/rows.ts b/packages/frontend-core/src/components/grid/stores/rows.ts index 7082b9fd03..f494bf51ae 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.ts +++ b/packages/frontend-core/src/components/grid/stores/rows.ts @@ -423,7 +423,7 @@ export const createActions = (context: StoreContext): RowActionStore => { // Add to state if (saved.length) { rows.update(state => { - return state.splice(index + 1, 0, ...saved) + return state.toSpliced(index + 1, 0, ...saved) }) } diff --git a/packages/frontend-core/tsconfig.json b/packages/frontend-core/tsconfig.json index 8ffb3f19be..d06da5a713 100644 --- a/packages/frontend-core/tsconfig.json +++ b/packages/frontend-core/tsconfig.json @@ -2,6 +2,7 @@ "extends": "../../tsconfig.build.json", "compilerOptions": { "target": "ESNext", + "lib": ["ESNext"], "module": "preserve", "moduleResolution": "bundler", "outDir": "./dist", From 2526997b47a26d3e3bbd2b0102ed3f98d875a969 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 17:44:50 +0100 Subject: [PATCH 06/21] Type anys --- packages/frontend-core/src/components/grid/stores/rows.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/rows.ts b/packages/frontend-core/src/components/grid/stores/rows.ts index f494bf51ae..c8dd340d58 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.ts +++ b/packages/frontend-core/src/components/grid/stores/rows.ts @@ -18,11 +18,11 @@ interface RowStore { rows: Writable fetch: Writable loaded: Writable - refreshing: Writable - loading: Writable + refreshing: Writable + loading: Writable rowChangeCache: Writable inProgressChanges: Writable - hasNextPage: Writable + hasNextPage: Writable error: Writable } From 8009ee7ec9b5900654bbf0f4e1498ce80544cdcf Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 17:47:11 +0100 Subject: [PATCH 07/21] Fix row types --- .../src/components/grid/stores/datasources/table.ts | 10 ++++++++-- .../src/components/grid/stores/datasources/viewV2.ts | 11 +++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasources/table.ts b/packages/frontend-core/src/components/grid/stores/datasources/table.ts index 894a65ba4c..65d68a7d5d 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/table.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/table.ts @@ -31,7 +31,8 @@ export const createActions = (context: StoreContext): TableActions => { ...row, tableId: get(datasource)?.tableId, } - return await API.saveRow(row, SuppressErrors) + const newRow = await API.saveRow(row, SuppressErrors) + return { ...newRow, _id: newRow._id! } } const deleteRows = async (rows: Row[]) => { @@ -52,7 +53,12 @@ export const createActions = (context: StoreContext): TableActions => { }, paginate: false, }) - return res?.rows?.[0] + const row = res?.rows?.[0] + if (!row) { + return + } + + return { ...row, _id: row._id! } } const canUseColumn = (name: string) => { diff --git a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts index d9cac5397d..e18b9f71c0 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/viewV2.ts @@ -34,8 +34,10 @@ export const createActions = (context: StoreContext): ViewActions => { tableId: $datasource?.tableId, _viewId: $datasource?.id, } + const newRow = await API.saveRow(row, SuppressErrors) return { - ...(await API.saveRow(row, SuppressErrors)), + ...newRow, + _id: newRow._id!, _viewId: row._viewId, } } @@ -54,7 +56,12 @@ export const createActions = (context: StoreContext): ViewActions => { }, paginate: false, }) - return res?.rows?.[0] + const row = res?.rows?.[0] + if (!row) { + return + } + + return { ...row, _id: row._id! } } const isDatasourceValid = (datasource: UIDatasource) => { From 067f38d0d84d7d0760d078237748510715fa5348 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 17:55:24 +0100 Subject: [PATCH 08/21] Type rows --- .../src/components/grid/stores/rows.ts | 14 +++++++++----- packages/types/src/ui/stores/grid/rows.ts | 4 +++- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/rows.ts b/packages/frontend-core/src/components/grid/stores/rows.ts index c8dd340d58..61acff5612 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.ts +++ b/packages/frontend-core/src/components/grid/stores/rows.ts @@ -14,8 +14,12 @@ import { FieldType, Row, UIRow } from "@budibase/types" import { getRelatedTableValues } from "../../../utils" import { Store as StoreContext } from "." +interface IndexedUIRow extends UIRow { + __idx: number +} + interface RowStore { - rows: Writable + rows: Writable fetch: Writable loaded: Writable refreshing: Writable @@ -28,7 +32,7 @@ interface RowStore { interface RowDerivedStore { rows: RowStore["rows"] - rowLookupMap: Readable + rowLookupMap: Readable> } interface RowActionStore { @@ -96,7 +100,7 @@ export const deriveStores = (context: StoreContext): RowDerivedStore => { const customColumns = Object.values($enrichedSchema || {}).filter( f => f.related ) - return $rows.map((row, idx) => ({ + return $rows.map((row, idx) => ({ ...row, __idx: idx, ...customColumns.reduce((map: any, column: any) => { @@ -110,7 +114,7 @@ export const deriveStores = (context: StoreContext): RowDerivedStore => { // Generate a lookup map to quick find a row by ID const rowLookupMap = derived(enrichedRows, $enrichedRows => { - let map: Record = {} + let map: Record = {} for (let i = 0; i < $enrichedRows.length; i++) { map[$enrichedRows[i]._id] = $enrichedRows[i] } @@ -560,7 +564,7 @@ export const createActions = (context: StoreContext): RowActionStore => { if (savedRow?._id) { if (updateState) { rows.update(state => { - state[row.__idx] = savedRow + state[row.__idx] = savedRow! return state.slice() }) } diff --git a/packages/types/src/ui/stores/grid/rows.ts b/packages/types/src/ui/stores/grid/rows.ts index 82065675d0..accb104a1a 100644 --- a/packages/types/src/ui/stores/grid/rows.ts +++ b/packages/types/src/ui/stores/grid/rows.ts @@ -1,3 +1,5 @@ import { Row } from "@budibase/types" -export type UIRow = Row & { _id: string } +export type UIRow = Row & { + _id: string +} From d67783df9720db86f579b88fd70865e9b9a2ffb7 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 17:57:51 +0100 Subject: [PATCH 09/21] Type anys --- packages/frontend-core/src/components/grid/stores/rows.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/rows.ts b/packages/frontend-core/src/components/grid/stores/rows.ts index 61acff5612..263a3c1469 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.ts +++ b/packages/frontend-core/src/components/grid/stores/rows.ts @@ -21,13 +21,13 @@ interface IndexedUIRow extends UIRow { interface RowStore { rows: Writable fetch: Writable - loaded: Writable + loaded: Writable refreshing: Writable loading: Writable rowChangeCache: Writable inProgressChanges: Writable hasNextPage: Writable - error: Writable + error: Writable } interface RowDerivedStore { From e3518b66a41a5fccd5d51fa62fd7f7cec1d97cfc Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 18:05:23 +0100 Subject: [PATCH 10/21] Type search api --- packages/frontend-core/src/components/grid/stores/rows.ts | 4 ++-- packages/types/src/ui/stores/grid/fetch.ts | 4 ++++ packages/types/src/ui/stores/grid/index.ts | 1 + 3 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 packages/types/src/ui/stores/grid/fetch.ts diff --git a/packages/frontend-core/src/components/grid/stores/rows.ts b/packages/frontend-core/src/components/grid/stores/rows.ts index 263a3c1469..f65730bd02 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.ts +++ b/packages/frontend-core/src/components/grid/stores/rows.ts @@ -10,7 +10,7 @@ import { import { tick } from "svelte" import { Helpers } from "@budibase/bbui" import { sleep } from "../../../utils/utils" -import { FieldType, Row, UIRow } from "@budibase/types" +import { FieldType, Row, UIFetchAPI, UIRow } from "@budibase/types" import { getRelatedTableValues } from "../../../utils" import { Store as StoreContext } from "." @@ -20,7 +20,7 @@ interface IndexedUIRow extends UIRow { interface RowStore { rows: Writable - fetch: Writable + fetch: Writable loaded: Writable refreshing: Writable loading: Writable diff --git a/packages/types/src/ui/stores/grid/fetch.ts b/packages/types/src/ui/stores/grid/fetch.ts new file mode 100644 index 0000000000..cca738bb0d --- /dev/null +++ b/packages/types/src/ui/stores/grid/fetch.ts @@ -0,0 +1,4 @@ +export interface UIFetchAPI { + getInitialData: () => Promise + nextPage: () => Promise +} diff --git a/packages/types/src/ui/stores/grid/index.ts b/packages/types/src/ui/stores/grid/index.ts index 880c3834c1..82126f13aa 100644 --- a/packages/types/src/ui/stores/grid/index.ts +++ b/packages/types/src/ui/stores/grid/index.ts @@ -5,3 +5,4 @@ export * from "./view" export * from "./user" export * from "./filters" export * from "./rows" +export * from "./fetch" From c1c95a60739eefcf627b4f30a07cbce4d5f03614 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 18:07:47 +0100 Subject: [PATCH 11/21] Fix tsconfig --- packages/builder/tsconfig.json | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/builder/tsconfig.json b/packages/builder/tsconfig.json index da5dcd67c6..77d77b618f 100644 --- a/packages/builder/tsconfig.json +++ b/packages/builder/tsconfig.json @@ -2,6 +2,7 @@ "extends": "./tsconfig.build.json", "compilerOptions": { "outDir": "./dist", + "lib": ["ESNext"], "baseUrl": ".", "paths": { "assets/*": ["./assets/*"], From e7920aeb34e14e0dae66f9bea1bf8e7b6ff848dd Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 18:15:33 +0100 Subject: [PATCH 12/21] Fix ui actions usage --- .../src/components/grid/stores/ui.ts | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/ui.ts b/packages/frontend-core/src/components/grid/stores/ui.ts index 45baebe4fe..3cde73207e 100644 --- a/packages/frontend-core/src/components/grid/stores/ui.ts +++ b/packages/frontend-core/src/components/grid/stores/ui.ts @@ -40,12 +40,21 @@ export interface UIDerivedStore { compact: Readable selectedRowCount: Readable isSelectingCells: Readable - selectedCells: Readable & { actions: any } + selectedCells: Readable selectedCellMap: Readable> selectedCellCount: Readable } -export type Store = UIStore & UIDerivedStore +interface UIActionStore { + selectedCells: UIDerivedStore["selectedCells"] & { + actions: { + clear: () => void + selectRange: (source: string | null, target: string | null) => void + } + } +} + +export type Store = UIStore & UIDerivedStore & UIActionStore export const createStores = (context: StoreContext): UIStore => { const { props } = context @@ -82,7 +91,7 @@ export const createStores = (context: StoreContext): UIStore => { } } -export const deriveStores = (context: StoreContext) => { +export const deriveStores = (context: StoreContext): UIDerivedStore => { const { focusedCellId, rows, @@ -97,14 +106,14 @@ export const deriveStores = (context: StoreContext) => { // Derive the current focused row ID const focusedRowId = derived(focusedCellId, $focusedCellId => { - return parseCellID($focusedCellId).rowId + return parseCellID($focusedCellId).rowId ?? null }) // Derive the row that contains the selected cell const focusedRow = derived( [focusedRowId, rowLookupMap], ([$focusedRowId, $rowLookupMap]) => { - if ($focusedRowId === undefined) { + if ($focusedRowId === null) { return } From 911fb59d5dc59276e090fa48107d2caab7fee8e8 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 18:16:31 +0100 Subject: [PATCH 13/21] Type anys from stores --- packages/frontend-core/src/components/grid/stores/rows.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/rows.ts b/packages/frontend-core/src/components/grid/stores/rows.ts index f65730bd02..ffdc3f704a 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.ts +++ b/packages/frontend-core/src/components/grid/stores/rows.ts @@ -24,8 +24,8 @@ interface RowStore { loaded: Writable refreshing: Writable loading: Writable - rowChangeCache: Writable - inProgressChanges: Writable + rowChangeCache: Writable> + inProgressChanges: Writable> hasNextPage: Writable error: Writable } From c4935ef60a7f3e2a1027b71b1e7435f3166b4323 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 18:19:16 +0100 Subject: [PATCH 14/21] Type action store --- .../src/components/grid/stores/rows.ts | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/rows.ts b/packages/frontend-core/src/components/grid/stores/rows.ts index ffdc3f704a..4b5b4121f5 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.ts +++ b/packages/frontend-core/src/components/grid/stores/rows.ts @@ -38,10 +38,23 @@ interface RowDerivedStore { interface RowActionStore { rows: RowStore["rows"] & { actions: { - addRow: any - duplicateRow: any - bulkDuplicate: any - updateValue: any + addRow: (params: { + row: Row + idx: number + bubble: boolean + notify: boolean + }) => Promise + duplicateRow: (row: UIRow) => Promise + bulkDuplicate: ( + rowsToDupe: UIRow[], + progressCallback: (any: number) => void + ) => Promise + updateValue: (params: { + rowId: string + column: any + value: any + apply: boolean + }) => Promise applyRowChanges: any deleteRows: any loadNextPage: any From 3d53609eb240f3c5a421b936019bd4ef88270554 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 18:21:16 +0100 Subject: [PATCH 15/21] Type action store --- .../src/components/grid/stores/rows.ts | 28 ++++++++++++------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/rows.ts b/packages/frontend-core/src/components/grid/stores/rows.ts index 4b5b4121f5..b8bb1142aa 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.ts +++ b/packages/frontend-core/src/components/grid/stores/rows.ts @@ -55,14 +55,22 @@ interface RowActionStore { value: any apply: boolean }) => Promise - applyRowChanges: any - deleteRows: any - loadNextPage: any - refreshRow: any - replaceRow: any - refreshData: any - cleanRow: any - bulkUpdate: any + applyRowChanges: (params: { + rowId: string + changes?: any + updateState?: boolean + handleErrors?: boolean + }) => Promise + deleteRows: (rowsToDelete: UIRow[]) => Promise + loadNextPage: () => void + refreshRow: (id: string) => Promise + replaceRow: (id: string, row: UIRow | undefined) => void + refreshData: () => void + cleanRow: (row: UIRow) => Row + bulkUpdate: ( + changeMap: Record, + progressCallback: (any: number) => void + ) => Promise } } } @@ -763,8 +771,8 @@ export const createActions = (context: StoreContext): RowActionStore => { // Cleans a row by removing any internal grid metadata from it. // Call this before passing a row to any sort of external flow. - const cleanRow = (row: Row) => { - let clone = { ...row } + const cleanRow = (row: UIRow) => { + let clone: Row = { ...row } delete clone.__idx delete clone.__metadata if (!get(hasBudibaseIdentifiers) && isGeneratedRowID(clone._id!)) { From aff3f01922ec75f9515696e65278b586709f7439 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 18:29:01 +0100 Subject: [PATCH 16/21] Type anys --- packages/frontend-core/src/components/grid/stores/rows.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/rows.ts b/packages/frontend-core/src/components/grid/stores/rows.ts index b8bb1142aa..7e37afadf8 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.ts +++ b/packages/frontend-core/src/components/grid/stores/rows.ts @@ -24,8 +24,8 @@ interface RowStore { loaded: Writable refreshing: Writable loading: Writable - rowChangeCache: Writable> - inProgressChanges: Writable> + rowChangeCache: Writable>> + inProgressChanges: Writable> hasNextPage: Writable error: Writable } From 63ed4fbf7c2b91e9534f5799e61cc97d959771f6 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 18:32:34 +0100 Subject: [PATCH 17/21] Type anys --- .../src/components/grid/stores/rows.ts | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/rows.ts b/packages/frontend-core/src/components/grid/stores/rows.ts index 7e37afadf8..0651435a7e 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.ts +++ b/packages/frontend-core/src/components/grid/stores/rows.ts @@ -47,17 +47,17 @@ interface RowActionStore { duplicateRow: (row: UIRow) => Promise bulkDuplicate: ( rowsToDupe: UIRow[], - progressCallback: (any: number) => void + progressCallback: (progressPercentage: number) => void ) => Promise updateValue: (params: { rowId: string - column: any + column: string value: any apply: boolean }) => Promise applyRowChanges: (params: { rowId: string - changes?: any + changes?: Record updateState?: boolean handleErrors?: boolean }) => Promise @@ -68,8 +68,8 @@ interface RowActionStore { refreshData: () => void cleanRow: (row: UIRow) => Row bulkUpdate: ( - changeMap: Record, - progressCallback: (any: number) => void + changeMap: Record>, + progressCallback: (progressPercentage: number) => void ) => Promise } } @@ -413,7 +413,7 @@ export const createActions = (context: StoreContext): RowActionStore => { // Duplicates multiple rows, inserting them after the last source row const bulkDuplicate = async ( rowsToDupe: UIRow[], - progressCallback: (any: number) => void + progressCallback: (progressPercentage: number) => void ) => { // Find index of last row const $rowLookupMap = get(rowLookupMap) @@ -557,7 +557,7 @@ export const createActions = (context: StoreContext): RowActionStore => { handleErrors = true, }: { rowId: string - changes?: any + changes?: Record | null updateState?: boolean handleErrors?: boolean }) => { @@ -627,7 +627,7 @@ export const createActions = (context: StoreContext): RowActionStore => { apply = true, }: { rowId: string - column: any + column: string value: any apply: boolean }) => { @@ -638,8 +638,8 @@ export const createActions = (context: StoreContext): RowActionStore => { } const bulkUpdate = async ( - changeMap: Record, - progressCallback: (any: number) => void + changeMap: Record>, + progressCallback: (progressPercentage: number) => void ) => { const rowIds = Object.keys(changeMap || {}) const count = rowIds.length From b37e1e65b0d11c2ed1339a0549e0b2fde562eaba Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 18:35:10 +0100 Subject: [PATCH 18/21] More types --- packages/frontend-core/src/components/grid/stores/rows.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/rows.ts b/packages/frontend-core/src/components/grid/stores/rows.ts index 0651435a7e..cc60f46463 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.ts +++ b/packages/frontend-core/src/components/grid/stores/rows.ts @@ -124,9 +124,13 @@ export const deriveStores = (context: StoreContext): RowDerivedStore => { return $rows.map((row, idx) => ({ ...row, __idx: idx, - ...customColumns.reduce((map: any, column: any) => { + ...customColumns.reduce>((map, column) => { const fromField = $enrichedSchema![column.related!.field] - map[column.name] = getRelatedTableValues(row, column, fromField) + map[column.name] = getRelatedTableValues( + row, + { ...column, related: column.related! }, + fromField + ) return map }, {}), })) From 4f8f23c1b38691a4d230e72f79c95743793d3e2a Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 18:47:37 +0100 Subject: [PATCH 19/21] More types --- .../src/components/grid/stores/rows.ts | 40 ++++++++++++------- packages/types/src/ui/stores/grid/fetch.ts | 13 ++++++ 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/rows.ts b/packages/frontend-core/src/components/grid/stores/rows.ts index cc60f46463..4eb3cd9380 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.ts +++ b/packages/frontend-core/src/components/grid/stores/rows.ts @@ -225,7 +225,7 @@ export const createActions = (context: StoreContext): RowActionStore => { }) // Subscribe to changes of this fetch model - unsubscribe = newFetch.subscribe(async ($fetch: any) => { + unsubscribe = newFetch.subscribe(async ($fetch: UIFetchAPI) => { if ($fetch.error) { // Present a helpful error to the user let message = "An unknown error occurred" @@ -282,7 +282,15 @@ export const createActions = (context: StoreContext): RowActionStore => { // Handles validation errors from the rows API and updates local validation // state, storing error messages against relevant cells - const handleValidationError = (rowId: string, error: any) => { + const handleValidationError = ( + rowId: string, + error: + | string + | { + message?: string + json: { validationErrors: Record } + } + ) => { let errorString if (typeof error === "string") { errorString = error @@ -292,7 +300,11 @@ export const createActions = (context: StoreContext): RowActionStore => { // If the server doesn't reply with a valid error, assume that the source // of the error is the focused cell's column - if (!error?.json?.validationErrors && errorString) { + if ( + typeof error !== "string" && + !error?.json?.validationErrors && + errorString + ) { const { field: focusedColumn } = parseCellID(get(focusedCellId)) if (focusedColumn) { error = { @@ -304,7 +316,7 @@ export const createActions = (context: StoreContext): RowActionStore => { } } } - if (error?.json?.validationErrors) { + if (typeof error !== "string" && error?.json?.validationErrors) { // Normal validation errors const keys = Object.keys(error.json.validationErrors) const $columns = get(columns) @@ -319,11 +331,11 @@ export const createActions = (context: StoreContext): RowActionStore => { missingColumns.push(column) } } - + const { json } = error // Process errors for columns that we have for (let column of erroredColumns) { // Ensure we have a valid error to display - let err = error.json.validationErrors[column] + let err = json.validationErrors[column] if (Array.isArray(err)) { err = err[0] } @@ -384,7 +396,7 @@ export const createActions = (context: StoreContext): RowActionStore => { get(notifications).success("Row created successfully") } return newRow - } catch (error) { + } catch (error: any) { if (bubble) { throw error } else { @@ -408,7 +420,7 @@ export const createActions = (context: StoreContext): RowActionStore => { }) get(notifications).success("Duplicated 1 row") return duped - } catch (error) { + } catch (error: any) { handleValidationError(row._id, error) validation.actions.focusFirstRowError(row._id) } @@ -608,7 +620,7 @@ export const createActions = (context: StoreContext): RowActionStore => { }) return state }) - } catch (error) { + } catch (error: any) { if (handleErrors) { handleValidationError(rowId, error) validation.actions.focusFirstRowError(rowId) @@ -728,7 +740,7 @@ export const createActions = (context: StoreContext): RowActionStore => { // Local handler to process new rows inside the fetch, and append any new // rows to state that we haven't encountered before - const handleNewRows = (newRows: UIRow[], resetRows?: boolean) => { + const handleNewRows = (newRows: Row[], resetRows?: boolean) => { if (resetRows) { rowCacheMap = {} } @@ -745,15 +757,15 @@ export const createActions = (context: StoreContext): RowActionStore => { newRow._id = generateRowID() } - if (!rowCacheMap[newRow._id]) { - rowCacheMap[newRow._id] = true + if (!rowCacheMap[newRow._id!]) { + rowCacheMap[newRow._id!] = true rowsToAppend.push(newRow) } } if (resetRows) { - rows.set(rowsToAppend) + rows.set(rowsToAppend as UIRow[]) } else if (rowsToAppend.length) { - rows.update(state => [...state, ...rowsToAppend]) + rows.update(state => [...state, ...(rowsToAppend as UIRow[])]) } } diff --git a/packages/types/src/ui/stores/grid/fetch.ts b/packages/types/src/ui/stores/grid/fetch.ts index cca738bb0d..490c027a9d 100644 --- a/packages/types/src/ui/stores/grid/fetch.ts +++ b/packages/types/src/ui/stores/grid/fetch.ts @@ -1,4 +1,17 @@ +import { Row, UIDatasource } from "@budibase/types" + export interface UIFetchAPI { + definition: UIDatasource + getInitialData: () => Promise + loading: any + loaded: boolean + + resetKey: string | null + error: any + + hasNextPage: boolean nextPage: () => Promise + + rows: Row[] } From 9c686cf7ca6a0c2936713b51f17d117b67fe57d7 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 30 Dec 2024 22:47:27 +0100 Subject: [PATCH 20/21] Fix types --- packages/types/src/ui/stores/grid/fetch.ts | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/packages/types/src/ui/stores/grid/fetch.ts b/packages/types/src/ui/stores/grid/fetch.ts index 490c027a9d..8901acc08b 100644 --- a/packages/types/src/ui/stores/grid/fetch.ts +++ b/packages/types/src/ui/stores/grid/fetch.ts @@ -1,4 +1,10 @@ -import { Row, UIDatasource } from "@budibase/types" +import { + Row, + SortOrder, + UIDatasource, + UILegacyFilter, + UISearchFilter, +} from "@budibase/types" export interface UIFetchAPI { definition: UIDatasource @@ -14,4 +20,19 @@ export interface UIFetchAPI { nextPage: () => Promise rows: Row[] + + options?: { + datasource?: { + tableId: string + id: string + } + } + update: ({ + sortOrder, + sortColumn, + }: { + sortOrder?: SortOrder + sortColumn?: string + filter?: UILegacyFilter[] | UISearchFilter + }) => any } From a41f0292a034d56b8dd7d0ea1ecf31f425042dd2 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Mon, 30 Dec 2024 22:47:41 +0100 Subject: [PATCH 21/21] Update promises --- .../src/components/grid/stores/datasources/nonPlus.ts | 4 ++-- packages/frontend-core/src/components/grid/stores/rows.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts b/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts index 17e5e8b8d9..15bbc9b396 100644 --- a/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts +++ b/packages/frontend-core/src/components/grid/stores/datasources/nonPlus.ts @@ -106,7 +106,7 @@ export const initialise = (context: StoreContext) => { if (!isSameDatasource($fetch?.options?.datasource, $datasource)) { return } - $fetch.update({ + $fetch?.update({ filter: $allFilters, }) }) @@ -120,7 +120,7 @@ export const initialise = (context: StoreContext) => { if (!isSameDatasource($fetch?.options?.datasource, $datasource)) { return } - $fetch.update({ + $fetch?.update({ sortOrder: $sort.order || SortOrder.ASCENDING, sortColumn: $sort.column, }) diff --git a/packages/frontend-core/src/components/grid/stores/rows.ts b/packages/frontend-core/src/components/grid/stores/rows.ts index 4eb3cd9380..d6b80df885 100644 --- a/packages/frontend-core/src/components/grid/stores/rows.ts +++ b/packages/frontend-core/src/components/grid/stores/rows.ts @@ -65,7 +65,7 @@ interface RowActionStore { loadNextPage: () => void refreshRow: (id: string) => Promise replaceRow: (id: string, row: UIRow | undefined) => void - refreshData: () => void + refreshData: () => Promise cleanRow: (row: UIRow) => Row bulkUpdate: ( changeMap: Record>, @@ -514,8 +514,8 @@ export const createActions = (context: StoreContext): RowActionStore => { } // Refreshes all data - const refreshData = () => { - get(fetch)?.getInitialData() + const refreshData = async () => { + await get(fetch)?.getInitialData() } // Checks if a changeset for a row actually mutates the row or not