Skip to content

Commit 6c80a4f

Browse files
zhangtengjinwewoor
authored andcommitted
fix(ci): fix ci error
fix ci error
1 parent 8fd97a8 commit 6c80a4f

File tree

4 files changed

+60
-86
lines changed

4 files changed

+60
-86
lines changed

src/controller/explorer/explorer.tsx

+3-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
explorerService,
88
} from 'mo';
99
import * as React from 'react';
10+
import { IFolderTree } from 'mo/model'
1011
import { ExplorerView, FolderTreeView } from 'mo/workbench/sidebar/explore';
1112
import { IActionBarItem } from 'mo/components/actionBar';
1213

@@ -99,7 +100,7 @@ export class ExplorerController
99100
id: 'new_file',
100101
title: 'New File',
101102
iconName: 'codicon-new-file',
102-
onClick: () => {},
103+
onClick: () => { },
103104
},
104105
{
105106
id: 'new_folder',
@@ -118,7 +119,7 @@ export class ExplorerController
118119
},
119120
],
120121
renderPanel: () => {
121-
const folderProps: any = {
122+
const folderProps: IFolderTree = {
122123
data: explorerState.folderTree?.data,
123124
contextMenu: explorerState.folderTree?.contextMenu,
124125
};

src/controller/explorer/folderTree.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ export class FolderTreeController
3333
this.initView();
3434
}
3535

36-
private initView() {}
36+
private initView() { }
3737

3838
public readonly onSelectFile = (file: ITreeNodeItem) => {
39-
const tabData: any = {
39+
const tabData = {
4040
...file,
41+
id: `${file.id}`,
4142
modified: false,
4243
data: {
4344
value: `hello tree ${file.id}`,
@@ -124,7 +125,7 @@ export class FolderTreeController
124125
},
125126
];
126127

127-
const folderContextMenu: any = baseContextMenu.concat(menus);
128+
const folderContextMenu = baseContextMenu.concat(menus);
128129

129130
const fileContextMenu = [
130131
{

src/services/workbench/explorerService.ts

+47-66
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ export class TreeView implements ITreeInterface {
154154
1,
155155
{
156156
...node,
157-
...extra,
157+
...extra
158158
}
159159
);
160160
this.updateChildren(parentIndex[this.childNodeName]);
@@ -164,12 +164,14 @@ export class TreeView implements ITreeInterface {
164164

165165
updateChildren(children: IIndex) {
166166
const self = this;
167-
children.forEach(function (id, i) {
168-
const index = self.getIndex(id);
169-
index.prev = index.next = null;
170-
if (i > 0) index.prev = children[i - 1];
171-
if (i < children.length - 1) index.next = children[i + 1];
172-
});
167+
children.forEach(
168+
function (id, i) {
169+
const index = self.getIndex(id);
170+
index.prev = index.next = null;
171+
if (i > 0) index.prev = children[i - 1];
172+
if (i < children.length - 1) index.next = children[i + 1];
173+
}
174+
);
173175
}
174176

175177
insert(obj: ITreeNodeItem, parentId: number, i: number) {
@@ -220,6 +222,7 @@ export class TreeView implements ITreeInterface {
220222
}
221223
}
222224

225+
223226
export interface IExplorerService extends Component<IExplorer> {
224227
addPanel(panel: IPanelItem | IPanelItem[]): void;
225228
reset(): void;
@@ -272,16 +275,13 @@ export class ExplorerService
272275
next.splice(index, 1);
273276
}
274277
this.setState({
275-
data: next,
278+
data: next
276279
});
277280
}
278281

279282
/* ============================Tree============================ */
280283

281-
private getFileIconByExtensionName(
282-
name: string,
283-
fileType: FileType
284-
): string {
284+
private getFileIconByExtensionName(name: string, fileType: FileType): string {
285285
if (fileType === FileTypes.FOLDER) return '';
286286
const fileExtension = name && name.split('.')?.[1];
287287
let icon = 'symbol-file';
@@ -310,19 +310,15 @@ export class ExplorerService
310310

311311
private getCurrentRootFolderAndIndex(id: number) {
312312
const currentRootFolder: ITreeNodeItem = this.getRootFolderById(id);
313-
const index = this.getRootFolderIndexByRootId(
314-
(currentRootFolder as any).id
315-
);
313+
const index = this.getRootFolderIndexByRootId((currentRootFolder as any).id) as number;
316314
return {
317315
index,
318-
currentRootFolder,
319-
};
316+
currentRootFolder
317+
}
320318
}
321319

322-
public getRootFolderIndexByRootId(id: number): number {
323-
return this.state.folderTree?.data!.findIndex(
324-
(folder) => folder.id === id
325-
);
320+
public getRootFolderIndexByRootId(id: number): number | undefined {
321+
return this.state.folderTree?.data!.findIndex((folder) => folder.id === id);
326322
}
327323

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

332328
public getRootFolderById(id: number): ITreeNodeItem {
333329
let rootNode = {};
334-
this.state.folderTree?.data?.forEach((folder) => {
330+
this.state.folderTree?.data?.forEach(folder => {
335331
const treeInstance = new TreeView(folder);
336332
if (treeInstance.get(id)) {
337333
rootNode = folder;
338334
}
339-
});
335+
})
340336
return rootNode;
341337
}
342338

@@ -349,123 +345,107 @@ export class ExplorerService
349345
next?.push(folder);
350346
}
351347
this.setState({
352-
folderTree: { ...folderTree, data: next },
348+
folderTree: { ...folderTree, data: next }
353349
});
354350
}
355351

356352
public removeRootFolder(id: number) {
357353
const { folderTree } = this.state;
358354
const next = [...folderTree?.data!];
359-
const index = this.getRootFolderIndexByRootId(id);
355+
const index = this.getRootFolderIndexByRootId(id) as number;
360356
if (index > -1) {
361357
next.splice(index, 1);
362358
}
363359
this.setState({
364-
folderTree: { ...folderTree, data: next },
360+
folderTree: { ...folderTree, data: next }
365361
});
366362
}
367363

368364
public updateFile(file, callback) {
369365
const { folderTree } = this.state;
370366
const { id, name, fileType } = file;
371367
const cloneData: ITreeNodeItem[] = folderTree?.data || [];
372-
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(
373-
id
374-
);
368+
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(id)
375369
const tree = new TreeView(currentRootFolder);
376370
if (name) {
377371
tree.update(id, {
378372
...file,
379373
icon: this.getFileIconByExtensionName(name, fileType),
380-
modify: false,
381-
});
374+
modify: false
375+
})
382376
} else {
383-
tree.remove(id);
377+
tree.remove(id)
384378
}
385379
if (index > -1) cloneData[index] = tree.obj;
386380
this.setState({
387-
folderTree: { ...folderTree, data: cloneData },
381+
folderTree: { ...folderTree, data: cloneData }
388382
});
389383
if (callback) callback();
390384
}
391385

392386
public rename(id: number, callback?: Function) {
393387
const { folderTree } = this.state;
394388
const cloneData: ITreeNodeItem[] = folderTree?.data || [];
395-
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(
396-
id
397-
);
389+
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(id)
398390
const tree = new TreeView(currentRootFolder);
399391
tree.update(id, {
400-
modify: true,
401-
});
392+
modify: true
393+
})
402394
if (index > -1) cloneData[index] = tree.obj;
403395
this.setState({
404-
folderTree: { ...folderTree, data: cloneData },
396+
folderTree: { ...folderTree, data: cloneData }
405397
});
406398
if (callback) callback();
407399
}
408400

409401
public delete(id: number, callback?: Function) {
410402
const { folderTree } = this.state;
411403
const cloneData: ITreeNodeItem[] = folderTree?.data || [];
412-
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(
413-
id
414-
);
404+
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(id)
415405
const tree = new TreeView(currentRootFolder);
416406
tree.remove(id);
417407
if (index > -1) cloneData[index] = tree.obj;
418408
this.setState({
419-
folderTree: { ...folderTree, data: cloneData },
409+
folderTree: { ...folderTree, data: cloneData }
420410
});
421411
if (callback) callback();
422412
}
423413

424414
public newFile(parentId: number, callback?: Function) {
425415
const { folderTree } = this.state;
426416
const cloneData: ITreeNodeItem[] = folderTree?.data || [];
427-
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(
428-
parentId
429-
);
417+
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(parentId)
430418
const tree = new TreeView(currentRootFolder);
431419
if (!parentId) {
432420
const tabData = {
433421
id: `${Math.random() * 10 + 1}`,
434422
name: `Untitled`,
435-
modified: false,
423+
modified: false
436424
};
437-
editorService.open(tabData);
425+
editorService.open(tabData)
438426
}
439-
tree.append(
440-
new TreeNodeModel({
441-
modify: true,
442-
}),
443-
parentId
444-
);
427+
tree.append(new TreeNodeModel({
428+
modify: true
429+
}), parentId)
445430
if (index > -1) cloneData[index] = tree.obj;
446431
this.setState({
447-
folderTree: { ...folderTree, data: cloneData },
432+
folderTree: { ...folderTree, data: cloneData }
448433
});
449434
if (callback) callback();
450435
}
451436

452437
public newFolder(parentId, callback: Function) {
453438
const { folderTree } = this.state;
454439
const cloneData: ITreeNodeItem[] = folderTree?.data || [];
455-
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(
456-
parentId
457-
);
440+
const { currentRootFolder, index } = this.getCurrentRootFolderAndIndex(parentId)
458441
const tree = new TreeView(currentRootFolder);
459-
tree.append(
460-
new TreeNodeModel({
461-
fileType: FileTypes.FOLDER as FileType,
462-
modify: true,
463-
}),
464-
parentId
465-
);
442+
tree.append(new TreeNodeModel({
443+
fileType: FileTypes.FOLDER as FileType,
444+
modify: true
445+
}), parentId)
466446
if (index > -1) cloneData[index] = tree.obj;
467447
this.setState({
468-
folderTree: { ...folderTree, data: cloneData },
448+
folderTree: { ...folderTree, data: cloneData }
469449
});
470450
if (callback) callback();
471451
}
@@ -477,4 +457,5 @@ export class ExplorerService
477457
}),
478458
});
479459
};
460+
480461
}

