From 1c33929bb9784493828a62ef7ffc381298ba4e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=8E=E8=BF=82=E8=BF=82?= Date: Tue, 11 Jan 2022 19:39:01 +0800 Subject: [PATCH] Revert "feat: support sort in folderTree (#524)" This reverts commit 8802b1f70ec85a597038f003ebf60feafb2ef127. --- .../__tests__/folderTreeService.test.ts | 117 +----------------- .../workbench/explorer/folderTreeService.ts | 44 +------ 2 files changed, 2 insertions(+), 159 deletions(-) diff --git a/src/services/workbench/__tests__/folderTreeService.test.ts b/src/services/workbench/__tests__/folderTreeService.test.ts index 77a085d64..7829e7e99 100644 --- a/src/services/workbench/__tests__/folderTreeService.test.ts +++ b/src/services/workbench/__tests__/folderTreeService.test.ts @@ -272,125 +272,10 @@ describe('Test StatusBarService', () => { const children = data[0].children!; expect(children).toHaveLength(2); expect(children[0]).toEqual({ - ...fileNode, + ...pendingNode, }); }); - test('Should in sort', () => { - const ignoreFolder = new TreeNodeModel({ - id: 'ignore-folder', - fileType: FileTypes.Folder, - name: '.git', - isLeaf: false, - children: [], - }); - const normalFolder = new TreeNodeModel({ - id: 'nomral-folder', - fileType: FileTypes.Folder, - name: 'folder', - isLeaf: false, - children: [], - }); - const normalFile = new TreeNodeModel({ - id: 'nomral-file', - fileType: FileTypes.File, - name: 'file', - isLeaf: true, - children: [], - }); - const ignoreFile = new TreeNodeModel({ - id: 'ignore-file', - fileType: FileTypes.File, - name: '.gitignore', - isLeaf: true, - children: [], - }); - const root = new TreeNodeModel({ - id: 'root', - fileType: FileTypes.RootFolder, - name: 'root-test', - isLeaf: false, - children: [ignoreFile, normalFile, normalFolder, ignoreFolder], - }); - folderTreeService.add(root); - - // let data = folderTreeService.getState().folderTree?.data || []; - let rootNode = folderTreeService.get('root')!; - expect(rootNode.children?.map((i) => i.name)).toEqual([ - '.git', - 'folder', - '.gitignore', - 'file', - ]); - - // add a file - folderTreeService.add( - new TreeNodeModel({ - id: 'another-ignore-file', - fileType: FileTypes.File, - name: '.prettierignore', - isLeaf: true, - children: [], - }), - 'root' - ); - - rootNode = folderTreeService.get('root')!; - expect(rootNode.children?.map((i) => i.name)).toEqual([ - '.git', - 'folder', - '.gitignore', - '.prettierignore', - 'file', - ]); - - // add a folder - folderTreeService.add( - new TreeNodeModel({ - id: 'another-normal-folder', - fileType: FileTypes.Folder, - name: 'another-folder', - isLeaf: false, - children: [], - }), - 'root' - ); - - rootNode = folderTreeService.get('root')!; - expect(rootNode.children?.map((i) => i.name)).toEqual([ - '.git', - 'another-folder', - 'folder', - '.gitignore', - '.prettierignore', - 'file', - ]); - - // add a input - folderTreeService.add( - new TreeNodeModel({ - id: 'create-folder', - fileType: FileTypes.Folder, - name: '', - isEditable: true, - isLeaf: false, - children: [], - }), - 'root' - ); - - rootNode = folderTreeService.get('root')!; - expect(rootNode.children?.map((i) => i.name)).toEqual([ - '', - '.git', - 'another-folder', - 'folder', - '.gitignore', - '.prettierignore', - 'file', - ]); - }); - test('Should support to set entry', () => { folderTreeService.setEntry(Button); expect(folderTreeService.getState().entry).toEqual(Button); diff --git a/src/services/workbench/explorer/folderTreeService.ts b/src/services/workbench/explorer/folderTreeService.ts index df9dedda8..fc3d9107b 100644 --- a/src/services/workbench/explorer/folderTreeService.ts +++ b/src/services/workbench/explorer/folderTreeService.ts @@ -157,42 +157,6 @@ export class FolderTreeService this.builtinService = container.resolve(BuiltinService); } - private isHiddenFile(file: IFolderTreeNodeProps) { - return !!file.name?.startsWith('.'); - } - - private sortTree(tree: IFolderTreeNodeProps[]) { - tree.sort((pre, cur) => { - // folder before file - if (pre.isLeaf !== cur.isLeaf) { - return pre.isLeaf! > cur.isLeaf! ? 1 : -1; - } - - // in general, both have name - if (pre.name && cur.name) { - const isHiddenFilePre = Number(this.isHiddenFile(pre)); - const isHiddenFileCur = Number(this.isHiddenFile(cur)); - // one is hidden file and another is not - if (isHiddenFilePre ^ isHiddenFileCur) { - return isHiddenFilePre ? -1 : 1; - } - // both are hidden files - if (isHiddenFilePre & isHiddenFilePre) { - // hidden file - return pre.name - .substring(1) - .localeCompare(cur.name.substring(1)); - } - return pre.name.localeCompare(cur.name!); - } - - // the node which is creating would without name - return pre.isEditable ? -1 : 1; - }); - - tree.forEach((treeNode) => this.sortTree(treeNode.children || [])); - } - public reset() { this.setState({ folderTree: { @@ -257,8 +221,6 @@ export class FolderTreeService // if root folder exists, then do nothing return; } - - this.sortTree(folder.children || []); this.setState({ folderTree: { ...folderTree, data: [folder] }, }); @@ -357,7 +319,6 @@ export class FolderTreeService } cloneData[index] = tree!.obj; - this.sortTree(cloneData[index].children || []); this.setState({ folderTree: { ...this.state.folderTree, @@ -402,10 +363,7 @@ export class FolderTreeService return; } tree.updateNode(id, restData); - if (index > -1) { - nextData[index] = tree.obj; - this.sortTree(nextData[index].children || []); - } + if (index > -1) nextData[index] = tree.obj; this.setState({ folderTree, });