Skip to content

Commit a3c8d85

Browse files
wewoormumiao
authored andcommitted
feat(panel): support show or hide, and maximize or restore the Panel
Builtin supports show/hide, maximize/restore the Panel features, also you can invoke showHide(), maximizeRestore() method by panelServie re #19
1 parent 551bc74 commit a3c8d85

File tree

6 files changed

+74
-31
lines changed

6 files changed

+74
-31
lines changed

src/controller/panel.tsx

+8-9
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import * as React from 'react';
22
import { IActionBarItem } from 'mo/components/actionBar';
3-
import { PanelStatus } from 'mo/model/workbench/panel';
43
import { Controller } from 'mo/react/controller';
54
import { panelService } from 'mo/services';
65
import { singleton } from 'tsyringe';
6+
import {
7+
PANEL_TOOLBOX_CLOSE,
8+
PANEL_TOOLBOX_RESIZE,
9+
} from 'mo/model/workbench/panel';
710

811
export interface IPanelController {
912
onTabChange(key: string | undefined): void;
@@ -29,14 +32,10 @@ export class PanelController extends Controller implements IPanelController {
2932
e: React.MouseEvent,
3033
item: IActionBarItem
3134
): void => {
32-
if (item.id === 'Closeable') {
33-
panelService.setState({
34-
status: PanelStatus.Close,
35-
});
36-
} else if (item.id === 'Resize') {
37-
panelService.setState({
38-
status: PanelStatus.Maximize,
39-
});
35+
if (item.id === PANEL_TOOLBOX_CLOSE.id) {
36+
panelService.showHide();
37+
} else if (item.id === PANEL_TOOLBOX_RESIZE.id) {
38+
panelService.maximizeRestore();
4039
}
4140
};
4241
}

src/model/workbench/panel.tsx

+10-14
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,6 @@ export enum PanelEvent {
1717
onClick = 'panel.onClick',
1818
}
1919

20-
export enum PanelStatus {
21-
Close = 'close',
22-
Open = 'open',
23-
Maximize = 'maximize',
24-
}
25-
26-
export interface IPanel {
27-
current?: IPanelItem;
28-
data?: IPanelItem[];
29-
toolbox?: IActionBarItem[];
30-
status?: PanelStatus;
31-
}
32-
3320
export const PANEL_PROBLEMS: IPanelItem = {
3421
id: 'ProblemsPane',
3522
name: 'problems',
@@ -58,11 +45,20 @@ export const PANEL_TOOLBOX_RESIZE = {
5845
iconName: 'codicon-chevron-up',
5946
};
6047

48+
export interface IPanel {
49+
current?: IPanelItem;
50+
data?: IPanelItem[];
51+
toolbox?: IActionBarItem[];
52+
hidden?: boolean;
53+
maximize?: boolean;
54+
}
55+
6156
@injectable()
6257
export class PanelModel implements IPanel {
6358
public current: IPanelItem | undefined = PANEL_OUTPUT;
6459
public data: IPanelItem[] = ([] = [PANEL_PROBLEMS, PANEL_OUTPUT]);
65-
public status = PanelStatus.Open;
60+
public hidden = false;
61+
public maximize = false;
6662
public toolbox: IActionBarItem[] = [
6763
PANEL_TOOLBOX_RESIZE,
6864
PANEL_TOOLBOX_CLOSE,

src/services/workbench/panelService.ts

+32
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
PanelModel,
77
PANEL_OUTPUT,
88
PANEL_PROBLEMS,
9+
PANEL_TOOLBOX_RESIZE,
910
} from 'mo/model/workbench/panel';
1011

1112
import { searchById } from '../helper';
@@ -20,6 +21,8 @@ export interface IPanelService extends Component<IPanel> {
2021
clearOutput(): void;
2122
updateProblems(data: IPanelItem): IPanelItem | undefined;
2223
clearProblems(): void;
24+
showHide(): void;
25+
maximizeRestore(): void;
2326
}
2427

2528
@singleton()
@@ -30,6 +33,35 @@ export class PanelService extends Component<IPanel> implements IPanelService {
3033
super();
3134
this.state = container.resolve(PanelModel);
3235
}
36+
37+
public showHide(): void {
38+
this.setState({
39+
hidden: !this.state.hidden,
40+
});
41+
}
42+
43+
public maximizeRestore(): void {
44+
const maximize = !this.state.maximize;
45+
const { toolbox = [] } = this.state;
46+
const resizeBtnIndex = toolbox?.findIndex(
47+
searchById(PANEL_TOOLBOX_RESIZE.id)
48+
);
49+
const resizeBtn = toolbox[resizeBtnIndex];
50+
if (resizeBtn) {
51+
if (maximize) {
52+
toolbox[resizeBtnIndex] = Object.assign({}, resizeBtn, {
53+
title: 'Restore Panel Size',
54+
iconName: 'codicon-chevron-down',
55+
});
56+
} else {
57+
toolbox[resizeBtnIndex] = PANEL_TOOLBOX_RESIZE;
58+
}
59+
this.setState({
60+
maximize: !this.state.maximize,
61+
});
62+
}
63+
}
64+
3365
public open(data: IPanelItem<any>): void {
3466
let current = this.getById(data.id);
3567
if (!current) {

src/workbench/panel/panel.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ const panelToolbarClassName = getBEMElement(defaultClassName, 'toolbar');
1414
const panelContainerClassName = getBEMElement(defaultClassName, 'container');
1515

1616
function Panel(props: IPanel & IPanelController) {
17-
console.log('Panel render:', props);
1817
const { data, current, toolbox = [], onTabChange, onToolbarClick } = props;
1918
let toolboxData = toolbox;
2019
if (current && current.toolbox) {

src/workbench/workbench.tsx

+19-7
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,18 @@ import { Utils } from '@dtinsight/dt-utils';
1515
import { APP_PREFIX } from 'mo/common/const';
1616
import { panelService } from 'mo/services';
1717
import { connect } from 'mo/react';
18+
import { IPanel } from 'mo/model/workbench/panel';
1819

19-
export interface IWorkbench {}
20+
export interface IWorkbench {
21+
panel: IPanel;
22+
}
2023

2124
const mainBenchClassName = prefixClaName('mainBench');
2225
const workbenchClassName = prefixClaName('workbench');
2326
const appClassName = classNames(APP_PREFIX, Utils.isMacOs() ? 'mac' : '');
2427

2528
export function WorkbenchView(props: IWorkbench) {
29+
const { panel } = props;
2630
return (
2731
<div id={ID_APP} className={appClassName}>
2832
<div className={workbenchClassName}>
@@ -42,12 +46,20 @@ export function WorkbenchView(props: IWorkbench) {
4246
split="horizontal"
4347
allowResize={true}
4448
>
45-
<Pane initialSize="70%" maxSize="99%" minSize="10%">
46-
<EditorView />
47-
</Pane>
48-
<Pane>
49-
<PanelView />
50-
</Pane>
49+
{!panel.maximize ? (
50+
<Pane
51+
initialSize="70%"
52+
maxSize="99%"
53+
minSize="10%"
54+
>
55+
<EditorView />
56+
</Pane>
57+
) : null}
58+
{!panel.hidden ? (
59+
<Pane>
60+
<PanelView />
61+
</Pane>
62+
) : null}
5163
</SplitPane>
5264
</SplitPane>
5365
</div>

stories/extensions/test/testPane.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ export default class TestPane extends React.Component {
6666
});
6767
};
6868

69+
const showHidePanel = function () {
70+
panelService.showHide();
71+
};
72+
6973
const newEditor = function () {
7074
const key = Math.random() * 10 + 1;
7175
const tabData: IEditorTab = {
@@ -98,6 +102,7 @@ export default class TestPane extends React.Component {
98102
<div style={{ margin: '50px 20px' }}>
99103
<h2>Add a new Panel:</h2>
100104
<Button onClick={addPanel}>Add Panel</Button>
105+
<Button onClick={showHidePanel}>Show/Hide Panel</Button>
101106
</div>
102107
</div>
103108
);

0 commit comments

Comments
 (0)