2022-04-06 21:10:53 +12:00
|
|
|
<script>
|
2022-04-22 23:22:21 +12:00
|
|
|
import { store } from "builderStore"
|
2022-04-26 01:57:12 +12:00
|
|
|
import {
|
|
|
|
ModalContent,
|
|
|
|
Layout,
|
|
|
|
notifications,
|
|
|
|
Icon,
|
|
|
|
Body,
|
|
|
|
} from "@budibase/bbui"
|
2022-04-22 23:22:21 +12:00
|
|
|
import { tables, datasources } from "stores/backend"
|
2022-04-06 21:10:53 +12:00
|
|
|
import getTemplates from "builderStore/store/screenTemplates"
|
2022-04-26 01:38:52 +12:00
|
|
|
import ICONS from "components/backend/DatasourceNavigator/icons"
|
2022-04-06 21:10:53 +12:00
|
|
|
import { IntegrationNames } from "constants"
|
2022-04-08 20:05:56 +12:00
|
|
|
import { onMount } from "svelte"
|
2022-04-06 21:10:53 +12:00
|
|
|
|
|
|
|
export let onCancel
|
|
|
|
export let onConfirm
|
2022-04-22 23:22:21 +12:00
|
|
|
export let initalScreens = []
|
2022-04-06 21:10:53 +12:00
|
|
|
|
2022-04-22 23:22:21 +12:00
|
|
|
let selectedScreens = [...initalScreens]
|
2022-04-06 21:10:53 +12:00
|
|
|
|
2022-04-07 20:35:12 +12:00
|
|
|
const toggleScreenSelection = (table, datasource) => {
|
2022-06-16 22:46:16 +12:00
|
|
|
if (selectedScreens.find(s => s.table === table._id)) {
|
2022-04-06 21:10:53 +12:00
|
|
|
selectedScreens = selectedScreens.filter(
|
2022-06-16 22:46:16 +12:00
|
|
|
screen => screen.table !== table._id
|
2022-04-06 21:10:53 +12:00
|
|
|
)
|
|
|
|
} else {
|
2022-04-07 20:35:12 +12:00
|
|
|
let partialTemplates = getTemplates($store, $tables.list).reduce(
|
|
|
|
(acc, template) => {
|
2022-06-16 22:46:16 +12:00
|
|
|
if (template.table === table._id) {
|
2022-04-07 20:35:12 +12:00
|
|
|
template.datasource = datasource.name
|
|
|
|
acc.push(template)
|
|
|
|
}
|
|
|
|
return acc
|
|
|
|
},
|
|
|
|
[]
|
2022-04-06 21:10:53 +12:00
|
|
|
)
|
|
|
|
selectedScreens = [...partialTemplates, ...selectedScreens]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const confirmDatasourceSelection = async () => {
|
|
|
|
await onConfirm({
|
|
|
|
templates: selectedScreens,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2022-04-08 20:05:56 +12:00
|
|
|
$: filteredSources = Array.isArray($datasources.list)
|
|
|
|
? $datasources.list.reduce((acc, datasource) => {
|
|
|
|
if (
|
|
|
|
datasource.source !== IntegrationNames.REST &&
|
|
|
|
datasource["entities"]
|
|
|
|
) {
|
|
|
|
acc.push(datasource)
|
|
|
|
}
|
|
|
|
return acc
|
|
|
|
}, [])
|
|
|
|
: []
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
try {
|
|
|
|
await datasources.fetch()
|
|
|
|
} catch (error) {
|
|
|
|
notifications.error("Error fetching datasources")
|
2022-04-06 21:10:53 +12:00
|
|
|
}
|
2022-04-08 20:05:56 +12:00
|
|
|
})
|
2022-04-06 21:10:53 +12:00
|
|
|
</script>
|
|
|
|
|
2022-04-23 01:57:13 +12:00
|
|
|
<span data-cy="data-source-modal">
|
|
|
|
<ModalContent
|
|
|
|
title="Create CRUD Screens"
|
|
|
|
confirmText="Confirm"
|
|
|
|
cancelText="Back"
|
|
|
|
onConfirm={confirmDatasourceSelection}
|
|
|
|
{onCancel}
|
|
|
|
disabled={!selectedScreens.length}
|
|
|
|
size="L"
|
|
|
|
>
|
2022-04-26 01:57:12 +12:00
|
|
|
<Body size="S">
|
2022-09-14 23:11:20 +12:00
|
|
|
Select which datasource you would like to use to create your screens
|
2022-04-26 01:57:12 +12:00
|
|
|
</Body>
|
2022-04-23 01:57:13 +12:00
|
|
|
<Layout noPadding gap="S">
|
|
|
|
{#each filteredSources as datasource}
|
|
|
|
<div class="data-source-wrap">
|
|
|
|
<div class="data-source-header">
|
2022-04-26 01:57:12 +12:00
|
|
|
<svelte:component
|
|
|
|
this={ICONS[datasource.source]}
|
|
|
|
height="24"
|
|
|
|
width="24"
|
|
|
|
/>
|
2022-04-23 01:57:13 +12:00
|
|
|
<div class="data-source-name">{datasource.name}</div>
|
2022-04-22 23:22:21 +12:00
|
|
|
</div>
|
2022-04-23 01:57:13 +12:00
|
|
|
{#if Array.isArray(datasource.entities)}
|
|
|
|
{#each datasource.entities.filter(table => table._id !== "ta_users") as table}
|
|
|
|
<div
|
|
|
|
class="data-source-entry"
|
|
|
|
class:selected={selectedScreens.find(
|
2022-06-16 22:46:16 +12:00
|
|
|
x => x.table === table._id
|
2022-04-23 01:57:13 +12:00
|
|
|
)}
|
|
|
|
on:click={() => toggleScreenSelection(table, datasource)}
|
2022-04-22 23:22:21 +12:00
|
|
|
>
|
2022-04-23 01:57:13 +12:00
|
|
|
<svg
|
|
|
|
width="16px"
|
|
|
|
height="16px"
|
|
|
|
class="spectrum-Icon"
|
|
|
|
style="color: white"
|
|
|
|
focusable="false"
|
|
|
|
>
|
|
|
|
<use xlink:href="#spectrum-icon-18-Table" />
|
|
|
|
</svg>
|
|
|
|
{table.name}
|
2022-06-16 22:46:16 +12:00
|
|
|
{#if selectedScreens.find(x => x.table === table._id)}
|
2022-04-23 01:57:13 +12:00
|
|
|
<span class="data-source-check">
|
|
|
|
<Icon size="S" name="CheckmarkCircle" />
|
|
|
|
</span>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
{/each}
|
|
|
|
{/if}
|
|
|
|
{#if datasource["entities"] && !Array.isArray(datasource.entities)}
|
|
|
|
{#each Object.keys(datasource.entities).filter(table => table._id !== "ta_users") as table_key}
|
|
|
|
<div
|
|
|
|
class="data-source-entry"
|
|
|
|
class:selected={selectedScreens.find(
|
2022-06-16 22:46:16 +12:00
|
|
|
x => x.table === datasource.entities[table_key]._id
|
2022-04-22 23:22:21 +12:00
|
|
|
)}
|
2022-04-23 01:57:13 +12:00
|
|
|
on:click={() =>
|
|
|
|
toggleScreenSelection(
|
|
|
|
datasource.entities[table_key],
|
|
|
|
datasource
|
|
|
|
)}
|
2022-04-22 23:22:21 +12:00
|
|
|
>
|
2022-04-23 01:57:13 +12:00
|
|
|
<svg
|
|
|
|
width="16px"
|
|
|
|
height="16px"
|
|
|
|
class="spectrum-Icon"
|
|
|
|
style="color: white"
|
|
|
|
focusable="false"
|
|
|
|
>
|
|
|
|
<use xlink:href="#spectrum-icon-18-Table" />
|
|
|
|
</svg>
|
|
|
|
{datasource.entities[table_key].name}
|
2022-06-16 22:46:16 +12:00
|
|
|
{#if selectedScreens.find(x => x.table === datasource.entities[table_key]._id)}
|
2022-04-23 01:57:13 +12:00
|
|
|
<span class="data-source-check">
|
|
|
|
<Icon size="S" name="CheckmarkCircle" />
|
|
|
|
</span>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
{/each}
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
{/each}
|
|
|
|
</Layout>
|
|
|
|
</ModalContent>
|
|
|
|
</span>
|
2022-04-06 21:10:53 +12:00
|
|
|
|
|
|
|
<style>
|
2022-04-22 23:22:21 +12:00
|
|
|
.data-source-wrap {
|
|
|
|
padding-bottom: var(--spectrum-alias-item-padding-s);
|
|
|
|
display: grid;
|
2022-04-26 01:57:12 +12:00
|
|
|
grid-gap: var(--spacing-s);
|
2022-04-22 23:22:21 +12:00
|
|
|
}
|
|
|
|
|
2022-04-06 21:10:53 +12:00
|
|
|
.data-source-header {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2022-04-26 01:57:12 +12:00
|
|
|
gap: var(--spacing-m);
|
|
|
|
padding-bottom: var(--spacing-xs);
|
2022-04-06 21:10:53 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
.data-source-entry {
|
|
|
|
cursor: pointer;
|
|
|
|
grid-gap: var(--spectrum-alias-grid-margin-xsmall);
|
|
|
|
padding: var(--spectrum-alias-item-padding-s);
|
2022-04-26 01:57:12 +12:00
|
|
|
background: var(--spectrum-alias-background-color-secondary);
|
2022-04-06 21:10:53 +12:00
|
|
|
transition: 0.3s all;
|
|
|
|
border: 1px solid var(--spectrum-global-color-gray-300);
|
|
|
|
border-radius: 4px;
|
|
|
|
border-width: 1px;
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.data-source-entry:hover,
|
|
|
|
.selected {
|
|
|
|
background: var(--spectrum-alias-background-color-tertiary);
|
|
|
|
}
|
2022-04-22 23:22:21 +12:00
|
|
|
|
|
|
|
.data-source-entry .data-source-check {
|
|
|
|
margin-left: auto;
|
|
|
|
}
|
|
|
|
|
|
|
|
.data-source-entry :global(.spectrum-Icon) {
|
|
|
|
min-width: 16px;
|
|
|
|
}
|
|
|
|
|
|
|
|
.data-source-entry .data-source-check :global(.spectrum-Icon) {
|
|
|
|
color: var(--spectrum-global-color-green-600);
|
|
|
|
display: block;
|
|
|
|
}
|
2022-04-06 21:10:53 +12:00
|
|
|
</style>
|