Instance name for components and screens

This commit is contained in:
Conor_Mack 2020-06-04 18:08:50 +01:00
parent 02469dec2f
commit 32ff7a5c89
7 changed files with 46 additions and 26 deletions

View File

@ -1,4 +1,5 @@
import { values } from "lodash/fp" import { values } from "lodash/fp"
import { get_capitalised_name } from "../../helpers"
import { backendUiStore } from "builderStore" import { backendUiStore } from "builderStore"
import * as backendStoreActions from "./backend" import * as backendStoreActions from "./backend"
import { writable, get } from "svelte/store" import { writable, get } from "svelte/store"
@ -153,7 +154,6 @@ const createScreen = store => (screenName, route, layoutComponentName) => {
const rootComponent = state.components[layoutComponentName] const rootComponent = state.components[layoutComponentName]
const newScreen = { const newScreen = {
name: screenName || "",
description: "", description: "",
url: "", url: "",
_css: "", _css: "",
@ -161,6 +161,7 @@ const createScreen = store => (screenName, route, layoutComponentName) => {
} }
newScreen.route = route newScreen.route = route
newScreen.props._instanceName = screenName || ""
state.currentPreviewItem = newScreen state.currentPreviewItem = newScreen
state.currentComponentInfo = newScreen.props state.currentComponentInfo = newScreen.props
state.currentFrontEndType = "screen" state.currentFrontEndType = "screen"
@ -336,12 +337,14 @@ const addChildComponent = store => (componentToAdd, presetName) => {
const presetProps = presetName ? component.presets[presetName] : {} const presetProps = presetName ? component.presets[presetName] : {}
const instanceId = get(backendUiStore).selectedDatabase._id const instanceId = get(backendUiStore).selectedDatabase._id
const instanceName = get_capitalised_name(componentToAdd)
const newComponent = createProps( const newComponent = createProps(
component, component,
{ {
...presetProps, ...presetProps,
_instanceId: instanceId, _instanceId: instanceId,
_instanceName: instanceName,
}, },
state state
) )

View File

@ -66,6 +66,8 @@
const onStyleChanged = store.setComponentStyle const onStyleChanged = store.setComponentStyle
const onPropChanged = store.setComponentProp const onPropChanged = store.setComponentProp
$: displayName = $store.currentFrontEndType === "screen" && componentInstance._instanceName
function walkProps(component, action) { function walkProps(component, action) {
action(component) action(component)
if (component.children) { if (component.children) {
@ -99,6 +101,12 @@
{categories} {categories}
{selectedCategory} /> {selectedCategory} />
{#if displayName}
<div class="instance-name">
<strong>{componentInstance._instanceName}</strong>
</div>
{/if}
<div class="component-props-container"> <div class="component-props-container">
{#if selectedCategory.value === 'design'} {#if selectedCategory.value === 'design'}
<DesignView {panelDefinition} {componentInstance} {onStyleChanged} /> <DesignView {panelDefinition} {componentInstance} {onStyleChanged} />
@ -107,6 +115,7 @@
{componentInstance} {componentInstance}
{componentDefinition} {componentDefinition}
{panelDefinition} {panelDefinition}
displayNameField={displayName}
onChange={onPropChanged} /> onChange={onPropChanged} />
{:else if selectedCategory.value === 'events'} {:else if selectedCategory.value === 'events'}
<EventsEditor component={componentInstance} /> <EventsEditor component={componentInstance} />
@ -137,9 +146,14 @@
} }
.component-props-container { .component-props-container {
margin-top: 20px; margin-top: 10px;
flex: 1 1 auto; flex: 1 1 auto;
min-height: 0; min-height: 0;
overflow-y: auto; overflow-y: auto;
} }
.instance-name {
margin-top: 10px;
font-size: 12px;
}
</style> </style>

View File

@ -22,48 +22,35 @@
trimChars(" "), trimChars(" "),
]) ])
const lastPartOfName = c => {
if (!c) return ""
const name = c.name ? c.name : c._component ? c._component : c
return last(name.split("/"))
}
const isComponentSelected = (current, comp) => current === comp
$: _screens = pipe(screens, [
map(c => ({ component: c, title: lastPartOfName(c) })),
sortBy("title"),
])
const changeScreen = screen => { const changeScreen = screen => {
store.setCurrentScreen(screen.title) store.setCurrentScreen(screen.props._instanceName)
$goto(`./:page/${screen.title}`) $goto(`./:page/${screen.title}`)
} }
</script> </script>
<div class="root"> <div class="root">
{#each _screens as screen} {#each screens as screen}
<div <div
class="budibase__nav-item component" class="budibase__nav-item component"
class:selected={$store.currentComponentInfo._id === screen.component.props._id} class:selected={$store.currentComponentInfo._id === screen.props._id}
on:click|stopPropagation={() => changeScreen(screen)}> on:click|stopPropagation={() => changeScreen(screen)}>
<span <span
class="icon" class="icon"
class:rotate={$store.currentPreviewItem.name !== screen.title}> class:rotate={$store.currentPreviewItem.name !== screen.props._instanceName}>
{#if screen.component.props._children.length} {#if screen.props._children.length}
<ArrowDownIcon /> <ArrowDownIcon />
{/if} {/if}
</span> </span>
<i class="ri-artboard-2-fill icon" /> <i class="ri-artboard-2-fill icon" />
<span class="title">{screen.title}</span> <span class="title">{screen.props._instanceName}</span>
</div> </div>
{#if $store.currentPreviewItem.name === screen.title && screen.component.props._children} {#if $store.currentPreviewItem.props._instanceName && $store.currentPreviewItem.props._instanceName === screen.props._instanceName && screen.props._children}
<ComponentsHierarchyChildren <ComponentsHierarchyChildren
components={screen.component.props._children} components={screen.props._children}
currentComponent={$store.currentComponentInfo} /> currentComponent={$store.currentComponentInfo} />
{/if} {/if}
{/each} {/each}

View File

@ -42,7 +42,7 @@
style="padding-left: {level * 20 + 53}px"> style="padding-left: {level * 20 + 53}px">
<div class="nav-item"> <div class="nav-item">
<i class="icon ri-arrow-right-circle-fill" /> <i class="icon ri-arrow-right-circle-fill" />
{get_capitalised_name(component._component)} {component._instanceName}
</div> </div>
<div class="actions"> <div class="actions">
<ComponentDropdownMenu {component} /> <ComponentDropdownMenu {component} />

View File

@ -1,6 +1,7 @@
<script> <script>
import PropertyControl from "./PropertyControl.svelte" import PropertyControl from "./PropertyControl.svelte"
import InputGroup from "../common/Inputs/InputGroup.svelte" import InputGroup from "../common/Inputs/InputGroup.svelte"
import Input from "../common/Input.svelte"
import Colorpicker from "../common/Colorpicker.svelte" import Colorpicker from "../common/Colorpicker.svelte"
import { excludeProps } from "./propertyCategories.js" import { excludeProps } from "./propertyCategories.js"
@ -8,6 +9,7 @@
export let componentDefinition = {} export let componentDefinition = {}
export let componentInstance = {} export let componentInstance = {}
export let onChange = () => {} export let onChange = () => {}
export let displayNameField = false
const propExistsOnComponentDef = prop => prop in componentDefinition.props const propExistsOnComponentDef = prop => prop in componentDefinition.props
@ -16,6 +18,10 @@
} }
</script> </script>
{#if displayNameField}
<PropertyControl control={Input} label="Name" key="_instanceName" value={componentInstance._instanceName} {onChange} />
{/if}
{#if panelDefinition && panelDefinition.length > 0} {#if panelDefinition && panelDefinition.length > 0}
{#each panelDefinition as definition} {#each panelDefinition as definition}
{#if propExistsOnComponentDef(definition.key)} {#if propExistsOnComponentDef(definition.key)}

View File

@ -30,8 +30,9 @@ export const searchAllComponents = (components, phrase) => {
export const getExactComponent = (components, name) => { export const getExactComponent = (components, name) => {
const stringEquals = (s1, s2) => normalString(s1) === normalString(s2) const stringEquals = (s1, s2) => normalString(s1) === normalString(s2)
return pipe(components, [
return pipe(components, [find(c => stringEquals(c.name, name))]) find(c => stringEquals(c.props._instanceName, name)),
])
} }
export const getAncestorProps = (components, name, found = []) => { export const getAncestorProps = (components, name, found = []) => {

View File

@ -1,3 +1,6 @@
import { last } from "lodash/fp"
import { pipe } from "components/common/core"
export const buildStyle = styles => { export const buildStyle = styles => {
let str = "" let str = ""
for (let s in styles) { for (let s in styles) {
@ -12,3 +15,9 @@ export const buildStyle = styles => {
export const convertCamel = str => { export const convertCamel = str => {
return str.replace(/[A-Z]/g, match => `-${match.toLowerCase()}`) return str.replace(/[A-Z]/g, match => `-${match.toLowerCase()}`)
} }
export const capitalise = s => s.substring(0, 1).toUpperCase() + s.substring(1)
export const get_name = s => (!s ? "" : last(s.split("/")))
export const get_capitalised_name = name => pipe(name, [get_name, capitalise])