Skip to content

Commit f8eddab

Browse files
authored
fix: can't add the new panel when open it (#390)
1 parent 1b250be commit f8eddab

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

src/services/__tests__/panelService.test.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,13 @@ describe('The PanelService test', () => {
165165

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

170-
panelService.open(paneOutput);
171-
expect(state.current).toEqual(paneOutput);
172+
panelService.open(newPanel);
173+
expect(state.current).toEqual(newPanel);
174+
expect(panelService.getPanel(newPanel.id)).not.toBeUndefined();
172175
});
173176

174177
test('Should support to toggle maximize status', () => {

src/services/workbench/panelService.ts

+8-3
Original file line numberDiff line numberDiff line change
@@ -163,9 +163,14 @@ export class PanelService extends Component<IPanel> implements IPanelService {
163163

164164
public open(data: IPanelItem<any>): void {
165165
const { data: stateData = [] } = this.state;
166-
const cloneData = cloneDeep(data);
167-
const index = stateData.findIndex(searchById(cloneData.id));
168-
const current = index === -1 ? cloneData : stateData[index];
166+
let current = cloneDeep(data);
167+
const index = stateData.findIndex(searchById(current.id));
168+
if (index > -1) {
169+
current = stateData[index];
170+
} else {
171+
// Add the new panel item
172+
this.add(current);
173+
}
169174

170175
this.setState({
171176
current,

0 commit comments

Comments
 (0)