From 6b5c1ffafabc44a92d3bcb2375aa3a64d9be56be Mon Sep 17 00:00:00 2001 From: Martin McKeaveney Date: Sat, 5 Dec 2020 12:09:58 +0000 Subject: [PATCH] consolidate routing and component selection --- .../src/builderStore/getNewComponentName.js | 3 +- packages/builder/src/builderStore/index.js | 12 ++-- .../ComponentTree.svelte | 7 +-- .../LayoutDropdownMenu.svelte | 8 +-- .../ComponentNavigationTree/PathTree.svelte | 2 +- .../ComponentPropertiesPanel.svelte | 23 +++----- .../ComponentSelectionList.svelte | 2 +- .../userInterface/FrontendNavigatePane.svelte | 13 ++-- .../components/userInterface/Layout.svelte | 6 +- .../userInterface/LayoutSelect.svelte | 14 ++--- .../userInterface/NewScreenModal.svelte | 2 +- .../userInterface/SettingsView.svelte | 3 +- .../pages/[application]/data/_layout.svelte | 2 +- .../[asset]}/_fallback.svelte | 0 .../[asset]}/_layout.svelte | 45 ++++++++------ .../design/{ => [assetType]}/_layout.svelte | 0 .../design/[assetType]/index.svelte | 17 ++++++ .../pages/[application]/design/index.svelte | 6 +- .../[application]/design/layouts/index.svelte | 9 --- .../design/screens/[screen]/_fallback.svelte | 0 .../design/screens/[screen]/_layout.svelte | 59 ------------------- .../[application]/design/screens/index.svelte | 9 --- packages/server/src/constants/screens.js | 2 + 23 files changed, 93 insertions(+), 151 deletions(-) rename packages/builder/src/pages/[application]/design/{layouts/[layout] => [assetType]/[asset]}/_fallback.svelte (100%) rename packages/builder/src/pages/[application]/design/{layouts/[layout] => [assetType]/[asset]}/_layout.svelte (53%) rename packages/builder/src/pages/[application]/design/{ => [assetType]}/_layout.svelte (100%) create mode 100644 packages/builder/src/pages/[application]/design/[assetType]/index.svelte delete mode 100644 packages/builder/src/pages/[application]/design/layouts/index.svelte delete mode 100644 packages/builder/src/pages/[application]/design/screens/[screen]/_fallback.svelte delete mode 100644 packages/builder/src/pages/[application]/design/screens/[screen]/_layout.svelte delete mode 100644 packages/builder/src/pages/[application]/design/screens/index.svelte diff --git a/packages/builder/src/builderStore/getNewComponentName.js b/packages/builder/src/builderStore/getNewComponentName.js index 1c156fd9f5..5937eb8823 100644 --- a/packages/builder/src/builderStore/getNewComponentName.js +++ b/packages/builder/src/builderStore/getNewComponentName.js @@ -2,6 +2,7 @@ import { walkProps } from "./storeUtils" import { get_capitalised_name } from "../helpers" import { get } from "svelte/store" import { allScreens } from "builderStore" +import { FrontendTypes } from "../constants" export default function(component, state) { const capitalised = get_capitalised_name( @@ -25,7 +26,7 @@ export default function(component, state) { } // if viewing screen, check current screen for duplicate - if (state.currentFrontEndType === "screen") { + if (state.currentFrontEndType === FrontendTypes.SCREEN) { findMatches(state.currentPreviewItem.props) } else { // viewing a layout - need to find against all screens diff --git a/packages/builder/src/builderStore/index.js b/packages/builder/src/builderStore/index.js index 0475a5c301..91559b585d 100644 --- a/packages/builder/src/builderStore/index.js +++ b/packages/builder/src/builderStore/index.js @@ -15,15 +15,15 @@ export const currentAsset = derived(store, $store => { const layout = $store.layouts ? $store.layouts.find(layout => layout._id === $store.currentAssetId) : null - if (layout) { - return layout - } + + if (layout) return layout + const screen = $store.screens ? $store.screens.find(screen => screen._id === $store.currentAssetId) : null - if (screen) { - return screen - } + + if (screen) return screen + return null }) diff --git a/packages/builder/src/components/userInterface/ComponentNavigationTree/ComponentTree.svelte b/packages/builder/src/components/userInterface/ComponentNavigationTree/ComponentTree.svelte index 347ce00ed2..b8568cae99 100644 --- a/packages/builder/src/components/userInterface/ComponentNavigationTree/ComponentTree.svelte +++ b/packages/builder/src/components/userInterface/ComponentNavigationTree/ComponentTree.svelte @@ -22,12 +22,7 @@ const path = store.actions.components.findRoute(component) // Go to correct URL - $goto(`./${$store.currentFrontEndType}s/${$store.currentAssetId}/${path}`) - // if (layout) { - // $goto(`./layouts/${path}`) - // } else { - // $goto(`./screens/${$currentAsset.id}/${path}`) - // } + $goto(`./${$store.currentAssetId}/${path}`) } const dragstart = component => e => { diff --git a/packages/builder/src/components/userInterface/ComponentNavigationTree/LayoutDropdownMenu.svelte b/packages/builder/src/components/userInterface/ComponentNavigationTree/LayoutDropdownMenu.svelte index 1767cae54c..79a66e0af4 100644 --- a/packages/builder/src/components/userInterface/ComponentNavigationTree/LayoutDropdownMenu.svelte +++ b/packages/builder/src/components/userInterface/ComponentNavigationTree/LayoutDropdownMenu.svelte @@ -42,14 +42,14 @@ - confirmDeleteDialog.show()} /> editLayoutNameModal.show()} /> + confirmDeleteDialog.show()} /> diff --git a/packages/builder/src/components/userInterface/ComponentNavigationTree/PathTree.svelte b/packages/builder/src/components/userInterface/ComponentNavigationTree/PathTree.svelte index cac25c303e..e304ed6d86 100644 --- a/packages/builder/src/components/userInterface/ComponentNavigationTree/PathTree.svelte +++ b/packages/builder/src/components/userInterface/ComponentNavigationTree/PathTree.svelte @@ -19,7 +19,7 @@ const changeScreen = screenId => { // select the route store.actions.screens.select(screenId) - $goto(`./screens/${screenId}`) + $goto(`./screen/${screenId}`) } diff --git a/packages/builder/src/components/userInterface/ComponentPropertiesPanel.svelte b/packages/builder/src/components/userInterface/ComponentPropertiesPanel.svelte index 009596e0f3..eb610f1397 100644 --- a/packages/builder/src/components/userInterface/ComponentPropertiesPanel.svelte +++ b/packages/builder/src/components/userInterface/ComponentPropertiesPanel.svelte @@ -1,5 +1,6 @@ diff --git a/packages/builder/src/components/userInterface/FrontendNavigatePane.svelte b/packages/builder/src/components/userInterface/FrontendNavigatePane.svelte index e3abc42c25..8c634e22f4 100644 --- a/packages/builder/src/components/userInterface/FrontendNavigatePane.svelte +++ b/packages/builder/src/components/userInterface/FrontendNavigatePane.svelte @@ -1,7 +1,8 @@ @@ -27,13 +27,13 @@ icon="ri-layout-3-line" text={layout.name} withArrow - selected={$store.currentComponentInfo?._id === layout.props._id} + selected={$store.currentComponentInfo?._id === layout.props?._id} opened={$store.currentAssetId === layout._id} on:click={selectLayout}> -{#if $store.currentAssetId === layout._id && layout.props._children} +{#if $store.currentAssetId === layout._id && layout.props?._children} -
- -
+ diff --git a/packages/builder/src/components/userInterface/NewScreenModal.svelte b/packages/builder/src/components/userInterface/NewScreenModal.svelte index 6c95987591..05a18adb7f 100644 --- a/packages/builder/src/components/userInterface/NewScreenModal.svelte +++ b/packages/builder/src/components/userInterface/NewScreenModal.svelte @@ -85,7 +85,7 @@ }) } - $goto(`./screens/${createdScreen._id}`) + $goto(`./screen/${createdScreen._id}`) } const routeNameExists = route => { diff --git a/packages/builder/src/components/userInterface/SettingsView.svelte b/packages/builder/src/components/userInterface/SettingsView.svelte index 551d8044bd..e3eed43121 100644 --- a/packages/builder/src/components/userInterface/SettingsView.svelte +++ b/packages/builder/src/components/userInterface/SettingsView.svelte @@ -1,5 +1,6 @@ - +