Merge pull request #70 from mathuo/69-dockview-error-on-duplicate-panel-id

feat: error in duplicate id
This commit is contained in:
mathuo 2022-04-23 22:56:16 +01:00 committed by GitHub
commit ec7116fbf1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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),