Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/services/__tests__/panelService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,10 +165,13 @@ describe('The PanelService test', () => {

test("Should support to open a panel that doesn't exist", () => {
const state = panelService.getState();
const newPanel = Object.assign({}, paneOutput, { id: 'test' });
expect(state.current).toBeNull();
expect(panelService.getPanel(newPanel.id)).toBeUndefined();

panelService.open(paneOutput);
expect(state.current).toEqual(paneOutput);
panelService.open(newPanel);
expect(state.current).toEqual(newPanel);
expect(panelService.getPanel(newPanel.id)).not.toBeUndefined();
});

test('Should support to toggle maximize status', () => {
Expand Down
11 changes: 8 additions & 3 deletions src/services/workbench/panelService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,14 @@ export class PanelService extends Component<IPanel> implements IPanelService {

public open(data: IPanelItem<any>): void {
const { data: stateData = [] } = this.state;
const cloneData = cloneDeep(data);
const index = stateData.findIndex(searchById(cloneData.id));
const current = index === -1 ? cloneData : stateData[index];
let current = cloneDeep(data);
const index = stateData.findIndex(searchById(current.id));
if (index > -1) {
current = stateData[index];
} else {
// Add the new panel item
this.add(current);
}

this.setState({
current,
Expand Down