}> = {
+ 'added': {name: 'octicon-diff-added', classes: ['text', 'green']},
+ 'modified': {name: 'octicon-diff-modified', classes: ['text', 'yellow']},
+ 'deleted': {name: 'octicon-diff-removed', classes: ['text', 'red']},
+ 'renamed': {name: 'octicon-diff-renamed', classes: ['text', 'teal']},
+ 'typechange': {name: 'octicon-diff-modified', classes: ['text', 'green']}, // there is no octicon for copied, so renamed should be ok
};
- return diffTypes[String(pType)];
+ return diffTypes[pType];
}
function fileIcon(file: File) {
@@ -54,7 +41,7 @@ function fileIcon(file: File) {
{{ item.name }}
-
+
diff --git a/web_src/js/components/file_tree.ts b/web_src/js/components/file_tree.ts
new file mode 100644
index 0000000000000..dd8ea52a4cf53
--- /dev/null
+++ b/web_src/js/components/file_tree.ts
@@ -0,0 +1,76 @@
+export type File = {
+ Name: string;
+ NameHash: string;
+ Status: FileStatus;
+ IsViewed: boolean;
+ IsSubmodule: boolean;
+}
+export type FileStatus = "added" | "modified" | "deleted" | "renamed" | "typechange";
+
+export type Item = {
+ name: string;
+ path: string;
+ isFile: boolean;
+ file?: File;
+ children?: Item[];
+};
+
+export function pathListToTree(fileEntries: File[]): Item[] {
+ const pathToItem = new Map();
+
+ // init root node
+ const root: Item = { name: '', path: '', isFile: false, children: [] };
+ pathToItem.set('', root);
+
+ for (const fileEntry of fileEntries) {
+ const [parentPath, fileName] = splitPathLast(fileEntry.Name);
+
+ let parentItem = pathToItem.get(parentPath);
+ if (!parentItem) {
+ parentItem = constructParents(pathToItem, parentPath);
+ }
+
+ const fileItem: Item = { name: fileName, path: fileEntry.Name, isFile: true, file: fileEntry };
+
+ parentItem.children.push(fileItem);
+ }
+
+ return root.children;
+}
+
+
+function constructParents(pathToItem: Map, dirPath: string): Item {
+ const [dirParentPath, dirName] = splitPathLast(dirPath);
+
+ let parentItem = pathToItem.get(dirParentPath);
+ if (!parentItem) {
+ // if the parent node does not exist, create it
+ parentItem = constructParents(pathToItem, dirParentPath);
+ }
+
+ const dirItem: Item = { name: dirName, path: dirPath, isFile: false, children: [] };
+ parentItem.children.push(dirItem);
+ pathToItem.set(dirPath, dirItem);
+
+ return dirItem;
+}
+
+function splitPathLast(path: string): [string, string] {
+ const lastSlash = path.lastIndexOf('/');
+ return [path.substring(0, lastSlash), path.substring(lastSlash + 1)];
+}
+
+export function mergeChildIfOnlyOneDir(nodes: Item[]): void {
+ for (const node of nodes) {
+ if (node.children) {
+ mergeChildIfOnlyOneDir(node.children);
+ }
+
+ if (node.children?.length === 1 && node.children[0].children) {
+ const child = node.children[0];
+ node.name = `${node.name}/${child.name}`;
+ node.path = child.path;
+ node.children = child.children;
+ }
+ }
+}
diff --git a/web_src/js/features/repo-diff-filetree.ts b/web_src/js/features/repo-diff-filetree.ts
index bc275a90f6ab3..6d4bba27a86a5 100644
--- a/web_src/js/features/repo-diff-filetree.ts
+++ b/web_src/js/features/repo-diff-filetree.ts
@@ -1,6 +1,5 @@
import {createApp} from 'vue';
import DiffFileTree from '../components/DiffFileTree.vue';
-import DiffFileList from '../components/DiffFileList.vue';
export function initDiffFileTree() {
const el = document.querySelector('#diff-file-tree');
@@ -10,10 +9,3 @@ export function initDiffFileTree() {
fileTreeView.mount(el);
}
-export function initDiffFileList() {
- const fileListElement = document.querySelector('#diff-file-list');
- if (!fileListElement) return;
-
- const fileListView = createApp(DiffFileList);
- fileListView.mount(fileListElement);
-}
diff --git a/web_src/js/features/repo-diff.ts b/web_src/js/features/repo-diff.ts
index 0dad4da86226f..50e68717297f7 100644
--- a/web_src/js/features/repo-diff.ts
+++ b/web_src/js/features/repo-diff.ts
@@ -1,7 +1,7 @@
import $ from 'jquery';
import {initCompReactionSelector} from './comp/ReactionSelector.ts';
import {initRepoIssueContentHistory} from './repo-issue-content.ts';
-import {initDiffFileTree, initDiffFileList} from './repo-diff-filetree.ts';
+import {initDiffFileTree} from './repo-diff-filetree.ts';
import {initDiffCommitSelect} from './repo-diff-commitselect.ts';
import {validateTextareaNonEmpty} from './comp/ComboMarkdownEditor.ts';
import {initViewedCheckboxListenerFor, countAndUpdateViewedFiles, initExpandAndCollapseFilesButton} from './pull-view-file.ts';
@@ -238,7 +238,6 @@ export function initRepoDiffView() {
initRepoDiffConversationForm();
if (!$('#diff-file-list').length) return;
initDiffFileTree();
- initDiffFileList();
initDiffCommitSelect();
initRepoDiffShowMore();
initDiffHeaderPopup();