From a7db499544838701141a8e1852d7f5a3cf71ec85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keviin=20=C3=85berg=20Kultalahti?= Date: Mon, 15 Feb 2021 17:12:39 +0100 Subject: [PATCH] initial work to switch toggle to radio button --- packages/builder/package.json | 2 +- .../builder/src/builderStore/store/backend.js | 6 ++-- .../screenTemplates/utils/commonComponents.js | 2 +- .../DataTable/modals/CreateEditColumn.svelte | 33 ++++++++++++++----- .../common/LinkedRowSelector.svelte | 2 +- packages/builder/yarn.lock | 8 ++--- .../src/forms/RelationshipField.svelte | 4 +-- 7 files changed, 37 insertions(+), 20 deletions(-) diff --git a/packages/builder/package.json b/packages/builder/package.json index 85580fa40b..947bce4b6a 100644 --- a/packages/builder/package.json +++ b/packages/builder/package.json @@ -63,7 +63,7 @@ } }, "dependencies": { - "@budibase/bbui": "^1.58.5", + "@budibase/bbui": "^1.58.6", "@budibase/client": "^0.7.7", "@budibase/colorpicker": "1.0.1", "@budibase/string-templates": "^0.7.7", diff --git a/packages/builder/src/builderStore/store/backend.js b/packages/builder/src/builderStore/store/backend.js index 69c601cf2b..a5d2a81bad 100644 --- a/packages/builder/src/builderStore/store/backend.js +++ b/packages/builder/src/builderStore/store/backend.js @@ -234,7 +234,7 @@ export const getBackendUiStore = () => { return state }) }, - saveField: ({ originalName, field, primaryDisplay = false, indexes, oneToMany = false }) => { + saveField: ({ originalName, field, primaryDisplay = false, indexes, relationshipType = 'many-to-many' }) => { store.update(state => { console.log(state) // delete the original if renaming @@ -252,8 +252,8 @@ export const getBackendUiStore = () => { state.draftTable.primaryDisplay = field.name } // Set one-to-many - if (oneToMany) { - state.draftTable.oneToMany = field.name + if (relationshipType) { + state.draftTable.relationshipType = field.name } if (indexes) { diff --git a/packages/builder/src/builderStore/store/screenTemplates/utils/commonComponents.js b/packages/builder/src/builderStore/store/screenTemplates/utils/commonComponents.js index 83b6391659..f901794b36 100644 --- a/packages/builder/src/builderStore/store/screenTemplates/utils/commonComponents.js +++ b/packages/builder/src/builderStore/store/screenTemplates/utils/commonComponents.js @@ -195,7 +195,7 @@ export function makeDatasourceFormComponents(datasource) { component.customProps({ placeholder: "Choose an option " }) } if (fieldType === "link") { - let placeholder = fieldSchema.oneToMany ? 'Choose an option' : 'Choose some options' + let placeholder = fieldSchema.relationshipType === 'one-to-many' ? 'Choose an option' : 'Choose some options' component.customProps({ placeholder }) } if (fieldType === "boolean") { diff --git a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte index 66317b26ea..96385d62ca 100644 --- a/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte +++ b/packages/builder/src/components/backend/DataTable/modals/CreateEditColumn.svelte @@ -6,6 +6,8 @@ TextButton, Select, Toggle, + Radio, + } from "@budibase/bbui" import { cloneDeep } from "lodash/fp" import { backendUiStore } from "builderStore" @@ -31,8 +33,15 @@ let primaryDisplay = $backendUiStore.selectedTable.primaryDisplay == null || $backendUiStore.selectedTable.primaryDisplay === field.name - - let oneToMany = false; + + let relationshipTypes = [ + {text: 'Many to many (N:N)', value: 'many-to-many',}, + {text: 'One to many (1:N)', value: 'one-to-many',} + ] + let relationshipType = 'many-to-many'; + + $: console.log(relationshipType) + let indexes = [...($backendUiStore.selectedTable.indexes || [])] let confirmDeleteDialog let deletion @@ -51,7 +60,7 @@ originalName, field, primaryDisplay, - oneToMany, + relationshipType, indexes, }) return state @@ -187,11 +196,14 @@ label="Max Value" bind:value={field.constraints.numericality.lessThanOrEqualTo} /> {:else if field.type === 'link'} - +
+ +
+ {#each relationshipTypes as {text, value}} + + {/each} +
+
linkedRows = [e.target.value]} name={label} {label}> {#each rows as row} diff --git a/packages/builder/yarn.lock b/packages/builder/yarn.lock index d44a9e63c0..dfa3e2aba0 100644 --- a/packages/builder/yarn.lock +++ b/packages/builder/yarn.lock @@ -842,10 +842,10 @@ lodash "^4.17.19" to-fast-properties "^2.0.0" -"@budibase/bbui@^1.58.5": - version "1.58.5" - resolved "https://registry.yarnpkg.com/@budibase/bbui/-/bbui-1.58.5.tgz#c9ce712941760825c7774a1de77594e989db4561" - integrity sha512-0j1I7BetJ2GzB1BXKyvvlkuFphLmADJh2U/Ihubwxx5qUDY8REoVzLgAB4c24zt0CGVTF9VMmOoMLd0zD0QwdQ== +"@budibase/bbui@^1.58.6": + version "1.58.6" + resolved "https://registry.yarnpkg.com/@budibase/bbui/-/bbui-1.58.6.tgz#ed74c99abdd61a2893cc30362ff893f98037fcce" + integrity sha512-xAKbQxucyVWLZGCaJiaacu1pyZX7vCqoPJJiQx/eF+7gX8uB1gCuzxhncM4ZaIwCCiuc51dD2Q19t3R4ObxxCA== dependencies: markdown-it "^12.0.2" quill "^1.3.7" diff --git a/packages/standard-components/src/forms/RelationshipField.svelte b/packages/standard-components/src/forms/RelationshipField.svelte index ffe6fcda3b..603f02e0ef 100644 --- a/packages/standard-components/src/forms/RelationshipField.svelte +++ b/packages/standard-components/src/forms/RelationshipField.svelte @@ -19,7 +19,7 @@ let fieldText = "" const setFieldText = (value) => { - if (fieldSchema?.oneToMany) { + if (fieldSchema?.relationshipType === 'one-to-many') { if (value?.length && options?.length) { const row = options.find(row => row._id === value[0]) return row.name @@ -73,7 +73,7 @@ } const toggleOption = option => { - if (fieldSchema.oneToMany) { + if (fieldSchema.type === 'one-to-many') { fieldApi.setValue([option]) } else { if ($fieldState.value.includes(option)) {