Skip to content

Commit

Permalink
feat: optimize fileType definition
Browse files Browse the repository at this point in the history
optimize fileType definition
  • Loading branch information
zhangtengjin authored and wewoor committed Feb 25, 2021
1 parent ec63d9b commit 768f176
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
22 changes: 11 additions & 11 deletions src/components/tree/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ import { IMenuItem } from 'mo/components/menu';
import { Icon } from 'mo/components/icon';
import { prefixClaName, classNames } from 'mo/common/className';

// TODO: 提出来
export enum FileTypes {
FILE = 'file',
FOLDER = 'folder',
ROOT = 'rootFolder',
file = 'file',
folder = 'folder',
rootFolder = 'rootFolder',
}
export type FileType = 'file' | 'folder' | 'rootFolder';

export type FileType = keyof typeof FileTypes;

export interface ITreeNodeItem {
name?: string;
Expand Down Expand Up @@ -51,11 +51,11 @@ export interface ITreeProps {
expandedKeys?: Key[];
defaultCheckedKeys?: Key[];
checkedKeys?:
| Key[]
| {
checked: Key[];
halfChecked: Key[];
};
| Key[]
| {
checked: Key[];
halfChecked: Key[];
};
defaultSelectedKeys?: Key[];
selectedKeys?: Key[];
titleRender?: (node: DataNode) => React.ReactNode;
Expand Down Expand Up @@ -220,7 +220,7 @@ const TreeView: React.FunctionComponent<ITreeProps> = (props: ITreeProps) => {
switcherIcon={<Icon type="chevron-right" />}
onSelect={(selectedKeys, e: any) => {
const { fileType, modify } = e.node.data;
const isFile = fileType === FileTypes.FILE;
const isFile = fileType === FileTypes.file;
if (isFile && !modify && props.onSelectFile) {
props.onSelectFile(e.node.data);
}
Expand Down
8 changes: 4 additions & 4 deletions src/controller/explorer/folderTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class FolderTreeController
this.initView();
}

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

public readonly onSelectFile = (file: ITreeNodeItem) => {
const tabData = {
Expand Down Expand Up @@ -142,15 +142,15 @@ export class FolderTreeController
);

switch (node.fileType) {
case FileTypes.FILE: {
case FileTypes.file: {
menu = fileContextMenu;
break;
}
case FileTypes.FOLDER: {
case FileTypes.folder: {
menu = folderContextMenu;
break;
}
case FileTypes.ROOT: {
case FileTypes.rootFolder: {
menu = rootFodlerContextMenu;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/model/workbench/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export class TreeNodeModel implements ITreeNodeItem {
id,
name = '',
location = '',
fileType = FileTypes.FILE as FileType,
fileType = FileTypes.file as FileType,
children = [],
icon = '',
modify = false,
Expand Down
4 changes: 2 additions & 2 deletions src/services/workbench/explorerService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export class ExplorerService
name: string,
fileType: FileType
): string {
if (fileType === FileTypes.FOLDER) return '';
if (fileType === FileTypes.folder) return '';
const fileExtension = name && name.split('.')?.[1];
let icon = 'symbol-file';
switch (fileExtension) {
Expand Down Expand Up @@ -458,7 +458,7 @@ export class ExplorerService
const tree = new TreeView(currentRootFolder);
tree.append(
new TreeNodeModel({
fileType: FileTypes.FOLDER as FileType,
fileType: FileTypes.folder as FileType,
modify: true,
}),
parentId
Expand Down
6 changes: 3 additions & 3 deletions src/workbench/sidebar/explore/folderTree.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const FolderTree: React.FunctionComponent<IFolderTree> = (
name: newName,
},
() => {
if (node?.fileType === FileTypes.FILE && newName) {
if (node?.fileType === FileTypes.file && newName) {
onSelectFile?.({
...node,
name: newName,
Expand Down Expand Up @@ -87,8 +87,8 @@ const FolderTree: React.FunctionComponent<IFolderTree> = (
onBlur={handleInputBlur}
/>
) : (
name
);
name
);
};

const renderByData = (
Expand Down
4 changes: 2 additions & 2 deletions stories/components/4-Tree.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { withKnobs } from '@storybook/addon-knobs';
const stories = storiesOf('Tree', module);
stories.addDecorator(withKnobs);

const folder = FileTypes.FOLDER as FileType;
const file = FileTypes.FILE as FileType;
const folder = FileTypes.folder as FileType;
const file = FileTypes.file as FileType;

stories.add('Basic Usage', () => {
const treeData = [
Expand Down

0 comments on commit 768f176

Please sign in to comment.