feat: error in duplicate id

This commit is contained in:
mathuo 2022-04-23 17:26:41 +01:00
parent 9c75701182
commit 2f8abd0e11
No known key found for this signature in database
GPG Key ID: C6EEDEFD6CA07281
2 changed files with 22 additions and 2 deletions

View File

@ -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);

View File

@ -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),