Skip to content

Commit 6a20411

Browse files
Dean OhashiDean Ohashi
authored andcommitted
Can select parent when creating a component
1 parent 2e1ad22 commit 6a20411

File tree

6 files changed

+79
-14
lines changed

6 files changed

+79
-14
lines changed

src/components/CreateComponent.vue

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,23 @@
1616
<div class="icon-container">
1717
<Icons @getClickedIcon="addToSelectedElementList" />
1818
</div>
19-
<!-- <ChildrenMultiselect /> -->
19+
<ParentMultiselect />
2020
<br />
21-
<!-- <button
22-
class="button is-primary"
23-
id="add-component-btn"
24-
@click="handleClick"
25-
:disabled="!componentNameInputValue"
26-
>Add Component</button> -->
2721
<q-btn id="add-component-btn" class="primary" color="secondary" label="Create Component" icon-right="add" @click="handleClick" :disabled="!componentNameInputValue" />
2822
</div>
2923
</template>
3024

3125
<script>
3226
import Icons from './Icons'
33-
// import ChildrenMultiselect from '@/components/ChildrenMultiselect';
27+
import ParentMultiselect from '../components/ParentMultiselect'
3428
import { mapState, mapActions } from 'vuex'
3529
// import * as types from '../store/types.js'
3630
3731
export default {
3832
name: 'HomeSidebar',
3933
components: {
40-
// ChildrenMultiselect,
41-
Icons
34+
Icons,
35+
ParentMultiselect
4236
},
4337
computed: {
4438
...mapState(['componentMap', 'selectedElementList']),
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<template>
2+
<div id="parent-select">
3+
<br />
4+
<multiselect
5+
placeholder="Choose Parent (if applicable)"
6+
:multiple="false"
7+
:close-on-select="true"
8+
:options="options"
9+
@input="handleSelect"
10+
:max-height="150"
11+
:option-height="20"
12+
:searchable="false"
13+
></multiselect>
14+
</div>
15+
</template>
16+
17+
<script>
18+
import { mapState, mapActions } from 'vuex'
19+
import Multiselect from 'vue-multiselect'
20+
21+
export default {
22+
name: 'ParentMultiselect',
23+
components: {
24+
Multiselect
25+
},
26+
computed: {
27+
...mapState([
28+
'routes',
29+
'componentMap',
30+
'activeComponent'
31+
]),
32+
options () {
33+
const routes = Object.keys(this.routes)
34+
const exceptions = new Set(['App', ...routes])
35+
return Object.keys(this.componentMap).filter(component => {
36+
if (!exceptions.has(component)) return component
37+
})
38+
}
39+
},
40+
methods: {
41+
...mapActions([
42+
'setActiveComponent',
43+
'parentSelected'
44+
]),
45+
handleSelect (value) {
46+
// Set Active Component to selected Parent
47+
this.setActiveComponent(value)
48+
// Set parentSelected to true IF VALUE IS A VALID PARENT (not null)
49+
this.parentSelected(true)
50+
}
51+
}
52+
}
53+
</script>
54+
55+
<style src="vue-multiselect/dist/vue-multiselect.min.css"></style>
56+
<style scoped>
57+
58+
</style>

src/store/actions.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@ const actions = {
1616
let value = state.componentChildrenMultiselectValue.map(component => {
1717
return state.componentMap[component]
1818
})
19+
20+
if (state.parentSelected) {
21+
commit(types.UPDATE_ACTIVE_COMPONENT_CHILDREN_VALUE, [...state.componentMap[state.activeComponent].children, payload.componentName])
22+
}
23+
1924
commit(types.UPDATE_COMPONENT_CHILDREN_VALUE, { component, value })
2025
commit(types.UPDATE_COMPONENT_CHILDREN_MULTISELECT_VALUE, [])
2126
commit(types.UPDATE_COMPONENT_NAME_INPUT_VALUE, '')
2227
commit(types.SET_SELECTED_ELEMENT_LIST, [])
28+
commit(types.SET_ACTIVE_COMPONENT, '')
29+
commit(types.PARENT_SELECTED, false)
2330
}
2431
},
2532
// sets component inside componentDisplay
@@ -102,6 +109,9 @@ const actions = {
102109
},
103110
[types.updateOpenModal]: ({ commit }, payload) => {
104111
commit(types.UPDATE_OPEN_MODAL, payload)
112+
},
113+
[types.parentSelected]: ({ commit }, payload) => {
114+
commit(types.PARENT_SELECTED, payload)
105115
}
106116
}
107117

src/store/mutations.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,9 +157,6 @@ const mutations = {
157157
// additionally addes children to the component
158158
[types.UPDATE_COMPONENT_CHILDREN_VALUE]: (state, payload) => {
159159
const { component, value } = payload
160-
console.log('IN MUTATIONS: ', value)
161-
console.log('Type: ', typeof value)
162-
163160
state.componentMap[component].children = value
164161
},
165162
[types.UPDATE_ACTIVE_COMPONENT_CHILDREN_VALUE]: (state, payload) => {
@@ -179,6 +176,9 @@ const mutations = {
179176
// invoked when element is double clicked, changing the boolean value
180177
[types.UPDATE_OPEN_MODAL]: (state, payload) => {
181178
state.modalOpen = payload
179+
},
180+
[types.PARENT_SELECTED]: (state, payload) => {
181+
state.parentSelected = payload
182182
}
183183
}
184184

src/store/state/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ const newState = {
3434
projectNumber: 2,
3535
activeTab: 0,
3636
componentChildrenMultiselectValue: [],
37-
modalOpen: false
37+
modalOpen: false,
38+
parentSelected: false
3839
}
3940

4041
export default newState

src/store/types.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export const UPDATE_ACTIVE_COMPONENT_CHILDREN_VALUE =
3838
export const ADD_COMPONENT_TO_COMPONENT_CHILDREN =
3939
'ADD_COMPONENT_TO_COMPONENT_CHILDREN'
4040
export const UPDATE_OPEN_MODAL = 'UPDATE_OPEN_MODAL'
41+
export const PARENT_SELECTED = 'PARENT_SELECTED'
4142

4243
// Actions
4344
export const registerComponent = 'registerComponent'
@@ -69,3 +70,4 @@ export const updateActiveComponentChildrenValue =
6970
export const updateComponentChildrenValue = 'updateComponentChildrenValue'
7071
export const updateComponentNameInputValue = 'updateComponentNameInputValue'
7172
export const updateOpenModal = 'updateOpenModal'
73+
export const parentSelected = 'parentSelected'

0 commit comments

Comments
 (0)