bug when saving components

This commit is contained in:
michael shanks 2019-08-22 07:57:56 +01:00
parent 5f0d8ce638
commit ef0b1a102e
4 changed files with 26 additions and 9 deletions

View File

@ -13,11 +13,13 @@ import { afterUpdate } from 'svelte';
let component; let component;
let stylesheetLinks = ""; let stylesheetLinks = "";
let componentHtml = ""; let componentHtml = "";
let props;
store.subscribe(s => { store.subscribe(s => {
const {componentName, libName} = splitName( const {componentName, libName} = splitName(
s.currentComponentInfo.rootComponent.name); s.currentComponentInfo.rootComponent.name);
props = s.currentComponentInfo.fullProps;
component = s.libraries[libName][componentName]; component = s.libraries[libName][componentName];
stylesheetLinks = pipe(s.pages.stylesheets, [ stylesheetLinks = pipe(s.pages.stylesheets, [
map(s => `<link rel="stylesheet" href="${s}"/>`), map(s => `<link rel="stylesheet" href="${s}"/>`),
@ -28,7 +30,9 @@ store.subscribe(s => {
afterUpdate(() => { afterUpdate(() => {
componentHtml = document.getElementById("comonent-container-mock").innerHTML setTimeout(() => {
componentHtml = document.getElementById("comonent-container-mock").innerHTML
}, 1);
}); });
@ -51,7 +55,7 @@ afterUpdate(() => {
</div> </div>
<div id="comonent-container-mock"> <div id="comonent-container-mock">
<svelte:component this={component} {...$store.currentComponentInfo.fullProps}/> <svelte:component this={component} {...props}/>
</div> </div>
<style> <style>

View File

@ -162,6 +162,7 @@ const componentInstancePropsChanged = (instanceProps) => {
<Textbox label="Name" <Textbox label="Name"
infoText="use forward slash to store in subfolders" infoText="use forward slash to store in subfolders"
bind:text={name} bind:text={name}
disabled={!$store.currentComponentIsNew}
hasError={!!nameInvalid}/> hasError={!!nameInvalid}/>
<div class="info-text"></div> <div class="info-text"></div>
<Textbox label="Description" <Textbox label="Description"

View File

@ -8,7 +8,8 @@ import {
filter, filter,
reduce, reduce,
cloneDeep, cloneDeep,
includes includes,
last
} from "lodash/fp"; } from "lodash/fp";
import { types, expandPropsDefinition } from "./types"; import { types, expandPropsDefinition } from "./types";
import { assign } from "lodash"; import { assign } from "lodash";
@ -74,9 +75,13 @@ export const getComponentInfo = (allComponents, comp, stack=[], subComponentProp
if(isRootComponent(component)) { if(isRootComponent(component)) {
subComponentProps = subComponentProps||{}; subComponentProps = subComponentProps||{};
const p = createProps(cname, component.props, subComponentProps); const p = createProps(cname, component.props, subComponentProps);
const rootProps = createProps(cname, component.props);
const inheritedProps = []; const inheritedProps = [];
const targetComponent = stack.length > 0
? last(stack)
: component;
if(stack.length > 0) { if(stack.length > 0) {
const targetComponent = stack[0];
for(let prop in subComponentProps) { for(let prop in subComponentProps) {
const hasProp = pipe(targetComponent.props, [ const hasProp = pipe(targetComponent.props, [
keys, keys,
@ -88,24 +93,27 @@ export const getComponentInfo = (allComponents, comp, stack=[], subComponentProp
} }
const unsetProps = pipe(p.props, [ const unsetProps = pipe(p.props, [
keys, keys,
filter(k => !includes(k)(keys(subComponentProps))) filter(k => !includes(k)(keys(subComponentProps)) && k !== "_component")
]); ]);
const fullProps = cloneDeep(p.props);
fullProps._component = targetComponent.name;
return ({ return ({
propsDefinition:expandPropsDefinition(component.props), propsDefinition:expandPropsDefinition(component.props),
inheritedProps, inheritedProps,
rootDefaultProps: p.props, rootDefaultProps: rootProps.props,
unsetProps, unsetProps,
fullProps: p.props, fullProps: fullProps,
errors: p.errors, errors: p.errors,
component: stack.length > 0 ? stack[0] : component, component: targetComponent,
rootComponent: component rootComponent: component
}); });
} }
return getComponentInfo( return getComponentInfo(
allComponents, allComponents,
component.inherits, component.inherits,
[...stack, component], [component, ...stack],
{...component.props, ...subComponentProps}); {...component.props, ...subComponentProps});
} }

View File

@ -18,6 +18,7 @@ describe("getComponentInfo", () => {
expect(result.errors).toEqual([]); expect(result.errors).toEqual([]);
expect(result.fullProps).toEqual({ expect(result.fullProps).toEqual({
_component: "budibase-components/TextBox",
size: "", size: "",
isPassword: false, isPassword: false,
placeholder: "", placeholder: "",
@ -42,6 +43,7 @@ describe("getComponentInfo", () => {
{size:"small"}); {size:"small"});
expect(result).toEqual({ expect(result).toEqual({
_component: "budibase-components/TextBox",
size: "small", size: "small",
isPassword: false, isPassword: false,
placeholder: "", placeholder: "",
@ -57,6 +59,7 @@ describe("getComponentInfo", () => {
expect(result.errors).toEqual([]); expect(result.errors).toEqual([]);
expect(result.fullProps).toEqual({ expect(result.fullProps).toEqual({
_component: "common/SmallTextbox",
size: "small", size: "small",
isPassword: false, isPassword: false,
placeholder: "", placeholder: "",
@ -71,6 +74,7 @@ describe("getComponentInfo", () => {
expect(result.errors).toEqual([]); expect(result.errors).toEqual([]);
expect(result.fullProps).toEqual({ expect(result.fullProps).toEqual({
_component: "common/PasswordBox",
size: "small", size: "small",
isPassword: true, isPassword: true,
placeholder: "", placeholder: "",