|
1 | 1 | import * as React from 'react';
|
2 |
| -import { useState } from 'react'; |
3 |
| -import Collapse, { Panel } from 'mo/components/collapse'; |
4 |
| -import TreeView from './tree'; |
| 2 | +import { mapState } from 'mo/react'; |
| 3 | +import Collapse from 'mo/components/collapse'; |
5 | 4 | import Toolbar from 'mo/components/toolbar';
|
6 |
| -import { Icon } from 'mo/components/icon'; |
7 | 5 | import { IActionBarItem } from 'mo/components/actionbar';
|
8 |
| -import { prefixClaName } from 'mo/common/className'; |
9 | 6 | import { Header, Content } from 'mo/workbench/sidebar';
|
10 |
| -import { data } from './treeMock'; |
11 |
| -interface IExplorerProps { |
12 |
| - isActive?: boolean; |
13 |
| -} |
| 7 | +import { prefixClaName } from 'mo/common/className'; |
| 8 | +import { explorerService } from 'mo/services'; |
| 9 | +import { IExpolorer } from 'mo/model/workbench/explorer' |
14 | 10 |
|
15 |
| -export interface IPanelItem<T = any> extends IActionBarItem { |
16 |
| - renderPanel?: () => React.ReactNode | JSX.Element; |
17 |
| - toolbar?: T; |
18 |
| -} |
19 |
| -interface IState { |
20 |
| - activePanelKey: React.Key | React.Key[]; |
21 |
| - panelSet: IPanelItem[]; |
22 |
| - explorerToolbar: IActionBarItem[]; |
23 |
| -} |
| 11 | +const explorerToolbar: IActionBarItem[] = [ |
| 12 | + { |
| 13 | + id: 'explorer-more', |
| 14 | + title: 'View and More Actions...', |
| 15 | + iconName: 'codicon-ellipsis', |
| 16 | + }, |
| 17 | +]; |
24 | 18 |
|
25 |
| -const initState = { |
26 |
| - activePanelKey: '', |
27 |
| - explorerToolbar: [ |
28 |
| - { |
29 |
| - id: 'explorer-more', |
30 |
| - title: 'View and More Actions...', |
31 |
| - iconName: 'codicon-ellipsis', |
32 |
| - }, |
33 |
| - ], |
34 |
| - panelSet: [ |
35 |
| - { |
36 |
| - id: 'editors', |
37 |
| - name: 'OPEN EDITORS', |
38 |
| - toolbar: [ |
39 |
| - { |
40 |
| - id: 'toggle', |
41 |
| - title: 'Toggle Vertical', |
42 |
| - disabled: true, |
43 |
| - iconName: 'codicon-editor-layout', |
44 |
| - }, |
45 |
| - { |
46 |
| - id: 'save', |
47 |
| - title: 'Save All', |
48 |
| - disabled: true, |
49 |
| - iconName: 'codicon-save-all', |
50 |
| - }, |
51 |
| - { |
52 |
| - id: 'close', |
53 |
| - title: 'Close All Editors', |
54 |
| - iconName: 'codicon-close-all', |
55 |
| - }, |
56 |
| - ], |
57 |
| - renderPanel: () => { |
58 |
| - return <span>editors</span>; |
59 |
| - }, |
60 |
| - }, |
61 |
| - { |
62 |
| - id: 'sample_folder', |
63 |
| - name: 'Sample Folder', |
64 |
| - toolbar: [ |
65 |
| - { |
66 |
| - id: 'new_file', |
67 |
| - title: 'New File', |
68 |
| - iconName: 'codicon-new-file', |
69 |
| - }, |
70 |
| - { |
71 |
| - id: 'new_folder', |
72 |
| - title: 'New Folder', |
73 |
| - iconName: 'codicon-new-folder', |
74 |
| - }, |
75 |
| - { |
76 |
| - id: 'refresh', |
77 |
| - title: 'Refresh Explorer', |
78 |
| - iconName: 'codicon-refresh', |
79 |
| - }, |
80 |
| - { |
81 |
| - id: 'collapse', |
82 |
| - title: 'Collapse Folders in Explorer', |
83 |
| - iconName: 'codicon-collapse-all', |
84 |
| - }, |
85 |
| - ], |
86 |
| - renderPanel: () => { |
87 |
| - return <TreeView data={data} />; |
88 |
| - }, |
89 |
| - }, |
90 |
| - { |
91 |
| - id: 'outline', |
92 |
| - name: 'OUTLINE', |
93 |
| - toolbar: [ |
94 |
| - { |
95 |
| - id: 'outline-collapse', |
96 |
| - title: 'Collapse All', |
97 |
| - iconName: 'codicon-collapse-all', |
98 |
| - }, |
99 |
| - { |
100 |
| - id: 'outline-more', |
101 |
| - title: 'More Actions...', |
102 |
| - iconName: 'codicon-ellipsis', |
103 |
| - }, |
104 |
| - ], |
105 |
| - }, |
106 |
| - ], |
107 |
| -}; |
108 |
| -export const Explorer: React.FunctionComponent<IExplorerProps> = ( |
109 |
| - IExplorerProps |
| 19 | +const Explorer: React.FunctionComponent<IExpolorer> = ( |
| 20 | + props: IExpolorer |
110 | 21 | ) => {
|
111 |
| - const [state, setState] = useState<IState>(initState); |
112 |
| - const onChangeCallback = (key: React.Key | React.Key[]) => { |
113 |
| - setState((state: IState) => ({ ...state, activePanelKey: key })); |
114 |
| - }; |
| 22 | + const { data = [] } = props; |
115 | 23 | const onClick = (e, item) => {
|
116 | 24 | e.stopPropagation();
|
117 | 25 | console.log('onClick:', e, item);
|
118 | 26 | };
|
119 |
| - /** |
120 |
| - * TODO: withdraw and log |
121 |
| - */ |
122 |
| - const render = (render) => { |
123 |
| - if (render) { |
124 |
| - return render(); |
125 |
| - } else { |
126 |
| - return 'Cannot provide...'; |
127 |
| - } |
128 |
| - }; |
129 |
| - const { panelSet, explorerToolbar, activePanelKey } = state; |
| 27 | + |
130 | 28 | return (
|
131 | 29 | <div className={prefixClaName('explorer', 'sidebar')}>
|
132 | 30 | <Header
|
133 | 31 | title={'Explorer'}
|
134 | 32 | toolbar={<Toolbar data={explorerToolbar} onClick={onClick} />}
|
135 | 33 | />
|
136 | 34 | <Content>
|
137 |
| - <Collapse |
138 |
| - accordion={true} |
139 |
| - activeKey={activePanelKey} |
140 |
| - onChange={(activeKey: React.Key | React.Key[]) => { |
141 |
| - onChangeCallback(activeKey); |
142 |
| - }} |
143 |
| - expandIcon={({ isActive }: IExplorerProps) => ( |
144 |
| - <Icon |
145 |
| - type={isActive ? 'chevron-down' : 'chevron-right'} |
146 |
| - /> |
147 |
| - )} |
148 |
| - > |
149 |
| - {panelSet.map((panel: IPanelItem) => ( |
150 |
| - <Panel |
151 |
| - key={panel.id} |
152 |
| - header={panel.name} |
153 |
| - extra={ |
154 |
| - activePanelKey === panel.id && ( |
155 |
| - <Toolbar |
156 |
| - key={panel.id} |
157 |
| - data={panel.toolbar} |
158 |
| - onClick={onClick} |
159 |
| - /> |
160 |
| - ) |
161 |
| - } |
162 |
| - > |
163 |
| - {render(panel.renderPanel)} |
164 |
| - </Panel> |
165 |
| - ))} |
166 |
| - </Collapse> |
| 35 | + <Collapse data={data} /> |
167 | 36 | </Content>
|
168 | 37 | </div>
|
169 | 38 | );
|
170 | 39 | };
|
| 40 | + |
| 41 | +export const ExplorerView = mapState( |
| 42 | + Explorer, |
| 43 | + explorerService.getState() |
| 44 | +); |
| 45 | + |
0 commit comments