1
0
Fork 0
mirror of synced 2024-08-14 17:42:01 +12:00

Fix datasource definitions to ensure they work with both tables and views, for both type datasource and type table, and fix bindings

This commit is contained in:
Andrew Kingston 2023-09-04 08:37:24 +01:00
parent 3d7a2d4ba9
commit 401c12732f
4 changed files with 20 additions and 25 deletions

View file

@ -8,7 +8,7 @@ export default function (datasources) {
}
return datasources.map(datasource => {
return {
name: `${datasource.name} - List`,
name: `${datasource.label} - List`,
create: () => createScreen(datasource),
id: ROW_LIST_TEMPLATE,
resourceId: datasource.resourceId,
@ -17,13 +17,13 @@ export default function (datasources) {
}
export const ROW_LIST_TEMPLATE = "ROW_LIST_TEMPLATE"
export const rowListUrl = datasource => sanitizeUrl(`/${datasource.name}`)
export const rowListUrl = datasource => sanitizeUrl(`/${datasource.label}`)
const generateTableBlock = datasource => {
const tableBlock = new Component("@budibase/standard-components/tableblock")
tableBlock
.customProps({
title: datasource.name,
title: datasource.label,
dataSource: datasource,
sortOrder: "Ascending",
size: "spectrum--medium",
@ -34,14 +34,14 @@ const generateTableBlock = datasource => {
titleButtonText: "Create row",
titleButtonClickBehaviour: "new",
})
.instanceName(`${datasource.name} - Table block`)
.instanceName(`${datasource.label} - Table block`)
return tableBlock
}
const createScreen = datasource => {
return new Screen()
.route(rowListUrl(datasource))
.instanceName(`${datasource.name} - List`)
.instanceName(`${datasource.label} - List`)
.addChild(generateTableBlock(datasource))
.json()
}

View file

@ -8,15 +8,16 @@
const dispatch = createEventDispatcher()
$: tables = $tablesStore.list.map(table => ({
...table,
type: "table",
label: table.name,
tableId: table._id,
resourceId: table._id,
}))
$: views = $viewsV2.list.map(view => ({
...view,
type: "viewV2",
id: view.id,
label: view.name,
tableId: view.tableId,
resourceId: view.id,
}))
$: options = [...(tables || []), ...(views || [])]
@ -32,7 +33,7 @@
// Migrate old values before "resourceId" existed
if (value && !value.resourceId) {
const view = views.find(x => x.resourceId === value.id)
const table = tables.find(x => x.resourceId === value._id)
const table = tables.find(x => x.resourceId === value.tableId)
dispatch("change", view || table)
}
})

View file

@ -75,43 +75,37 @@
{@const views = Object.values(table.views || {}).filter(
view => view.version === 2
)}
{@const datasource = {
...table,
// Legacy properties
{@const tableDS = {
tableId: table._id,
label: table.name,
// New consistent properties
resourceId: table._id,
name: table.name,
type: "table",
}}
{@const selected = selectedScreens.find(
screen => screen.resourceId === datasource.resourceId
screen => screen.resourceId === tableDS.resourceId
)}
<DatasourceTemplateRow
on:click={() => toggleSelection(datasource)}
on:click={() => toggleSelection(tableDS)}
{selected}
{datasource}
datasource={tableDS}
/>
<!-- List all views inside this table -->
{#each views as view}
{@const datasource = {
...view,
// Legacy properties
{@const viewDS = {
label: view.name,
// New consistent properties
id: view.id,
resourceId: view.id,
name: view.name,
tableId: view.tableId,
type: "viewV2",
}}
{@const selected = selectedScreens.find(
x => x.resourceId === datasource.resourceId
x => x.resourceId === viewDS.resourceId
)}
<DatasourceTemplateRow
on:click={() => toggleSelection(datasource)}
on:click={() => toggleSelection(viewDS)}
{selected}
{datasource}
datasource={viewDS}
/>
{/each}
{/each}

View file

@ -8,7 +8,7 @@
<div class="data-source-entry" class:selected on:click>
<Icon name={icon} color="var(--spectrum-global-color-gray-600)" />
{datasource.name}
{datasource.label}
{#if selected}
<span class="data-source-check">
<Icon size="S" name="CheckmarkCircle" />