add nodes style based on text props

This commit is contained in:
axolotle
2021-02-24 22:13:02 +01:00
parent 7813b9aa07
commit ced1d9c354
3 changed files with 30 additions and 13 deletions
+10 -5
View File
@@ -27,26 +27,31 @@ export default new Vuex.Store({
'GET_TREE' ({ dispatch }, id) {
return api.post('', { query: print(TextdepartRecursive), variables: { id } }).then(({ data }) => {
return parse(data.data.textref)
const text = data.data.textref
return parse(text, text.id)
})
}
}
})
// Temp data processing
function parse (d) {
function parse (d, originalId) {
const child = {
name: d.title,
type: d.__typename.toLowerCase()
type: d.__typename.toLowerCase(),
class: 'family-' + d.familles[0].id
}
if (d.id === originalId) {
child.class += ' first'
}
let children = []
for (const key of ['text_en_rebond', 'text_produits']) {
if (d[key]) {
children = [...children, ...d[key].map(text => parse(text))]
children = [...children, ...d[key].filter(text => text.id !== originalId)]
}
}
if (children.length) {
child.children = children
child.children = children.map(child => parse(child, originalId))
}
return child
}