diff --git a/src/sql/parts/dashboard/common/actions.ts b/src/sql/parts/dashboard/common/actions.ts index 5d42553547..8ca2a224db 100644 --- a/src/sql/parts/dashboard/common/actions.ts +++ b/src/sql/parts/dashboard/common/actions.ts @@ -210,7 +210,6 @@ export class CollapseWidgetAction extends Action { private _uri: string, private _widgetUuid: string, private collpasedState: boolean, - private collapsedStateChangedEvent: Event, @IAngularEventingService private _angularEventService: IAngularEventingService ) { super( @@ -218,7 +217,6 @@ export class CollapseWidgetAction extends Action { collpasedState ? CollapseWidgetAction.EXPAND_LABEL : CollapseWidgetAction.COLLPASE_LABEL, collpasedState ? CollapseWidgetAction.EXPAND_ICON : CollapseWidgetAction.COLLAPSE_ICON ); - this.collapsedStateChangedEvent(collapsed => this._updateState(collapsed)); } run(): TPromise { @@ -232,8 +230,15 @@ export class CollapseWidgetAction extends Action { } private _updateState(collapsed: boolean): void { + if (collapsed === this.collpasedState) { + return; + } this.collpasedState = collapsed; this._setClass(this.collpasedState ? CollapseWidgetAction.EXPAND_ICON : CollapseWidgetAction.COLLAPSE_ICON); this._setLabel(this.collpasedState ? CollapseWidgetAction.EXPAND_LABEL : CollapseWidgetAction.COLLPASE_LABEL); } + + public set state(collapsed: boolean) { + this._updateState(collapsed); + } } diff --git a/src/sql/parts/dashboard/contents/dashboardWidgetWrapper.component.ts b/src/sql/parts/dashboard/contents/dashboardWidgetWrapper.component.ts index 4bfb335633..395fbbdef6 100644 --- a/src/sql/parts/dashboard/contents/dashboardWidgetWrapper.component.ts +++ b/src/sql/parts/dashboard/contents/dashboardWidgetWrapper.component.ts @@ -53,6 +53,7 @@ export class DashboardWidgetWrapper extends AngularDisposable implements OnInit @Input() private _config: WidgetConfig; @Input() private collapsable = false; + private _collapseAction: CollapseWidgetAction; private _collapsed = false; public get collapsed(): boolean { @@ -64,17 +65,13 @@ export class DashboardWidgetWrapper extends AngularDisposable implements OnInit return; } this._collapsed = val; - if (this.collapsedStateChangedEmitter) { - this.collapsedStateChangedEmitter.fire(this._collapsed); - } + this._collapseAction.state = val; this._changeref.detectChanges(); if (!val) { this.loadWidget(); } } - private collapsedStateChangedEmitter: Emitter; - @memoize public get guid(): string { return generateUuid(); @@ -114,8 +111,8 @@ export class DashboardWidgetWrapper extends AngularDisposable implements OnInit this._actionbar = new ActionBar(this._actionbarRef.nativeElement); if (this._actions) { if (this.collapsable) { - this.collapsedStateChangedEmitter = new Emitter(); - this._actionbar.push(this._bootstrap.instantiationService.createInstance(CollapseWidgetAction, this._bootstrap.getUnderlyingUri(), this.guid, this.collapsed, this.collapsedStateChangedEmitter.event), { icon: true, label: false }); + this._collapseAction = this._bootstrap.instantiationService.createInstance(CollapseWidgetAction, this._bootstrap.getUnderlyingUri(), this.guid, this.collapsed); + this._actionbar.push(this._collapseAction, { icon: true, label: false }); } this._actionbar.push(this._bootstrap.instantiationService.createInstance(ToggleMoreWidgetAction, this._actions, this._component.actionsContext), { icon: true, label: false }); } @@ -123,13 +120,13 @@ export class DashboardWidgetWrapper extends AngularDisposable implements OnInit } public refresh(): void { - if (this._component && this._component.refresh) { + if (!this.collapsed && this._component && this._component.refresh) { this._component.refresh(); } } public layout(): void { - if (this._component && this._component.layout) { + if (!this.collapsed && this._component && this._component.layout) { this._component.layout(); } } @@ -170,7 +167,7 @@ export class DashboardWidgetWrapper extends AngularDisposable implements OnInit this._component = componentRef.instance; let actions = componentRef.instance.actions; if (componentRef.instance.refresh) { - actions.push(new RefreshWidgetAction(componentRef.instance.refresh, componentRef.instance)); + actions.push(new RefreshWidgetAction(this.refresh, this)); } if (actions !== undefined && actions.length > 0) { this._actions = actions;