From 6b9e61e7e6359cafb812d94ee9b58fcbf4eeef3e Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 14 Jan 2021 09:09:23 +0000 Subject: [PATCH] Fix component navigation, fix settings editing, fix design editing --- .../src/builderStore/store/frontend.js | 60 +++++++++--- .../ComponentDropdownMenu.svelte | 60 ++++++------ .../ComponentPropertiesPanel.svelte | 49 +++------- .../userInterface/DesignView.svelte | 16 ++-- .../userInterface/IconSelect/index.js | 3 - .../MultiTableViewFieldSelect.svelte | 2 +- .../userInterface/PropertyGroup.svelte | 5 +- .../EventsEditor/EventEditorModal.svelte | 0 .../EventsEditor/EventPropertyControl.svelte | 0 .../EventsEditor/actions/CreateRow.svelte | 0 .../EventsEditor/actions/DeleteRow.svelte | 0 .../EventsEditor/actions/NavigateTo.svelte | 0 .../EventsEditor/actions/SaveFields.svelte | 0 .../EventsEditor/actions/SaveRow.svelte | 0 .../EventsEditor/actions/UpdateRow.svelte | 0 .../EventsEditor/actions/index.js | 0 .../EventsEditor/index.js | 2 + .../FlatButtonGroup}/FlatButton.svelte | 0 .../FlatButtonGroup}/FlatButtonGroup.svelte | 0 .../FlatButtonGroup/index.js | 2 + .../IconSelect/IconSelect.svelte | 0 .../IconSelect/icons.js | 0 .../PropertyPanelControls/IconSelect/index.js | 4 + .../LayoutSelect.svelte | 2 +- .../MultiOptionSelect.svelte | 0 .../OptionSelect.svelte | 2 +- .../PropertyControl.svelte | 2 +- .../RoleSelect.svelte | 0 .../ScreenSelect.svelte | 0 .../TableSelect.svelte | 0 .../TableViewFieldSelect.svelte | 0 .../TableViewSelect.svelte | 4 +- .../userInterface/SettingsView.svelte | 93 +++++++++++-------- .../assetParsing/getRootComponent.js | 10 -- .../assetParsing/searchComponents.js | 46 --------- .../assetParsing/splitRootComponentName.js | 13 --- .../userInterface/assetParsing/types.js | 25 ----- ...opertyCategories.js => componentStyles.js} | 29 +----- .../userInterface/temporaryPanelStructure.js | 14 +-- .../standard-components/src/ScreenSlot.svelte | 27 +++--- 40 files changed, 190 insertions(+), 280 deletions(-) delete mode 100644 packages/builder/src/components/userInterface/IconSelect/index.js rename packages/builder/src/components/userInterface/{ => PropertyPanelControls}/EventsEditor/EventEditorModal.svelte (100%) rename packages/builder/src/components/userInterface/{ => PropertyPanelControls}/EventsEditor/EventPropertyControl.svelte (100%) rename packages/builder/src/components/userInterface/{ => PropertyPanelControls}/EventsEditor/actions/CreateRow.svelte (100%) rename packages/builder/src/components/userInterface/{ => PropertyPanelControls}/EventsEditor/actions/DeleteRow.svelte (100%) rename packages/builder/src/components/userInterface/{ => PropertyPanelControls}/EventsEditor/actions/NavigateTo.svelte (100%) rename packages/builder/src/components/userInterface/{ => PropertyPanelControls}/EventsEditor/actions/SaveFields.svelte (100%) rename packages/builder/src/components/userInterface/{ => PropertyPanelControls}/EventsEditor/actions/SaveRow.svelte (100%) rename packages/builder/src/components/userInterface/{ => PropertyPanelControls}/EventsEditor/actions/UpdateRow.svelte (100%) rename packages/builder/src/components/userInterface/{ => PropertyPanelControls}/EventsEditor/actions/index.js (100%) create mode 100644 packages/builder/src/components/userInterface/PropertyPanelControls/EventsEditor/index.js rename packages/builder/src/components/userInterface/{ => PropertyPanelControls/FlatButtonGroup}/FlatButton.svelte (100%) rename packages/builder/src/components/userInterface/{ => PropertyPanelControls/FlatButtonGroup}/FlatButtonGroup.svelte (100%) create mode 100644 packages/builder/src/components/userInterface/PropertyPanelControls/FlatButtonGroup/index.js rename packages/builder/src/components/userInterface/{ => PropertyPanelControls}/IconSelect/IconSelect.svelte (100%) rename packages/builder/src/components/userInterface/{ => PropertyPanelControls}/IconSelect/icons.js (100%) create mode 100644 packages/builder/src/components/userInterface/PropertyPanelControls/IconSelect/index.js rename packages/builder/src/components/userInterface/{ => PropertyPanelControls}/LayoutSelect.svelte (84%) rename packages/builder/src/components/userInterface/{ => PropertyPanelControls}/MultiOptionSelect.svelte (100%) rename packages/builder/src/components/userInterface/{ => PropertyPanelControls}/OptionSelect.svelte (99%) rename packages/builder/src/components/userInterface/{ => PropertyPanelControls}/PropertyControl.svelte (98%) rename packages/builder/src/components/userInterface/{ => PropertyPanelControls}/RoleSelect.svelte (100%) rename packages/builder/src/components/userInterface/{ => PropertyPanelControls}/ScreenSelect.svelte (100%) rename packages/builder/src/components/userInterface/{ => PropertyPanelControls}/TableSelect.svelte (100%) rename packages/builder/src/components/userInterface/{ => PropertyPanelControls}/TableViewFieldSelect.svelte (100%) rename packages/builder/src/components/userInterface/{ => PropertyPanelControls}/TableViewSelect.svelte (96%) delete mode 100644 packages/builder/src/components/userInterface/assetParsing/getRootComponent.js delete mode 100644 packages/builder/src/components/userInterface/assetParsing/searchComponents.js delete mode 100644 packages/builder/src/components/userInterface/assetParsing/splitRootComponentName.js delete mode 100644 packages/builder/src/components/userInterface/assetParsing/types.js rename packages/builder/src/components/userInterface/{propertyCategories.js => componentStyles.js} (96%) diff --git a/packages/builder/src/builderStore/store/frontend.js b/packages/builder/src/builderStore/store/frontend.js index 8f131ac0ff..fcb1224608 100644 --- a/packages/builder/src/builderStore/store/frontend.js +++ b/packages/builder/src/builderStore/store/frontend.js @@ -11,12 +11,13 @@ import { } from "builderStore" import { fetchComponentLibDefinitions } from "../loadComponentLibraries" import api from "../api" -import { FrontendTypes } from "../../constants" +import { FrontendTypes } from "constants" import analytics from "analytics" import { findComponentType, findComponentParent, findComponentPath, + findComponent, } from "../storeUtils" import { uuid } from "../uuid" @@ -44,21 +45,21 @@ export const getFrontendStore = () => { store.actions = { initialise: async pkg => { const { layouts, screens, application } = pkg - const components = await fetchComponentLibDefinitions(pkg.application._id) + const components = await fetchComponentLibDefinitions(application._id) store.update(state => ({ ...state, - libraries: pkg.application.componentLibraries, + libraries: application.componentLibraries, components, - name: pkg.application.name, - description: pkg.application.description, - appId: pkg.application._id, + name: application.name, + description: application.description, + appId: application._id, layouts, screens, hasAppPackage: true, - appInstance: pkg.application.instance, + appInstance: application.instance, })) await hostingStore.actions.fetch() - await backendUiStore.actions.database.select(pkg.application.instance) + await backendUiStore.actions.database.select(application.instance) }, routing: { fetch: async () => { @@ -226,6 +227,25 @@ export const getFrontendStore = () => { }, components: { select: component => { + if (!component) { + return + } + + // If this is the root component, select the asset instead + const asset = get(currentAsset) + const parent = findComponentParent(asset.props, component._id) + if (parent == null) { + const state = get(store) + const isLayout = state.currentFrontEndType === FrontendTypes.LAYOUT + if (isLayout) { + store.actions.layouts.select(asset._id) + } else { + store.actions.screens.select(asset._id) + } + return + } + + // Otherwise select the component store.update(state => { state.selectedComponentId = component._id state.currentView = "component" @@ -236,10 +256,10 @@ export const getFrontendStore = () => { if (!componentName) { return null } - const name = componentName.startsWith("@budibase") - ? componentName - : `@budibase/standard-components/${componentName}` - return get(store).components[name] + if (!componentName.startsWith("@budibase")) { + componentName = `@budibase/standard-components/${componentName}` + } + return get(store).components[componentName] }, createInstance: (componentName, presetProps) => { const definition = store.actions.components.getDefinition(componentName) @@ -273,6 +293,19 @@ export const getFrontendStore = () => { } }, create: (componentName, presetProps) => { + const selected = get(selectedComponent) + const asset = get(currentAsset) + const state = get(store) + + // Only allow one screen slot, and in the layout + if (componentName.endsWith("screenslot")) { + const isLayout = state.currentFrontEndType === FrontendTypes.LAYOUT + const slot = findComponentType(asset.props, componentName) + if (!isLayout || slot != null) { + return + } + } + // Create new component const componentInstance = store.actions.components.createInstance( componentName, @@ -284,8 +317,7 @@ export const getFrontendStore = () => { // Find parent node to attach this component to let parentComponent - const selected = get(selectedComponent) - const asset = get(currentAsset) + if (!asset) { return } diff --git a/packages/builder/src/components/userInterface/ComponentDropdownMenu.svelte b/packages/builder/src/components/userInterface/ComponentDropdownMenu.svelte index 0b97684d82..5ab3898c8d 100644 --- a/packages/builder/src/components/userInterface/ComponentDropdownMenu.svelte +++ b/packages/builder/src/components/userInterface/ComponentDropdownMenu.svelte @@ -32,43 +32,35 @@ } const moveUpComponent = () => { - store.update(state => { - const asset = get(currentAsset) - const parent = findComponentParent(asset.props, component) - - if (parent) { - const currentIndex = parent._children.indexOf(component) - if (currentIndex === 0) return state - - const newChildren = parent._children.filter(c => c !== component) - newChildren.splice(currentIndex - 1, 0, component) - parent._children = newChildren - } - state.selectedComponentId = component._id - store.actions.preview.saveSelected() - - return state - }) + const asset = get(currentAsset) + const parent = findComponentParent(asset.props, component._id) + if (!parent) { + return + } + const currentIndex = parent._children.indexOf(component) + if (currentIndex === 0) { + return + } + const newChildren = parent._children.filter(c => c !== component) + newChildren.splice(currentIndex - 1, 0, component) + parent._children = newChildren + store.actions.preview.saveSelected() } const moveDownComponent = () => { - store.update(state => { - const asset = get(currentAsset) - const parent = findComponentParent(asset.props, component) - - if (parent) { - const currentIndex = parent._children.indexOf(component) - if (currentIndex === parent._children.length - 1) return state - - const newChildren = parent._children.filter(c => c !== component) - newChildren.splice(currentIndex + 1, 0, component) - parent._children = newChildren - } - state.selectedComponentId = component._id - store.actions.preview.saveSelected() - - return state - }) + const asset = get(currentAsset) + const parent = findComponentParent(asset.props, component._id) + if (!parent) { + return + } + const currentIndex = parent._children.indexOf(component) + if (currentIndex === parent._children.length - 1) { + return + } + const newChildren = parent._children.filter(c => c !== component) + newChildren.splice(currentIndex + 1, 0, component) + parent._children = newChildren + store.actions.preview.saveSelected() } const duplicateComponent = () => { diff --git a/packages/builder/src/components/userInterface/ComponentPropertiesPanel.svelte b/packages/builder/src/components/userInterface/ComponentPropertiesPanel.svelte index cee504719a..6291917cd0 100644 --- a/packages/builder/src/components/userInterface/ComponentPropertiesPanel.svelte +++ b/packages/builder/src/components/userInterface/ComponentPropertiesPanel.svelte @@ -2,48 +2,30 @@ import { get } from "svelte/store" import { store, selectedComponent, currentAsset } from "builderStore" import { FrontendTypes } from "constants" - import panelStructure from "./temporaryPanelStructure.js" import CategoryTab from "./CategoryTab.svelte" import DesignView from "./DesignView.svelte" import SettingsView from "./SettingsView.svelte" import { setWith } from "lodash" - let flattenedPanel = flattenComponents(panelStructure.categories) - let categories = [ + const categories = [ { value: "settings", name: "Settings" }, { value: "design", name: "Design" }, ] let selectedCategory = categories[0] - $: componentInstance = - $store.currentView !== "component" - ? { ...$currentAsset, ...$selectedComponent } - : $selectedComponent - $: componentDefinition = store.actions.components.getDefinition( - componentInstance._component + $: definition = store.actions.components.getDefinition( + $selectedComponent._component ) - $: componentPropDefinition = - flattenedPanel.find( - // use for getting controls for each component property - c => c._component === componentInstance._component - ) || {} - - $: panelDefinition = - componentPropDefinition.properties && - componentPropDefinition.properties[selectedCategory.value] + $: isComponentOrScreen = + $store.currentView === "component" || + $store.currentFrontEndType === FrontendTypes.SCREEN + $: isNotScreenslot = !$selectedComponent._component.endsWith("screenslot") + $: showDisplayName = isComponentOrScreen && isNotScreenslot const onStyleChanged = store.actions.components.updateStyle const onCustomStyleChanged = store.actions.components.updateCustomStyle const onResetStyles = store.actions.components.resetStyles - $: isComponentOrScreen = - $store.currentView === "component" || - $store.currentFrontEndType === FrontendTypes.SCREEN - $: isNotScreenslot = !componentInstance._component.endsWith("screenslot") - - $: displayName = - isComponentOrScreen && componentInstance._instanceName && isNotScreenslot - function walkProps(component, action) { action(component) if (component.children) { @@ -91,24 +73,23 @@ {categories} {selectedCategory} /> -{#if displayName} -
{componentInstance._instanceName}
+{#if showDisplayName} +
{$selectedComponent._instanceName}
{/if}
{#if selectedCategory.value === 'design'} {:else if selectedCategory.value === 'settings'} diff --git a/packages/builder/src/components/userInterface/DesignView.svelte b/packages/builder/src/components/userInterface/DesignView.svelte index cbc110d3b9..5be4a421ba 100644 --- a/packages/builder/src/components/userInterface/DesignView.svelte +++ b/packages/builder/src/components/userInterface/DesignView.svelte @@ -1,16 +1,16 @@
@@ -32,12 +32,12 @@
-
- {#if propertyGroupNames.length > 0} - {#each propertyGroupNames as groupName} +
+ {#if groups.length > 0} + {#each groups as groupName} - import TableViewFieldSelect from "./TableViewFieldSelect.svelte" + import TableViewFieldSelect from "./PropertyPanelControls/TableViewFieldSelect.svelte" diff --git a/packages/builder/src/components/userInterface/PropertyGroup.svelte b/packages/builder/src/components/userInterface/PropertyGroup.svelte index 69797c4a21..548e13399b 100644 --- a/packages/builder/src/components/userInterface/PropertyGroup.svelte +++ b/packages/builder/src/components/userInterface/PropertyGroup.svelte @@ -1,6 +1,5 @@ -
+

Screen Slot

The screens that you create will be displayed inside this box. @@ -14,16 +18,15 @@