chore: fixed typescript errors which are thrown in EE because of split (#28009)

## Description
few type errors which are being thrown in ee because of the split is
fixed in this PR

#### Type of change
- Chore (housekeeping or task changes that don't impact user perception)

>
>
>
## 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
- [ ] JUnit
- [ ] 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/Guidelines-for-test-plans#speedbreakers-)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans#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
This commit is contained in:
Apeksha Bhosale 2023-10-16 14:53:47 +05:30 committed by GitHub
parent 63a02af32d
commit 575d7fcc36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 91 additions and 56 deletions

View File

@ -626,9 +626,10 @@ describe("5. overrideWidgetProperties", () => {
});
// When default text is re-evaluated it will override values of meta.text and text in InputWidget
it("1. defaultText updating meta.text and text", () => {
const widgetEntity = currentTree.Input1 as WidgetEntity;
const evalMetaUpdates: EvalMetaUpdates = [];
const overwriteObj = overrideWidgetProperties({
entity: currentTree.Input1 as WidgetEntity,
entity: widgetEntity,
propertyPath: "defaultText",
value: "abcde",
@ -643,30 +644,28 @@ describe("5. overrideWidgetProperties", () => {
expect(evalMetaUpdates).toStrictEqual([
{
//@ts-expect-error: widgetId does not exits on type DataTreeEntity
widgetId: currentTree.Input1.widgetId,
widgetId: widgetEntity.widgetId,
metaPropertyPath: ["inputText"],
value: "abcde",
},
{
//@ts-expect-error: widgetId does not exits on type DataTreeEntity
widgetId: currentTree.Input1.widgetId,
widgetId: widgetEntity.widgetId,
metaPropertyPath: ["text"],
value: "abcde",
},
]);
//@ts-expect-error: meta does not exits on type DataTreeEntity
expect(currentTree.Input1.meta).toStrictEqual({
expect(widgetEntity.meta).toStrictEqual({
text: "abcde",
inputText: "abcde",
});
});
// When meta.text is re-evaluated it will override values text in InputWidget
it("2. meta.text updating text", () => {
const widgetEntity = currentTree.Input1 as WidgetEntity;
const evalMetaUpdates: EvalMetaUpdates = [];
const overwriteObj = overrideWidgetProperties({
entity: currentTree.Input1 as WidgetEntity,
entity: widgetEntity,
propertyPath: "meta.text",
value: "abcdefg",
currentTree,
@ -680,8 +679,7 @@ describe("5. overrideWidgetProperties", () => {
expect(evalMetaUpdates).toStrictEqual([]);
//@ts-expect-error: text does not exits on type DataTreeEntity
expect(currentTree.Input1.text).toStrictEqual("abcdefg");
expect(widgetEntity.text).toStrictEqual("abcdefg");
});
});
@ -713,9 +711,10 @@ describe("5. overrideWidgetProperties", () => {
});
// When default defaultSelectedRow is re-evaluated it will override values of meta.selectedRowIndices, selectedRowIndices, meta.selectedRowIndex & selectedRowIndex.
it("1. On change of defaultSelectedRow ", () => {
const widgetEntity = currentTree.Table1 as WidgetEntity;
const evalMetaUpdates: EvalMetaUpdates = [];
const overwriteObj = overrideWidgetProperties({
entity: currentTree.Table1 as WidgetEntity,
entity: widgetEntity,
propertyPath: "defaultSelectedRow",
value: [0, 1],
currentTree,
@ -729,29 +728,27 @@ describe("5. overrideWidgetProperties", () => {
expect(evalMetaUpdates).toStrictEqual([
{
//@ts-expect-error: widgetId does not exits on type DataTreeEntity
widgetId: currentTree.Table1.widgetId,
widgetId: widgetEntity.widgetId,
metaPropertyPath: ["selectedRowIndex"],
value: [0, 1],
},
{
//@ts-expect-error: widgetId does not exits on type DataTreeEntity
widgetId: currentTree.Table1.widgetId,
widgetId: widgetEntity.widgetId,
metaPropertyPath: ["selectedRowIndices"],
value: [0, 1],
},
]);
//@ts-expect-error: meta does not exits on type DataTreeEntity
expect(currentTree.Table1.meta.selectedRowIndex).toStrictEqual([0, 1]);
//@ts-expect-error: meta does not exits on type DataTreeEntity
expect(currentTree.Table1.meta.selectedRowIndices).toStrictEqual([0, 1]);
expect(widgetEntity.meta.selectedRowIndex).toStrictEqual([0, 1]);
expect(widgetEntity.meta.selectedRowIndices).toStrictEqual([0, 1]);
});
// When meta.selectedRowIndex is re-evaluated it will override values selectedRowIndex
it("2. meta.selectedRowIndex updating selectedRowIndex", () => {
const widgetEntity = currentTree.Table1 as WidgetEntity;
const evalMetaUpdates: EvalMetaUpdates = [];
const overwriteObj = overrideWidgetProperties({
entity: currentTree.Table1 as WidgetEntity,
entity: widgetEntity,
propertyPath: "meta.selectedRowIndex",
value: 0,
currentTree,
@ -765,8 +762,7 @@ describe("5. overrideWidgetProperties", () => {
expect(evalMetaUpdates).toStrictEqual([]);
//@ts-expect-error: selectedRowIndex does not exits on type DataTreeEntity
expect(currentTree.Table1.selectedRowIndex).toStrictEqual(0);
expect(widgetEntity.selectedRowIndex).toStrictEqual(0);
});
});
});

View File

@ -737,7 +737,9 @@ const getDataTreeWithoutSuppressedAutoComplete = (
): DataTree => {
const entityIds = Object.keys(dataTree).filter((entityName) => {
const entity = dataTree[entityName];
return isWidget(entity) && shouldSuppressAutoComplete(entity);
return (
isWidget(entity) && shouldSuppressAutoComplete(entity as WidgetEntity)
);
});
return _.omit(dataTree, entityIds);

View File

@ -24,6 +24,7 @@ import history, { NavigationMethod } from "utils/history";
import { jsCollectionIdURL } from "@appsmith/RouteBuilder";
import store from "store";
import { PluginType } from "entities/Action";
import type { WidgetEntity } from "@appsmith/entities/DataTree/types";
export const useFilteredLogs = (query: string, filter?: any) => {
let logs = useSelector((state: AppState) => state.ui.debugger.logs);
@ -141,8 +142,9 @@ export const useEntityLink = () => {
const entityConfig = configTree[name];
if (!pageId) return;
if (isWidget(entity)) {
const widgetEntity = entity as WidgetEntity;
navigateToWidget(
entity.widgetId,
widgetEntity.widgetId,
entity.type,
pageId || "",
NavigationMethod.Debugger,

View File

@ -16,6 +16,7 @@ import {
import { doesEntityHaveErrors } from "../helpers";
import React from "react";
import WidgetIcon from "pages/Editor/Explorer/Widgets/WidgetIcon";
import type { WidgetEntity } from "@appsmith/entities/DataTree/types";
export const useGetEntityInfo = (name: string) => {
const entity = useSelector((state: AppState) => state.evaluations.tree[name]);
@ -36,15 +37,19 @@ export const useGetEntityInfo = (name: string) => {
const getEntityInfo = useCallback(() => {
if (isWidget(entity)) {
const widgetEntity = entity as WidgetEntity;
const icon = <WidgetIcon type={entity.type} />;
const hasError = doesEntityHaveErrors(entity.widgetId, debuggerErrors);
const hasError = doesEntityHaveErrors(
widgetEntity.widgetId,
debuggerErrors,
);
return {
name,
icon,
hasError,
type: ENTITY_TYPE.WIDGET,
entityType: entity.type,
entityType: widgetEntity.type,
};
} else if (isAction(entity)) {
const hasError = doesEntityHaveErrors(entity.actionId, debuggerErrors);

View File

@ -49,31 +49,33 @@ export default class EntityFactory {
T extends DataTreeEntity,
K extends DataTreeEntityConfig | undefined,
>(entity: T, config: K, classLoader: EntityClassLoader): IEntity {
const { DiffGenerator, Parser } = classLoader.load(entity);
const { DiffGenerator, Parser } = classLoader.load(
entity as DataTreeEntity,
);
if (isWidget(entity)) {
return new WidgetEntity(
entity,
entity as TWidgetEntity,
config as TWidgetEntityConfig,
new Parser(),
new DiffGenerator(),
);
} else if (isJSAction(entity)) {
return new JSEntity(
entity,
entity as TJSActionEntity,
config as TJSActionEntityConfig,
new Parser(),
new DiffGenerator(),
);
} else if (isAction(entity)) {
return new ActionEntity(
entity,
entity as TActionEntity,
config as TActionEntityConfig,
new Parser(),
new DiffGenerator(),
);
} else if (isAppsmith(entity)) {
return new AppsmithEntity(
entity,
entity as TAppsmithEntity,
undefined,
new Parser(),
new DiffGenerator(),

View File

@ -13,7 +13,10 @@ import { getType, Types } from "utils/TypeHelpers";
import type { FlattenedWidgetProps } from "WidgetProvider/constants";
import { ReduxActionTypes } from "@appsmith/constants/ReduxActionConstants";
import { getDataTree, getConfigTree } from "selectors/dataTreeSelectors";
import type { WidgetEntityConfig } from "@appsmith/entities/DataTree/types";
import type {
WidgetEntity,
WidgetEntityConfig,
} from "@appsmith/entities/DataTree/types";
import type { DataTree, ConfigTree } from "entities/DataTree/dataTreeTypes";
import { isWidget } from "@appsmith/workers/Evaluation/evaluationUtils";
import type { TResetWidgetDescription } from "workers/Evaluation/fns/resetWidget";
@ -47,7 +50,7 @@ export default function* resetWidgetActionSaga(
yield put(
resetWidgetMetaProperty(
widget.widgetId,
evaluatedEntity,
evaluatedEntity as WidgetEntity,
evaluatedEntityConfig as WidgetEntityConfig,
),
);

View File

@ -64,6 +64,10 @@ import {
isWidget,
} from "@appsmith/workers/Evaluation/evaluationUtils";
import { getCurrentEnvironmentDetails } from "@appsmith/selectors/environmentSelectors";
import type {
ActionEntity,
WidgetEntity,
} from "@appsmith/entities/DataTree/types";
import { getActiveEditorField } from "selectors/activeEditorFieldSelectors";
let blockedSource: string | null = null;
@ -186,23 +190,25 @@ function getLogsFromDependencyChain(
};
if (isAction(entity)) {
const actionEntity = entity as ActionEntity;
log = {
...log,
text: createMessage(ACTION_CONFIGURATION_UPDATED),
source: {
type: ENTITY_TYPE.ACTION,
name: entityInfo.entityName,
id: entity.actionId,
id: actionEntity.actionId,
},
};
} else if (isWidget(entity)) {
const widgetEntity = entity as WidgetEntity;
log = {
...log,
text: createMessage(WIDGET_PROPERTIES_UPDATED),
source: {
type: ENTITY_TYPE.WIDGET,
name: entityInfo.entityName,
id: entity.widgetId,
id: widgetEntity.widgetId,
},
};
}

View File

@ -4,7 +4,12 @@ import {
PLATFORM_ERROR,
Severity,
} from "entities/AppsmithConsole";
import type { WidgetEntityConfig } from "@appsmith/entities/DataTree/types";
import type {
ActionEntity,
JSActionEntity,
WidgetEntity,
WidgetEntityConfig,
} from "@appsmith/entities/DataTree/types";
import type {
ConfigTree,
DataTree,
@ -75,7 +80,10 @@ function logLatestEvalPropertyErrors(
for (const evaluatedPath of evalAndValidationOrder) {
const { entityName, propertyPath } =
getEntityNameAndPropertyPath(evaluatedPath);
const entity = dataTree[entityName];
const entity = dataTree[entityName] as
| WidgetEntity
| ActionEntity
| JSActionEntity;
const entityConfig = configTree[entityName] as any;
if (isWidget(entity) || isAction(entity) || isJSAction(entity)) {
@ -490,7 +498,10 @@ export function* updateTernDefinitions(
);
const entity = dataTree[entityName];
if (!entity || !isWidget(entity)) return false;
return isWidgetPropertyNamePath(entity, update.payload.propertyPath);
return isWidgetPropertyNamePath(
entity as WidgetEntity,
update.payload.propertyPath,
);
});
if (!shouldUpdate) return;

View File

@ -46,22 +46,24 @@ export const getFilteredErrors = createSelector(
// filter error - when widget or parent widget is hidden
// parent widgets e.g. modal, tab, container
if (entity && isWidget(entity)) {
if (shouldSuppressDebuggerError(entity)) {
const widgetEntity = entity as WidgetEntity;
if (shouldSuppressDebuggerError(widgetEntity)) {
return false;
}
if (!hasParentWidget(entity)) {
return entity.isVisible
if (!hasParentWidget(widgetEntity)) {
return widgetEntity.isVisible
? true
: alwaysShowEntities[entity.widgetId];
: alwaysShowEntities[widgetEntity.widgetId];
} else {
const isParentWidgetVisible = isParentVisible(
entity,
widgetEntity,
canvasWidgets,
dataTree,
);
return entity.isVisible
return widgetEntity.isVisible
? isParentWidgetVisible
: isParentWidgetVisible && alwaysShowEntities[entity.widgetId];
: isParentWidgetVisible &&
alwaysShowEntities[widgetEntity.widgetId];
}
}
return true;

View File

@ -1,6 +1,7 @@
import type {
WidgetEntityConfig,
JSActionEntityConfig,
WidgetEntity,
} from "@appsmith/entities/DataTree/types";
import type {
ConfigTree,
@ -57,7 +58,7 @@ export const dataTreeTypeDefCreator = (
if (isFunction(autocompleteDefinitions)) {
def[entityName] = autocompleteDefinitions(
entity,
entity as WidgetEntity,
extraDefsToDefine,
entityConfig,
);

View File

@ -119,10 +119,11 @@ export const entityFns = [
name: "run",
qualifier: (entity: DataTreeEntity) => isAction(entity),
fn: (entity: DataTreeEntity, entityName: string) => {
const actionEntity = entity as ActionEntity;
// @ts-expect-error: name is not defined on ActionEntity
entity.name = entityName;
actionEntity.name = entityName;
return getFnWithGuards(
run.bind(entity as ActionEntity),
run.bind(actionEntity as ActionEntity),
`${entityName}.run`,
[isAsyncGuard],
);

View File

@ -39,7 +39,7 @@ export function getEntityForEvalContext(
switch (entity.ENTITY_TYPE) {
case ENTITY_TYPE_VALUE.JSACTION: {
const jsObjectName = entityName;
const jsObject = entity;
const jsObject = entity as JSActionEntity;
let jsObjectForEval = JSObjectCollection.getVariableState(entityName);

View File

@ -8,7 +8,10 @@ import { evalTreeWithChanges } from "./evalTreeWithChanges";
import { dataTreeEvaluator } from "./handlers/evalTree";
import { get, set } from "lodash";
import { validate } from "./validations";
import type { DataTreeEntityConfig } from "@appsmith/entities/DataTree/types";
import type {
DataTreeEntityConfig,
WidgetEntity,
} from "@appsmith/entities/DataTree/types";
import type {
ConfigTree,
DataTree,
@ -89,7 +92,7 @@ class Setters {
if (isWidget(entity)) {
overrideWidgetProperties({
entity,
entity: entity as WidgetEntity,
propertyPath,
value: parsedValue,
currentTree: evalTree,

View File

@ -1046,9 +1046,7 @@ export default class DataTreeEvaluator {
);
const entityType = entityConfig.ENTITY_TYPE;
if (!propertyPath) continue;
switch (entityType) {
case ENTITY_TYPE_VALUE.WIDGET: {
if (isATriggerPath) continue;
@ -1278,7 +1276,7 @@ export default class DataTreeEvaluator {
const node = result.cyclicNode;
let entityType = "UNKNOWN";
const entityName = node.split(".")[0];
const entity = get(this.oldUnEvalTree, entityName);
const entity = get(this.oldUnEvalTree, entityName) as DataTreeEntity;
const entityConfig = get(this.oldConfigTree, entityName);
if (entity && isWidget(entity)) {
entityType = entity.type;

View File

@ -16,6 +16,7 @@ import { replaceThisDotParams } from "./utils";
import { isDataField } from "./utils";
import widgets from "widgets";
import type { WidgetConfiguration } from "WidgetProvider/constants";
import type { WidgetEntity } from "@appsmith/entities/DataTree/types";
const widgetConfigMap: Record<
string,
@ -179,10 +180,11 @@ describe("DataTreeEvaluator", () => {
event: "EDIT",
},
];
const button2 = dataTreeEvaluator.oldUnEvalTree.Button2 as WidgetEntity;
const newUnevalTree = {
...dataTreeEvaluator.oldUnEvalTree,
Button2: {
...dataTreeEvaluator.oldUnEvalTree.Button2,
...button2,
text: '{{""}}',
},
};
@ -210,10 +212,11 @@ describe("DataTreeEvaluator", () => {
event: "EDIT",
},
];
const button2 = dataTreeEvaluator.oldUnEvalTree.Button2 as WidgetEntity;
const newUnevalTree = {
...dataTreeEvaluator.oldUnEvalTree,
Button2: {
...dataTreeEvaluator.oldUnEvalTree.Button2,
...button2,
text: "abc",
},
};