Merge pull request #146 from mathuo/145-remove-suppressclosable

feat: remove suppress closable option
This commit is contained in:
mathuo 2022-07-17 15:31:37 +01:00 committed by GitHub
commit 3533671406
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 6 additions and 126 deletions

View File

@ -144,7 +144,6 @@ class TestGroupPanel implements IDockviewPanel {
private _group: GroupPanel | undefined;
readonly view: IGroupPanelView;
readonly suppressClosable: boolean = false;
readonly api: DockviewPanelApi;
constructor(

View File

@ -41,46 +41,6 @@ describe('dockviewGroupPanel', () => {
disposable.dispose();
});
test('update suppress closable', () => {
const dockviewApiMock = jest.fn<DockviewApi, []>(() => {
return {} as any;
});
const accessorMock = jest.fn<DockviewComponent, []>(() => {
return {} as any;
});
const groupMock = jest.fn<GroupPanel, []>(() => {
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<DockviewApi, []>(() => {
return {} as any;

View File

@ -144,10 +144,6 @@ export class TestPanel implements IDockviewPanel {
return '';
}
get suppressClosable() {
return false;
}
get group() {
return this._group!;
}

View File

@ -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<GridviewPanelApi, 'setVisible'> {
readonly group: GroupPanel;
readonly isGroupActive: boolean;
readonly title: string;
readonly suppressClosable: boolean;
readonly onDidActiveGroupChange: Event<void>;
readonly onDidGroupChange: Event<void>;
readonly onDidSuppressClosableChange: Event<SuppressClosableEvent>;
close(): void;
setTitle(title: string): void;
}
@ -37,11 +31,6 @@ export class DockviewPanelApiImpl
readonly _onDidTitleChange = new Emitter<TitleEvent>();
readonly onDidTitleChange = this._onDidTitleChange.event;
readonly _onDidSuppressClosableChange =
new Emitter<SuppressClosableEvent>();
readonly onDidSuppressClosableChange =
this._onDidSuppressClosableChange.event;
private readonly _onDidActiveGroupChange = new Emitter<void>();
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
);

View File

@ -68,10 +68,6 @@
border-radius: 2px;
background-color: var(--dv-icon-hover-background-color);
}
&.disable-close {
display: none;
}
}
}
}

View File

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

View File

@ -731,7 +731,6 @@ export class DockviewComponent
panel.init({
view,
title: options.title || options.id,
suppressClosable: options?.suppressClosable,
params: options?.params || {},
});

View File

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

View File

@ -76,7 +76,6 @@ export interface PanelOptions {
params?: { [key: string]: any };
id: string;
title?: string;
suppressClosable?: boolean;
}
export interface AddPanelOptions

View File

@ -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<string, any> | 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;
}

View File

@ -14,7 +14,6 @@ export interface IRenderable {
export interface HeaderPartInitParameters {
title: string;
suppressClosable?: boolean;
}
export interface GroupPanelPartInitParameters

View File

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

View File

@ -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 || {},
});

View File

@ -29,7 +29,7 @@ export const DockviewDefaultTab: React.FunctionComponent<IDockviewDefaultTabProp
const iconClassname = React.useMemo(() => {
const cn = ['dockview-react-tab-action'];
return cn.join(',');
}, [api.suppressClosable]);
}, []);
return (
<div {...rest} onClick={onClick} className="dockview-react-tab">