fix(code/frontend): fix sort file tree node function (#41218) (#41543)

This commit is contained in:
WangQianliang 2019-07-19 12:23:41 +08:00 committed by GitHub
parent 2d503cc0eb
commit 062919d711
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -56,11 +56,24 @@ export interface FileTree {
}
export function sortFileTree(a: FileTree, b: FileTree) {
if (a.type !== b.type) {
return b.type - a.type;
} else {
return a.name.localeCompare(b.name);
// consider Link and File are the same type, Submodule and Directory are the same type when sorting.
// Submodule and Directory are before Link and File
const types1 = [FileTreeItemType.File, FileTreeItemType.Link];
const types2 = [FileTreeItemType.Directory, FileTreeItemType.Submodule];
if (types1.includes(a.type)) {
if (types1.includes(b.type)) {
return a.name.localeCompare(b.name);
} else {
return 1;
}
} else if (types2.includes(a.type)) {
if (types2.includes(b.type)) {
return a.name.localeCompare(b.name);
} else {
return -1;
}
}
return a.name.localeCompare(b.name);
}
export enum FileTreeItemType {