1
0
Fork 0
mirror of synced 2024-07-04 14:01:27 +12:00

started on opinionated relationships

This commit is contained in:
Martin McKeaveney 2021-06-23 14:29:40 +01:00
parent 9fbb9d8d72
commit 46c14fafc5
2 changed files with 127 additions and 13 deletions

View file

@ -0,0 +1,79 @@
<script>
import { Button, ModalContent, RadioGroup, Heading } from "@budibase/bbui"
const STEPS = 3
export let save
let relationship = {}
let step = 0
function nextStep() {
if (step + 1 === STEPS) return
step = step + 1
}
function previousStep() {
if (step === 0) return
step = step - 1
}
function saveRelationship() {
// save the relationship on to the datasource
// save()
}
function getRelationshipOptions(field) {
if (!field || !field.tableId) {
return null
}
const linkTable = tableOptions.find(table => table._id === field.tableId)
if (!linkTable) {
return null
}
const thisName = truncate(table.name, { length: 14 }),
linkName = truncate(linkTable.name, { length: 14 })
return [
{
name: `Many ${thisName} rows → many ${linkName} rows`,
alt: `Many ${table.name} rows → many ${linkTable.name} rows`,
value: RelationshipTypes.MANY_TO_MANY,
},
{
name: `One ${linkName} row → many ${thisName} rows`,
alt: `One ${linkTable.name} rows → many ${table.name} rows`,
value: RelationshipTypes.ONE_TO_MANY,
},
{
name: `One ${thisName} row → many ${linkName} rows`,
alt: `One ${table.name} rows → many ${linkTable.name} rows`,
value: RelationshipTypes.MANY_TO_ONE,
},
]
}
</script>
<ModalContent
size="XL"
title="Edit Code"
showConfirmButton={false}
showCancelButton={false}
>
{#if step === 0}
<Heading>Select your table</Heading>
{:else if step === 1}
<!-- <RadioGroup
disabled={linkEditDisabled}
label="Define the relationship"
bind:value={relationship}
options={relationshipOptions}
getOptionLabel={option => option.name}
getOptionValue={option => option.value}
/> -->
Step 2
{:else if step === 2}
Step 3
{/if}
<Button on:click={previousStep}>Previous</Button>
<Button on:click={nextStep}>Next</Button>
</ModalContent>

View file

@ -1,16 +1,19 @@
<script>
import { goto, beforeUrlChange } from "@roxi/routify"
import { Button, Heading, Body, Divider, Layout } from "@budibase/bbui"
import { Button, Heading, Body, Divider, Layout, Modal } from "@budibase/bbui"
import { datasources, integrations, queries, tables } from "stores/backend"
import { notifications } from "@budibase/bbui"
import IntegrationConfigForm from "components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte"
import CreateEditRelationship from "./CreateEditRelationship.svelte"
import ICONS from "components/backend/DatasourceNavigator/icons"
import { capitalise } from "helpers"
let unsaved = false
let relationshipModal
$: datasource = $datasources.list.find(ds => ds._id === $datasources.selected)
$: integration = datasource && $integrations[datasource.source]
$: plusTables = datasource?.plus ? Object.values(datasource.entities) : []
async function saveDatasource() {
try {
@ -48,6 +51,10 @@
unsaved = true
}
function openRelationshipModal() {
relationshipModal.show()
}
$beforeUrlChange(() => {
if (unsaved) {
notifications.error(
@ -59,6 +66,10 @@
})
</script>
<Modal bind:this={relationshipModal}>
<CreateEditRelationship save={saveDatasource} tables={plusTables} />
</Modal>
{#if datasource && integration}
<section>
<Layout>
@ -100,19 +111,43 @@
having to write any queries at all.
</Body>
<div class="query-list">
{#if datasource.entities}
{#each Object.keys(datasource.entities) as entity}
<div
class="query-list-item"
on:click={() => onClickTable(datasource.entities[entity])}
>
<p class="query-name">{entity}</p>
<p>Primary Key: {datasource.entities[entity].primary}</p>
<p></p>
</div>
{/each}
{/if}
{#each plusTables as table}
<div
class="query-list-item"
on:click={() => onClickTable(table)}
>
<p class="query-name">{table.name}</p>
<p>Primary Key: {table.primary}</p>
<p></p>
</div>
{/each}
</div>
<Divider />
<div class="query-header">
<Heading size="S">Relationships</Heading>
<Button primary on:click={openRelationshipModal}>Create Relationship</Button>
</div>
<Body>
Tell budibase how your tables are related to get even more smart features.
</Body>
<div class="query-list">
{#each plusTables as table}
{#each Object.keys(table) as column}
{#if table[column].type === "link"}
<div
class="query-list-item"
on:click={() => onClickTable(table[column])}
>
<p class="query-name">{table[column].name}</p>
<p>Primary Key: {table[column].primary}</p>
<p></p>
</div>
{/if}
{/each}
{/each}
</div>
{/if}
<Divider />
<div class="query-header">