diff --git a/frontend/src/Editor/Components/components.js b/frontend/src/Editor/Components/components.js index 54d152f9ca..b096561351 100644 --- a/frontend/src/Editor/Components/components.js +++ b/frontend/src/Editor/Components/components.js @@ -481,7 +481,7 @@ export const componentTypes = [ placeholder: { value: 'Placeholder text' } }, events: { - + }, styles: { diff --git a/frontend/src/Editor/Editor.jsx b/frontend/src/Editor/Editor.jsx index 333bf322d3..1753f49d5f 100644 --- a/frontend/src/Editor/Editor.jsx +++ b/frontend/src/Editor/Editor.jsx @@ -214,8 +214,6 @@ class Editor extends React.Component { }; componentDefinitionChanged = (newDefinition) => { - console.log('new component definition', newDefinition); - console.log('app definition', this.state.appDefinition); this.setState({ appDefinition: { ...this.state.appDefinition, @@ -230,6 +228,21 @@ class Editor extends React.Component { }); }; + componentChanged = (newComponent) => { + this.setState({ + appDefinition: { + ...this.state.appDefinition, + components: { + ...this.state.appDefinition.components, + [newComponent.id]: { + ...this.state.appDefinition.components[newComponent.id], + ...newComponent + } + } + } + }); + } + saveApp = (id, attributes, notify = false) => { appService.saveApp(id, attributes).then(() => { if (notify) { @@ -735,6 +748,7 @@ class Editor extends React.Component { { const [component, setComponent] = useState(selectedComponent); const componentMeta = componentTypes.find((comp) => component.component.component === comp.component); @@ -23,6 +26,17 @@ export const Inspector = ({ setComponent(selectedComponent); }, [selectedComponent]); + function handleComponentNameChange(newName) { + if (validateQueryName(newName)) { + let newComponent = { ...component }; + newComponent.component.name = newName; + setComponent(newComponent); + componentChanged(newComponent); + } else { + toast.error('Invalid query name. Should be unique and only include letters, numbers and underscore.', { hideProgressBar: true }); + } + } + function paramUpdated(param, attr, value, paramType) { let newDefinition = { ...component.component.definition }; @@ -72,37 +86,49 @@ export const Inspector = ({ return (
-
- - {component.component.name} - +
+
+
+ handleComponentNameChange(e.target.value)} + className="form-control-plaintext form-control-plaintext-sm mt-1" + value={component.component.name} + /> + + + +
+
+
+ + {/* brrr */} + +
+ +

+ +
+
+ + } + > + +
+
- - {/* brrr */} - -
- -

- -
-
- - } - > - -
{componentMeta.component === 'Table' ? ( diff --git a/frontend/src/_helpers/utils.js b/frontend/src/_helpers/utils.js index d48965d968..1e83c23cb2 100644 --- a/frontend/src/_helpers/utils.js +++ b/frontend/src/_helpers/utils.js @@ -122,3 +122,8 @@ export function computeActionName(actions) { return actionName; } + +export function validateQueryName(name){ + const nameRegex = new RegExp('^[A-Za-z0-9_-]*$'); + return nameRegex.test(name); +};