Skip to content

Commit

Permalink
fix(ci): fix ci error
Browse files Browse the repository at this point in the history
fix ci error
  • Loading branch information
zhangtengjin authored and wewoor committed Feb 25, 2021
1 parent 8fd97a8 commit 6c80a4f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 86 deletions.
5 changes: 3 additions & 2 deletions src/controller/explorer/explorer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
explorerService,
} from 'mo';
import * as React from 'react';
import { IFolderTree } from 'mo/model'
import { ExplorerView, FolderTreeView } from 'mo/workbench/sidebar/explore';
import { IActionBarItem } from 'mo/components/actionBar';

Expand Down Expand Up @@ -99,7 +100,7 @@ export class ExplorerController
id: 'new_file',
title: 'New File',
iconName: 'codicon-new-file',
onClick: () => {},
onClick: () => { },
},
{
id: 'new_folder',
Expand All @@ -118,7 +119,7 @@ export class ExplorerController
},
],
renderPanel: () => {
const folderProps: any = {
const folderProps: IFolderTree = {
data: explorerState.folderTree?.data,
contextMenu: explorerState.folderTree?.contextMenu,
};
Expand Down
7 changes: 4 additions & 3 deletions src/controller/explorer/folderTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,12 @@ export class FolderTreeController
this.initView();
}

private initView() {}
private initView() { }

public readonly onSelectFile = (file: ITreeNodeItem) => {
const tabData: any = {
const tabData = {
...file,
id: `${file.id}`,
modified: false,
data: {
value: `hello tree ${file.id}`,
Expand Down Expand Up @@ -124,7 +125,7 @@ export class FolderTreeController
},
];

const folderContextMenu: any = baseContextMenu.concat(menus);
const folderContextMenu = baseContextMenu.concat(menus);

const fileContextMenu = [
{
Expand Down
113 changes: 47 additions & 66 deletions src/services/workbench/explorerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class TreeView implements ITreeInterface {
1,
{
...node,
...extra,
...extra
}
);
this.updateChildren(parentIndex[this.childNodeName]);
Expand All @@ -164,12 +164,14 @@ export class TreeView implements ITreeInterface {

updateChildren(children: IIndex) {
const self = this;
children.forEach(function (id, i) {
const index = self.getIndex(id);
index.prev = index.next = null;
if (i > 0) index.prev = children[i - 1];
if (i < children.length - 1) index.next = children[i + 1];
});
children.forEach(
function (id, i) {
const index = self.getIndex(id);
index.prev = index.next = null;
if (i > 0) index.prev = children[i - 1];
if (i < children.length - 1) index.next = children[i + 1];
}
);
}

insert(obj: ITreeNodeItem, parentId: number, i: number) {
Expand Down Expand Up @@ -220,6 +222,7 @@ export class TreeView implements ITreeInterface {
}
}


export interface IExplorerService extends Component<IExplorer> {
addPanel(panel: IPanelItem | IPanelItem[]): void;
reset(): void;
Expand Down Expand Up @@ -272,16 +275,13 @@ export class ExplorerService
next.splice(index, 1);
}
this.setState({
data: next,
data: next
});
}

/* ============================Tree============================ */

private getFileIconByExtensionName(
name: string,
fileType: FileType
): string {
private getFileIconByExtensionName(name: string, fileType: FileType): string {
if (fileType === FileTypes.FOLDER) return '';
const fileExtension = name && name.split('.')?.[1];
let icon = 'symbol-file';
Expand Down Expand Up @@ -310,19 +310,15 @@ export class ExplorerService

private getCurrentRootFolderAndIndex(id: number) {
const currentRootFolder: ITreeNodeItem = this.getRootFolderById(id);
const index = this.getRootFolderIndexByRootId(
(currentRootFolder as any).id
);
const index = this.getRootFolderIndexByRootId((currentRootFolder as any).id) as number;
return {
index,
currentRootFolder,
};
currentRootFolder
}
}

public getRootFolderIndexByRootId(id: number): number {
return this.state.folderTree?.data!.findIndex(
(folder) => folder.id === id
);
public getRootFolderIndexByRootId(id: number): number | undefined {
return this.state.folderTree?.data!.findIndex((folder) => folder.id === id);
}

public getRootFolderByRootId(id: number): ITreeNodeItem | undefined {
Expand All @@ -331,12 +327,12 @@ export class ExplorerService

public getRootFolderById(id: number): ITreeNodeItem {
let rootNode = {};
this.state.folderTree?.data?.forEach((folder) => {
this.state.folderTree?.data?.forEach(folder => {
const treeInstance = new TreeView(folder);
if (treeInstance.get(id)) {
rootNode = folder;
}
});
})
return rootNode;
}

Expand All @@ -349,123 +345,107 @@ export class ExplorerService
next?.push(folder);
}
this.setState({
folderTree: { ...folderTree, data: next },
folderTree: { ...folderTree, data: next }
});
}

public removeRootFolder(id: number) {
const { folderTree } = this.state;
const next = [...folderTree?.data!];
const index = this.getRootFolderIndexByRootId(id);
const index = this.getRootFolderIndexByRootId(id) as number;
if (index > -1) {
next.splice(index, 1);
}
this.setState({
folderTree: { ...folderTree, data: next },
folderTree: { ...folderTree, data: next }
});
}

public updateFile(file, callback) {
const { folderTree } = this.state;
const { id, name, fileType } = file;
const cloneData: ITreeNodeItem[] = folderTree?.data || [];
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(
id
);
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(id)
const tree = new TreeView(currentRootFolder);
if (name) {
tree.update(id, {
...file,
icon: this.getFileIconByExtensionName(name, fileType),
modify: false,
});
modify: false
})
} else {
tree.remove(id);
tree.remove(id)
}
if (index > -1) cloneData[index] = tree.obj;
this.setState({
folderTree: { ...folderTree, data: cloneData },
folderTree: { ...folderTree, data: cloneData }
});
if (callback) callback();
}

public rename(id: number, callback?: Function) {
const { folderTree } = this.state;
const cloneData: ITreeNodeItem[] = folderTree?.data || [];
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(
id
);
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(id)
const tree = new TreeView(currentRootFolder);
tree.update(id, {
modify: true,
});
modify: true
})
if (index > -1) cloneData[index] = tree.obj;
this.setState({
folderTree: { ...folderTree, data: cloneData },
folderTree: { ...folderTree, data: cloneData }
});
if (callback) callback();
}

public delete(id: number, callback?: Function) {
const { folderTree } = this.state;
const cloneData: ITreeNodeItem[] = folderTree?.data || [];
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(
id
);
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(id)
const tree = new TreeView(currentRootFolder);
tree.remove(id);
if (index > -1) cloneData[index] = tree.obj;
this.setState({
folderTree: { ...folderTree, data: cloneData },
folderTree: { ...folderTree, data: cloneData }
});
if (callback) callback();
}

public newFile(parentId: number, callback?: Function) {
const { folderTree } = this.state;
const cloneData: ITreeNodeItem[] = folderTree?.data || [];
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(
parentId
);
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(parentId)
const tree = new TreeView(currentRootFolder);
if (!parentId) {
const tabData = {
id: `${Math.random() * 10 + 1}`,
name: `Untitled`,
modified: false,
modified: false
};
editorService.open(tabData);
editorService.open(tabData)
}
tree.append(
new TreeNodeModel({
modify: true,
}),
parentId
);
tree.append(new TreeNodeModel({
modify: true
}), parentId)
if (index > -1) cloneData[index] = tree.obj;
this.setState({
folderTree: { ...folderTree, data: cloneData },
folderTree: { ...folderTree, data: cloneData }
});
if (callback) callback();
}

public newFolder(parentId, callback: Function) {
const { folderTree } = this.state;
const cloneData: ITreeNodeItem[] = folderTree?.data || [];
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(
parentId
);
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(parentId)
const tree = new TreeView(currentRootFolder);
tree.append(
new TreeNodeModel({
fileType: FileTypes.FOLDER as FileType,
modify: true,
}),
parentId
);
tree.append(new TreeNodeModel({
fileType: FileTypes.FOLDER as FileType,
modify: true
}), parentId)
if (index > -1) cloneData[index] = tree.obj;
this.setState({
folderTree: { ...folderTree, data: cloneData },
folderTree: { ...folderTree, data: cloneData }
});
if (callback) callback();
}
Expand All @@ -477,4 +457,5 @@ export class ExplorerService
}),
});
};

}
21 changes: 6 additions & 15 deletions stories/components/4-Tree.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,38 @@ const file = FileTypes.FILE as FileType;
stories.add('Basic Usage', () => {
const treeData = [
{
id: '1',
id: 1,
name: folder,
fileType: folder,
contextMenu: [
{
id: 'custom',
name: 'Custom ContextMenu',
onClick: () => {
console.log("i'm custom contextMenu");
},
},
],
children: [
{
id: '2',
id: 2,
name: 'abc',
fileType: folder,
children: [
{
id: '3',
id: 3,
name: 'test.txt',
fileType: file,
icon: 'symbol-file',
},
],
},
{
id: '6',
id: 6,
name: 'xyz',
fileType: folder,
children: [
{
id: '7',
id: 7,
name: 'test.pdf',
fileType: file,
icon: 'file-pdf',
},
],
},
{
id: '10',
id: 10,
name: 'file.yaml',
fileType: file,
},
Expand Down

0 comments on commit 6c80a4f

Please sign in to comment.