PromucFlow_constructor/app/client/src/components/autoHeightOverlay/store.tsx

138 lines
3.5 KiB
TypeScript
Raw Normal View History

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 17:12:00 +00:00
import { GridDefaults } from "constants/WidgetConstants";
fix: auto height limits one row difference (#19001) ## Description Issue:- Currently, the min and max limits handle in Auto Height with Limits move with each other on collision, while we can change the max when they have the same values but we cannot change min because the max handle is on top of it so they move together if we want to decrease the max. Solution:- We added a one-row difference between the two. When you increase the min towards the max, the max will increase but with one row extra, similarly, the min will decrease with one row extra when the max is decreased towards the min. Fixes #19079 Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video ## Type of change - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual ### 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 - [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 - [x] 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 ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>
2022-12-22 12:48:47 +00:00
import React, { useContext, useReducer } from "react";
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 17:12:00 +00:00
interface AutoHeightLimitsUIState {
isMaxDotDragging: boolean;
isMinDotDragging: boolean;
maxY: number; // the actual value
maxdY: number; // the difference during dragging
minY: number; // the actual value
mindY: number; // the difference during dragging
}
type SET_MAX_Y = { type: "SET_MAX_Y"; payload: { maxY: number } };
type SET_MIN_Y = { type: "SET_MIN_Y"; payload: { minY: number } };
type SET_MAX_D_Y = { type: "SET_MAX_D_Y"; payload: { maxdY: number } };
type SET_MIN_D_Y = { type: "SET_MIN_D_Y"; payload: { mindY: number } };
type SET_IS_MIN_DOT_DRAGGING = {
type: "SET_IS_MIN_DOT_DRAGGING";
payload: { isMinDotDragging: boolean };
};
type SET_IS_MAX_DOT_DRAGGING = {
type: "SET_IS_MAX_DOT_DRAGGING";
payload: { isMaxDotDragging: boolean };
};
type AutoHeightLimitsUIAction =
| SET_MAX_Y
| SET_MIN_Y
| SET_MAX_D_Y
| SET_MIN_D_Y
| SET_IS_MIN_DOT_DRAGGING
| SET_IS_MAX_DOT_DRAGGING;
export function AutoHeightOverlayUIStateReducer(
state: AutoHeightLimitsUIState,
action: AutoHeightLimitsUIAction,
) {
if (action.type === "SET_IS_MAX_DOT_DRAGGING") {
return {
...state,
isMaxDotDragging: action.payload.isMaxDotDragging,
};
}
if (action.type === "SET_IS_MIN_DOT_DRAGGING") {
return {
...state,
isMinDotDragging: action.payload.isMinDotDragging,
};
}
if (action.type === "SET_MAX_Y") {
return {
...state,
maxY: action.payload.maxY,
};
}
if (action.type === "SET_MIN_Y") {
return {
...state,
minY: action.payload.minY,
};
}
if (action.type === "SET_MAX_D_Y") {
return {
...state,
maxdY: action.payload.maxdY,
};
}
if (action.type === "SET_MIN_D_Y") {
return {
...state,
mindY: action.payload.mindY,
};
}
return state;
}
interface CreateInitialAutoHeightUIStateProps {
maxDynamicHeight: number;
minDynamicHeight: number;
}
export function createInitialAutoHeightUIState({
maxDynamicHeight,
minDynamicHeight,
}: CreateInitialAutoHeightUIStateProps) {
return {
isMinDotDragging: false,
isMaxDotDragging: false,
maxY: maxDynamicHeight * GridDefaults.DEFAULT_GRID_ROW_HEIGHT, // the actual value
maxdY: 0, // the difference during dragging
minY: minDynamicHeight * GridDefaults.DEFAULT_GRID_ROW_HEIGHT, // the actual value
mindY: 0, // the difference during dragging
};
}
fix: auto height limits one row difference (#19001) ## Description Issue:- Currently, the min and max limits handle in Auto Height with Limits move with each other on collision, while we can change the max when they have the same values but we cannot change min because the max handle is on top of it so they move together if we want to decrease the max. Solution:- We added a one-row difference between the two. When you increase the min towards the max, the max will increase but with one row extra, similarly, the min will decrease with one row extra when the max is decreased towards the min. Fixes #19079 Media > A video or a GIF is preferred. when using Loom, don’t embed because it looks like it’s a GIF. instead, just link to the video ## Type of change - New feature (non-breaking change which adds functionality) ## How Has This Been Tested? - Manual ### 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 - [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 - [x] 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 ### QA activity: - [ ] Test plan has been approved by relevant developers - [ ] Test plan has been peer reviewed by QA - [ ] Cypress test cases have been added and approved by either SDET or manual QA - [ ] Organized project review call with relevant stakeholders after Round 1/2 of QA - [ ] Added Test Plan Approved label after reveiwing all Cypress test Co-authored-by: Aishwarya UR <aishwarya@appsmith.com>
2022-12-22 12:48:47 +00:00
interface StateContextType {
state: AutoHeightLimitsUIState;
dispatch: React.Dispatch<AutoHeightLimitsUIAction>;
}
export const AutoHeightLimitsStateContext = React.createContext<
StateContextType
>({} as StateContextType);
export const AutoHeightLimitsStateContextProvider: React.FC<{
children: React.ReactNode;
maxDynamicHeight: number;
minDynamicHeight: number;
}> = ({ children, maxDynamicHeight, minDynamicHeight }) => {
const [state, dispatch] = useReducer(
AutoHeightOverlayUIStateReducer,
createInitialAutoHeightUIState({ maxDynamicHeight, minDynamicHeight }),
);
return (
<AutoHeightLimitsStateContext.Provider value={{ state, dispatch }}>
{children}
</AutoHeightLimitsStateContext.Provider>
);
};
export const useAutoHeightLimitsDispatch = () => {
const { dispatch } = useContext(AutoHeightLimitsStateContext);
return dispatch;
};
export const useAutoHeightLimitsState = () => {
const { state } = useContext(AutoHeightLimitsStateContext);
return state;
};