From 3e82abd88ece345c6755a1cc6542ee680f7fc77e Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 1 Nov 2021 21:15:46 +0000 Subject: [PATCH] Updating external table UI a bit, adding the concept of defining an existing relationship, updating the data sources UI to make it a bit less cluttered and make the creation of tables more obvious. --- .../backend/DataTable/DataTable.svelte | 7 +++ .../buttons/ExistingRelationshipButton.svelte | 54 +++++++++++++++++++ .../CreateEditRelationship.svelte | 30 ++++++++++- .../backend/Datasources}/TableSelect.svelte | 0 .../[selectedDatasource]/index.svelte | 32 ++++++++--- packages/builder/src/stores/backend/tables.js | 1 + 6 files changed, 114 insertions(+), 10 deletions(-) create mode 100644 packages/builder/src/components/backend/DataTable/buttons/ExistingRelationshipButton.svelte rename packages/builder/src/{pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship => components/backend/Datasources}/CreateEditRelationship.svelte (92%) rename packages/builder/src/{pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship => components/backend/Datasources}/TableSelect.svelte (100%) diff --git a/packages/builder/src/components/backend/DataTable/DataTable.svelte b/packages/builder/src/components/backend/DataTable/DataTable.svelte index 1af703800f..6bebf2ca02 100644 --- a/packages/builder/src/components/backend/DataTable/DataTable.svelte +++ b/packages/builder/src/components/backend/DataTable/DataTable.svelte @@ -4,6 +4,7 @@ import CreateRowButton from "./buttons/CreateRowButton.svelte" import CreateColumnButton from "./buttons/CreateColumnButton.svelte" import CreateViewButton from "./buttons/CreateViewButton.svelte" + import ExistingRelationshipButton from "./buttons/ExistingRelationshipButton.svelte" import ExportButton from "./buttons/ExportButton.svelte" import EditRolesButton from "./buttons/EditRolesButton.svelte" import ManageAccessButton from "./buttons/ManageAccessButton.svelte" @@ -114,6 +115,12 @@ {#if isUsersTable} {/if} + {#if !isInternal} + + {/if} diff --git a/packages/builder/src/components/backend/DataTable/buttons/ExistingRelationshipButton.svelte b/packages/builder/src/components/backend/DataTable/buttons/ExistingRelationshipButton.svelte new file mode 100644 index 0000000000..4a7abf487f --- /dev/null +++ b/packages/builder/src/components/backend/DataTable/buttons/ExistingRelationshipButton.svelte @@ -0,0 +1,54 @@ + + +{#if table.sourceId} +
+ + Define existing relationship + +
+ + + +{/if} diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship/CreateEditRelationship.svelte b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte similarity index 92% rename from packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship/CreateEditRelationship.svelte rename to packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte index 583ca5e887..81032da716 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship/CreateEditRelationship.svelte +++ b/packages/builder/src/components/backend/Datasources/CreateEditRelationship.svelte @@ -18,10 +18,19 @@ export let fromRelationship = {} export let toRelationship = {} export let close + export let selectedFromTable let originalFromName = fromRelationship.name, originalToName = toRelationship.name + if (fromRelationship && !fromRelationship.relationshipType) { + fromRelationship.relationshipType = RelationshipTypes.MANY_TO_ONE + } + + if (toRelationship && selectedFromTable) { + toRelationship.tableId = selectedFromTable._id + } + function inSchema(table, prop, ogName) { if (!table || !prop || prop === ogName) { return false @@ -114,6 +123,7 @@ }, ] $: updateRelationshipType(fromRelationship?.relationshipType) + $: tableChanged(fromTable, toTable) function updateRelationshipType(fromType) { if (fromType === RelationshipTypes.MANY_TO_MANY) { @@ -205,7 +215,6 @@ originalToName = toRelationship.name originalFromName = fromRelationship.name await save() - await tables.fetch() } async function deleteRelationship() { @@ -215,10 +224,26 @@ await tables.fetch() close() } + + function tableChanged(fromTbl, toTbl) { + fromRelationship.name = toTbl?.name || "" + errors.fromCol = "" + toRelationship.name = fromTbl?.name || "" + errors.toCol = "" + if (toTbl || fromTbl) { + checkForErrors( + fromTable, + toTable, + through, + fromRelationship, + toRelationship + ) + } + } ($touched.from = true)} bind:error={errors.from} bind:value={toRelationship.tableId} diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship/TableSelect.svelte b/packages/builder/src/components/backend/Datasources/TableSelect.svelte similarity index 100% rename from packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/CreateEditRelationship/TableSelect.svelte rename to packages/builder/src/components/backend/Datasources/TableSelect.svelte diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/index.svelte index 7c56d502e4..9bd2e10a08 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/index.svelte @@ -8,11 +8,12 @@ Layout, Modal, InlineAlert, + ActionButton, } 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/CreateEditRelationship.svelte" + import CreateEditRelationship from "components/backend/Datasources/CreateEditRelationship.svelte" import CreateExternalTableModal from "./modals/CreateExternalTableModal.svelte" import DisplayColumnModal from "./modals/EditDisplayColumnsModal.svelte" import ICONS from "components/backend/DatasourceNavigator/icons" @@ -174,14 +175,24 @@ Tables
{#if plusTables && plusTables.length !== 0} - + {/if}
- +
@@ -214,9 +225,15 @@
Relationships - + Define existing relationship +
Tell budibase how your tables are related to get even more smart @@ -331,7 +348,6 @@ .table-buttons { display: grid; - grid-gap: var(--spacing-l); grid-template-columns: 1fr 1fr; } diff --git a/packages/builder/src/stores/backend/tables.js b/packages/builder/src/stores/backend/tables.js index 7f90a04a05..baa9e38ab9 100644 --- a/packages/builder/src/stores/backend/tables.js +++ b/packages/builder/src/stores/backend/tables.js @@ -11,6 +11,7 @@ export function createTablesStore() { const tablesResponse = await api.get(`/api/tables`) const tables = await tablesResponse.json() update(state => ({ ...state, list: tables })) + return tables } async function select(table) {