From 3af8fb18a57bd24393d0b8e9153874997c295d69 Mon Sep 17 00:00:00 2001 From: Filippo Ledda Date: Tue, 29 Aug 2023 14:43:51 +0200 Subject: [PATCH] GEP-21 GEP-23 fix minimize and maximize actions --- .../src/common/layout/LayoutManager.tsx | 60 +++++-------------- .../common/layout/helpers/MinimizeHelper.tsx | 11 +++- 2 files changed, 22 insertions(+), 49 deletions(-) diff --git a/geppetto.js/geppetto-client/src/common/layout/LayoutManager.tsx b/geppetto.js/geppetto-client/src/common/layout/LayoutManager.tsx index 05bdf70f9..e866b3ce1 100644 --- a/geppetto.js/geppetto-client/src/common/layout/LayoutManager.tsx +++ b/geppetto.js/geppetto-client/src/common/layout/LayoutManager.tsx @@ -284,8 +284,10 @@ class LayoutManager { break; } case layoutActions.UPDATE_WIDGET: { + let updatedWidget = this.updateWidget(action.data); action = { ...action, data: updatedWidget }; + break; } case layoutActions.DESTROY_WIDGET: { @@ -303,6 +305,7 @@ class LayoutManager { this.updateWidget(widget); break; } + case layoutActions.SET_WIDGETS: { const newWidgets: Map = action.data; for (let widget of this.getWidgets()) { @@ -473,51 +476,6 @@ class LayoutManager { } } - /** - * Return the id of a tabset based on passed action. - * - * @param action - * @private - */ - private getTabsetId(action) { - const widgetId = action.data.fromNode; - return this.model - .getNodeById(widgetId) - .getParent() - .getId(); - } - - /** - * Find a maximized widget. - * - * @private - */ - private findMaximizedWidget() { - return this.getWidgets().find( - (widget) => widget && widget.status == WidgetStatus.MAXIMIZED - ); - } - - - /** - * Update maximized widget based on action. - * - * @param action - * @private - */ - private updateMaximizedWidget(action) { - const { model } = this; - const maximizedWidget = this.findMaximizedWidget(); - // check if the current maximized widget is the same than in the action dispatched - if (maximizedWidget && maximizedWidget.id == action.data.node) { - // find if there exists another widget in the maximized panel that could take its place - const panelChildren = model.getActiveTabset().getChildren(); - const index = panelChildren.findIndex( - (child) => child.getId() == action.data.node - ); - } - } - /** * Update a widget. * @@ -536,10 +494,20 @@ class LayoutManager { this.widgetFactory.updateWidget(mergedWidget); - if (this.model.getNodeById(widget.id)) { + const node = this.model.getNodeById(widget.id); + + + if (node) { model.doAction(Actions.updateNodeAttributes(mergedWidget.id, widget2Node(mergedWidget))); if (mergedWidget.status == WidgetStatus.ACTIVE) { model.doAction(FlexLayout.Actions.selectTab(mergedWidget.id)); + } + if((widget.status == WidgetStatus.MAXIMIZED && !node.getParent().isMaximized()) || + (widget.status == WidgetStatus.ACTIVE && node.getParent().isMaximized())) { + this.model.doAction(FlexLayout.Actions.maximizeToggle(node.getParent().getId())); + } + else if(widget.status == WidgetStatus.MINIMIZED && !this.minimizeHelper.isMinimized(widget)) { + this.minimizeHelper.minimizeWidget(node.getId()); } } diff --git a/geppetto.js/geppetto-client/src/common/layout/helpers/MinimizeHelper.tsx b/geppetto.js/geppetto-client/src/common/layout/helpers/MinimizeHelper.tsx index 110b3d213..075f99f55 100644 --- a/geppetto.js/geppetto-client/src/common/layout/helpers/MinimizeHelper.tsx +++ b/geppetto.js/geppetto-client/src/common/layout/helpers/MinimizeHelper.tsx @@ -28,13 +28,17 @@ export class MinimizeHelper { this.store = store; } + isMinimized(widget: Widget): boolean { + return widget.panelName == this.minimizeBorderID; + } + addMinimizeButtonToTabset(panel, renderValues) { if (this.isMinimizeEnabled && this.minimizeBorderID) { if (panel.getChildren().length > 0) { renderValues.buttons.push(
{ this.minimizeWidget(panel.getSelectedNode().getId()); }} @@ -51,13 +55,14 @@ export class MinimizeHelper { * @private */ minimizeWidget(widgetId) { - if(this.store && this.minimizeBorderID){ + if(this.store && this.minimizeBorderID) { + let updatedWidget = { ...getWidget(this.store, widgetId) }; updatedWidget.status = WidgetStatus.MINIMIZED; updatedWidget.defaultPanel = updatedWidget.panelName; updatedWidget.panelName = this.minimizeBorderID; this.store.dispatch(updateWidget(updatedWidget)) - }else{ + } else{ console.warn("Unable to minimize widget"); } }