## Description - Enabled the rule `@typescript-eslint/no-explicit-any` - Suppressed errors with comment ``` // TODO: Fix this the next time the file is edited // eslint-disable-next-line @typescript-eslint/no-explicit-any ``` Fixes #35308 ## Automation /ok-to-test tags="@tag.All" ### 🔍 Cypress test results <!-- This is an auto-generated comment: Cypress test results --> > [!TIP] > 🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉 > Workflow run: <https://github.com/appsmithorg/appsmith/actions/runs/10181176984> > Commit: 7fc604e24fa234da7ab2ff56e0b1c715268796ee > <a href="https://internal.appsmith.com/app/cypress-dashboard/rundetails-65890b3c81d7400d08fa9ee5?branch=master&workflowId=10181176984&attempt=2" target="_blank">Cypress dashboard</a>. > Tags: `@tag.All` > Spec: > <hr>Wed, 31 Jul 2024 15:00:45 UTC <!-- end of auto-generated comment: Cypress test results --> ## Communication Should the DevRel and Marketing teams inform users about this change? - [ ] Yes - [x] No
189 lines
4.3 KiB
TypeScript
189 lines
4.3 KiB
TypeScript
import { get, set } from "lodash";
|
|
import type { Diff } from "deep-diff";
|
|
|
|
import type { CanvasWidgetsReduxState } from "reducers/entityReducers/canvasWidgetsReducer";
|
|
|
|
export type DSLDiff = Diff<CanvasWidgetsReduxState, CanvasWidgetsReduxState>;
|
|
|
|
const positionProps = [
|
|
"leftColumn",
|
|
"rightColumn",
|
|
"topRow",
|
|
"bottomRow",
|
|
"minHeight",
|
|
"parentColumnSpace",
|
|
"parentRowSpace",
|
|
"children",
|
|
"parentId",
|
|
"renderMode",
|
|
"detachFromLayout",
|
|
"noContainerOffset",
|
|
"isCanvas",
|
|
"height",
|
|
];
|
|
|
|
export const TOASTS = "toasts";
|
|
export const FOCUSES = "needsFocus";
|
|
export const UPDATES = "propertyUpdates";
|
|
|
|
export const WIDGETS = "widgets";
|
|
|
|
/**
|
|
* this function update the replay object that holds info about change happened in widgets
|
|
* also, it creates toast for new/deleted widgets on undo/redo
|
|
*
|
|
* @param dsl
|
|
* @param diff
|
|
* @param replay
|
|
* @param isUndo
|
|
* @returns
|
|
*/
|
|
export function processDiff(
|
|
dsl: CanvasWidgetsReduxState,
|
|
diff: DSLDiff,
|
|
// TODO: Fix this the next time the file is edited
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
replay: any,
|
|
isUndo: boolean,
|
|
) {
|
|
if (!diff || !diff.path || !diff.path.length || diff.path[0] === "0") return;
|
|
|
|
const widgetId = diff.path[0];
|
|
|
|
switch (diff.kind) {
|
|
// new elements is added in dsl
|
|
case "N":
|
|
if (diff.path.length == 1) {
|
|
const toast = createToast(
|
|
diff.rhs,
|
|
dsl[widgetId],
|
|
widgetId,
|
|
isUndo,
|
|
!isUndo,
|
|
);
|
|
addToArray(replay, TOASTS, toast);
|
|
} else {
|
|
setPropertyUpdate(replay, [WIDGETS, widgetId, UPDATES], diff.path);
|
|
}
|
|
break;
|
|
// element is deleted in dsl
|
|
case "D":
|
|
if (diff.path.length == 1) {
|
|
const toast = createToast(
|
|
diff.lhs,
|
|
dsl[widgetId],
|
|
widgetId,
|
|
isUndo,
|
|
isUndo,
|
|
);
|
|
addToArray(replay, TOASTS, toast);
|
|
} else {
|
|
setPropertyUpdate(replay, [WIDGETS, widgetId, UPDATES], diff.path);
|
|
}
|
|
break;
|
|
// element is edited
|
|
case "E":
|
|
if (isPositionUpdate(diff.path[diff.path.length - 1])) {
|
|
set(replay, [WIDGETS, widgetId, FOCUSES], true);
|
|
} else {
|
|
setPropertyUpdate(replay, [WIDGETS, widgetId, UPDATES], diff.path);
|
|
}
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* creates toast on undo/redo ( most used in addition/deletion of widgets )
|
|
*
|
|
* @param diffWidget
|
|
* @param dslWidget
|
|
* @param widgetId
|
|
* @param isUndo
|
|
* @param isCreated
|
|
* @returns
|
|
*/
|
|
function createToast(
|
|
diffWidget: CanvasWidgetsReduxState,
|
|
dslWidget: CanvasWidgetsReduxState | undefined,
|
|
widgetId: string,
|
|
isUndo: boolean,
|
|
isCreated: boolean,
|
|
) {
|
|
const widgetName = isCreated ? diffWidget.widgetName : dslWidget?.widgetName;
|
|
return {
|
|
isCreated,
|
|
isUndo,
|
|
widgetName,
|
|
widgetId,
|
|
};
|
|
}
|
|
|
|
/**
|
|
* checks property changed is a positional property
|
|
*
|
|
* @param widgetProperty
|
|
* @returns
|
|
*/
|
|
function isPositionUpdate(widgetProperty: string) {
|
|
return positionProps.indexOf(widgetProperty) !== -1;
|
|
}
|
|
|
|
/**
|
|
* checks the existing value and sets he propertyUpdate if required
|
|
*
|
|
* @param replay
|
|
* @param path
|
|
* @param value
|
|
* @returns
|
|
*/
|
|
// TODO: Fix this the next time the file is edited
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
function setPropertyUpdate(replay: any, path: string[], value: string[]) {
|
|
const existingPathValue = get(replay, path);
|
|
|
|
if (!existingPathValue || existingPathValue.length > 2) {
|
|
set(replay, path, value);
|
|
set(replay, UPDATES, true);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* pushes value to array element in array of objects
|
|
*
|
|
* @param obj
|
|
* @param key
|
|
* @param value
|
|
* @returns
|
|
*/
|
|
// TODO: Fix this the next time the file is edited
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
function addToArray(obj: any, key: string, value: any) {
|
|
if (!obj) return;
|
|
|
|
if (obj[key] && Array.isArray(obj[key])) {
|
|
obj[key].push(value);
|
|
} else {
|
|
obj[key] = [value];
|
|
}
|
|
}
|
|
|
|
/**
|
|
* creates paths changed from diffs array
|
|
*
|
|
* @param diffs
|
|
* @returns
|
|
*/
|
|
// TODO: Fix this the next time the file is edited
|
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
export function getPathsFromDiff(diffs: any) {
|
|
const paths = [];
|
|
|
|
for (const diff of diffs) {
|
|
paths.push(diff.path.join("."));
|
|
}
|
|
|
|
return paths;
|
|
}
|