From c4ab6ac56219566e341f48d1f42d14d051bee725 Mon Sep 17 00:00:00 2001 From: mathuo <6710312+mathuo@users.noreply.github.com> Date: Mon, 13 May 2024 20:50:05 +0100 Subject: [PATCH] chore: sonarcloud requests --- .../dockview-core/src/api/dockviewPanelApi.ts | 15 +++++------ .../dockview-core/src/dnd/dataTransfer.ts | 6 ++++- .../src/dockview/dockviewComponent.ts | 25 ++++++++----------- .../src/dockview/dockviewGroupPanelModel.ts | 2 +- packages/dockview/src/dockview/dockview.tsx | 17 ++++++------- 5 files changed, 32 insertions(+), 33 deletions(-) diff --git a/packages/dockview-core/src/api/dockviewPanelApi.ts b/packages/dockview-core/src/api/dockviewPanelApi.ts index 25d9d59e8..e640bc716 100644 --- a/packages/dockview-core/src/api/dockviewPanelApi.ts +++ b/packages/dockview-core/src/api/dockviewPanelApi.ts @@ -204,13 +204,14 @@ export class DockviewPanelApiImpl this.groupEventsDisposable.value = new CompositeDisposable( this.group.api.onDidVisibilityChange((event) => { - if (!event.isVisible && this.isVisible) { - this._onDidVisibilityChange.fire(event); - } else if ( - event.isVisible && - !this.isVisible && - this.group.model.isPanelActive(this.panel) - ) { + const hasBecomeHidden = !event.isVisible && this.isVisible; + const hasBecomeVisible = event.isVisible && !this.isVisible; + + const isActivePanel = this.group.model.isPanelActive( + this.panel + ); + + if (hasBecomeHidden || (hasBecomeVisible && isActivePanel)) { this._onDidVisibilityChange.fire(event); } }), diff --git a/packages/dockview-core/src/dnd/dataTransfer.ts b/packages/dockview-core/src/dnd/dataTransfer.ts index efb3d4347..150b60cbc 100644 --- a/packages/dockview-core/src/dnd/dataTransfer.ts +++ b/packages/dockview-core/src/dnd/dataTransfer.ts @@ -1,4 +1,8 @@ -class TransferObject {} +class TransferObject { + constructor() { + // intentionally empty class + } +} export class PanelTransfer extends TransferObject { constructor( diff --git a/packages/dockview-core/src/dockview/dockviewComponent.ts b/packages/dockview-core/src/dockview/dockviewComponent.ts index 34670cd7a..c4e71f34f 100644 --- a/packages/dockview-core/src/dockview/dockviewComponent.ts +++ b/packages/dockview-core/src/dockview/dockviewComponent.ts @@ -652,7 +652,7 @@ export class DockviewComponent const box: Box = getBox(); const groupId = - options?.overridePopoutGroup?.id ?? this.getNextGroupId(); //item.id; + options?.overridePopoutGroup?.id ?? this.getNextGroupId(); if (itemToPopout.api.location.type === 'grid') { itemToPopout.api.setVisible(false); @@ -811,17 +811,15 @@ export class DockviewComponent skipPopoutAssociated: true, }); } - } else { - if (this.getPanel(group.id)) { - const removedGroup = this.doRemoveGroup(group, { - skipDispose: true, - skipActive: true, - }); - removedGroup.model.renderContainer = - this.overlayRenderContainer; - removedGroup.model.location = { type: 'grid' }; - returnedGroup = removedGroup; - } + } else if (this.getPanel(group.id)) { + const removedGroup = this.doRemoveGroup(group, { + skipDispose: true, + skipActive: true, + }); + removedGroup.model.renderContainer = + this.overlayRenderContainer; + removedGroup.model.location = { type: 'grid' }; + returnedGroup = removedGroup; } }) ); @@ -894,7 +892,7 @@ export class DockviewComponent this.doRemoveGroup(item, { skipDispose: true, skipPopoutReturn: true, - skipPopoutAssociated: !!popoutReferenceGroup, + skipPopoutAssociated: false, }); } } @@ -1372,7 +1370,6 @@ export class DockviewComponent const groups = Array.from(this._groups.values()).map((_) => _.value); const hasActiveGroup = !!this.activeGroup; - const hasActivePanel = !!this.activePanel; for (const group of groups) { // remove the group will automatically remove the panels diff --git a/packages/dockview-core/src/dockview/dockviewGroupPanelModel.ts b/packages/dockview-core/src/dockview/dockviewGroupPanelModel.ts index 10d09ad5f..6f573fb74 100644 --- a/packages/dockview-core/src/dockview/dockviewGroupPanelModel.ts +++ b/packages/dockview-core/src/dockview/dockviewGroupPanelModel.ts @@ -993,7 +993,7 @@ export class DockviewGroupPanelModel target, position, getPanelData, - this.accessor.getPanel(this.id)! + this.accessor.getPanel(this.id) ); this._onUnhandledDragOverEvent.fire(firedEvent); diff --git a/packages/dockview/src/dockview/dockview.tsx b/packages/dockview/src/dockview/dockview.tsx index bf14b7f4e..5b7f196d9 100644 --- a/packages/dockview/src/dockview/dockview.tsx +++ b/packages/dockview/src/dockview/dockview.tsx @@ -63,15 +63,12 @@ export interface IDockviewReactProps extends DockviewOptions { } function extractCoreOptions(props: IDockviewReactProps): DockviewOptions { - const coreOptions = (PROPERTY_KEYS as (keyof DockviewOptions)[]).reduce( - (obj, key) => { - if (key in props) { - obj[key] = props[key] as any; - } - return obj; - }, - {} as Partial - ); + const coreOptions = PROPERTY_KEYS.reduce((obj, key) => { + if (key in props) { + obj[key] = props[key] as any; + } + return obj; + }, {} as Partial); return coreOptions as DockviewOptions; } @@ -91,7 +88,7 @@ export const DockviewReact = React.forwardRef( const changes: Partial = {}; PROPERTY_KEYS.forEach((propKey) => { - const key = propKey as keyof DockviewOptions; + const key = propKey; const propValue = props[key]; if (key in props && propValue !== prevProps.current[key]) {