Skip to content

Commit

Permalink
make not recursive
Browse files Browse the repository at this point in the history
  • Loading branch information
mutdmour committed Aug 8, 2022
1 parent b0cc1ab commit f064fc1
Showing 1 changed file with 44 additions and 8 deletions.
52 changes: 44 additions & 8 deletions packages/design-system/src/components/N8nTree/Tree.vue
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
<template>
<div class="n8n-tree">
<n8n-tree-node :input="input" :path="path">
<template v-for="(index, name) in $scopedSlots" v-slot:[name]="data">
<slot :name="name" v-bind="data"></slot>
</template>
</n8n-tree-node>
<div v-for="row in parsedData" :style="getStyles(row)">
<slot name="label" v-bind:label="row.label" />
<span v-if="row.value">&nbsp:&nbsp;</span>
<span v-if="row.value" :class="$style.value">{{ row.value }}</span>
</div>
</div>
</template>

<script lang="ts">
import Vue from 'vue';
import N8nTreeNode from './TreeNode.vue';
const INDENT = 24;
export default Vue.extend({
name: 'n8n-tree',
components: {
N8nTreeNode,
},
props: {
input: {
},
Expand All @@ -26,9 +25,46 @@ export default Vue.extend({
},
},
computed: {
parsedData() {
const data = traverse(this.input);
console.log(data);
return data;
},
},
methods: {
getStyles(row) {
return {marginLeft: `${INDENT * row.depth}px`};
},
},
});
function traverse(data, parsed = [], depth = 0) {
Object.keys(data).forEach((label, i) => {
const row = {
label,
depth,
};
parsed.push(row);
if (typeof data[label] !== 'object') {
row.value = data[label];
}
else {
traverse(data[label], parsed, depth + 1);
}
});
return parsed;
}
</script>

<style lang="scss" module>
.simple {
text-indent: -24px;
margin-left: var(--spacing-l);
}
.value {
word-break: break-all;
}
</style>

0 comments on commit f064fc1

Please sign in to comment.