Skip to content

Commit

Permalink
GEP-21 GEP-23 fix minimize and maximize actions
Browse files Browse the repository at this point in the history
  • Loading branch information
filippomc committed Aug 29, 2023
1 parent 6bb82d1 commit 3af8fb1
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 49 deletions.
60 changes: 14 additions & 46 deletions geppetto.js/geppetto-client/src/common/layout/LayoutManager.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand All @@ -303,6 +305,7 @@ class LayoutManager {
this.updateWidget(widget);
break;
}

case layoutActions.SET_WIDGETS: {
const newWidgets: Map<string, Widget> = action.data;
for (let widget of this.getWidgets()) {
Expand Down Expand Up @@ -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.
*
Expand All @@ -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());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
<div
key={panel.getId()}
className="fa fa-window-minimize customIconFlexLayout"
className="fa fa-window-minimize customIconFlexLayout minimizeButton"
onClick={() => {
this.minimizeWidget(panel.getSelectedNode().getId());
}}
Expand All @@ -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");
}
}
Expand Down

0 comments on commit 3af8fb1

Please sign in to comment.