diff --git a/packages/dockview/src/__tests__/dockview/dockviewComponent.spec.ts b/packages/dockview/src/__tests__/dockview/dockviewComponent.spec.ts index c982a8bc9..652f73e85 100644 --- a/packages/dockview/src/__tests__/dockview/dockviewComponent.spec.ts +++ b/packages/dockview/src/__tests__/dockview/dockviewComponent.spec.ts @@ -167,6 +167,22 @@ describe('dockviewComponent', () => { }); }); + test('duplicate panel', () => { + dockview.layout(500, 1000); + + dockview.addPanel({ + id: 'panel1', + component: 'default', + }); + + expect(() => { + dockview.addPanel({ + id: 'panel1', + component: 'default', + }); + }).toThrowError('panel with id panel1 already exists'); + }); + test('set active panel', () => { dockview.layout(500, 1000); diff --git a/packages/dockview/src/dockview/dockviewComponent.ts b/packages/dockview/src/dockview/dockviewComponent.ts index 5c1532ae2..9925de735 100644 --- a/packages/dockview/src/dockview/dockviewComponent.ts +++ b/packages/dockview/src/dockview/dockviewComponent.ts @@ -407,7 +407,11 @@ export class DockviewComponent } addPanel(options: AddPanelOptions): IGroupPanel { - const panel = this._addPanel(options); + if (this.panels.find((_) => _.id === options.id)) { + throw new Error(`panel with id ${options.id} already exists`); + } + + const panel = this.createPanel(options); let referenceGroup: GroupviewPanel | undefined; @@ -693,7 +697,7 @@ export class DockviewComponent return view; } - private _addPanel(options: AddPanelOptions): IGroupPanel { + private createPanel(options: AddPanelOptions): IGroupPanel { const view = new DefaultGroupPanelView({ content: this.createContentComponent(options.id, options.component), tab: this.createTabComponent(options.id, options.tabComponent),