PromucFlow_constructor/app/client/src/sagas/AutoLayoutUpdateSagas.tsx

532 lines
15 KiB
TypeScript
Raw Normal View History

import { updateAndSaveLayout } from "actions/pageActions";
import type { ReduxAction } from "@appsmith/constants/ReduxActionConstants";
import {
ReduxActionErrorTypes,
ReduxActionTypes,
} from "@appsmith/constants/ReduxActionConstants";
import log from "loglevel";
feat: Expand auto height implementation to handle auto height use cases. (#22974) ## Description Expand auto layout implementation to handle auto height use cases. Use cases handled in this PR: 1. Change canvas and container-like widget height on adding / removing widgets. 2. Container height update on content change of individual props, e.g. text, checkbox groups. 3. Tabs widget use cases - change height on tab change, shouldShowProps update. 4. Correct modal widget height. 5. List widget updates - disable auto height, enable manual resizing of item container. 6. Fix resize loop. Fixes https://github.com/appsmithorg/appsmith/issues/21977 Fixes https://github.com/appsmithorg/appsmith/issues/22093 Fixes https://github.com/appsmithorg/appsmith/issues/21837 Fixes https://github.com/appsmithorg/appsmith/issues/22183 Fixes https://github.com/appsmithorg/appsmith/issues/21758 Fixes https://github.com/appsmithorg/appsmith/issues/21870 Fixes https://github.com/appsmithorg/appsmith/issues/22086 Fixes https://github.com/appsmithorg/appsmith/issues/22539 Fixes https://github.com/appsmithorg/appsmith/issues/22329 Fixes #22588 ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual - Jest - Cypress ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag --------- Co-authored-by: Aswath K <aswath@appsmith.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com>
2023-05-11 04:45:14 +00:00
import type {
CanvasWidgetsReduxState,
UpdateWidgetsPayload,
} from "reducers/entityReducers/canvasWidgetsReducer";
import {
all,
call,
debounce,
put,
select,
takeLatest,
} from "redux-saga/effects";
import {
alterLayoutForDesktop,
alterLayoutForMobile,
getCanvasDimensions,
} from "utils/autoLayout/AutoLayoutUtils";
feat: Expand auto height implementation to handle auto height use cases. (#22974) ## Description Expand auto layout implementation to handle auto height use cases. Use cases handled in this PR: 1. Change canvas and container-like widget height on adding / removing widgets. 2. Container height update on content change of individual props, e.g. text, checkbox groups. 3. Tabs widget use cases - change height on tab change, shouldShowProps update. 4. Correct modal widget height. 5. List widget updates - disable auto height, enable manual resizing of item container. 6. Fix resize loop. Fixes https://github.com/appsmithorg/appsmith/issues/21977 Fixes https://github.com/appsmithorg/appsmith/issues/22093 Fixes https://github.com/appsmithorg/appsmith/issues/21837 Fixes https://github.com/appsmithorg/appsmith/issues/22183 Fixes https://github.com/appsmithorg/appsmith/issues/21758 Fixes https://github.com/appsmithorg/appsmith/issues/21870 Fixes https://github.com/appsmithorg/appsmith/issues/22086 Fixes https://github.com/appsmithorg/appsmith/issues/22539 Fixes https://github.com/appsmithorg/appsmith/issues/22329 Fixes #22588 ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual - Jest - Cypress ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag --------- Co-authored-by: Aswath K <aswath@appsmith.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com>
2023-05-11 04:45:14 +00:00
import {
getCanvasAndMetaWidgets,
getWidgets,
getWidgetsMeta,
} from "./selectors";
import { AppPositioningTypes } from "reducers/entityReducers/pageListReducer";
import {
GridDefaults,
MAIN_CONTAINER_WIDGET_ID,
} from "constants/WidgetConstants";
import {
getCurrentApplicationId,
getCurrentAppPositioningType,
getIsAutoLayout,
getIsAutoLayoutMobileBreakPoint,
getMainCanvasProps,
} from "selectors/editorSelectors";
import type { MainCanvasReduxState } from "reducers/uiReducers/mainCanvasReducer";
import { updateLayoutForMobileBreakpointAction } from "actions/autoLayoutActions";
import CanvasWidgetsNormalizer from "normalizers/CanvasWidgetsNormalizer";
import convertDSLtoAuto from "utils/DSLConversions/fixedToAutoLayout";
import { convertNormalizedDSLToFixed } from "utils/DSLConversions/autoToFixedLayout";
import { updateWidgetPositions } from "utils/autoLayout/positionUtils";
import { getCanvasWidth as getMainCanvasWidth } from "selectors/editorSelectors";
import {
getLeftColumn,
getTopRow,
getWidgetMinMaxDimensionsInPixel,
setBottomRow,
setRightColumn,
} from "utils/autoLayout/flexWidgetUtils";
feat: Expand auto height implementation to handle auto height use cases. (#22974) ## Description Expand auto layout implementation to handle auto height use cases. Use cases handled in this PR: 1. Change canvas and container-like widget height on adding / removing widgets. 2. Container height update on content change of individual props, e.g. text, checkbox groups. 3. Tabs widget use cases - change height on tab change, shouldShowProps update. 4. Correct modal widget height. 5. List widget updates - disable auto height, enable manual resizing of item container. 6. Fix resize loop. Fixes https://github.com/appsmithorg/appsmith/issues/21977 Fixes https://github.com/appsmithorg/appsmith/issues/22093 Fixes https://github.com/appsmithorg/appsmith/issues/21837 Fixes https://github.com/appsmithorg/appsmith/issues/22183 Fixes https://github.com/appsmithorg/appsmith/issues/21758 Fixes https://github.com/appsmithorg/appsmith/issues/21870 Fixes https://github.com/appsmithorg/appsmith/issues/22086 Fixes https://github.com/appsmithorg/appsmith/issues/22539 Fixes https://github.com/appsmithorg/appsmith/issues/22329 Fixes #22588 ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual - Jest - Cypress ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag --------- Co-authored-by: Aswath K <aswath@appsmith.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com>
2023-05-11 04:45:14 +00:00
import {
updateMultipleMetaWidgetPropertiesAction,
updateMultipleWidgetPropertiesAction,
} from "actions/controlActions";
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";
import type { AppState } from "@appsmith/reducers";
feat: Expand auto height implementation to handle auto height use cases. (#22974) ## Description Expand auto layout implementation to handle auto height use cases. Use cases handled in this PR: 1. Change canvas and container-like widget height on adding / removing widgets. 2. Container height update on content change of individual props, e.g. text, checkbox groups. 3. Tabs widget use cases - change height on tab change, shouldShowProps update. 4. Correct modal widget height. 5. List widget updates - disable auto height, enable manual resizing of item container. 6. Fix resize loop. Fixes https://github.com/appsmithorg/appsmith/issues/21977 Fixes https://github.com/appsmithorg/appsmith/issues/22093 Fixes https://github.com/appsmithorg/appsmith/issues/21837 Fixes https://github.com/appsmithorg/appsmith/issues/22183 Fixes https://github.com/appsmithorg/appsmith/issues/21758 Fixes https://github.com/appsmithorg/appsmith/issues/21870 Fixes https://github.com/appsmithorg/appsmith/issues/22086 Fixes https://github.com/appsmithorg/appsmith/issues/22539 Fixes https://github.com/appsmithorg/appsmith/issues/22329 Fixes #22588 ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual - Jest - Cypress ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag --------- Co-authored-by: Aswath K <aswath@appsmith.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com>
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);
}
}
export function* updateLayoutForMobileCheckpoint(
actionPayload: ReduxAction<{
parentId: string;
isMobile: boolean;
canvasWidth: number;
widgets?: CanvasWidgetsReduxState;
}>,
) {
try {
const start = performance.now();
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);
}
feat: Expand auto height implementation to handle auto height use cases. (#22974) ## Description Expand auto layout implementation to handle auto height use cases. Use cases handled in this PR: 1. Change canvas and container-like widget height on adding / removing widgets. 2. Container height update on content change of individual props, e.g. text, checkbox groups. 3. Tabs widget use cases - change height on tab change, shouldShowProps update. 4. Correct modal widget height. 5. List widget updates - disable auto height, enable manual resizing of item container. 6. Fix resize loop. Fixes https://github.com/appsmithorg/appsmith/issues/21977 Fixes https://github.com/appsmithorg/appsmith/issues/22093 Fixes https://github.com/appsmithorg/appsmith/issues/21837 Fixes https://github.com/appsmithorg/appsmith/issues/22183 Fixes https://github.com/appsmithorg/appsmith/issues/21758 Fixes https://github.com/appsmithorg/appsmith/issues/21870 Fixes https://github.com/appsmithorg/appsmith/issues/22086 Fixes https://github.com/appsmithorg/appsmith/issues/22539 Fixes https://github.com/appsmithorg/appsmith/issues/22329 Fixes #22588 ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual - Jest - Cypress ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag --------- Co-authored-by: Aswath K <aswath@appsmith.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com>
2023-05-11 04:45:14 +00:00
const metaProps: Record<string, any> = yield select(getWidgetsMeta);
const updatedWidgets: CanvasWidgetsReduxState = isMobile
feat: Expand auto height implementation to handle auto height use cases. (#22974) ## Description Expand auto layout implementation to handle auto height use cases. Use cases handled in this PR: 1. Change canvas and container-like widget height on adding / removing widgets. 2. Container height update on content change of individual props, e.g. text, checkbox groups. 3. Tabs widget use cases - change height on tab change, shouldShowProps update. 4. Correct modal widget height. 5. List widget updates - disable auto height, enable manual resizing of item container. 6. Fix resize loop. Fixes https://github.com/appsmithorg/appsmith/issues/21977 Fixes https://github.com/appsmithorg/appsmith/issues/22093 Fixes https://github.com/appsmithorg/appsmith/issues/21837 Fixes https://github.com/appsmithorg/appsmith/issues/22183 Fixes https://github.com/appsmithorg/appsmith/issues/21758 Fixes https://github.com/appsmithorg/appsmith/issues/21870 Fixes https://github.com/appsmithorg/appsmith/issues/22086 Fixes https://github.com/appsmithorg/appsmith/issues/22539 Fixes https://github.com/appsmithorg/appsmith/issues/22329 Fixes #22588 ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual - Jest - Cypress ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag --------- Co-authored-by: Aswath K <aswath@appsmith.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com>
2023-05-11 04:45:14 +00:00
? alterLayoutForMobile(
allWidgets,
parentId,
canvasWidth,
canvasWidth,
false,
metaProps,
)
: alterLayoutForDesktop(
allWidgets,
parentId,
canvasWidth,
false,
metaProps,
);
yield put(updateAndSaveLayout(updatedWidgets));
yield put(generateAutoHeightLayoutTreeAction(true, true));
log.debug(
"Auto Layout : updating layout for mobile viewport took",
performance.now() - start,
"ms",
);
} catch (error) {
yield put({
type: ReduxActionErrorTypes.WIDGET_OPERATION_ERROR,
payload: {
action: ReduxActionTypes.RECALCULATE_COLUMNS,
error,
},
});
}
}
/**
* This Method is called when fixed and Auto are switched between each other using the Switch button on the right Pane
* @param actionPayload
* @returns
*/
export function* updateLayoutPositioningSaga(
actionPayload: ReduxAction<AppPositioningTypes>,
) {
try {
const currPositioningType: AppPositioningTypes = yield select(
getCurrentAppPositioningType,
);
const payloadPositioningType = actionPayload.payload;
if (currPositioningType === payloadPositioningType) return;
const allWidgets: CanvasWidgetsReduxState = yield select(getWidgets);
//Convert Fixed Layout to Auto
if (payloadPositioningType === AppPositioningTypes.AUTO) {
const denormalizedDSL = CanvasWidgetsNormalizer.denormalize(
MAIN_CONTAINER_WIDGET_ID,
{ canvasWidgets: allWidgets },
);
const autoDSL = convertDSLtoAuto(denormalizedDSL);
log.debug("autoDSL", autoDSL);
yield put(
updateAndSaveLayout(
CanvasWidgetsNormalizer.normalize(autoDSL).entities.canvasWidgets,
),
);
yield call(recalculateAutoLayoutColumnsAndSave);
}
// Convert Auto layout to fixed
else {
yield put(
updateAndSaveLayout(convertNormalizedDSLToFixed(allWidgets, "DESKTOP")),
);
}
yield call(updateApplicationLayoutType, payloadPositioningType);
} 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,
) {
const appPositioningType: AppPositioningTypes = yield select(
getCurrentAppPositioningType,
);
const mainCanvasProps: MainCanvasReduxState = yield select(
getMainCanvasProps,
);
yield put(
updateLayoutForMobileBreakpointAction(
MAIN_CONTAINER_WIDGET_ID,
appPositioningType === AppPositioningTypes.AUTO
? 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;
feat: Expand auto height implementation to handle auto height use cases. (#22974) ## Description Expand auto layout implementation to handle auto height use cases. Use cases handled in this PR: 1. Change canvas and container-like widget height on adding / removing widgets. 2. Container height update on content change of individual props, e.g. text, checkbox groups. 3. Tabs widget use cases - change height on tab change, shouldShowProps update. 4. Correct modal widget height. 5. List widget updates - disable auto height, enable manual resizing of item container. 6. Fix resize loop. Fixes https://github.com/appsmithorg/appsmith/issues/21977 Fixes https://github.com/appsmithorg/appsmith/issues/22093 Fixes https://github.com/appsmithorg/appsmith/issues/21837 Fixes https://github.com/appsmithorg/appsmith/issues/22183 Fixes https://github.com/appsmithorg/appsmith/issues/21758 Fixes https://github.com/appsmithorg/appsmith/issues/21870 Fixes https://github.com/appsmithorg/appsmith/issues/22086 Fixes https://github.com/appsmithorg/appsmith/issues/22539 Fixes https://github.com/appsmithorg/appsmith/issues/22329 Fixes #22588 ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual - Jest - Cypress ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag --------- Co-authored-by: Aswath K <aswath@appsmith.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com>
2023-05-11 04:45:14 +00:00
const allWidgets: CanvasWidgetsReduxState = yield select(
getCanvasAndMetaWidgets,
);
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;
feat: Expand auto height implementation to handle auto height use cases. (#22974) ## Description Expand auto layout implementation to handle auto height use cases. Use cases handled in this PR: 1. Change canvas and container-like widget height on adding / removing widgets. 2. Container height update on content change of individual props, e.g. text, checkbox groups. 3. Tabs widget use cases - change height on tab change, shouldShowProps update. 4. Correct modal widget height. 5. List widget updates - disable auto height, enable manual resizing of item container. 6. Fix resize loop. Fixes https://github.com/appsmithorg/appsmith/issues/21977 Fixes https://github.com/appsmithorg/appsmith/issues/22093 Fixes https://github.com/appsmithorg/appsmith/issues/21837 Fixes https://github.com/appsmithorg/appsmith/issues/22183 Fixes https://github.com/appsmithorg/appsmith/issues/21758 Fixes https://github.com/appsmithorg/appsmith/issues/21870 Fixes https://github.com/appsmithorg/appsmith/issues/22086 Fixes https://github.com/appsmithorg/appsmith/issues/22539 Fixes https://github.com/appsmithorg/appsmith/issues/22329 Fixes #22588 ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual - Jest - Cypress ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag --------- Co-authored-by: Aswath K <aswath@appsmith.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com>
2023-05-11 04:45:14 +00:00
const allWidgets: CanvasWidgetsReduxState = yield select(
getCanvasAndMetaWidgets,
);
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,
};
}
feat: Expand auto height implementation to handle auto height use cases. (#22974) ## Description Expand auto layout implementation to handle auto height use cases. Use cases handled in this PR: 1. Change canvas and container-like widget height on adding / removing widgets. 2. Container height update on content change of individual props, e.g. text, checkbox groups. 3. Tabs widget use cases - change height on tab change, shouldShowProps update. 4. Correct modal widget height. 5. List widget updates - disable auto height, enable manual resizing of item container. 6. Fix resize loop. Fixes https://github.com/appsmithorg/appsmith/issues/21977 Fixes https://github.com/appsmithorg/appsmith/issues/22093 Fixes https://github.com/appsmithorg/appsmith/issues/21837 Fixes https://github.com/appsmithorg/appsmith/issues/22183 Fixes https://github.com/appsmithorg/appsmith/issues/21758 Fixes https://github.com/appsmithorg/appsmith/issues/21870 Fixes https://github.com/appsmithorg/appsmith/issues/22086 Fixes https://github.com/appsmithorg/appsmith/issues/22539 Fixes https://github.com/appsmithorg/appsmith/issues/22329 Fixes #22588 ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual - Jest - Cypress ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag --------- Co-authored-by: Aswath K <aswath@appsmith.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com>
2023-05-11 04:45:14 +00:00
const metaProps: Record<string, any> = yield select(getWidgetsMeta);
// Update the position of all the widgets
for (const parentId of parentIds) {
widgets = updateWidgetPositions(
widgets,
parentId,
isMobile,
mainCanvasWidth,
feat: Expand auto height implementation to handle auto height use cases. (#22974) ## Description Expand auto layout implementation to handle auto height use cases. Use cases handled in this PR: 1. Change canvas and container-like widget height on adding / removing widgets. 2. Container height update on content change of individual props, e.g. text, checkbox groups. 3. Tabs widget use cases - change height on tab change, shouldShowProps update. 4. Correct modal widget height. 5. List widget updates - disable auto height, enable manual resizing of item container. 6. Fix resize loop. Fixes https://github.com/appsmithorg/appsmith/issues/21977 Fixes https://github.com/appsmithorg/appsmith/issues/22093 Fixes https://github.com/appsmithorg/appsmith/issues/21837 Fixes https://github.com/appsmithorg/appsmith/issues/22183 Fixes https://github.com/appsmithorg/appsmith/issues/21758 Fixes https://github.com/appsmithorg/appsmith/issues/21870 Fixes https://github.com/appsmithorg/appsmith/issues/22086 Fixes https://github.com/appsmithorg/appsmith/issues/22539 Fixes https://github.com/appsmithorg/appsmith/issues/22329 Fixes #22588 ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual - Jest - Cypress ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag --------- Co-authored-by: Aswath K <aswath@appsmith.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com>
2023-05-11 04:45:14 +00:00
false,
metaProps,
);
}
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",
fix: Auto dimension not working within Modal widget (#23724) ## Description - Auto dimension within Modal widget was not working after resizing modal widget since we were not triggering PROCESS_AUTO_LAYOUT_DIMENSION_UPDATES after resizing modal widget. - Auto dimension induced height changes were not getting updated for the modal widget since we were only considering position properties and not "height" property for the auto-dimension updates #### PR fixes following issues Fixes #23658 Fixes #23714 #### Type of change - Bug fix (non-breaking change which fixes an issue) ## Testing > #### How Has This Been Tested? > Please describe the tests that you ran to verify your changes. Also list any relevant details for your test configuration. > Delete anything that is not relevant - [ ] Manual - [ ] Jest - [ ] Cypress > > #### Test Plan > Add Testsmith test cases links that relate to this PR > > #### Issues raised during DP testing > Link issues raised during DP testing for better visiblity and tracking (copy link from comments dropped on this PR) > > > ## Checklist: #### Dev activity - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [ ] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag #### QA activity: - [ ] [Speedbreak features](https://github.com/appsmithorg/TestSmith/wiki/Test-plan-implementation#speedbreaker-features-to-consider-for-every-change) have been covered - [ ] Test plan covers all impacted features and [areas of interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans/_edit#areas-of-interest) - [ ] Test plan has been peer reviewed by project stakeholders and other QA members - [ ] Manually tested functionality on DP - [ ] We had an implementation alignment call with stakeholders post QA Round 2 - [ ] Cypress test cases have been added and approved by SDET/manual QA - [ ] Added `Test Plan Approved` label after Cypress tests were reviewed - [ ] Added `Test Plan Approved` label after JUnit tests were reviewed
2023-06-01 03:39:23 +00:00
"height",
];
for (const prop of positionProperties) {
if (widget[prop] !== oldWidget[prop]) {
propertiesToUpdate[prop] = widget[prop];
}
}
if (isEmpty(propertiesToUpdate)) continue;
widgetsToUpdate = mutation_setPropertiesToUpdate(
widgetsToUpdate,
widgetId,
propertiesToUpdate,
);
}
feat: Expand auto height implementation to handle auto height use cases. (#22974) ## Description Expand auto layout implementation to handle auto height use cases. Use cases handled in this PR: 1. Change canvas and container-like widget height on adding / removing widgets. 2. Container height update on content change of individual props, e.g. text, checkbox groups. 3. Tabs widget use cases - change height on tab change, shouldShowProps update. 4. Correct modal widget height. 5. List widget updates - disable auto height, enable manual resizing of item container. 6. Fix resize loop. Fixes https://github.com/appsmithorg/appsmith/issues/21977 Fixes https://github.com/appsmithorg/appsmith/issues/22093 Fixes https://github.com/appsmithorg/appsmith/issues/21837 Fixes https://github.com/appsmithorg/appsmith/issues/22183 Fixes https://github.com/appsmithorg/appsmith/issues/21758 Fixes https://github.com/appsmithorg/appsmith/issues/21870 Fixes https://github.com/appsmithorg/appsmith/issues/22086 Fixes https://github.com/appsmithorg/appsmith/issues/22539 Fixes https://github.com/appsmithorg/appsmith/issues/22329 Fixes #22588 ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual - Jest - Cypress ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag --------- Co-authored-by: Aswath K <aswath@appsmith.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com>
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];
}
}
// Push all updates to the CanvasWidgetsReducer.
// Note that we're not calling `UPDATE_LAYOUT`
// as we don't need to trigger an eval
feat: Expand auto height implementation to handle auto height use cases. (#22974) ## Description Expand auto layout implementation to handle auto height use cases. Use cases handled in this PR: 1. Change canvas and container-like widget height on adding / removing widgets. 2. Container height update on content change of individual props, e.g. text, checkbox groups. 3. Tabs widget use cases - change height on tab change, shouldShowProps update. 4. Correct modal widget height. 5. List widget updates - disable auto height, enable manual resizing of item container. 6. Fix resize loop. Fixes https://github.com/appsmithorg/appsmith/issues/21977 Fixes https://github.com/appsmithorg/appsmith/issues/22093 Fixes https://github.com/appsmithorg/appsmith/issues/21837 Fixes https://github.com/appsmithorg/appsmith/issues/22183 Fixes https://github.com/appsmithorg/appsmith/issues/21758 Fixes https://github.com/appsmithorg/appsmith/issues/21870 Fixes https://github.com/appsmithorg/appsmith/issues/22086 Fixes https://github.com/appsmithorg/appsmith/issues/22539 Fixes https://github.com/appsmithorg/appsmith/issues/22329 Fixes #22588 ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual - Jest - Cypress ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag --------- Co-authored-by: Aswath K <aswath@appsmith.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com>
2023-05-11 04:45:14 +00:00
if (!isEmpty(canvasWidgetsToUpdate)) {
yield put(updateMultipleWidgetPropertiesAction(canvasWidgetsToUpdate));
}
if (!isEmpty(metaWidgetsToUpdate)) {
yield put(updateMultipleMetaWidgetPropertiesAction(metaWidgetsToUpdate));
}
// clear the batch after processing
autoLayoutWidgetDimensionUpdateBatch = {};
}
export function* updateApplicationLayoutType(
positioningType: AppPositioningTypes,
) {
const applicationId: string = yield select(getCurrentApplicationId);
yield put(
updateApplication(applicationId || "", {
applicationDetail: {
appPositioning: {
type: positioningType,
},
},
}),
);
}
feat: Expand auto height implementation to handle auto height use cases. (#22974) ## Description Expand auto layout implementation to handle auto height use cases. Use cases handled in this PR: 1. Change canvas and container-like widget height on adding / removing widgets. 2. Container height update on content change of individual props, e.g. text, checkbox groups. 3. Tabs widget use cases - change height on tab change, shouldShowProps update. 4. Correct modal widget height. 5. List widget updates - disable auto height, enable manual resizing of item container. 6. Fix resize loop. Fixes https://github.com/appsmithorg/appsmith/issues/21977 Fixes https://github.com/appsmithorg/appsmith/issues/22093 Fixes https://github.com/appsmithorg/appsmith/issues/21837 Fixes https://github.com/appsmithorg/appsmith/issues/22183 Fixes https://github.com/appsmithorg/appsmith/issues/21758 Fixes https://github.com/appsmithorg/appsmith/issues/21870 Fixes https://github.com/appsmithorg/appsmith/issues/22086 Fixes https://github.com/appsmithorg/appsmith/issues/22539 Fixes https://github.com/appsmithorg/appsmith/issues/22329 Fixes #22588 ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual - Jest - Cypress ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag --------- Co-authored-by: Aswath K <aswath@appsmith.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com>
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));
}
export default function* layoutUpdateSagas() {
yield all([
takeLatest(
ReduxActionTypes.RECALCULATE_COLUMNS,
updateLayoutForMobileCheckpoint,
),
takeLatest(
ReduxActionTypes.UPDATE_LAYOUT_POSITIONING,
updateLayoutPositioningSaga,
),
takeLatest(
ReduxActionTypes.UPDATE_WIDGET_DIMENSIONS,
updateWidgetDimensionsSaga,
),
debounce(
50,
ReduxActionTypes.PROCESS_AUTO_LAYOUT_DIMENSION_UPDATES,
processAutoLayoutDimensionUpdatesSaga,
),
feat: Expand auto height implementation to handle auto height use cases. (#22974) ## Description Expand auto layout implementation to handle auto height use cases. Use cases handled in this PR: 1. Change canvas and container-like widget height on adding / removing widgets. 2. Container height update on content change of individual props, e.g. text, checkbox groups. 3. Tabs widget use cases - change height on tab change, shouldShowProps update. 4. Correct modal widget height. 5. List widget updates - disable auto height, enable manual resizing of item container. 6. Fix resize loop. Fixes https://github.com/appsmithorg/appsmith/issues/21977 Fixes https://github.com/appsmithorg/appsmith/issues/22093 Fixes https://github.com/appsmithorg/appsmith/issues/21837 Fixes https://github.com/appsmithorg/appsmith/issues/22183 Fixes https://github.com/appsmithorg/appsmith/issues/21758 Fixes https://github.com/appsmithorg/appsmith/issues/21870 Fixes https://github.com/appsmithorg/appsmith/issues/22086 Fixes https://github.com/appsmithorg/appsmith/issues/22539 Fixes https://github.com/appsmithorg/appsmith/issues/22329 Fixes #22588 ## Type of change > Please delete options that are not relevant. - Bug fix (non-breaking change which fixes an issue) - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual - Jest - Cypress ## Checklist: ### Dev activity - [x] My code follows the style guidelines of this project - [x] I have performed a self-review of my own code - [x] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings - [ ] I have added tests that prove my fix is effective or that my feature works - [x] New and existing unit tests pass locally with my changes - [ ] PR is being merged under a feature flag --------- Co-authored-by: Aswath K <aswath@appsmith.com> Co-authored-by: rahulramesha <rahul@appsmith.com> Co-authored-by: Aswath K <aswath.sana@gmail.com> Co-authored-by: Ashok Kumar M <35134347+marks0351@users.noreply.github.com>
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,
),
]);
}