2023-03-04 07:25:54 +00:00
|
|
|
import { updateAndSaveLayout } from "actions/pageActions";
|
2023-04-26 07:18:16 +00:00
|
|
|
import type { ReduxAction } from "@appsmith/constants/ReduxActionConstants";
|
2023-03-04 07:25:54 +00:00
|
|
|
import {
|
|
|
|
|
ReduxActionErrorTypes,
|
|
|
|
|
ReduxActionTypes,
|
2023-04-26 07:18:16 +00:00
|
|
|
} from "@appsmith/constants/ReduxActionConstants";
|
2023-03-04 07:25:54 +00:00
|
|
|
import log from "loglevel";
|
2023-05-11 04:45:14 +00:00
|
|
|
import type {
|
|
|
|
|
CanvasWidgetsReduxState,
|
|
|
|
|
UpdateWidgetsPayload,
|
|
|
|
|
} from "reducers/entityReducers/canvasWidgetsReducer";
|
2023-04-07 13:51:35 +00:00
|
|
|
import {
|
|
|
|
|
all,
|
|
|
|
|
call,
|
|
|
|
|
debounce,
|
|
|
|
|
put,
|
|
|
|
|
select,
|
|
|
|
|
takeLatest,
|
|
|
|
|
} from "redux-saga/effects";
|
2023-03-04 07:25:54 +00:00
|
|
|
import {
|
|
|
|
|
alterLayoutForDesktop,
|
|
|
|
|
alterLayoutForMobile,
|
2023-04-07 13:51:35 +00:00
|
|
|
getCanvasDimensions,
|
2023-09-11 15:55:11 +00:00
|
|
|
} from "layoutSystems/autolayout/utils/AutoLayoutUtils";
|
2023-05-11 04:45:14 +00:00
|
|
|
import {
|
|
|
|
|
getCanvasAndMetaWidgets,
|
|
|
|
|
getWidgets,
|
|
|
|
|
getWidgetsMeta,
|
|
|
|
|
} from "./selectors";
|
2023-10-04 08:54:16 +00:00
|
|
|
import { LayoutSystemTypes } from "layoutSystems/types";
|
2023-04-07 13:51:35 +00:00
|
|
|
import {
|
|
|
|
|
GridDefaults,
|
|
|
|
|
MAIN_CONTAINER_WIDGET_ID,
|
|
|
|
|
} from "constants/WidgetConstants";
|
|
|
|
|
import {
|
|
|
|
|
getCurrentApplicationId,
|
|
|
|
|
getIsAutoLayout,
|
|
|
|
|
getIsAutoLayoutMobileBreakPoint,
|
|
|
|
|
getMainCanvasProps,
|
|
|
|
|
} from "selectors/editorSelectors";
|
|
|
|
|
import type { MainCanvasReduxState } from "reducers/uiReducers/mainCanvasReducer";
|
|
|
|
|
import { updateLayoutForMobileBreakpointAction } from "actions/autoLayoutActions";
|
|
|
|
|
import convertDSLtoAuto from "utils/DSLConversions/fixedToAutoLayout";
|
|
|
|
|
import { convertNormalizedDSLToFixed } from "utils/DSLConversions/autoToFixedLayout";
|
2023-09-11 15:55:11 +00:00
|
|
|
import { updateWidgetPositions } from "layoutSystems/autolayout/utils/positionUtils";
|
2023-04-07 13:51:35 +00:00
|
|
|
import { getCanvasWidth as getMainCanvasWidth } from "selectors/editorSelectors";
|
|
|
|
|
import {
|
|
|
|
|
getLeftColumn,
|
|
|
|
|
getTopRow,
|
|
|
|
|
getWidgetMinMaxDimensionsInPixel,
|
|
|
|
|
setBottomRow,
|
|
|
|
|
setRightColumn,
|
2023-09-11 15:55:11 +00:00
|
|
|
} from "layoutSystems/autolayout/utils/flexWidgetUtils";
|
2023-05-11 04:45:14 +00:00
|
|
|
import {
|
|
|
|
|
updateMultipleMetaWidgetPropertiesAction,
|
|
|
|
|
updateMultipleWidgetPropertiesAction,
|
|
|
|
|
} from "actions/controlActions";
|
2023-04-07 13:51:35 +00:00
|
|
|
import { isEmpty } from "lodash";
|
|
|
|
|
import { mutation_setPropertiesToUpdate } from "./autoHeightSagas/helpers";
|
|
|
|
|
import { updateApplication } from "@appsmith/actions/applicationActions";
|
|
|
|
|
import { getIsCurrentlyConvertingLayout } from "selectors/autoLayoutSelectors";
|
|
|
|
|
import { getIsResizing } from "selectors/widgetSelectors";
|
|
|
|
|
import { generateAutoHeightLayoutTreeAction } from "actions/autoHeightActions";
|
2023-04-26 07:18:16 +00:00
|
|
|
import type { AppState } from "@appsmith/reducers";
|
2023-06-26 06:55:55 +00:00
|
|
|
import { nestDSL, flattenDSL } from "@shared/dsl";
|
2023-10-04 08:54:16 +00:00
|
|
|
import { getLayoutSystemType } from "selectors/layoutSystemSelectors";
|
2023-03-04 07:25:54 +00:00
|
|
|
|
2023-05-11 04:45:14 +00:00
|
|
|
function* shouldRunSaga(saga: any, action: ReduxAction<unknown>) {
|
|
|
|
|
const isAutoLayout: boolean = yield select(getIsAutoLayout);
|
|
|
|
|
if (isAutoLayout) {
|
|
|
|
|
yield call(saga, action);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-04 07:25:54 +00:00
|
|
|
export function* updateLayoutForMobileCheckpoint(
|
|
|
|
|
actionPayload: ReduxAction<{
|
|
|
|
|
parentId: string;
|
|
|
|
|
isMobile: boolean;
|
|
|
|
|
canvasWidth: number;
|
2023-04-07 13:51:35 +00:00
|
|
|
widgets?: CanvasWidgetsReduxState;
|
2023-03-04 07:25:54 +00:00
|
|
|
}>,
|
|
|
|
|
) {
|
|
|
|
|
try {
|
|
|
|
|
const start = performance.now();
|
2023-04-07 13:51:35 +00:00
|
|
|
const isAutoLayout: boolean = yield select(getIsAutoLayout);
|
|
|
|
|
if (!isAutoLayout) return;
|
|
|
|
|
//Do not recalculate columns and update layout while converting layout
|
|
|
|
|
const isCurrentlyConvertingLayout: boolean = yield select(
|
|
|
|
|
getIsCurrentlyConvertingLayout,
|
|
|
|
|
);
|
|
|
|
|
if (isCurrentlyConvertingLayout) return;
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
canvasWidth,
|
|
|
|
|
isMobile,
|
|
|
|
|
parentId,
|
|
|
|
|
widgets: payloadWidgets,
|
|
|
|
|
} = actionPayload.payload;
|
|
|
|
|
|
|
|
|
|
let allWidgets: CanvasWidgetsReduxState;
|
|
|
|
|
|
|
|
|
|
if (payloadWidgets) {
|
|
|
|
|
allWidgets = payloadWidgets;
|
|
|
|
|
} else {
|
|
|
|
|
allWidgets = yield select(getWidgets);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-11 04:45:14 +00:00
|
|
|
const metaProps: Record<string, any> = yield select(getWidgetsMeta);
|
2023-03-04 07:25:54 +00:00
|
|
|
const updatedWidgets: CanvasWidgetsReduxState = isMobile
|
2023-05-11 04:45:14 +00:00
|
|
|
? alterLayoutForMobile(
|
|
|
|
|
allWidgets,
|
|
|
|
|
parentId,
|
|
|
|
|
canvasWidth,
|
|
|
|
|
canvasWidth,
|
|
|
|
|
false,
|
|
|
|
|
metaProps,
|
|
|
|
|
)
|
|
|
|
|
: alterLayoutForDesktop(
|
|
|
|
|
allWidgets,
|
|
|
|
|
parentId,
|
|
|
|
|
canvasWidth,
|
|
|
|
|
false,
|
|
|
|
|
metaProps,
|
|
|
|
|
);
|
2023-03-04 07:25:54 +00:00
|
|
|
yield put(updateAndSaveLayout(updatedWidgets));
|
2023-04-07 13:51:35 +00:00
|
|
|
yield put(generateAutoHeightLayoutTreeAction(true, true));
|
2023-03-04 07:25:54 +00:00
|
|
|
log.debug(
|
2023-06-09 08:52:27 +00:00
|
|
|
"Auto-layout : updating layout for mobile viewport took",
|
2023-03-04 07:25:54 +00:00
|
|
|
performance.now() - start,
|
|
|
|
|
"ms",
|
|
|
|
|
);
|
|
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionErrorTypes.WIDGET_OPERATION_ERROR,
|
|
|
|
|
payload: {
|
|
|
|
|
action: ReduxActionTypes.RECALCULATE_COLUMNS,
|
|
|
|
|
error,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-07 13:51:35 +00:00
|
|
|
/**
|
|
|
|
|
* This Method is called when fixed and Auto are switched between each other using the Switch button on the right Pane
|
|
|
|
|
* @param actionPayload
|
|
|
|
|
* @returns
|
|
|
|
|
*/
|
2023-10-04 08:54:16 +00:00
|
|
|
export function* updateLayoutSystemTypeSaga(
|
|
|
|
|
actionPayload: ReduxAction<LayoutSystemTypes>,
|
2023-04-07 13:51:35 +00:00
|
|
|
) {
|
|
|
|
|
try {
|
2023-10-04 08:54:16 +00:00
|
|
|
const currLayoutSystemType: LayoutSystemTypes = yield select(
|
|
|
|
|
getLayoutSystemType,
|
2023-04-07 13:51:35 +00:00
|
|
|
);
|
2023-10-04 08:54:16 +00:00
|
|
|
const payloadLayoutSystemType = actionPayload.payload;
|
2023-04-07 13:51:35 +00:00
|
|
|
|
2023-10-04 08:54:16 +00:00
|
|
|
if (currLayoutSystemType === payloadLayoutSystemType) return;
|
2023-04-07 13:51:35 +00:00
|
|
|
|
|
|
|
|
const allWidgets: CanvasWidgetsReduxState = yield select(getWidgets);
|
|
|
|
|
|
2023-06-09 08:52:27 +00:00
|
|
|
//Convert fixed layout to auto-layout
|
2023-10-04 08:54:16 +00:00
|
|
|
if (payloadLayoutSystemType === LayoutSystemTypes.AUTO) {
|
2023-06-26 06:55:55 +00:00
|
|
|
const nestedDSL = nestDSL(allWidgets);
|
2023-04-07 13:51:35 +00:00
|
|
|
|
2023-06-26 06:55:55 +00:00
|
|
|
const autoDSL = convertDSLtoAuto(nestedDSL);
|
2023-04-07 13:51:35 +00:00
|
|
|
log.debug("autoDSL", autoDSL);
|
|
|
|
|
|
2023-06-26 06:55:55 +00:00
|
|
|
const flattenedDSL = flattenDSL(autoDSL);
|
|
|
|
|
yield put(updateAndSaveLayout(flattenedDSL));
|
2023-04-07 13:51:35 +00:00
|
|
|
|
|
|
|
|
yield call(recalculateAutoLayoutColumnsAndSave);
|
|
|
|
|
}
|
2023-06-09 08:52:27 +00:00
|
|
|
// Convert auto-layout to fixed
|
2023-04-07 13:51:35 +00:00
|
|
|
else {
|
|
|
|
|
yield put(
|
|
|
|
|
updateAndSaveLayout(convertNormalizedDSLToFixed(allWidgets, "DESKTOP")),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-10-04 08:54:16 +00:00
|
|
|
yield call(updateApplicationLayoutType, payloadLayoutSystemType);
|
2023-04-07 13:51:35 +00:00
|
|
|
} catch (error) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionErrorTypes.WIDGET_OPERATION_ERROR,
|
|
|
|
|
payload: {
|
|
|
|
|
action: ReduxActionTypes.RECALCULATE_COLUMNS,
|
|
|
|
|
error,
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//This Method is used to re calculate Positions based on canvas width
|
|
|
|
|
export function* recalculateAutoLayoutColumnsAndSave(
|
|
|
|
|
widgets?: CanvasWidgetsReduxState,
|
|
|
|
|
) {
|
2023-10-04 08:54:16 +00:00
|
|
|
const layoutSystemType: LayoutSystemTypes = yield select(getLayoutSystemType);
|
2023-04-07 13:51:35 +00:00
|
|
|
const mainCanvasProps: MainCanvasReduxState = yield select(
|
|
|
|
|
getMainCanvasProps,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
yield put(
|
|
|
|
|
updateLayoutForMobileBreakpointAction(
|
|
|
|
|
MAIN_CONTAINER_WIDGET_ID,
|
2023-10-04 08:54:16 +00:00
|
|
|
layoutSystemType === LayoutSystemTypes.AUTO
|
2023-04-07 13:51:35 +00:00
|
|
|
? mainCanvasProps?.isMobile
|
|
|
|
|
: false,
|
|
|
|
|
mainCanvasProps.width,
|
|
|
|
|
widgets,
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let autoLayoutWidgetDimensionUpdateBatch: Record<
|
|
|
|
|
string,
|
|
|
|
|
{ width: number; height: number }
|
|
|
|
|
> = {};
|
|
|
|
|
|
|
|
|
|
function batchWidgetDimensionsUpdateForAutoLayout(
|
|
|
|
|
widgetId: string,
|
|
|
|
|
width: number,
|
|
|
|
|
height: number,
|
|
|
|
|
) {
|
|
|
|
|
autoLayoutWidgetDimensionUpdateBatch[widgetId] = { width, height };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function* updateWidgetDimensionsSaga(
|
|
|
|
|
action: ReduxAction<{ widgetId: string; width: number; height: number }>,
|
|
|
|
|
) {
|
|
|
|
|
let { height, width } = action.payload;
|
|
|
|
|
const { widgetId } = action.payload;
|
2023-05-11 04:45:14 +00:00
|
|
|
const allWidgets: CanvasWidgetsReduxState = yield select(
|
|
|
|
|
getCanvasAndMetaWidgets,
|
|
|
|
|
);
|
2023-04-07 13:51:35 +00:00
|
|
|
const mainCanvasWidth: number = yield select(getMainCanvasWidth);
|
|
|
|
|
const isMobile: boolean = yield select(getIsAutoLayoutMobileBreakPoint);
|
|
|
|
|
const isWidgetResizing: boolean = yield select(getIsResizing);
|
|
|
|
|
const isCanvasResizing: boolean = yield select(
|
|
|
|
|
(state: AppState) => state.ui.widgetDragResize.isAutoCanvasResizing,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const widget = allWidgets[widgetId];
|
|
|
|
|
if (!widget) return;
|
|
|
|
|
|
|
|
|
|
const widgetMinMaxDimensions = getWidgetMinMaxDimensionsInPixel(
|
|
|
|
|
widget,
|
|
|
|
|
mainCanvasWidth,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
if (!isMobile && widget.widthInPercentage) {
|
|
|
|
|
width = widget.widthInPercentage * mainCanvasWidth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isMobile && widget.mobileWidthInPercentage) {
|
|
|
|
|
width = widget.mobileWidthInPercentage * mainCanvasWidth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (
|
|
|
|
|
widgetMinMaxDimensions.minHeight &&
|
|
|
|
|
height < widgetMinMaxDimensions.minHeight
|
|
|
|
|
) {
|
|
|
|
|
height = widgetMinMaxDimensions.minHeight;
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
widgetMinMaxDimensions.maxHeight &&
|
|
|
|
|
height > widgetMinMaxDimensions.maxHeight
|
|
|
|
|
) {
|
|
|
|
|
height = widgetMinMaxDimensions.maxHeight;
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
widgetMinMaxDimensions.minWidth &&
|
|
|
|
|
width < widgetMinMaxDimensions.minWidth
|
|
|
|
|
) {
|
|
|
|
|
width = widgetMinMaxDimensions.minWidth;
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
widgetMinMaxDimensions.maxWidth &&
|
|
|
|
|
width > widgetMinMaxDimensions.maxWidth
|
|
|
|
|
) {
|
|
|
|
|
width = widgetMinMaxDimensions.maxWidth;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
batchWidgetDimensionsUpdateForAutoLayout(widgetId, width, height);
|
|
|
|
|
|
|
|
|
|
if (!isWidgetResizing && !isCanvasResizing) {
|
|
|
|
|
yield put({
|
|
|
|
|
type: ReduxActionTypes.PROCESS_AUTO_LAYOUT_DIMENSION_UPDATES,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* This saga is responsible for updating the bounding box of the widget
|
|
|
|
|
* when the widget component get resized internally.
|
|
|
|
|
* It also updates the position of other affected widgets as well.
|
|
|
|
|
*/
|
|
|
|
|
function* processAutoLayoutDimensionUpdatesSaga() {
|
|
|
|
|
if (Object.keys(autoLayoutWidgetDimensionUpdateBatch).length === 0) return;
|
|
|
|
|
|
2023-05-11 04:45:14 +00:00
|
|
|
const allWidgets: CanvasWidgetsReduxState = yield select(
|
|
|
|
|
getCanvasAndMetaWidgets,
|
|
|
|
|
);
|
2023-04-07 13:51:35 +00:00
|
|
|
const mainCanvasWidth: number = yield select(getMainCanvasWidth);
|
|
|
|
|
const isMobile: boolean = yield select(getIsAutoLayoutMobileBreakPoint);
|
|
|
|
|
let widgets = allWidgets;
|
|
|
|
|
const widgetsOld = { ...widgets };
|
|
|
|
|
const parentIds = new Set<string>();
|
|
|
|
|
// Iterate through the batch and update the new dimensions
|
|
|
|
|
for (const widgetId in autoLayoutWidgetDimensionUpdateBatch) {
|
|
|
|
|
const { height, width } = autoLayoutWidgetDimensionUpdateBatch[widgetId];
|
|
|
|
|
const widget = allWidgets[widgetId];
|
|
|
|
|
if (!widget) continue;
|
|
|
|
|
const parentId = widget.parentId;
|
|
|
|
|
if (parentId === undefined) continue;
|
|
|
|
|
if (parentId) parentIds.add(parentId);
|
|
|
|
|
|
|
|
|
|
const { columnSpace } = getCanvasDimensions(
|
|
|
|
|
widgets[parentId],
|
|
|
|
|
widgets,
|
|
|
|
|
mainCanvasWidth,
|
|
|
|
|
isMobile,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
//get row space
|
|
|
|
|
const rowSpace = widget.detachFromLayout
|
|
|
|
|
? 1
|
|
|
|
|
: GridDefaults.DEFAULT_GRID_ROW_HEIGHT;
|
|
|
|
|
|
|
|
|
|
let widgetToBeUpdated = { ...widget };
|
|
|
|
|
|
|
|
|
|
widgetToBeUpdated = setBottomRow(
|
|
|
|
|
widgetToBeUpdated,
|
|
|
|
|
getTopRow(widget, isMobile) + height / rowSpace,
|
|
|
|
|
isMobile,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
widgetToBeUpdated = setRightColumn(
|
|
|
|
|
widgetToBeUpdated,
|
|
|
|
|
getLeftColumn(widget, isMobile) + width / columnSpace,
|
|
|
|
|
isMobile,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
widgets = {
|
|
|
|
|
...widgets,
|
|
|
|
|
[widgetId]: widgetToBeUpdated,
|
|
|
|
|
};
|
|
|
|
|
}
|
2023-05-11 04:45:14 +00:00
|
|
|
const metaProps: Record<string, any> = yield select(getWidgetsMeta);
|
2023-04-07 13:51:35 +00:00
|
|
|
// Update the position of all the widgets
|
|
|
|
|
for (const parentId of parentIds) {
|
|
|
|
|
widgets = updateWidgetPositions(
|
|
|
|
|
widgets,
|
|
|
|
|
parentId,
|
|
|
|
|
isMobile,
|
|
|
|
|
mainCanvasWidth,
|
2023-05-11 04:45:14 +00:00
|
|
|
false,
|
|
|
|
|
metaProps,
|
2023-04-07 13:51:35 +00:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let widgetsToUpdate: any = {};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Iterate over all widgets and check if any of their dimensions have changed
|
|
|
|
|
* If they have, add them to the list of widgets to update
|
|
|
|
|
* Note: We need to iterate through all widgets since changing dimension of one widget might affect the dimensions of other widgets
|
|
|
|
|
*/
|
|
|
|
|
for (const widgetId of Object.keys(widgets)) {
|
|
|
|
|
const widget = widgets[widgetId];
|
|
|
|
|
const oldWidget = widgetsOld[widgetId];
|
|
|
|
|
const propertiesToUpdate: Record<string, any> = {};
|
|
|
|
|
|
|
|
|
|
const positionProperties = [
|
|
|
|
|
"topRow",
|
|
|
|
|
"bottomRow",
|
|
|
|
|
"leftColumn",
|
|
|
|
|
"rightColumn",
|
|
|
|
|
"mobileTopRow",
|
|
|
|
|
"mobileBottomRow",
|
|
|
|
|
"mobileLeftColumn",
|
|
|
|
|
"mobileRightColumn",
|
2023-06-01 03:39:23 +00:00
|
|
|
"height",
|
2023-04-07 13:51:35 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
for (const prop of positionProperties) {
|
|
|
|
|
if (widget[prop] !== oldWidget[prop]) {
|
|
|
|
|
propertiesToUpdate[prop] = widget[prop];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isEmpty(propertiesToUpdate)) continue;
|
|
|
|
|
|
|
|
|
|
widgetsToUpdate = mutation_setPropertiesToUpdate(
|
|
|
|
|
widgetsToUpdate,
|
|
|
|
|
widgetId,
|
|
|
|
|
propertiesToUpdate,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-11 04:45:14 +00:00
|
|
|
const canvasWidgetsToUpdate: UpdateWidgetsPayload = {};
|
|
|
|
|
const metaWidgetsToUpdate: UpdateWidgetsPayload = {};
|
|
|
|
|
|
|
|
|
|
for (const widgetId in widgetsToUpdate) {
|
|
|
|
|
const widget = widgets[widgetId];
|
|
|
|
|
if (widget.isMetaWidget) {
|
|
|
|
|
metaWidgetsToUpdate[widgetId] = widgetsToUpdate[widgetId];
|
|
|
|
|
} else {
|
|
|
|
|
canvasWidgetsToUpdate[widgetId] = widgetsToUpdate[widgetId];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-04-07 13:51:35 +00:00
|
|
|
// Push all updates to the CanvasWidgetsReducer.
|
|
|
|
|
// Note that we're not calling `UPDATE_LAYOUT`
|
|
|
|
|
// as we don't need to trigger an eval
|
2023-05-11 04:45:14 +00:00
|
|
|
if (!isEmpty(canvasWidgetsToUpdate)) {
|
|
|
|
|
yield put(updateMultipleWidgetPropertiesAction(canvasWidgetsToUpdate));
|
|
|
|
|
}
|
|
|
|
|
if (!isEmpty(metaWidgetsToUpdate)) {
|
|
|
|
|
yield put(updateMultipleMetaWidgetPropertiesAction(metaWidgetsToUpdate));
|
2023-04-07 13:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// clear the batch after processing
|
|
|
|
|
autoLayoutWidgetDimensionUpdateBatch = {};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function* updateApplicationLayoutType(
|
2023-10-04 08:54:16 +00:00
|
|
|
layoutSystemType: LayoutSystemTypes,
|
2023-04-07 13:51:35 +00:00
|
|
|
) {
|
|
|
|
|
const applicationId: string = yield select(getCurrentApplicationId);
|
|
|
|
|
yield put(
|
|
|
|
|
updateApplication(applicationId || "", {
|
|
|
|
|
applicationDetail: {
|
|
|
|
|
appPositioning: {
|
2023-10-04 08:54:16 +00:00
|
|
|
type: layoutSystemType,
|
2023-04-07 13:51:35 +00:00
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-11 04:45:14 +00:00
|
|
|
function* updatePositionsOnTabChangeSaga(
|
|
|
|
|
action: ReduxAction<{ selectedTabWidgetId: string; widgetId: string }>,
|
|
|
|
|
) {
|
|
|
|
|
const { selectedTabWidgetId, widgetId } = action.payload;
|
|
|
|
|
const allWidgets: CanvasWidgetsReduxState = yield select(getWidgets);
|
|
|
|
|
if (!selectedTabWidgetId || !allWidgets[selectedTabWidgetId]) return;
|
|
|
|
|
const isMobile: boolean = yield select(getIsAutoLayoutMobileBreakPoint);
|
|
|
|
|
const mainCanvasWidth: number = yield select(getMainCanvasWidth);
|
|
|
|
|
const metaProps: Record<string, any> = yield select(getWidgetsMeta);
|
|
|
|
|
|
|
|
|
|
const updatedWidgets: CanvasWidgetsReduxState = updateWidgetPositions(
|
|
|
|
|
allWidgets,
|
|
|
|
|
selectedTabWidgetId,
|
|
|
|
|
isMobile,
|
|
|
|
|
mainCanvasWidth,
|
|
|
|
|
false,
|
|
|
|
|
{
|
|
|
|
|
...metaProps,
|
|
|
|
|
[widgetId]: { ...metaProps[widgetId], selectedTabWidgetId },
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
yield put(updateAndSaveLayout(updatedWidgets));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TODO: BATCH_UPDATE_MULTIPLE_WIDGETS_PROPERTY is already updating the height of tabs widget and the canvas. Why?
|
|
|
|
|
function* updatePositionsSaga(action: ReduxAction<{ widgetId: string }>) {
|
|
|
|
|
const { widgetId } = action.payload;
|
|
|
|
|
const allWidgets: CanvasWidgetsReduxState = yield select(getWidgets);
|
|
|
|
|
if (!widgetId || !allWidgets[widgetId]) return;
|
|
|
|
|
const isMobile: boolean = yield select(getIsAutoLayoutMobileBreakPoint);
|
|
|
|
|
const mainCanvasWidth: number = yield select(getMainCanvasWidth);
|
|
|
|
|
const metaProps: Record<string, any> = yield select(getWidgetsMeta);
|
|
|
|
|
let canvasId: string = widgetId;
|
|
|
|
|
if (allWidgets[canvasId].type === "TABS_WIDGET") {
|
|
|
|
|
// For tabs widget, recalculate the height of child canvas.
|
|
|
|
|
if (
|
|
|
|
|
metaProps &&
|
|
|
|
|
metaProps[canvasId] &&
|
|
|
|
|
metaProps[canvasId]?.selectedTabWidgetId
|
|
|
|
|
)
|
|
|
|
|
canvasId = metaProps[canvasId]?.selectedTabWidgetId;
|
|
|
|
|
}
|
|
|
|
|
const updatedWidgets: CanvasWidgetsReduxState = updateWidgetPositions(
|
|
|
|
|
allWidgets,
|
|
|
|
|
canvasId,
|
|
|
|
|
isMobile,
|
|
|
|
|
mainCanvasWidth,
|
|
|
|
|
false,
|
|
|
|
|
metaProps,
|
|
|
|
|
);
|
|
|
|
|
yield put(updateAndSaveLayout(updatedWidgets));
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-04 07:25:54 +00:00
|
|
|
export default function* layoutUpdateSagas() {
|
|
|
|
|
yield all([
|
|
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.RECALCULATE_COLUMNS,
|
|
|
|
|
updateLayoutForMobileCheckpoint,
|
|
|
|
|
),
|
2023-04-07 13:51:35 +00:00
|
|
|
takeLatest(
|
2023-10-04 08:54:16 +00:00
|
|
|
ReduxActionTypes.UPDATE_LAYOUT_SYSTEM_TYPE,
|
|
|
|
|
updateLayoutSystemTypeSaga,
|
2023-04-07 13:51:35 +00:00
|
|
|
),
|
|
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.UPDATE_WIDGET_DIMENSIONS,
|
|
|
|
|
updateWidgetDimensionsSaga,
|
|
|
|
|
),
|
|
|
|
|
debounce(
|
|
|
|
|
50,
|
|
|
|
|
ReduxActionTypes.PROCESS_AUTO_LAYOUT_DIMENSION_UPDATES,
|
|
|
|
|
processAutoLayoutDimensionUpdatesSaga,
|
|
|
|
|
),
|
2023-05-11 04:45:14 +00:00
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.UPDATE_POSITIONS_ON_TAB_CHANGE,
|
|
|
|
|
shouldRunSaga,
|
|
|
|
|
updatePositionsOnTabChangeSaga,
|
|
|
|
|
),
|
|
|
|
|
takeLatest(
|
|
|
|
|
ReduxActionTypes.CHECK_CONTAINERS_FOR_AUTO_HEIGHT,
|
|
|
|
|
shouldRunSaga,
|
|
|
|
|
updatePositionsSaga,
|
|
|
|
|
),
|
2023-03-04 07:25:54 +00:00
|
|
|
]);
|
|
|
|
|
}
|