From 067f38d0d84d7d0760d078237748510715fa5348 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Fri, 27 Dec 2024 17:55:24 +0100 Subject: [PATCH] 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 +}