diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship.svelte deleted file mode 100644 index b9f6dbf092..0000000000 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship.svelte +++ /dev/null @@ -1,79 +0,0 @@ - - - - {#if step === 0} - Select your table - {:else if step === 1} - - Step 2 - {:else if step === 2} - Step 3 - {/if} - - - \ No newline at end of file diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship/CreateEditRelationship.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship/CreateEditRelationship.svelte index cbab467e40..0ed5a93c0a 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship/CreateEditRelationship.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship/CreateEditRelationship.svelte @@ -2,33 +2,44 @@ import { RelationshipTypes } from "constants/backend" import { Menu, MenuItem, MenuSection, Button, Input, Icon, ModalContent, RadioGroup, Heading } from "@budibase/bbui" + // "tasks_something": { + // "name": "tasks_something", + // "type": "link", + // "tableId": "whatever/othertable", + // "relationshipType": "one-to-many", + // }, + export let save export let datasource + export let from export let tables - - let relationship = {} + export let relationship = {} $: console.log(relationship) - $: console.log("ds", datasource) - $: valid = relationship.name && relationship.from && relationship.to && relationship.relationshipType + $: valid = relationship.name && relationship.tableId && relationship.relationshipType + $: from = tables.find(table => table._id === relationship.source) + $: to = tables.find(table => table._id === relationship.tableId) + $: through = tables.find(table => table._id === relationship.through) + $: linkTable = through || to - $: relationshipOptions = relationship.from && relationship.to ? [ + $: relationshipOptions = from && to ? [ { - name: `Many ${relationship.from.name} rows → many ${relationship.to.name} rows`, - alt: `Many ${relationship.from.name} rows → many ${relationship.to.name} rows`, + name: `Many ${from.name} rows → many ${to.name} rows`, + alt: `Many ${from.name} rows → many ${to.name} rows`, value: RelationshipTypes.MANY_TO_MANY, }, { - name: `One ${relationship.from.name} row → many ${relationship.to.name} rows`, - alt: `One ${relationship.from.name} rows → many ${relationship.to.name} rows`, + name: `One ${from.name} row → many ${to.name} rows`, + alt: `One ${from.name} rows → many ${to.name} rows`, value: RelationshipTypes.ONE_TO_MANY, - }, - { - name: `One ${relationship.from.name} row → many ${relationship.to.name} rows`, - alt: `One ${relationship.from.name} row → many ${relationship.to.name} rows`, - value: RelationshipTypes.MANY_TO_ONE, - }, + } ] : [] + + function onChangeRelationshipType(evt) { + if (evt.detail === RelationshipTypes.ONE_TO_MANY) { + relationship.through = null + } + } // save the relationship on to the datasource function saveRelationship() { @@ -67,9 +78,9 @@ {#each tables as table} - (relationship.from = table)}> + (relationship.source = table._id)}> {table.name} - {#if relationship.from?._id === table._id} + {#if relationship.source === table._id} {/if} @@ -79,9 +90,9 @@ {#each tables as table} - (relationship.to = table)}> + (relationship.tableId = table._id)}> {table.name} - {#if relationship.to?._id === table._id} + {#if relationship.tableId === table._id} {/if} @@ -90,61 +101,50 @@ - {#if relationship.from && relationship.to} + {#if from && to}
option.name} getOptionValue={option => option.value} />
- {/if} {#if relationship?.relationshipType === RelationshipTypes.MANY_TO_MANY} {#each tables as table} - (relationship.through = table)}> + (relationship.through = table._id)}> {table.name} - {#if relationship.through?._id === table._id} + {#if relationship.through === table._id} {/if} {/each} - - {#if relationship.through} -
- - - {#each Object.keys(relationship.through) as column} - (relationship.through.from = column)}> - {column} - {#if relationship.through.from?._id === column._id} - - {/if} - - {/each} - - - - - {#each Object.keys(relationship.through) as column} - (relationship.through.to = column)}> - {column} - {#if relationship.through.to?._id === column._id} - - {/if} - - {/each} - - -
- {/if} {/if} + + +
+ + + {#each Object.keys(linkTable.schema) as column} + (relationship.foreignKey = column)}> + {column} + {#if relationship.foreignKey === column} + + {/if} + + {/each} + + +
+ {/if} +