add action GET_TREE to resolve d3 ready text hierachy
This commit is contained in:
+27
-2
@@ -4,6 +4,7 @@ import Vuex from 'vuex'
|
||||
import api from '@/api'
|
||||
import { print } from 'graphql/language/printer'
|
||||
import TextRef from '@/api/queries/TextRef.gql'
|
||||
import TextdepartRecursive from '@/api/queries/TextdepartRecursive.gql'
|
||||
|
||||
|
||||
Vue.use(Vuex)
|
||||
@@ -20,8 +21,32 @@ export default new Vuex.Store({
|
||||
},
|
||||
|
||||
actions: {
|
||||
'GET_TEXT' ({ state }, id) {
|
||||
return api.post('', { query: print(TextRef), variables: { id } })
|
||||
'GET_TEXT' ({ state }, { id }) {
|
||||
return api.post('', { query: print(TextRef), variables: { id } }).then(data => (data.data.data))
|
||||
},
|
||||
|
||||
'GET_TREE' ({ dispatch }, id) {
|
||||
return api.post('', { query: print(TextdepartRecursive), variables: { id } }).then(({ data }) => {
|
||||
return parse(data.data.textref)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
// Temp data processing
|
||||
function parse (d) {
|
||||
const child = {
|
||||
name: d.title,
|
||||
type: d.__typename.toLowerCase()
|
||||
}
|
||||
let children = []
|
||||
for (const key of ['text_en_rebond', 'text_produits']) {
|
||||
if (d[key]) {
|
||||
children = [...children, ...d[key].map(text => parse(text))]
|
||||
}
|
||||
}
|
||||
if (children.length) {
|
||||
child.children = children
|
||||
}
|
||||
return child
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user