PromucFlow_constructor/app/client/src/utils/autoHeight/reflow.ts
Abhinav Jha b2070083a6
fix: Switch to preview mode performance issue (#18457)
* In progress fixes for auto height perf

* Revert collapse logic

* Revert changes

* Remove console logs, and fix tests

* Fix scenario where container widgets don't collapse

* Bring back hidden widgets

* fix: Overlapping of widgets while reflowing other widgets (#18460)

* fix: api url z-index to show it above response panel (#18200)

* chore: Switched to sequential checks instead of a parallel one for RTS check (#18440)

fix: Switched to sequential checks instead of a parallel one

* chore: Added size limit check for the message before sending the data to segment (#18453)

* fix: Allowing multi form to json switching and eliminating json to form sw… (#18192)

* Allowing multi form to json switching and eliminating json to form switching unless form data is cleared

* Fix failing jest test case

Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>

* add missed width and height limits instead of incrementing depth by 1

Co-authored-by: Aman Agarwal <aman@appsmith.com>
Co-authored-by: Nidhi <nidhi@appsmith.com>
Co-authored-by: Anagh Hegde <anagh@appsmith.com>
Co-authored-by: Ayangade Adeoluwa <37867493+Irongade@users.noreply.github.com>
Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>

* fix: auto height with limits deselect widget (#18455)

* fix: api url z-index to show it above response panel (#18200)

* chore: Switched to sequential checks instead of a parallel one for RTS check (#18440)

fix: Switched to sequential checks instead of a parallel one

* chore: Added size limit check for the message before sending the data to segment (#18453)

* fix: Allowing multi form to json switching and eliminating json to form sw… (#18192)

* Allowing multi form to json switching and eliminating json to form switching unless form data is cleared

* Fix failing jest test case

Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>

* refactor overlay and handles state into ui reducer and added a check for is limits changing in the widgets editor as well

* added helpful comments at relevant places

Co-authored-by: Aman Agarwal <aman@appsmith.com>
Co-authored-by: Nidhi <nidhi@appsmith.com>
Co-authored-by: Anagh Hegde <anagh@appsmith.com>
Co-authored-by: Ayangade Adeoluwa <37867493+Irongade@users.noreply.github.com>
Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>
Co-authored-by: Ankur Singhal <ankurrsinghal@gmail.com>

* changes the label on limit handles collision to height

* fix: issues related to tabs widget in auto height (#18468)

* Fix issues related to tabs widget in auto height

* Fix issue where preview mode canvas did not scroll

* Fix scroll issues with fixed containers

* Fix issue where tabs widget computed the canvas height incorrectly

* Re-compute in case of tabs widget

* fix: widgets increase spacing  (#18462)

* Change how the spacing works when widgets push or pull widgets below

* Fix type issues in test file

* Fix tests to reflect changes

* Add comment to describe why we're generating distanceToNearestAbove

Co-authored-by: rahulramesha <71900764+rahulramesha@users.noreply.github.com>
Co-authored-by: Aman Agarwal <aman@appsmith.com>
Co-authored-by: Nidhi <nidhi@appsmith.com>
Co-authored-by: Anagh Hegde <anagh@appsmith.com>
Co-authored-by: Ayangade Adeoluwa <37867493+Irongade@users.noreply.github.com>
Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>
Co-authored-by: ankurrsinghal <ankur@appsmith.com>
Co-authored-by: Ankur Singhal <ankurrsinghal@gmail.com>
2022-11-27 22:42:00 +05:30

109 lines
4.0 KiB
TypeScript

import { TreeNode } from "./constants";
import { getNearestAbove } from "./helpers";
function getAllEffectedBoxes(
effectorBoxId: string,
tree: Record<string, TreeNode>,
effectedBoxes: string[] = [],
_processed: { [key: string]: boolean } = {},
): string[] {
const belows = tree[effectorBoxId].belows;
belows.forEach((belowId) => {
if (!_processed[belowId]) {
getAllEffectedBoxes(belowId, tree, effectedBoxes, _processed);
(effectedBoxes as string[]).push(belowId);
_processed[belowId] = true;
}
});
return effectedBoxes;
}
// This function computes the new positions for boxes based on the boxes which have changed height
// delta: a map of boxes with change in heights
// tree: a layout tree which contains the current state of the boxes.
export function computeChangeInPositionBasedOnDelta(
tree: Record<string, TreeNode>,
delta: Record<string, number>,
): Record<string, { topRow: number; bottomRow: number }> {
const repositionedBoxes: Record<
string,
{ topRow: number; bottomRow: number }
> = {};
let effectedBoxes: string[] = [];
// This value stores all the effectedBoxes that have already been computed,
// So that it doesn't repeat itself while computing the effectedBoxes
const _processed = {};
// For each box which has changed height (box delta)
for (const boxId in delta) {
// Create an effectedBoxMap, which contains the changes for each of the boxes effected by the delta of this box
// This is a map, because multiple box deltas can effect one box
// We simply take all the boxes which are below this box from the tree
// and add the delta to the effectedBoxMap where the key is the below boxId from the tree
effectedBoxes = getAllEffectedBoxes(boxId, tree, effectedBoxes, _processed);
// Add this box's delta to the repositioning, as this won't show up in the effectedBoxMap
repositionedBoxes[boxId] = {
topRow: tree[boxId].topRow,
bottomRow: tree[boxId].bottomRow + delta[boxId],
};
}
// Sort the effected box ids, this is to make sure we compute from top to bottom.
const sortedEffectedBoxIds = effectedBoxes.sort(
(a, b) => tree[a].topRow - tree[b].topRow,
);
// For each of the boxes which have been effected
for (const effectedBoxId of sortedEffectedBoxIds) {
let _offset = 0;
const bottomMostAboves = getNearestAbove(
tree,
effectedBoxId,
repositionedBoxes,
);
// for each of the bottom most above boxes.
// Note: There can be more than one if two above widgets have the same bottomrow
for (const aboveId of bottomMostAboves) {
// If the above box has been effected by another box change height
// Or, if this above box itself has changed height
if (effectedBoxes.includes(aboveId) || delta[aboveId]) {
// If we have the above repositioned
if (repositionedBoxes[aboveId]) {
// Get the new expected top row of this effectedBox
const newTopRow =
repositionedBoxes[aboveId].bottomRow +
tree[effectedBoxId].distanceToNearestAbove;
// Get the offset this effectedBox needs to consider moving
_offset = newTopRow - tree[effectedBoxId].topRow;
} else {
// Since the above hasn't changed, don't change this.
_offset = 0;
}
} else {
// Maintain distance from the bottom most above.
const newTopRow =
tree[aboveId].bottomRow + tree[effectedBoxId].distanceToNearestAbove;
_offset = newTopRow - tree[effectedBoxId].topRow;
}
}
// Finally update the repositioned box with the _offset.
if (repositionedBoxes[effectedBoxId]) {
repositionedBoxes[effectedBoxId].bottomRow += _offset;
repositionedBoxes[effectedBoxId].topRow += _offset;
} else {
repositionedBoxes[effectedBoxId] = {
topRow: tree[effectedBoxId].topRow + _offset,
bottomRow: tree[effectedBoxId].bottomRow + _offset,
};
}
}
return repositionedBoxes;
}