simplify relationship configuration UI
This commit is contained in:
parent
9f3e5cdc7f
commit
93569ccc87
|
@ -172,11 +172,6 @@
|
||||||
alt: `Many ${table.name} rows → many ${linkTable.name} rows`,
|
alt: `Many ${table.name} rows → many ${linkTable.name} rows`,
|
||||||
value: RelationshipTypes.MANY_TO_MANY,
|
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`,
|
name: `One ${thisName} row → many ${linkName} rows`,
|
||||||
alt: `One ${table.name} rows → many ${linkTable.name} rows`,
|
alt: `One ${table.name} rows → many ${linkTable.name} rows`,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<script>
|
<script>
|
||||||
import { RelationshipTypes } from "constants/backend"
|
import { RelationshipTypes } from "constants/backend"
|
||||||
import { Menu, MenuItem, MenuSection, Button, Input, Icon, ModalContent, RadioGroup, Heading } from "@budibase/bbui"
|
import { Menu, MenuItem, MenuSection, Button, Input, Icon, ModalContent, RadioGroup, Heading, Select } from "@budibase/bbui"
|
||||||
import { tables } from "stores/backend"
|
import { tables } from "stores/backend"
|
||||||
|
|
||||||
export let save
|
export let save
|
||||||
|
@ -12,6 +12,7 @@
|
||||||
let originalName = relationship.name
|
let originalName = relationship.name
|
||||||
|
|
||||||
$: console.log(relationship)
|
$: console.log(relationship)
|
||||||
|
$: tableOptions = plusTables.map(table => ({ label: table.name, value: table._id }))
|
||||||
$: valid = relationship.name && relationship.tableId && relationship.relationshipType
|
$: valid = relationship.name && relationship.tableId && relationship.relationshipType
|
||||||
$: from = plusTables.find(table => table._id === relationship.source)
|
$: from = plusTables.find(table => table._id === relationship.source)
|
||||||
$: to = plusTables.find(table => table._id === relationship.tableId)
|
$: to = plusTables.find(table => table._id === relationship.tableId)
|
||||||
|
@ -30,6 +31,17 @@
|
||||||
value: RelationshipTypes.ONE_TO_MANY,
|
value: RelationshipTypes.ONE_TO_MANY,
|
||||||
}
|
}
|
||||||
] : []
|
] : []
|
||||||
|
|
||||||
|
$: relationshipTypes = [
|
||||||
|
{
|
||||||
|
label: "Many",
|
||||||
|
value: RelationshipTypes.MANY_TO_MANY,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
label: "One",
|
||||||
|
value: RelationshipTypes.ONE_TO_MANY,
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
function onChangeRelationshipType(evt) {
|
function onChangeRelationshipType(evt) {
|
||||||
if (evt.detail === RelationshipTypes.ONE_TO_MANY) {
|
if (evt.detail === RelationshipTypes.ONE_TO_MANY) {
|
||||||
|
@ -38,17 +50,25 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// save the relationship on to the datasource
|
// save the relationship on to the datasource
|
||||||
function saveRelationship() {
|
async function saveRelationship() {
|
||||||
|
// source of relationship
|
||||||
datasource.entities[from.name].schema[relationship.name] = {
|
datasource.entities[from.name].schema[relationship.name] = {
|
||||||
type: "link",
|
type: "link",
|
||||||
...relationship
|
...relationship
|
||||||
}
|
}
|
||||||
if (originalName) {
|
// if (originalName !== from.name) {
|
||||||
delete datasource.entities[from.name].schema[originalName]
|
// delete datasource.entities[from.name].schema[originalName]
|
||||||
|
// }
|
||||||
|
|
||||||
|
// save other side of relationship in the other schema
|
||||||
|
datasource.entities[to.name].schema[relationship.name] = {
|
||||||
|
type: "link",
|
||||||
|
relationshipType: relationship.relationshipType === RelationshipTypes.MANY_TO_MANY ? RelationshipTypes.MANY_TO_MANY : RelationshipTypes.MANY_TO_ONE,
|
||||||
|
tableId: to._id
|
||||||
}
|
}
|
||||||
|
|
||||||
save()
|
await save()
|
||||||
tables.fetch()
|
await tables.fetch()
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
@ -62,7 +82,41 @@
|
||||||
<Input label="Relationship Name" bind:value={relationship.name} />
|
<Input label="Relationship Name" bind:value={relationship.name} />
|
||||||
|
|
||||||
<div class="table-selector">
|
<div class="table-selector">
|
||||||
<Menu>
|
<Select
|
||||||
|
label="Relationship"
|
||||||
|
options={relationshipTypes}
|
||||||
|
bind:value={relationship.relationshipType}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Select
|
||||||
|
label="From"
|
||||||
|
options={tableOptions}
|
||||||
|
bind:value={relationship.source}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<Select
|
||||||
|
label={"Has many"}
|
||||||
|
options={tableOptions}
|
||||||
|
bind:value={relationship.tableId}
|
||||||
|
/>
|
||||||
|
|
||||||
|
{#if relationship?.relationshipType === RelationshipTypes.MANY_TO_MANY}
|
||||||
|
<Select
|
||||||
|
label={"Through"}
|
||||||
|
options={tableOptions}
|
||||||
|
bind:value={relationship.through}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
{#if relationship?.relationshipType === RelationshipTypes.ONE_TO_MANY}
|
||||||
|
<Select
|
||||||
|
label={"Foreign Key"}
|
||||||
|
options={Object.keys(linkTable.schema)}
|
||||||
|
bind:value={relationship.foreignKey}
|
||||||
|
/>
|
||||||
|
{/if}
|
||||||
|
|
||||||
|
<!-- <Menu>
|
||||||
<MenuSection heading="From">
|
<MenuSection heading="From">
|
||||||
{#each plusTables as table}
|
{#each plusTables as table}
|
||||||
<MenuItem noClose icon="Table" on:click={() => (relationship.source = table._id)}>
|
<MenuItem noClose icon="Table" on:click={() => (relationship.source = table._id)}>
|
||||||
|
@ -73,8 +127,8 @@
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
{/each}
|
{/each}
|
||||||
</MenuSection>
|
</MenuSection>
|
||||||
</Menu>
|
</Menu> -->
|
||||||
<Menu>
|
<!-- <Menu>
|
||||||
<MenuSection heading="To">
|
<MenuSection heading="To">
|
||||||
{#each plusTables as table}
|
{#each plusTables as table}
|
||||||
<MenuItem noClose icon="Table" on:click={() => (relationship.tableId = table._id)}>
|
<MenuItem noClose icon="Table" on:click={() => (relationship.tableId = table._id)}>
|
||||||
|
@ -85,11 +139,9 @@
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
{/each}
|
{/each}
|
||||||
</MenuSection>
|
</MenuSection>
|
||||||
</Menu>
|
</Menu> -->
|
||||||
</div>
|
|
||||||
|
|
||||||
{#if from && to}
|
{#if from && to}
|
||||||
<div class="cardinality">
|
<!-- <div class="cardinality">
|
||||||
<RadioGroup
|
<RadioGroup
|
||||||
label="Define the relationship"
|
label="Define the relationship"
|
||||||
bind:value={relationship.relationshipType}
|
bind:value={relationship.relationshipType}
|
||||||
|
@ -98,25 +150,15 @@
|
||||||
getOptionLabel={option => option.name}
|
getOptionLabel={option => option.name}
|
||||||
getOptionValue={option => option.value}
|
getOptionValue={option => option.value}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div> -->
|
||||||
|
|
||||||
{#if relationship?.relationshipType === RelationshipTypes.MANY_TO_MANY}
|
<!-- <Select
|
||||||
<Menu>
|
label={`${linkTable.name} Column`}
|
||||||
<MenuSection heading="Join Table">
|
options={Object.keys(linkTable.schema)}
|
||||||
{#each plusTables as table}
|
bind:value={relationship.fieldName}
|
||||||
<MenuItem noClose icon="Table" on:click={() => (relationship.through = table._id)}>
|
/> -->
|
||||||
{table.name}
|
|
||||||
{#if relationship.through === table._id}
|
|
||||||
<Icon size="S" name="Checkmark" />
|
|
||||||
{/if}
|
|
||||||
</MenuItem>
|
|
||||||
{/each}
|
|
||||||
</MenuSection>
|
|
||||||
</Menu>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
|
<!-- <div class="table-selector">
|
||||||
<div class="table-selector">
|
|
||||||
<Menu>
|
<Menu>
|
||||||
<MenuSection heading={`${linkTable.name} Column`}>
|
<MenuSection heading={`${linkTable.name} Column`}>
|
||||||
{#each Object.keys(linkTable.schema) as column}
|
{#each Object.keys(linkTable.schema) as column}
|
||||||
|
@ -129,15 +171,21 @@
|
||||||
{/each}
|
{/each}
|
||||||
</MenuSection>
|
</MenuSection>
|
||||||
</Menu>
|
</Menu>
|
||||||
</div>
|
</div> -->
|
||||||
{/if}
|
{/if}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.table-selector {
|
.table-selector {
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 1fr;
|
grid-template-columns: repeat(4, 1fr);
|
||||||
grid-gap: var(--spacing-xl);
|
grid-gap: var(--spacing-xl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.cardinality {
|
||||||
|
padding: 10px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
|
@ -8,7 +8,19 @@
|
||||||
"type": "node",
|
"type": "node",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"name": "Start Server",
|
"name": "Start Server",
|
||||||
"program": "${workspaceFolder}/src/index.js"
|
"sourceMaps": true,
|
||||||
|
"program": "${workspaceFolder}/src/index.ts",
|
||||||
|
"preLaunchTask": "npm: build",
|
||||||
|
"outFiles": ["${workspaceFolder}/dist/**/*.js"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "TS",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"runtimeExecutable": "node",
|
||||||
|
"runtimeArgs": ["--nolazy", "-r", "ts-node/register/transpile-only"],
|
||||||
|
"args": ["src/index.ts"],
|
||||||
|
"cwd": "${workspaceRoot}",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "node",
|
"type": "node",
|
||||||
|
|
Loading…
Reference in New Issue