stories/components/4-Tree.stories.tsx

+6-15
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,38 @@ const file = FileTypes.FILE as FileType;
1313
stories.add('Basic Usage', () => {
1414
const treeData = [
1515
{
16-
id: '1',
16+
id: 1,
1717
name: folder,
1818
fileType: folder,
19-
contextMenu: [
20-
{
21-
id: 'custom',
22-
name: 'Custom ContextMenu',
23-
onClick: () => {
24-
console.log("i'm custom contextMenu");
25-
},
26-
},
27-
],
2819
children: [
2920
{
30-
id: '2',
21+
id: 2,
3122
name: 'abc',
3223
fileType: folder,
3324
children: [
3425
{
35-
id: '3',
26+
id: 3,
3627
name: 'test.txt',
3728
fileType: file,
3829
icon: 'symbol-file',
3930
},
4031
],
4132
},
4233
{
43-
id: '6',
34+
id: 6,
4435
name: 'xyz',
4536
fileType: folder,
4637
children: [
4738
{
48-
id: '7',
39+
id: 7,
4940
name: 'test.pdf',
5041
fileType: file,
5142
icon: 'file-pdf',
5243
},
5344
],
5445
},
5546
{
56-
id: '10',
47+
id: 10,
5748
name: 'file.yaml',
5849
fileType: file,
5950
},

0 commit comments

Comments
 (0)