Skip to content

Commit 95470fe

Browse files
authored
feat: support set the sorting of the panel (#351)
1 parent d2913e9 commit 95470fe

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/model/problems.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ export function builtInPanelProblems(): IPanelItem {
5151
id: PANEL_PROBLEMS,
5252
name: localize(PANEL_PROBLEMS, 'problems'),
5353
data: null,
54+
sortIndex: 1,
5455
};
5556
}
5657

src/model/workbench/panel.tsx

+5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export interface IPanelItem<T = any> extends ITabProps<T> {
1313
title?: string;
1414
toolbox?: IActionBarItemProps[];
1515
data?: T;
16+
/**
17+
* The sort of panel item
18+
*/
19+
sortIndex?: number;
1620
}
1721

1822
export enum PanelEvent {
@@ -44,6 +48,7 @@ export function builtInOutputPanel() {
4448
id: PANEL_OUTPUT,
4549
name: localize(PANEL_OUTPUT, 'output'),
4650
data: '',
51+
sortIndex: 2,
4752
};
4853

4954
function onUpdateEditorIns(

src/workbench/panel/panel.tsx

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
22
import { getBEMElement, prefixClaName } from 'mo/common/className';
3-
import { IPanel } from 'mo/model/workbench/panel';
3+
import { IPanel, IPanelItem } from 'mo/model/workbench/panel';
44
import { IPanelController } from 'mo/controller/panel';
55
import { Tabs } from 'mo/components/tabs';
66
import { ActionBar } from 'mo/components/actionBar';
@@ -30,13 +30,20 @@ export function Panel(props: IPanel & IPanelController) {
3030
? current?.renderPane?.(current)
3131
: current?.renderPane;
3232

33+
const sortedPanels = data?.sort((a: IPanelItem, b: IPanelItem) => {
34+
if (a.sortIndex && b.sortIndex) {
35+
return a.sortIndex - b.sortIndex;
36+
}
37+
return 1;
38+
});
39+
3340
return (
3441
<div className={defaultClassName}>
3542
<div className={panelHeaderClassName}>
3643
<Scrollable noScrollY isShowShadow>
3744
<Tabs
3845
activeTab={current?.id}
39-
data={data}
46+
data={sortedPanels}
4047
onSelectTab={onTabChange}
4148
onCloseTab={onClose}
4249
/>

0 commit comments

Comments
 (0)