Use ID rather than name to identiy datasources when creating autoscreens

This commit is contained in:
Andrew Kingston 2022-06-16 11:46:16 +01:00
parent eb3a7b44b6
commit 947840e79e
4 changed files with 10 additions and 12 deletions

View File

@ -15,7 +15,7 @@ export default function (tables) {
name: `${table.name} - New`, name: `${table.name} - New`,
create: () => createScreen(table), create: () => createScreen(table),
id: NEW_ROW_TEMPLATE, id: NEW_ROW_TEMPLATE,
table: table.name, table: table._id,
} }
}) })
} }

View File

@ -17,7 +17,7 @@ export default function (tables) {
name: `${table.name} - Detail`, name: `${table.name} - Detail`,
create: () => createScreen(table), create: () => createScreen(table),
id: ROW_DETAIL_TEMPLATE, id: ROW_DETAIL_TEMPLATE,
table: table.name, table: table._id,
} }
}) })
} }

View File

@ -10,7 +10,7 @@ export default function (tables) {
name: `${table.name} - List`, name: `${table.name} - List`,
create: () => createScreen(table), create: () => createScreen(table),
id: ROW_LIST_TEMPLATE, id: ROW_LIST_TEMPLATE,
table: table.name, table: table._id,
} }
}) })
} }

View File

@ -14,14 +14,14 @@
let selectedScreens = [...initalScreens] let selectedScreens = [...initalScreens]
const toggleScreenSelection = (table, datasource) => { const toggleScreenSelection = (table, datasource) => {
if (selectedScreens.find(s => s.table === table.name)) { if (selectedScreens.find(s => s.table === table._id)) {
selectedScreens = selectedScreens.filter( selectedScreens = selectedScreens.filter(
screen => screen.table !== table.name screen => screen.table !== table._id
) )
} else { } else {
let partialTemplates = getTemplates($store, $tables.list).reduce( let partialTemplates = getTemplates($store, $tables.list).reduce(
(acc, template) => { (acc, template) => {
if (template.table === table.name) { if (template.table === table._id) {
template.datasource = datasource.name template.datasource = datasource.name
acc.push(template) acc.push(template)
} }
@ -88,7 +88,7 @@
<div <div
class="data-source-entry" class="data-source-entry"
class:selected={selectedScreens.find( class:selected={selectedScreens.find(
x => x.table === table.name x => x.table === table._id
)} )}
on:click={() => toggleScreenSelection(table, datasource)} on:click={() => toggleScreenSelection(table, datasource)}
> >
@ -102,8 +102,7 @@
<use xlink:href="#spectrum-icon-18-Table" /> <use xlink:href="#spectrum-icon-18-Table" />
</svg> </svg>
{table.name} {table.name}
{#if selectedScreens.find(x => x.table === table._id)}
{#if selectedScreens.find(x => x.table === table.name)}
<span class="data-source-check"> <span class="data-source-check">
<Icon size="S" name="CheckmarkCircle" /> <Icon size="S" name="CheckmarkCircle" />
</span> </span>
@ -116,7 +115,7 @@
<div <div
class="data-source-entry" class="data-source-entry"
class:selected={selectedScreens.find( class:selected={selectedScreens.find(
x => x.table === datasource.entities[table_key].name x => x.table === datasource.entities[table_key]._id
)} )}
on:click={() => on:click={() =>
toggleScreenSelection( toggleScreenSelection(
@ -134,8 +133,7 @@
<use xlink:href="#spectrum-icon-18-Table" /> <use xlink:href="#spectrum-icon-18-Table" />
</svg> </svg>
{datasource.entities[table_key].name} {datasource.entities[table_key].name}
{#if selectedScreens.find(x => x.table === datasource.entities[table_key]._id)}
{#if selectedScreens.find(x => x.table === datasource.entities[table_key].name)}
<span class="data-source-check"> <span class="data-source-check">
<Icon size="S" name="CheckmarkCircle" /> <Icon size="S" name="CheckmarkCircle" />
</span> </span>