Type rows
This commit is contained in:
parent
8009ee7ec9
commit
067f38d0d8
|
@ -14,8 +14,12 @@ import { FieldType, Row, UIRow } from "@budibase/types"
|
||||||
import { getRelatedTableValues } from "../../../utils"
|
import { getRelatedTableValues } from "../../../utils"
|
||||||
import { Store as StoreContext } from "."
|
import { Store as StoreContext } from "."
|
||||||
|
|
||||||
|
interface IndexedUIRow extends UIRow {
|
||||||
|
__idx: number
|
||||||
|
}
|
||||||
|
|
||||||
interface RowStore {
|
interface RowStore {
|
||||||
rows: Writable<any[]>
|
rows: Writable<UIRow[]>
|
||||||
fetch: Writable<any>
|
fetch: Writable<any>
|
||||||
loaded: Writable<any>
|
loaded: Writable<any>
|
||||||
refreshing: Writable<boolean>
|
refreshing: Writable<boolean>
|
||||||
|
@ -28,7 +32,7 @@ interface RowStore {
|
||||||
|
|
||||||
interface RowDerivedStore {
|
interface RowDerivedStore {
|
||||||
rows: RowStore["rows"]
|
rows: RowStore["rows"]
|
||||||
rowLookupMap: Readable<any>
|
rowLookupMap: Readable<Record<string, IndexedUIRow>>
|
||||||
}
|
}
|
||||||
|
|
||||||
interface RowActionStore {
|
interface RowActionStore {
|
||||||
|
@ -96,7 +100,7 @@ export const deriveStores = (context: StoreContext): RowDerivedStore => {
|
||||||
const customColumns = Object.values($enrichedSchema || {}).filter(
|
const customColumns = Object.values($enrichedSchema || {}).filter(
|
||||||
f => f.related
|
f => f.related
|
||||||
)
|
)
|
||||||
return $rows.map((row, idx) => ({
|
return $rows.map<IndexedUIRow>((row, idx) => ({
|
||||||
...row,
|
...row,
|
||||||
__idx: idx,
|
__idx: idx,
|
||||||
...customColumns.reduce((map: any, column: any) => {
|
...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
|
// Generate a lookup map to quick find a row by ID
|
||||||
const rowLookupMap = derived(enrichedRows, $enrichedRows => {
|
const rowLookupMap = derived(enrichedRows, $enrichedRows => {
|
||||||
let map: Record<string, UIRow> = {}
|
let map: Record<string, IndexedUIRow> = {}
|
||||||
for (let i = 0; i < $enrichedRows.length; i++) {
|
for (let i = 0; i < $enrichedRows.length; i++) {
|
||||||
map[$enrichedRows[i]._id] = $enrichedRows[i]
|
map[$enrichedRows[i]._id] = $enrichedRows[i]
|
||||||
}
|
}
|
||||||
|
@ -560,7 +564,7 @@ export const createActions = (context: StoreContext): RowActionStore => {
|
||||||
if (savedRow?._id) {
|
if (savedRow?._id) {
|
||||||
if (updateState) {
|
if (updateState) {
|
||||||
rows.update(state => {
|
rows.update(state => {
|
||||||
state[row.__idx] = savedRow
|
state[row.__idx] = savedRow!
|
||||||
return state.slice()
|
return state.slice()
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
import { Row } from "@budibase/types"
|
import { Row } from "@budibase/types"
|
||||||
|
|
||||||
export type UIRow = Row & { _id: string }
|
export type UIRow = Row & {
|
||||||
|
_id: string
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue