mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2025-09-13 02:49:48 +00:00
Collapse changed files file-tree (#5451)
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Anbraten <6918444+anbraten@users.noreply.github.com>
This commit is contained in:
@@ -28,28 +28,48 @@ useWPTitle(
|
|||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
function collapseNode(node: TreeNode): TreeNode {
|
||||||
|
if (!node.isDirectory) return node;
|
||||||
|
const collapsedChildren = node.children.map(collapseNode);
|
||||||
|
let currentNode = { ...node, children: collapsedChildren };
|
||||||
|
|
||||||
|
while (currentNode.children.length === 1 && currentNode.children[0].isDirectory) {
|
||||||
|
const onlyChild = currentNode.children[0];
|
||||||
|
currentNode = {
|
||||||
|
name: `${currentNode.name}/${onlyChild.name}`,
|
||||||
|
path: onlyChild.path,
|
||||||
|
isDirectory: true,
|
||||||
|
children: onlyChild.children,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return currentNode;
|
||||||
|
}
|
||||||
|
|
||||||
const fileTree = computed(() =>
|
const fileTree = computed(() =>
|
||||||
(pipeline.value.changed_files ?? []).reduce((acc, file) => {
|
(pipeline.value.changed_files ?? [])
|
||||||
const parts = file.split('/');
|
.reduce((acc, file) => {
|
||||||
let currentLevel = acc;
|
const parts = file.split('/');
|
||||||
|
let currentLevel = acc;
|
||||||
|
|
||||||
parts.forEach((part, index) => {
|
parts.forEach((part, index) => {
|
||||||
const existingNode = currentLevel.find((node) => node.name === part);
|
const existingNode = currentLevel.find((node) => node.name === part);
|
||||||
if (existingNode) {
|
if (existingNode) {
|
||||||
currentLevel = existingNode.children;
|
currentLevel = existingNode.children;
|
||||||
} else {
|
} else {
|
||||||
const newNode = {
|
const newNode = {
|
||||||
name: part,
|
name: part,
|
||||||
path: parts.slice(0, index + 1).join('/'),
|
path: parts.slice(0, index + 1).join('/'),
|
||||||
isDirectory: index < parts.length - 1,
|
isDirectory: index < parts.length - 1,
|
||||||
children: [],
|
children: [],
|
||||||
};
|
};
|
||||||
currentLevel.push(newNode);
|
currentLevel.push(newNode);
|
||||||
currentLevel = newNode.children;
|
currentLevel = newNode.children;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return acc;
|
return acc;
|
||||||
}, [] as TreeNode[]),
|
}, [] as TreeNode[])
|
||||||
|
.map(collapseNode),
|
||||||
);
|
);
|
||||||
</script>
|
</script>
|
||||||
|
Reference in New Issue
Block a user