Skip to content

Commit

Permalink
feat: support set the sorting of the panel (#351)
Browse files Browse the repository at this point in the history
  • Loading branch information
wewoor authored Aug 21, 2021
1 parent d2913e9 commit 95470fe
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/model/problems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export function builtInPanelProblems(): IPanelItem {
id: PANEL_PROBLEMS,
name: localize(PANEL_PROBLEMS, 'problems'),
data: null,
sortIndex: 1,
};
}

Expand Down
5 changes: 5 additions & 0 deletions src/model/workbench/panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export interface IPanelItem<T = any> extends ITabProps<T> {
title?: string;
toolbox?: IActionBarItemProps[];
data?: T;
/**
* The sort of panel item
*/
sortIndex?: number;
}

export enum PanelEvent {
Expand Down Expand Up @@ -44,6 +48,7 @@ export function builtInOutputPanel() {
id: PANEL_OUTPUT,
name: localize(PANEL_OUTPUT, 'output'),
data: '',
sortIndex: 2,
};

function onUpdateEditorIns(
Expand Down
11 changes: 9 additions & 2 deletions src/workbench/panel/panel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from 'react';
import { getBEMElement, prefixClaName } from 'mo/common/className';
import { IPanel } from 'mo/model/workbench/panel';
import { IPanel, IPanelItem } from 'mo/model/workbench/panel';
import { IPanelController } from 'mo/controller/panel';
import { Tabs } from 'mo/components/tabs';
import { ActionBar } from 'mo/components/actionBar';
Expand Down Expand Up @@ -30,13 +30,20 @@ export function Panel(props: IPanel & IPanelController) {
? current?.renderPane?.(current)
: current?.renderPane;

const sortedPanels = data?.sort((a: IPanelItem, b: IPanelItem) => {
if (a.sortIndex && b.sortIndex) {
return a.sortIndex - b.sortIndex;
}
return 1;
});

return (
<div className={defaultClassName}>
<div className={panelHeaderClassName}>
<Scrollable noScrollY isShowShadow>
<Tabs
activeTab={current?.id}
data={data}
data={sortedPanels}
onSelectTab={onTabChange}
onCloseTab={onClose}
/>
Expand Down

0 comments on commit 95470fe

Please sign in to comment.