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:
parent
3d7a2d4ba9
commit
401c12732f
|
@ -8,7 +8,7 @@ export default function (datasources) {
|
||||||
}
|
}
|
||||||
return datasources.map(datasource => {
|
return datasources.map(datasource => {
|
||||||
return {
|
return {
|
||||||
name: `${datasource.name} - List`,
|
name: `${datasource.label} - List`,
|
||||||
create: () => createScreen(datasource),
|
create: () => createScreen(datasource),
|
||||||
id: ROW_LIST_TEMPLATE,
|
id: ROW_LIST_TEMPLATE,
|
||||||
resourceId: datasource.resourceId,
|
resourceId: datasource.resourceId,
|
||||||
|
@ -17,13 +17,13 @@ export default function (datasources) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const ROW_LIST_TEMPLATE = "ROW_LIST_TEMPLATE"
|
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 generateTableBlock = datasource => {
|
||||||
const tableBlock = new Component("@budibase/standard-components/tableblock")
|
const tableBlock = new Component("@budibase/standard-components/tableblock")
|
||||||
tableBlock
|
tableBlock
|
||||||
.customProps({
|
.customProps({
|
||||||
title: datasource.name,
|
title: datasource.label,
|
||||||
dataSource: datasource,
|
dataSource: datasource,
|
||||||
sortOrder: "Ascending",
|
sortOrder: "Ascending",
|
||||||
size: "spectrum--medium",
|
size: "spectrum--medium",
|
||||||
|
@ -34,14 +34,14 @@ const generateTableBlock = datasource => {
|
||||||
titleButtonText: "Create row",
|
titleButtonText: "Create row",
|
||||||
titleButtonClickBehaviour: "new",
|
titleButtonClickBehaviour: "new",
|
||||||
})
|
})
|
||||||
.instanceName(`${datasource.name} - Table block`)
|
.instanceName(`${datasource.label} - Table block`)
|
||||||
return tableBlock
|
return tableBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
const createScreen = datasource => {
|
const createScreen = datasource => {
|
||||||
return new Screen()
|
return new Screen()
|
||||||
.route(rowListUrl(datasource))
|
.route(rowListUrl(datasource))
|
||||||
.instanceName(`${datasource.name} - List`)
|
.instanceName(`${datasource.label} - List`)
|
||||||
.addChild(generateTableBlock(datasource))
|
.addChild(generateTableBlock(datasource))
|
||||||
.json()
|
.json()
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,15 +8,16 @@
|
||||||
const dispatch = createEventDispatcher()
|
const dispatch = createEventDispatcher()
|
||||||
|
|
||||||
$: tables = $tablesStore.list.map(table => ({
|
$: tables = $tablesStore.list.map(table => ({
|
||||||
...table,
|
|
||||||
type: "table",
|
type: "table",
|
||||||
label: table.name,
|
label: table.name,
|
||||||
|
tableId: table._id,
|
||||||
resourceId: table._id,
|
resourceId: table._id,
|
||||||
}))
|
}))
|
||||||
$: views = $viewsV2.list.map(view => ({
|
$: views = $viewsV2.list.map(view => ({
|
||||||
...view,
|
|
||||||
type: "viewV2",
|
type: "viewV2",
|
||||||
|
id: view.id,
|
||||||
label: view.name,
|
label: view.name,
|
||||||
|
tableId: view.tableId,
|
||||||
resourceId: view.id,
|
resourceId: view.id,
|
||||||
}))
|
}))
|
||||||
$: options = [...(tables || []), ...(views || [])]
|
$: options = [...(tables || []), ...(views || [])]
|
||||||
|
@ -32,7 +33,7 @@
|
||||||
// Migrate old values before "resourceId" existed
|
// Migrate old values before "resourceId" existed
|
||||||
if (value && !value.resourceId) {
|
if (value && !value.resourceId) {
|
||||||
const view = views.find(x => x.resourceId === value.id)
|
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)
|
dispatch("change", view || table)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
@ -75,43 +75,37 @@
|
||||||
{@const views = Object.values(table.views || {}).filter(
|
{@const views = Object.values(table.views || {}).filter(
|
||||||
view => view.version === 2
|
view => view.version === 2
|
||||||
)}
|
)}
|
||||||
{@const datasource = {
|
{@const tableDS = {
|
||||||
...table,
|
|
||||||
// Legacy properties
|
|
||||||
tableId: table._id,
|
tableId: table._id,
|
||||||
label: table.name,
|
label: table.name,
|
||||||
// New consistent properties
|
|
||||||
resourceId: table._id,
|
resourceId: table._id,
|
||||||
name: table.name,
|
|
||||||
type: "table",
|
type: "table",
|
||||||
}}
|
}}
|
||||||
{@const selected = selectedScreens.find(
|
{@const selected = selectedScreens.find(
|
||||||
screen => screen.resourceId === datasource.resourceId
|
screen => screen.resourceId === tableDS.resourceId
|
||||||
)}
|
)}
|
||||||
<DatasourceTemplateRow
|
<DatasourceTemplateRow
|
||||||
on:click={() => toggleSelection(datasource)}
|
on:click={() => toggleSelection(tableDS)}
|
||||||
{selected}
|
{selected}
|
||||||
{datasource}
|
datasource={tableDS}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- List all views inside this table -->
|
<!-- List all views inside this table -->
|
||||||
{#each views as view}
|
{#each views as view}
|
||||||
{@const datasource = {
|
{@const viewDS = {
|
||||||
...view,
|
|
||||||
// Legacy properties
|
|
||||||
label: view.name,
|
label: view.name,
|
||||||
// New consistent properties
|
id: view.id,
|
||||||
resourceId: view.id,
|
resourceId: view.id,
|
||||||
name: view.name,
|
tableId: view.tableId,
|
||||||
type: "viewV2",
|
type: "viewV2",
|
||||||
}}
|
}}
|
||||||
{@const selected = selectedScreens.find(
|
{@const selected = selectedScreens.find(
|
||||||
x => x.resourceId === datasource.resourceId
|
x => x.resourceId === viewDS.resourceId
|
||||||
)}
|
)}
|
||||||
<DatasourceTemplateRow
|
<DatasourceTemplateRow
|
||||||
on:click={() => toggleSelection(datasource)}
|
on:click={() => toggleSelection(viewDS)}
|
||||||
{selected}
|
{selected}
|
||||||
{datasource}
|
datasource={viewDS}
|
||||||
/>
|
/>
|
||||||
{/each}
|
{/each}
|
||||||
{/each}
|
{/each}
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
|
|
||||||
<div class="data-source-entry" class:selected on:click>
|
<div class="data-source-entry" class:selected on:click>
|
||||||
<Icon name={icon} color="var(--spectrum-global-color-gray-600)" />
|
<Icon name={icon} color="var(--spectrum-global-color-gray-600)" />
|
||||||
{datasource.name}
|
{datasource.label}
|
||||||
{#if selected}
|
{#if selected}
|
||||||
<span class="data-source-check">
|
<span class="data-source-check">
|
||||||
<Icon size="S" name="CheckmarkCircle" />
|
<Icon size="S" name="CheckmarkCircle" />
|
||||||
|
|
Loading…
Reference in New Issue