From fba2f27638d5aac92f3e39552959b8390fcd7c63 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Fri, 15 Jan 2021 14:23:27 +0000 Subject: [PATCH] Update and improve state <-> URL binding --- .../src/builderStore/store/frontend.js | 22 +-- .../AppPreview/ComponentSelectionList.svelte | 6 +- .../ComponentDropdownMenu.svelte | 3 - .../ComponentTree.svelte | 2 - .../ComponentNavigationTree/PathTree.svelte | 2 - .../FrontendNavigatePane.svelte | 2 +- .../design/NavigationPanel/Layout.svelte | 1 - .../NavigationPanel/NewLayoutModal.svelte | 3 +- .../NavigationPanel/NewScreenModal.svelte | 4 +- .../PropertyControls/TableViewSelect.svelte | 1 - .../design/[assetType]/[asset]/_layout.svelte | 132 +++++++++++------- .../design/[assetType]/_layout.svelte | 16 +-- .../design/[assetType]/index.svelte | 62 ++++---- 13 files changed, 121 insertions(+), 135 deletions(-) diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index 4f9f343469..0bb1f59c5d 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -13,12 +13,7 @@ import { fetchComponentLibDefinitions } from "../loadComponentLibraries" import api from "../api" import { FrontendTypes } from "constants" import analytics from "analytics" -import { - findComponentType, - findComponentParent, - findComponentPath, - findComponent, -} from "../storeUtils" +import { findComponentType, findComponentParent } from "../storeUtils" import { uuid } from "../uuid" const INITIAL_FRONTEND_STATE = { @@ -487,21 +482,6 @@ export const getFrontendStore = () => { }) store.actions.preview.saveSelected() }, - findRoute: component => { - const selectedAsset = get(currentAsset) - if (!component || !selectedAsset) { - return "/" - } - - // Get the path to this component - const path = findComponentPath(selectedAsset.props, component._id) || [] - - // Remove root entry since it's the screen or layout - return path - .slice(1) - .map(component => component._id) - .join("/") - }, links: { save: async (url, title) => { const layout = get(mainLayout) diff --git a/packages/builder/src/components/design/AppPreview/ComponentSelectionList.svelte b/packages/builder/src/components/design/AppPreview/ComponentSelectionList.svelte index 7e6e1a4631..7ec58fc2c3 100644 --- a/packages/builder/src/components/design/AppPreview/ComponentSelectionList.svelte +++ b/packages/builder/src/components/design/AppPreview/ComponentSelectionList.svelte @@ -46,11 +46,7 @@ popover.show() } else { // Add this component - const newComponent = store.actions.components.create(item.component) - if (newComponent) { - const path = store.actions.components.findRoute(newComponent) - $goto(`./${$currentAssetId}/${path}`) - } + store.actions.components.create(item.component) popover.hide() } } diff --git a/packages/builder/src/components/design/NavigationPanel/ComponentDropdownMenu.svelte b/packages/builder/src/components/design/NavigationPanel/ComponentDropdownMenu.svelte index 5ab3898c8d..a027beab18 100644 --- a/packages/builder/src/components/design/NavigationPanel/ComponentDropdownMenu.svelte +++ b/packages/builder/src/components/design/NavigationPanel/ComponentDropdownMenu.svelte @@ -1,5 +1,4 @@ diff --git a/packages/builder/src/components/design/NavigationPanel/FrontendNavigatePane.svelte b/packages/builder/src/components/design/NavigationPanel/FrontendNavigatePane.svelte index db5e3e941b..147f32bb3e 100644 --- a/packages/builder/src/components/design/NavigationPanel/FrontendNavigatePane.svelte +++ b/packages/builder/src/components/design/NavigationPanel/FrontendNavigatePane.svelte @@ -28,7 +28,7 @@ let modal let routes = {} - let tab = $params.assetType + $: tab = $params.assetType const navigate = ({ detail }) => { if (!detail) { diff --git a/packages/builder/src/components/design/NavigationPanel/Layout.svelte b/packages/builder/src/components/design/NavigationPanel/Layout.svelte index 77bab330c5..bab9cf56b6 100644 --- a/packages/builder/src/components/design/NavigationPanel/Layout.svelte +++ b/packages/builder/src/components/design/NavigationPanel/Layout.svelte @@ -19,7 +19,6 @@ const selectLayout = () => { store.actions.layouts.select(layout._id) - $goto(`./${layout._id}`) } diff --git a/packages/builder/src/components/design/NavigationPanel/NewLayoutModal.svelte b/packages/builder/src/components/design/NavigationPanel/NewLayoutModal.svelte index 1781c6a2d3..7920f9bbf5 100644 --- a/packages/builder/src/components/design/NavigationPanel/NewLayoutModal.svelte +++ b/packages/builder/src/components/design/NavigationPanel/NewLayoutModal.svelte @@ -8,8 +8,7 @@ async function save() { try { - const layout = await store.actions.layouts.save({ name }) - $goto(`./${layout._id}`) + await store.actions.layouts.save({ name }) notifier.success(`Layout ${name} created successfully`) } catch (err) { notifier.danger(`Error creating layout ${name}.`) diff --git a/packages/builder/src/components/design/NavigationPanel/NewScreenModal.svelte b/packages/builder/src/components/design/NavigationPanel/NewScreenModal.svelte index db9181b1bd..c33d12c1a1 100644 --- a/packages/builder/src/components/design/NavigationPanel/NewScreenModal.svelte +++ b/packages/builder/src/components/design/NavigationPanel/NewScreenModal.svelte @@ -63,7 +63,7 @@ draftScreen.props._component = baseComponent draftScreen.routing = { route, roleId } - const createdScreen = await store.actions.screens.create(draftScreen) + await store.actions.screens.create(draftScreen) if (createLink) { await store.actions.components.links.save(route, name) } @@ -75,8 +75,6 @@ template: template.id || template.name, }) } - - $goto(`./${createdScreen._id}`) } const routeExists = (route, roleId) => { diff --git a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/TableViewSelect.svelte b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/TableViewSelect.svelte index f66333e4c0..f815cac786 100644 --- a/packages/builder/src/components/design/PropertiesPanel/PropertyControls/TableViewSelect.svelte +++ b/packages/builder/src/components/design/PropertiesPanel/PropertyControls/TableViewSelect.svelte @@ -35,7 +35,6 @@ $currentAsset.props, $store.selectedComponentId ) - $: console.log(bindableProperties) $: links = bindableProperties .filter(x => x.fieldSchema?.type === "link") diff --git a/packages/builder/src/pages/[application]/design/[assetType]/[asset]/_layout.svelte b/packages/builder/src/pages/[application]/design/[assetType]/[asset]/_layout.svelte index eb266293d9..baa253ce9f 100644 --- a/packages/builder/src/pages/[application]/design/[assetType]/[asset]/_layout.svelte +++ b/packages/builder/src/pages/[application]/design/[assetType]/[asset]/_layout.svelte @@ -1,64 +1,92 @@ diff --git a/packages/builder/src/pages/[application]/design/[assetType]/_layout.svelte b/packages/builder/src/pages/[application]/design/[assetType]/_layout.svelte index 19cf59cebd..f3bd8499f5 100644 --- a/packages/builder/src/pages/[application]/design/[assetType]/_layout.svelte +++ b/packages/builder/src/pages/[application]/design/[assetType]/_layout.svelte @@ -11,25 +11,11 @@ import ComponentSelectionList from "components/design/AppPreview/ComponentSelectionList.svelte" import FrontendNavigatePane from "components/design/NavigationPanel/FrontendNavigatePane.svelte" - $: instance = $store.appInstance - - async function selectDatabase(database) { - backendUiStore.actions.database.select(database) - } - onMount(async () => { if ($store.appInstance && !$backendUiStore.database) { - await selectDatabase($store.appInstance) + backendUiStore.actions.database.select($store.appInstance) } }) - - let confirmDeleteDialog - let componentToDelete = "" - - let settingsView - const settings = () => { - settingsView.show() - } diff --git a/packages/builder/src/pages/[application]/design/[assetType]/index.svelte b/packages/builder/src/pages/[application]/design/[assetType]/index.svelte index 30545212a9..de74eef1ac 100644 --- a/packages/builder/src/pages/[application]/design/[assetType]/index.svelte +++ b/packages/builder/src/pages/[application]/design/[assetType]/index.svelte @@ -1,37 +1,45 @@