From eece63bf38e8aafe8cf2a55ca86e0a78967a982d Mon Sep 17 00:00:00 2001 From: bsilkyn Date: Thu, 23 May 2024 16:58:52 +0200 Subject: [PATCH 1/7] chore: refactor the conversion of structureChecks to TreeNodes to the Project.ts file --- .../projects/ProjectStructureEditor.vue | 69 ++---------------- frontend/src/types/Project.ts | 70 +++++++++++++++++++ 2 files changed, 74 insertions(+), 65 deletions(-) diff --git a/frontend/src/components/projects/ProjectStructureEditor.vue b/frontend/src/components/projects/ProjectStructureEditor.vue index c1ee1f5e..8810c48b 100644 --- a/frontend/src/components/projects/ProjectStructureEditor.vue +++ b/frontend/src/components/projects/ProjectStructureEditor.vue @@ -3,11 +3,12 @@ import Tree from 'primevue/tree'; import Button from 'primevue/button'; import Chips from 'primevue/chips'; import InputText from 'primevue/inputtext'; -import { StructureCheck } from '@/types/StructureCheck.ts'; -import { computed, ref } from 'vue'; +import { ref } from 'vue'; import { type TreeNode } from 'primevue/treenode'; import { PrimeIcons } from 'primevue/api'; import { useI18n } from 'vue-i18n'; +import { Project } from "@/types/Project.ts"; +import { StructureCheck } from '@/types/StructureCheck.ts'; /* Models */ const structureChecks = defineModel(); @@ -21,30 +22,6 @@ const editingStructureCheck = ref(null); const selectedKeys = ref([]); const expandedKeys = ref([]); -/* Computed */ -const nodes = computed(() => { - const nodes: TreeNode[] = []; - - if (structureChecks.value !== undefined) { - for (const [i, check] of structureChecks.value.entries()) { - const hierarchy = check.getDirectoryHierarchy(); - let currentNodes = nodes; - - for (const [j, part] of hierarchy.entries()) { - let node = currentNodes.find((node) => node.label === part); - - if (node === undefined) { - node = newTreeNode(check, `${i}${j}`, part, j === hierarchy.length - 1); - currentNodes.push(node); - } - - currentNodes = node.children ?? []; - } - } - } - - return nodes; -}); /** * Delete a structure check from the list. @@ -119,44 +96,6 @@ function selectStructureCheck(node: TreeNode): void { selectedStructureCheck.value = node.data; } } - -/** - * Construct a tree node from a structure check folder path. - * - * @param check - * @param key - * @param label - * @param leaf - */ -function newTreeNode(check: StructureCheck, key: string, label: string, leaf: boolean = false): TreeNode { - const node: TreeNode = { - key, - label, - data: check, - icon: PrimeIcons.FOLDER, - check: leaf, - children: [], - }; - - if (leaf) { - node.children = [ - { - key: key + '-obligated', - icon: PrimeIcons.CHECK_CIRCLE, - data: check, - obligated: true, - }, - { - key: key + '-blocked', - icon: PrimeIcons.TIMES_CIRCLE, - data: check, - blocked: true, - }, - ]; - } - - return node; -}