From 9ca535efa7c6e943f196d57654cfc8ceb1154ef3 Mon Sep 17 00:00:00 2001 From: mathuo <6710312+mathuo@users.noreply.github.com> Date: Fri, 15 Jul 2022 19:29:59 +0100 Subject: [PATCH] feat: remove suppress closable option --- .../dockview/dockviewComponent.spec.ts | 1 - .../dockview/dockviewGroupPanel.spec.ts | 40 ------------------- .../src/__tests__/groupview/groupview.spec.ts | 4 -- packages/dockview/src/api/groupPanelApi.ts | 16 -------- .../dockview/components/tab/defaultTab.scss | 4 -- .../src/dockview/components/tab/defaultTab.ts | 12 ++---- .../src/dockview/dockviewComponent.ts | 1 - .../src/dockview/dockviewGroupPanel.ts | 39 ------------------ packages/dockview/src/dockview/options.ts | 1 - packages/dockview/src/groupview/groupPanel.ts | 3 -- packages/dockview/src/groupview/types.ts | 1 - packages/dockview/src/index.ts | 6 +-- packages/dockview/src/react/deserializer.ts | 2 - .../src/react/dockview/defaultTab.tsx | 2 +- 14 files changed, 6 insertions(+), 126 deletions(-) diff --git a/packages/dockview/src/__tests__/dockview/dockviewComponent.spec.ts b/packages/dockview/src/__tests__/dockview/dockviewComponent.spec.ts index 3d26a0c33..5080f5b1a 100644 --- a/packages/dockview/src/__tests__/dockview/dockviewComponent.spec.ts +++ b/packages/dockview/src/__tests__/dockview/dockviewComponent.spec.ts @@ -144,7 +144,6 @@ class TestGroupPanel implements IDockviewPanel { private _group: GroupPanel | undefined; readonly view: IGroupPanelView; - readonly suppressClosable: boolean = false; readonly api: DockviewPanelApi; constructor( diff --git a/packages/dockview/src/__tests__/dockview/dockviewGroupPanel.spec.ts b/packages/dockview/src/__tests__/dockview/dockviewGroupPanel.spec.ts index dd5489046..2c4e3e568 100644 --- a/packages/dockview/src/__tests__/dockview/dockviewGroupPanel.spec.ts +++ b/packages/dockview/src/__tests__/dockview/dockviewGroupPanel.spec.ts @@ -41,46 +41,6 @@ describe('dockviewGroupPanel', () => { disposable.dispose(); }); - test('update suppress closable', () => { - const dockviewApiMock = jest.fn(() => { - return {} as any; - }); - const accessorMock = jest.fn(() => { - return {} as any; - }); - const groupMock = jest.fn(() => { - return {} as any; - }); - const api = new dockviewApiMock(); - const accessor = new accessorMock(); - const group = new groupMock(); - - const cut = new DockviewGroupPanel('fake-id', accessor, api, group); - - let latestSuppressClosable: boolean | undefined = undefined; - - const disposable = cut.api.onDidSuppressClosableChange((event) => { - latestSuppressClosable = event.suppressClosable; - }); - - expect(latestSuppressClosable).toBeFalsy(); - - cut.init({ - title: 'new title', - suppressClosable: true, - params: {}, - view: null, - }); - expect(latestSuppressClosable).toBeTruthy(); - expect(cut.suppressClosable).toBeTruthy(); - - cut.update({ params: { suppressClosable: false } }); - expect(latestSuppressClosable).toBeFalsy(); - expect(cut.suppressClosable).toBeFalsy(); - - disposable.dispose(); - }); - test('dispose cleanup', () => { const dockviewApiMock = jest.fn(() => { return {} as any; diff --git a/packages/dockview/src/__tests__/groupview/groupview.spec.ts b/packages/dockview/src/__tests__/groupview/groupview.spec.ts index c93e4c093..85f29c0a0 100644 --- a/packages/dockview/src/__tests__/groupview/groupview.spec.ts +++ b/packages/dockview/src/__tests__/groupview/groupview.spec.ts @@ -144,10 +144,6 @@ export class TestPanel implements IDockviewPanel { return ''; } - get suppressClosable() { - return false; - } - get group() { return this._group!; } diff --git a/packages/dockview/src/api/groupPanelApi.ts b/packages/dockview/src/api/groupPanelApi.ts index 10a82df6c..33f00de38 100644 --- a/packages/dockview/src/api/groupPanelApi.ts +++ b/packages/dockview/src/api/groupPanelApi.ts @@ -8,10 +8,6 @@ export interface TitleEvent { readonly title: string; } -export interface SuppressClosableEvent { - readonly suppressClosable: boolean; -} - /* * omit visibility modifiers since the visibility of a single group doesn't make sense * because it belongs to a groupview @@ -20,10 +16,8 @@ export interface DockviewPanelApi extends Omit { readonly group: GroupPanel; readonly isGroupActive: boolean; readonly title: string; - readonly suppressClosable: boolean; readonly onDidActiveGroupChange: Event; readonly onDidGroupChange: Event; - readonly onDidSuppressClosableChange: Event; close(): void; setTitle(title: string): void; } @@ -37,11 +31,6 @@ export class DockviewPanelApiImpl readonly _onDidTitleChange = new Emitter(); readonly onDidTitleChange = this._onDidTitleChange.event; - readonly _onDidSuppressClosableChange = - new Emitter(); - readonly onDidSuppressClosableChange = - this._onDidSuppressClosableChange.event; - private readonly _onDidActiveGroupChange = new Emitter(); readonly onDidActiveGroupChange = this._onDidActiveGroupChange.event; @@ -54,10 +43,6 @@ export class DockviewPanelApiImpl return this.panel.title; } - get suppressClosable() { - return !!this.panel.suppressClosable; - } - get isGroupActive() { return !!this.group?.isActive; } @@ -91,7 +76,6 @@ export class DockviewPanelApiImpl this.addDisposables( this.disposable, this._onDidTitleChange, - this._onDidSuppressClosableChange, this._onDidGroupChange, this._onDidActiveGroupChange ); diff --git a/packages/dockview/src/dockview/components/tab/defaultTab.scss b/packages/dockview/src/dockview/components/tab/defaultTab.scss index c84acdb69..65f794f31 100644 --- a/packages/dockview/src/dockview/components/tab/defaultTab.scss +++ b/packages/dockview/src/dockview/components/tab/defaultTab.scss @@ -68,10 +68,6 @@ border-radius: 2px; background-color: var(--dv-icon-hover-background-color); } - - &.disable-close { - display: none; - } } } } diff --git a/packages/dockview/src/dockview/components/tab/defaultTab.ts b/packages/dockview/src/dockview/components/tab/defaultTab.ts index 3d228e216..651b12ea7 100644 --- a/packages/dockview/src/dockview/components/tab/defaultTab.ts +++ b/packages/dockview/src/dockview/components/tab/defaultTab.ts @@ -81,14 +81,10 @@ export class DefaultTab extends CompositeDisposable implements ITabRenderer { this.params = params; this._content.textContent = params.title; - if (!this.params.suppressClosable) { - addDisposableListener(this.action, 'click', (ev) => { - ev.preventDefault(); // - this.params.api.close(); - }); - } else { - this.action.classList.add('disable-close'); - } + addDisposableListener(this.action, 'click', (ev) => { + ev.preventDefault(); // + this.params.api.close(); + }); } public updateParentGroup(group: GroupPanel, isPanelVisible: boolean) { diff --git a/packages/dockview/src/dockview/dockviewComponent.ts b/packages/dockview/src/dockview/dockviewComponent.ts index fa75505d8..1ddfa193a 100644 --- a/packages/dockview/src/dockview/dockviewComponent.ts +++ b/packages/dockview/src/dockview/dockviewComponent.ts @@ -731,7 +731,6 @@ export class DockviewComponent panel.init({ view, title: options.title || options.id, - suppressClosable: options?.suppressClosable, params: options?.params || {}, }); diff --git a/packages/dockview/src/dockview/dockviewGroupPanel.ts b/packages/dockview/src/dockview/dockviewGroupPanel.ts index e52ea2921..9747d4b25 100644 --- a/packages/dockview/src/dockview/dockviewGroupPanel.ts +++ b/packages/dockview/src/dockview/dockviewGroupPanel.ts @@ -25,7 +25,6 @@ export class DockviewGroupPanel private _view?: IGroupPanelView; private _title: string; - private _suppressClosable: boolean; get params() { return this._params; @@ -35,10 +34,6 @@ export class DockviewGroupPanel return this._title; } - get suppressClosable() { - return this._suppressClosable; - } - get group(): GroupPanel { return this._group; } @@ -54,7 +49,6 @@ export class DockviewGroupPanel group: GroupPanel ) { super(); - this._suppressClosable = false; this._title = ''; this._group = group; @@ -72,7 +66,6 @@ export class DockviewGroupPanel this._view = params.view; this.setTitle(params.title); - this.setSuppressClosable(params.suppressClosable || false); this.view?.init({ ...params, @@ -93,7 +86,6 @@ export class DockviewGroupPanel Object.keys(this._params || {}).length > 0 ? this._params : undefined, - suppressClosable: this.suppressClosable || undefined, title: this.title, }; } @@ -108,33 +100,12 @@ export class DockviewGroupPanel params: { params: this._params, title: this.title, - suppressClosable: this.suppressClosable, }, }); this.api._onDidTitleChange.fire({ title }); } } - setSuppressClosable(suppressClosable: boolean) { - const didSuppressChangableClose = - suppressClosable !== this._params?.suppressClosable; - - if (didSuppressChangableClose) { - this._suppressClosable = suppressClosable; - - this.view?.update({ - params: { - params: this._params, - title: this.title, - suppressClosable: this.suppressClosable, - }, - }); - this.api._onDidSuppressClosableChange.fire({ - suppressClosable: !!this.suppressClosable, - }); - } - } - public update(event: GroupPanelUpdateEvent): void { const params = event.params as IGroupPanelInitParameters; @@ -150,20 +121,10 @@ export class DockviewGroupPanel } } - if (typeof params.suppressClosable === 'boolean') { - if (params.suppressClosable !== this._suppressClosable) { - this._suppressClosable = params.suppressClosable; - this.api._onDidSuppressClosableChange.fire({ - suppressClosable: !!this.suppressClosable, - }); - } - } - this.view?.update({ params: { params: this._params, title: this.title, - suppressClosable: this.suppressClosable, }, }); } diff --git a/packages/dockview/src/dockview/options.ts b/packages/dockview/src/dockview/options.ts index ad0652291..08c88c88a 100644 --- a/packages/dockview/src/dockview/options.ts +++ b/packages/dockview/src/dockview/options.ts @@ -76,7 +76,6 @@ export interface PanelOptions { params?: { [key: string]: any }; id: string; title?: string; - suppressClosable?: boolean; } export interface AddPanelOptions diff --git a/packages/dockview/src/groupview/groupPanel.ts b/packages/dockview/src/groupview/groupPanel.ts index 8b99f184e..155c9c2ab 100644 --- a/packages/dockview/src/groupview/groupPanel.ts +++ b/packages/dockview/src/groupview/groupPanel.ts @@ -19,7 +19,6 @@ export interface IGroupPanelInitParameters export type GroupPanelUpdateEvent = PanelUpdateEvent<{ params?: Parameters; title?: string; - suppressClosable?: boolean; }>; export interface IDockviewPanel extends IDisposable, IPanel { @@ -27,7 +26,6 @@ export interface IDockviewPanel extends IDisposable, IPanel { readonly group: GroupPanel; readonly api: DockviewPanelApi; readonly title: string; - readonly suppressClosable: boolean; readonly params: Record | undefined; updateParentGroup(group: GroupPanel, isGroupActive: boolean): void; init(params: IGroupPanelInitParameters): void; @@ -40,5 +38,4 @@ export interface GroupviewPanelState { view?: any; title: string; params?: { [key: string]: any }; - suppressClosable?: boolean; } diff --git a/packages/dockview/src/groupview/types.ts b/packages/dockview/src/groupview/types.ts index e0241c0ba..c7cc7b4f2 100644 --- a/packages/dockview/src/groupview/types.ts +++ b/packages/dockview/src/groupview/types.ts @@ -14,7 +14,6 @@ export interface IRenderable { export interface HeaderPartInitParameters { title: string; - suppressClosable?: boolean; } export interface GroupPanelPartInitParameters diff --git a/packages/dockview/src/index.ts b/packages/dockview/src/index.ts index 1e57c384f..8177eb720 100644 --- a/packages/dockview/src/index.ts +++ b/packages/dockview/src/index.ts @@ -40,11 +40,7 @@ export { GridviewPanelApi, GridConstraintChangeEvent, } from './api/gridviewPanelApi'; -export { - TitleEvent, - SuppressClosableEvent, - DockviewPanelApi, -} from './api/groupPanelApi'; +export { TitleEvent, DockviewPanelApi } from './api/groupPanelApi'; export { PanelSizeEvent, PanelConstraintChangeEvent, diff --git a/packages/dockview/src/react/deserializer.ts b/packages/dockview/src/react/deserializer.ts index 68bbe2978..0810afdf3 100644 --- a/packages/dockview/src/react/deserializer.ts +++ b/packages/dockview/src/react/deserializer.ts @@ -19,7 +19,6 @@ export class ReactPanelDeserialzier implements IPanelDeserializer { const panelId = panelData.id; const params = panelData.params; const title = panelData.title; - const suppressClosable = panelData.suppressClosable; const viewData = panelData.view; let tab: ITabRenderer; @@ -67,7 +66,6 @@ export class ReactPanelDeserialzier implements IPanelDeserializer { panel.init({ view, title, - suppressClosable, params: params || {}, }); diff --git a/packages/dockview/src/react/dockview/defaultTab.tsx b/packages/dockview/src/react/dockview/defaultTab.tsx index e42af684e..9a35feea0 100644 --- a/packages/dockview/src/react/dockview/defaultTab.tsx +++ b/packages/dockview/src/react/dockview/defaultTab.tsx @@ -29,7 +29,7 @@ export const DockviewDefaultTab: React.FunctionComponent { const cn = ['dockview-react-tab-action']; return cn.join(','); - }, [api.suppressClosable]); + }, []); return (