Skip to content

Commit 2dc9571

Browse files
committed
Import component functionality is fully functioning now. Properly handles nested HTML children, props, state, actions, adds state and actions to the store if not present.
Co-authored-by: Kerolos Nesem <[email protected]>
1 parent 387e180 commit 2dc9571

File tree

3 files changed

+138
-139
lines changed

3 files changed

+138
-139
lines changed

src/components/ComponentDisplay.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,6 @@ export default {
167167
activeComponentData() {
168168
// Must deep clone this so we are not directly mutating state
169169
// return this.activeComponentObj;
170-
console.log(this.activeComponentObj)
171170
return cloneDeep(this.activeComponentObj);
172171
},
173172
options() {

src/components/home_sidebar_items/ComponentTab/CreateComponent.vue

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Description:
4141
@click="createComponent"
4242
:disabled="!componentNameInputValue.trim()"
4343
/>
44-
<ImportComponent v-if="activeComponent === ''" />
44+
<ImportComponent v-if="activeComponent === ''" @imported="createComponent"/>
4545

4646
</div>
4747
</template>
@@ -64,6 +64,8 @@ export default {
6464
"selectedElementList",
6565
"activeComponent",
6666
"activeHTML",
67+
"userActions",
68+
"userState",
6769
]),
6870
componentNameInputValue: {
6971
get() {
@@ -85,13 +87,32 @@ export default {
8587
"addNestedNoActive",
8688
"editComponentName",
8789
"openProject",
90+
"createAction",
91+
"createState",
8892
]),
8993
90-
createComponent() {
91-
if (!this.componentNameInputValue.replace(/[^a-z0-9-_.]/gi, "")) {
94+
createComponent(importObj) {
95+
let imported = false;
96+
if (importObj.hasOwnProperty('componentName')){
97+
imported = true;
98+
//Check if state and actions on import exist in the store. If not, add them.
99+
for (let i = 0; i < importObj.actions.length; i++){
100+
if (!this.userActions.includes(importObj.actions[i])){
101+
this.createAction(importObj.actions[i])
102+
}
103+
}
104+
for (let i = 0; i < importObj.state.length; i++){
105+
if (!this.userState.includes(importObj.state[i])){
106+
this.createState(importObj.state[i])
107+
}
108+
}
109+
}
110+
111+
if (!this.componentNameInputValue.replace(/[^a-z0-9-_.]/gi, "") && imported === false) {
92112
event.preventDefault();
93113
return false;
94114
}
115+
95116
// boilerplate properties for each component upon creation
96117
const component = {
97118
componentName: this.componentNameInputValue.replace(
@@ -111,13 +132,20 @@ export default {
111132
parent: {},
112133
isActive: false,
113134
};
114-
console.log(component.htmlList)
135+
136+
if (imported === true){
137+
component.componentName = importObj.componentName;
138+
component.htmlList = importObj.htmlList;
139+
component.actions = importObj.actions;
140+
component.state = importObj.state;
141+
component.props = importObj.props;
142+
}
143+
115144
if (!this.componentMap[component.componentName]) {
116145
this.registerComponent(component);
117146
this.setActiveComponent(component.componentName);
118147
}
119148
120-
console.log(this.$store.state);
121149
},
122150
},
123151
};

0 commit comments

Comments
 (0)