File tree Expand file tree Collapse file tree 6 files changed +79
-14
lines changed Expand file tree Collapse file tree 6 files changed +79
-14
lines changed Original file line number Diff line number Diff line change 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 >
3226import Icons from ' ./Icons'
33- // import ChildrenMultiselect from '@ /components/ChildrenMultiselect';
27+ import ParentMultiselect from ' .. /components/ParentMultiselect '
3428import { mapState , mapActions } from ' vuex'
3529// import * as types from '../store/types.js'
3630
3731export default {
3832 name: ' HomeSidebar' ,
3933 components: {
40- // ChildrenMultiselect ,
41- Icons
34+ Icons ,
35+ ParentMultiselect
4236 },
4337 computed: {
4438 ... mapState ([' componentMap' , ' selectedElementList' ]),
Original file line number Diff line number Diff line change 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 >
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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
4041export default newState
Original file line number Diff line number Diff line change @@ -38,6 +38,7 @@ export const UPDATE_ACTIVE_COMPONENT_CHILDREN_VALUE =
3838export const ADD_COMPONENT_TO_COMPONENT_CHILDREN =
3939 'ADD_COMPONENT_TO_COMPONENT_CHILDREN'
4040export const UPDATE_OPEN_MODAL = 'UPDATE_OPEN_MODAL'
41+ export const PARENT_SELECTED = 'PARENT_SELECTED'
4142
4243// Actions
4344export const registerComponent = 'registerComponent'
@@ -69,3 +70,4 @@ export const updateActiveComponentChildrenValue =
6970export const updateComponentChildrenValue = 'updateComponentChildrenValue'
7071export const updateComponentNameInputValue = 'updateComponentNameInputValue'
7172export const updateOpenModal = 'updateOpenModal'
73+ export const parentSelected = 'parentSelected'
You can’t perform that action at this time.
0 commit comments