From b4ded22ac9067d3eb3b36ef02627eaffd059386b Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 13 Oct 2020 11:11:59 +0100 Subject: [PATCH 01/17] Fix crashing when rendering any components settings that uses a ScreenSelect --- .../builder/src/components/userInterface/ScreenSelect.svelte | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/builder/src/components/userInterface/ScreenSelect.svelte b/packages/builder/src/components/userInterface/ScreenSelect.svelte index 6c999a5b01..9c80e54b00 100644 --- a/packages/builder/src/components/userInterface/ScreenSelect.svelte +++ b/packages/builder/src/components/userInterface/ScreenSelect.svelte @@ -9,6 +9,7 @@ export let value = "" $: urls = getUrls() + $: console.log(urls) const handleBlur = () => dispatch("change", value) @@ -61,9 +62,9 @@ sort: detailScreen.props._component, }) } - - return urls } + + return urls } From f9f939152ad4680ca6d10ceb16040d78ff8d0181 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 13 Oct 2020 11:27:18 +0100 Subject: [PATCH 02/17] Update all old references in datasources from isModel to type=model --- .../store/screenTemplates/recordListScreen.js | 2 +- .../tests/fetchBindableProperties.spec.js | 176 +++++++++++------- 2 files changed, 110 insertions(+), 68 deletions(-) diff --git a/packages/builder/src/builderStore/store/screenTemplates/recordListScreen.js b/packages/builder/src/builderStore/store/screenTemplates/recordListScreen.js index 0210e7a85e..9246def7f7 100644 --- a/packages/builder/src/builderStore/store/screenTemplates/recordListScreen.js +++ b/packages/builder/src/builderStore/store/screenTemplates/recordListScreen.js @@ -98,7 +98,7 @@ const createScreen = model => ({ label: "Deals", name: `all_${model._id}`, modelId: model._id, - isModel: true, + type: "model", }, _instanceName: `${model.name} Table`, _children: [], diff --git a/packages/builder/tests/fetchBindableProperties.spec.js b/packages/builder/tests/fetchBindableProperties.spec.js index 76e8e33f05..79d4a272fe 100644 --- a/packages/builder/tests/fetchBindableProperties.spec.js +++ b/packages/builder/tests/fetchBindableProperties.spec.js @@ -1,13 +1,14 @@ import fetchBindableProperties from "../src/builderStore/fetchBindableProperties" describe("fetch bindable properties", () => { - it("should return bindable properties from screen components", () => { const result = fetchBindableProperties({ componentInstanceId: "heading-id", - ...testData() + ...testData(), }) - const componentBinding = result.find(r => r.instance._id === "search-input-id" && r.type === "instance") + const componentBinding = result.find( + r => r.instance._id === "search-input-id" && r.type === "instance" + ) expect(componentBinding).toBeDefined() expect(componentBinding.type).toBe("instance") expect(componentBinding.runtimeBinding).toBe("search-input-id.value") @@ -16,29 +17,39 @@ describe("fetch bindable properties", () => { it("should not return bindable components when not in their context", () => { const result = fetchBindableProperties({ componentInstanceId: "heading-id", - ...testData() + ...testData(), }) - const componentBinding = result.find(r => r.instance._id === "list-item-input-id") + const componentBinding = result.find( + r => r.instance._id === "list-item-input-id" + ) expect(componentBinding).not.toBeDefined() }) it("should return model schema, when inside a context", () => { const result = fetchBindableProperties({ componentInstanceId: "list-item-input-id", - ...testData() + ...testData(), }) - const contextBindings = result.filter(r => r.instance._id === "list-id" && r.type==="context") - // 2 fields + _id + _rev + const contextBindings = result.filter( + r => r.instance._id === "list-id" && r.type === "context" + ) + // 2 fields + _id + _rev expect(contextBindings.length).toBe(4) - - const namebinding = contextBindings.find(b => b.runtimeBinding === "data.name") + + const namebinding = contextBindings.find( + b => b.runtimeBinding === "data.name" + ) expect(namebinding).toBeDefined() expect(namebinding.readableBinding).toBe("list-name.Test Model.name") - - const descriptionbinding = contextBindings.find(b => b.runtimeBinding === "data.description") + + const descriptionbinding = contextBindings.find( + b => b.runtimeBinding === "data.description" + ) expect(descriptionbinding).toBeDefined() - expect(descriptionbinding.readableBinding).toBe("list-name.Test Model.description") - + expect(descriptionbinding.readableBinding).toBe( + "list-name.Test Model.description" + ) + const idbinding = contextBindings.find(b => b.runtimeBinding === "data._id") expect(idbinding).toBeDefined() expect(idbinding.readableBinding).toBe("list-name.Test Model._id") @@ -47,35 +58,51 @@ describe("fetch bindable properties", () => { it("should return model schema, for grantparent context", () => { const result = fetchBindableProperties({ componentInstanceId: "child-list-item-input-id", - ...testData() + ...testData(), }) - const contextBindings = result.filter(r => r.type==="context") + const contextBindings = result.filter(r => r.type === "context") // 2 fields + _id + _rev ... x 2 models expect(contextBindings.length).toBe(8) - - const namebinding_parent = contextBindings.find(b => b.runtimeBinding === "parent.data.name") + + const namebinding_parent = contextBindings.find( + b => b.runtimeBinding === "parent.data.name" + ) expect(namebinding_parent).toBeDefined() expect(namebinding_parent.readableBinding).toBe("list-name.Test Model.name") - - const descriptionbinding_parent = contextBindings.find(b => b.runtimeBinding === "parent.data.description") + + const descriptionbinding_parent = contextBindings.find( + b => b.runtimeBinding === "parent.data.description" + ) expect(descriptionbinding_parent).toBeDefined() - expect(descriptionbinding_parent.readableBinding).toBe("list-name.Test Model.description") - - const namebinding_own = contextBindings.find(b => b.runtimeBinding === "data.name") + expect(descriptionbinding_parent.readableBinding).toBe( + "list-name.Test Model.description" + ) + + const namebinding_own = contextBindings.find( + b => b.runtimeBinding === "data.name" + ) expect(namebinding_own).toBeDefined() - expect(namebinding_own.readableBinding).toBe("child-list-name.Test Model.name") - - const descriptionbinding_own = contextBindings.find(b => b.runtimeBinding === "data.description") + expect(namebinding_own.readableBinding).toBe( + "child-list-name.Test Model.name" + ) + + const descriptionbinding_own = contextBindings.find( + b => b.runtimeBinding === "data.description" + ) expect(descriptionbinding_own).toBeDefined() - expect(descriptionbinding_own.readableBinding).toBe("child-list-name.Test Model.description") + expect(descriptionbinding_own.readableBinding).toBe( + "child-list-name.Test Model.description" + ) }) it("should return bindable component props, from components in same context", () => { const result = fetchBindableProperties({ componentInstanceId: "list-item-heading-id", - ...testData() + ...testData(), }) - const componentBinding = result.find(r => r.instance._id === "list-item-input-id" && r.type === "instance") + const componentBinding = result.find( + r => r.instance._id === "list-item-input-id" && r.type === "instance" + ) expect(componentBinding).toBeDefined() expect(componentBinding.runtimeBinding).toBe("list-item-input-id.value") }) @@ -83,125 +110,140 @@ describe("fetch bindable properties", () => { it("should not return components from child context", () => { const result = fetchBindableProperties({ componentInstanceId: "list-item-heading-id", - ...testData() + ...testData(), }) - const componentBinding = result.find(r => r.instance._id === "child-list-item-input-id" && r.type === "instance") + const componentBinding = result.find( + r => + r.instance._id === "child-list-item-input-id" && r.type === "instance" + ) expect(componentBinding).not.toBeDefined() }) - + it("should return bindable component props, from components in same context (when nested context)", () => { const result = fetchBindableProperties({ componentInstanceId: "child-list-item-heading-id", - ...testData() + ...testData(), }) - const componentBinding = result.find(r => r.instance._id === "child-list-item-input-id" && r.type === "instance") + const componentBinding = result.find( + r => + r.instance._id === "child-list-item-input-id" && r.type === "instance" + ) expect(componentBinding).toBeDefined() - }) - + }) }) const testData = () => { - const screen = { instanceName: "test screen", name: "screen-id", route: "/", props: { - _id:"screent-root-id", + _id: "screent-root-id", _component: "@budibase/standard-components/container", _children: [ { _id: "heading-id", _instanceName: "list item heading", _component: "@budibase/standard-components/heading", - text: "Screen Title" + text: "Screen Title", }, { _id: "search-input-id", _instanceName: "Search Input", _component: "@budibase/standard-components/input", - value: "search phrase" + value: "search phrase", }, { _id: "list-id", _component: "@budibase/standard-components/list", _instanceName: "list-name", - model: { isModel: true, modelId: "test-model-id", label: "Test Model", name: "all_test-model-id" }, + model: { + type: "model", + modelId: "test-model-id", + label: "Test Model", + name: "all_test-model-id", + }, _children: [ { _id: "list-item-heading-id", _instanceName: "list item heading", _component: "@budibase/standard-components/heading", - text: "hello" + text: "hello", }, { _id: "list-item-input-id", _instanceName: "List Item Input", _component: "@budibase/standard-components/input", - value: "list item" + value: "list item", }, { _id: "child-list-id", _component: "@budibase/standard-components/list", _instanceName: "child-list-name", - model: { isModel: true, modelId: "test-model-id", label: "Test Model", name: "all_test-model-id"}, + model: { + type: "model", + modelId: "test-model-id", + label: "Test Model", + name: "all_test-model-id", + }, _children: [ { _id: "child-list-item-heading-id", _instanceName: "child list item heading", _component: "@budibase/standard-components/heading", - text: "hello" + text: "hello", }, { _id: "child-list-item-input-id", _instanceName: "Child List Item Input", _component: "@budibase/standard-components/input", - value: "child list item" + value: "child list item", }, - ] + ], }, - ] + ], }, - ] - } + ], + }, } - const models = [{ - _id: "test-model-id", - name: "Test Model", + const models = [ + { + _id: "test-model-id", + name: "Test Model", schema: { name: { - type: "string" + type: "string", }, description: { - type: "string" - } - } - }] + type: "string", + }, + }, + }, + ] const components = { - "@budibase/standard-components/container" : { + "@budibase/standard-components/container": { props: {}, }, - "@budibase/standard-components/list" : { + "@budibase/standard-components/list": { context: "model", props: { - model: "string" + model: "string", }, }, - "@budibase/standard-components/input" : { + "@budibase/standard-components/input": { bindable: "value", props: { - value: "string" + value: "string", }, }, - "@budibase/standard-components/heading" : { + "@budibase/standard-components/heading": { props: { - text: "string" + text: "string", }, }, } return { screen, models, components } - -} \ No newline at end of file +} From 751e19c40e141cb0516766aea3732330a6c51753 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Tue, 13 Oct 2020 14:29:32 +0100 Subject: [PATCH 03/17] Fix checkbox depth in frontend settings --- packages/builder/src/components/common/Checkbox.svelte | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/builder/src/components/common/Checkbox.svelte b/packages/builder/src/components/common/Checkbox.svelte index 3c5888d7c8..45e4947da6 100644 --- a/packages/builder/src/components/common/Checkbox.svelte +++ b/packages/builder/src/components/common/Checkbox.svelte @@ -12,13 +12,18 @@ -
+
diff --git a/packages/standard-components/src/NewRow.svelte b/packages/standard-components/src/NewRow.svelte index 817e07e0d0..e7446f9bdc 100644 --- a/packages/standard-components/src/NewRow.svelte +++ b/packages/standard-components/src/NewRow.svelte @@ -19,7 +19,7 @@ } onMount(async () => { - if (table) { + if (table && typeof table === "string") { const tableObj = await fetchTable(table) row.tableId = table row._table = tableObj From d2ac13a253192338c8ebc3e9cd47957e9ba56b3b Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 14 Oct 2020 09:53:27 +0100 Subject: [PATCH 13/17] Fix grid not allowing adding rows due to model -> table rename --- packages/standard-components/src/DataGrid/Component.svelte | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/standard-components/src/DataGrid/Component.svelte b/packages/standard-components/src/DataGrid/Component.svelte index a292104bd1..dd700c55f7 100644 --- a/packages/standard-components/src/DataGrid/Component.svelte +++ b/packages/standard-components/src/DataGrid/Component.svelte @@ -23,7 +23,7 @@ // These can never change at runtime so don't need to be reactive let canEdit = editable && datasource && datasource.type !== "view" - let canAddDelete = editable && datasource && datasource.type === "model" + let canAddDelete = editable && datasource && datasource.type === "table" let store = _bb.store let dataLoaded = false From 2fc44f03d0d9fa49cc13f2ce292ae7609916a80e Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 14 Oct 2020 10:06:33 +0100 Subject: [PATCH 14/17] Remove console.log statements --- packages/standard-components/src/DataTable.svelte | 1 - packages/standard-components/src/fetchData.js | 1 - 2 files changed, 2 deletions(-) diff --git a/packages/standard-components/src/DataTable.svelte b/packages/standard-components/src/DataTable.svelte index eabd48c4c6..bdb0c76183 100644 --- a/packages/standard-components/src/DataTable.svelte +++ b/packages/standard-components/src/DataTable.svelte @@ -40,7 +40,6 @@ onMount(async () => { if (!isEmpty(datasource)) { - console.log(datasource) data = await fetchData(datasource, $store) // Get schema for datasource diff --git a/packages/standard-components/src/fetchData.js b/packages/standard-components/src/fetchData.js index a9fc45bcf4..68aca7eac6 100644 --- a/packages/standard-components/src/fetchData.js +++ b/packages/standard-components/src/fetchData.js @@ -46,7 +46,6 @@ export default async function fetchData(datasource, store) { } async function fetchViewData() { - console.log("fetching view") const { field, groupBy } = datasource const params = new URLSearchParams() From 2dce25c99aca2df389c9a95a0c9d6d7243046b97 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Wed, 14 Oct 2020 10:10:16 +0100 Subject: [PATCH 15/17] Remove console.log statement --- .../builder/src/components/userInterface/ScreenSelect.svelte | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/builder/src/components/userInterface/ScreenSelect.svelte b/packages/builder/src/components/userInterface/ScreenSelect.svelte index a8c4b96227..33174355bb 100644 --- a/packages/builder/src/components/userInterface/ScreenSelect.svelte +++ b/packages/builder/src/components/userInterface/ScreenSelect.svelte @@ -9,7 +9,6 @@ export let value = "" $: urls = getUrls() - $: console.log(urls) const handleBlur = () => dispatch("change", value) From e96098c5f4aedfbd7f4af8485a41f758661b11df Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 14 Oct 2020 11:56:02 +0100 Subject: [PATCH 16/17] Some design changes and moving around screen deletion to centralise it. --- .../builder/src/builderStore/store/index.js | 21 +++++++++++++++++++ .../popovers/EditTablePopover.svelte | 20 +++--------------- .../userInterface/ScreenDropdownMenu.svelte | 17 ++------------- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/packages/builder/src/builderStore/store/index.js b/packages/builder/src/builderStore/store/index.js index 4eeb2e3842..bb61712f1a 100644 --- a/packages/builder/src/builderStore/store/index.js +++ b/packages/builder/src/builderStore/store/index.js @@ -53,6 +53,7 @@ export const getStore = () => { store.saveScreen = saveScreen(store) store.setCurrentScreen = setCurrentScreen(store) + store.deleteScreens = deleteScreens(store) store.setCurrentPage = setCurrentPage(store) store.createScreen = createScreen(store) store.addStylesheet = addStylesheet(store) @@ -185,6 +186,26 @@ const setCurrentScreen = store => screenName => { }) } +const deleteScreens = store => (screens, pageName = null) => { + if (!(screens instanceof Array)) { + screens = [screens] + } + store.update(state => { + if (pageName == null) { + pageName = state.pages.main.name + } + for (let screen of screens) { + state.screens = state.screens.filter(c => c.name !== screen.name) + // Remove screen from current page as well + state.pages[pageName]._screens = state.pages[pageName]._screens.filter( + scr => scr.name !== screen.name + ) + api.delete(`/_builder/api/pages/${pageName}/screens/${screen.name}`) + } + return state + }) +} + const savePage = store => async page => { store.update(state => { if (state.currentFrontEndType !== "page" || !state.currentPageName) { diff --git a/packages/builder/src/components/backend/TableNavigator/popovers/EditTablePopover.svelte b/packages/builder/src/components/backend/TableNavigator/popovers/EditTablePopover.svelte index d9e7e6867b..c4f5e2176c 100644 --- a/packages/builder/src/components/backend/TableNavigator/popovers/EditTablePopover.svelte +++ b/packages/builder/src/components/backend/TableNavigator/popovers/EditTablePopover.svelte @@ -35,24 +35,10 @@ confirmDeleteDialog.show() } - function deleteTemplateScreens() { - store.update(state => { - for (let screen of templateScreens) { - const mainPageName = state.pages.main.name - state.screens = state.screens.filter(c => c.name !== screen.name) - // Remove screen from current page as well - state.pages[state.currentPageName]._screens = state.pages[mainPageName]._screens.filter( - scr => scr.name !== screen.name - ) - api.delete(`/_builder/api/pages/${mainPageName}/screens/${screen.name}`) - } - return state - }) - } async function deleteTable() { await backendUiStore.actions.tables.delete(table) - deleteTemplateScreens() + store.deleteScreens(templateScreens) notifier.success("Table deleted") hideEditor() } @@ -102,11 +88,10 @@ - The following will also be deleted: + Are you sure you wish to delete the table {table.name}? The following will also be deleted:
{#each willBeDeleted as item} @@ -137,6 +122,7 @@ div.delete-items div { margin-top: 4px; + font-weight: 500 } .actions { diff --git a/packages/builder/src/components/userInterface/ScreenDropdownMenu.svelte b/packages/builder/src/components/userInterface/ScreenDropdownMenu.svelte index 69e9ea498a..7ae8bbf432 100644 --- a/packages/builder/src/components/userInterface/ScreenDropdownMenu.svelte +++ b/packages/builder/src/components/userInterface/ScreenDropdownMenu.svelte @@ -17,26 +17,13 @@ } const deleteScreen = () => { + store.deleteScreens(screen, $store.currentPageName) + // update the page if required store.update(state => { - // Remove screen from screens - const screens = state.screens.filter(c => c.name !== screen.name) - state.screens = screens - - // Remove screen from current page as well - const pageScreens = state.pages[state.currentPageName]._screens.filter( - scr => scr.name !== screen.name - ) - state.pages[state.currentPageName]._screens = pageScreens - if (state.currentPreviewItem.name === screen.name) { store.setCurrentPage($store.currentPageName) $goto(`./:page/page-layout`) } - - api.delete( - `/_builder/api/pages/${state.currentPageName}/screens/${screen.name}` - ) - return state }) } From e33dd657684b22da77d19e51d2960067d844eba7 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 14 Oct 2020 12:22:43 +0100 Subject: [PATCH 17/17] Upgrading prettier svelte plugin until found a version that works for our formatting without breaking on some syntax. --- package.json | 2 +- .../popovers/EditTablePopover.svelte | 21 +++++++++++-------- .../components/common/ConfirmDialog.svelte | 5 ++++- yarn.lock | 11 +++++----- 4 files changed, 22 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 5a7d40fe1c..15d9088466 100644 --- a/package.json +++ b/package.json @@ -10,7 +10,7 @@ "eslint-plugin-svelte3": "^2.7.3", "lerna": "3.14.1", "prettier": "^1.19.1", - "prettier-plugin-svelte": "^0.7.0", + "prettier-plugin-svelte": "^1.1.0", "rimraf": "^3.0.2", "rollup-plugin-replace": "^2.2.0", "svelte": "^3.28.0" diff --git a/packages/builder/src/components/backend/TableNavigator/popovers/EditTablePopover.svelte b/packages/builder/src/components/backend/TableNavigator/popovers/EditTablePopover.svelte index c4f5e2176c..4e74ea163a 100644 --- a/packages/builder/src/components/backend/TableNavigator/popovers/EditTablePopover.svelte +++ b/packages/builder/src/components/backend/TableNavigator/popovers/EditTablePopover.svelte @@ -30,12 +30,13 @@ function showModal() { const screens = $store.allScreens templateScreens = screens.filter(screen => screen.props.table === table._id) - willBeDeleted = ["All table data"].concat(templateScreens.map(screen => `Screen ${screen.props._instanceName}`)) + willBeDeleted = ["All table data"].concat( + templateScreens.map(screen => `Screen ${screen.props._instanceName}`) + ) hideEditor() confirmDeleteDialog.show() } - async function deleteTable() { await backendUiStore.actions.tables.delete(table) store.deleteScreens(templateScreens) @@ -91,13 +92,15 @@ okText="Delete Table" onOk={deleteTable} title="Confirm Delete"> - Are you sure you wish to delete the table {table.name}? The following will also be deleted: + Are you sure you wish to delete the table + {table.name}? + The following will also be deleted: -
- {#each willBeDeleted as item} -
{item}
- {/each} -
+
+ {#each willBeDeleted as item} +
{item}
+ {/each} +
This action cannot be undone. @@ -122,7 +125,7 @@ div.delete-items div { margin-top: 4px; - font-weight: 500 + font-weight: 500; } .actions { diff --git a/packages/builder/src/components/common/ConfirmDialog.svelte b/packages/builder/src/components/common/ConfirmDialog.svelte index 7d4c3ff0e2..27a7517fce 100644 --- a/packages/builder/src/components/common/ConfirmDialog.svelte +++ b/packages/builder/src/components/common/ConfirmDialog.svelte @@ -20,7 +20,10 @@ -
{body}
+
+ {body} + +
diff --git a/yarn.lock b/yarn.lock index 9b84e373af..076a4a90dd 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3690,11 +3690,10 @@ prettier-linter-helpers@^1.0.0: dependencies: fast-diff "^1.1.2" -prettier-plugin-svelte@^0.7.0: - version "0.7.0" - resolved "https://registry.yarnpkg.com/prettier-plugin-svelte/-/prettier-plugin-svelte-0.7.0.tgz#5ac0b9f194e0450c88ff1e167cbf3b32d2642df2" - dependencies: - tslib "^1.9.3" +prettier-plugin-svelte@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/prettier-plugin-svelte/-/prettier-plugin-svelte-1.1.0.tgz#e6ec282d8457598b0c02164083b11ad8cb8ab304" + integrity sha512-wmIggG/ryV0wcmE9D5p+k5TwKDpS2SGKJpF6IV1aYHK7dkBJD+di1w47Ci00DRsI4RrXZRC2Ef37DSyrTb6Zqg== prettier@^1.19.1: version "1.19.1" @@ -4529,7 +4528,7 @@ trim-off-newlines@^1.0.0: version "1.0.1" resolved "https://registry.yarnpkg.com/trim-off-newlines/-/trim-off-newlines-1.0.1.tgz#9f9ba9d9efa8764c387698bcbfeb2c848f11adb3" -tslib@^1.9.0, tslib@^1.9.3: +tslib@^1.9.0: version "1.10.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a"