Display related
This commit is contained in:
parent
77587c8686
commit
5519088376
|
@ -75,7 +75,7 @@ const getDefault = (schema = {}) => {
|
||||||
field: `${column.name}.${relColumn}`,
|
field: `${column.name}.${relColumn}`,
|
||||||
active: column.visible ?? true,
|
active: column.visible ?? true,
|
||||||
order,
|
order,
|
||||||
related: true,
|
related: { field: column.name, subField: relColumn },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,6 @@ export const deriveStores = context => {
|
||||||
...$schemaOverrides[field],
|
...$schemaOverrides[field],
|
||||||
name: field,
|
name: field,
|
||||||
type: FieldType.FORMULA,
|
type: FieldType.FORMULA,
|
||||||
related: true,
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import { tick } from "svelte"
|
||||||
import { Helpers } from "@budibase/bbui"
|
import { Helpers } from "@budibase/bbui"
|
||||||
import { sleep } from "../../../utils/utils"
|
import { sleep } from "../../../utils/utils"
|
||||||
import { FieldType } from "@budibase/types"
|
import { FieldType } from "@budibase/types"
|
||||||
|
import { processStringSync } from "@budibase/string-templates"
|
||||||
|
|
||||||
export const createStores = () => {
|
export const createStores = () => {
|
||||||
const rows = writable([])
|
const rows = writable([])
|
||||||
|
@ -42,15 +43,32 @@ export const createStores = () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const deriveStores = context => {
|
export const deriveStores = context => {
|
||||||
const { rows } = context
|
const { rows, enrichedSchema } = context
|
||||||
|
|
||||||
// Enrich rows with an index property and any pending changes
|
// Enrich rows with an index property and any pending changes
|
||||||
const enrichedRows = derived(rows, $rows => {
|
const enrichedRows = derived(
|
||||||
return $rows.map((row, idx) => ({
|
[rows, enrichedSchema],
|
||||||
...row,
|
([$rows, $enrichedSchema]) => {
|
||||||
__idx: idx,
|
const customColumns = Object.values($enrichedSchema || {}).filter(
|
||||||
}))
|
f => f.related
|
||||||
})
|
)
|
||||||
|
return $rows.map((row, idx) => ({
|
||||||
|
...row,
|
||||||
|
__idx: idx,
|
||||||
|
...customColumns.reduce((acc, c) => {
|
||||||
|
try {
|
||||||
|
acc[c.name] = processStringSync(
|
||||||
|
`{{ join (pluck ${c.related.field} '${c.related.subField}') ', ' }}`,
|
||||||
|
row
|
||||||
|
)
|
||||||
|
} catch {
|
||||||
|
// It might be some formula not set, or anything being incorrect
|
||||||
|
}
|
||||||
|
return acc
|
||||||
|
}, {}),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
// 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 => {
|
||||||
|
|
Loading…
Reference in New Issue