fix: Remove private widgets from autocompletion (#10535)
This commit is contained in:
parent
6bc1bdd5e1
commit
1b858bcf5c
|
|
@ -3,6 +3,7 @@ import { DataTree } from "entities/DataTree/dataTreeFactory";
|
||||||
import {
|
import {
|
||||||
DataTreeDiff,
|
DataTreeDiff,
|
||||||
DataTreeDiffEvent,
|
DataTreeDiffEvent,
|
||||||
|
getDataTreeWithoutPrivateWidgets,
|
||||||
getEntityNameAndPropertyPath,
|
getEntityNameAndPropertyPath,
|
||||||
isAction,
|
isAction,
|
||||||
isJSAction,
|
isJSAction,
|
||||||
|
|
@ -367,7 +368,13 @@ export function* updateTernDefinitions(
|
||||||
}
|
}
|
||||||
if (shouldUpdate) {
|
if (shouldUpdate) {
|
||||||
const start = performance.now();
|
const start = performance.now();
|
||||||
const { def, entityInfo } = dataTreeTypeDefCreator(dataTree);
|
// remove private widgets from dataTree used for autocompletion
|
||||||
|
const treeWithoutPrivateWidgets = getDataTreeWithoutPrivateWidgets(
|
||||||
|
dataTree,
|
||||||
|
);
|
||||||
|
const { def, entityInfo } = dataTreeTypeDefCreator(
|
||||||
|
treeWithoutPrivateWidgets,
|
||||||
|
);
|
||||||
TernServer.updateDef("DATA_TREE", def, entityInfo);
|
TernServer.updateDef("DATA_TREE", def, entityInfo);
|
||||||
const end = performance.now();
|
const end = performance.now();
|
||||||
log.debug("Tern", { updates });
|
log.debug("Tern", { updates });
|
||||||
|
|
|
||||||
|
|
@ -225,6 +225,7 @@ const BASE_WIDGET: DataTreeWidget = {
|
||||||
triggerPaths: {},
|
triggerPaths: {},
|
||||||
validationPaths: {},
|
validationPaths: {},
|
||||||
ENTITY_TYPE: ENTITY_TYPE.WIDGET,
|
ENTITY_TYPE: ENTITY_TYPE.WIDGET,
|
||||||
|
privateWidgets: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
const BASE_ACTION: DataTreeAction = {
|
const BASE_ACTION: DataTreeAction = {
|
||||||
|
|
@ -247,6 +248,7 @@ const BASE_ACTION: DataTreeAction = {
|
||||||
data: EvaluationSubstitutionType.TEMPLATE,
|
data: EvaluationSubstitutionType.TEMPLATE,
|
||||||
},
|
},
|
||||||
dependencyMap: {},
|
dependencyMap: {},
|
||||||
|
datasourceUrl: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
describe("DataTreeEvaluator", () => {
|
describe("DataTreeEvaluator", () => {
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,106 @@
|
||||||
import { PrivateWidgets } from "entities/DataTree/dataTreeFactory";
|
import { RenderModes } from "constants/WidgetConstants";
|
||||||
import { getAllPaths, isPrivateEntityPath } from "./evaluationUtils";
|
import { ValidationTypes } from "constants/WidgetValidation";
|
||||||
|
import {
|
||||||
|
DataTreeWidget,
|
||||||
|
ENTITY_TYPE,
|
||||||
|
EvaluationSubstitutionType,
|
||||||
|
PrivateWidgets,
|
||||||
|
} from "entities/DataTree/dataTreeFactory";
|
||||||
|
import {
|
||||||
|
getAllPaths,
|
||||||
|
getAllPrivateWidgetsInDataTree,
|
||||||
|
getDataTreeWithoutPrivateWidgets,
|
||||||
|
isPrivateEntityPath,
|
||||||
|
} from "./evaluationUtils";
|
||||||
|
|
||||||
|
const BASE_WIDGET: DataTreeWidget = {
|
||||||
|
logBlackList: {},
|
||||||
|
widgetId: "randomID",
|
||||||
|
widgetName: "randomWidgetName",
|
||||||
|
bottomRow: 0,
|
||||||
|
isLoading: false,
|
||||||
|
leftColumn: 0,
|
||||||
|
parentColumnSpace: 0,
|
||||||
|
parentRowSpace: 0,
|
||||||
|
renderMode: RenderModes.CANVAS,
|
||||||
|
rightColumn: 0,
|
||||||
|
topRow: 0,
|
||||||
|
type: "SKELETON_WIDGET",
|
||||||
|
parentId: "0",
|
||||||
|
version: 1,
|
||||||
|
bindingPaths: {},
|
||||||
|
triggerPaths: {},
|
||||||
|
validationPaths: {},
|
||||||
|
ENTITY_TYPE: ENTITY_TYPE.WIDGET,
|
||||||
|
privateWidgets: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
const testDataTree: Record<string, DataTreeWidget> = {
|
||||||
|
Text1: {
|
||||||
|
...BASE_WIDGET,
|
||||||
|
widgetName: "Text1",
|
||||||
|
text: "Label",
|
||||||
|
type: "TEXT_WIDGET",
|
||||||
|
bindingPaths: {
|
||||||
|
text: EvaluationSubstitutionType.TEMPLATE,
|
||||||
|
},
|
||||||
|
validationPaths: {
|
||||||
|
text: { type: ValidationTypes.TEXT },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Text2: {
|
||||||
|
...BASE_WIDGET,
|
||||||
|
widgetName: "Text2",
|
||||||
|
text: "{{Text1.text}}",
|
||||||
|
dynamicBindingPathList: [{ key: "text" }],
|
||||||
|
type: "TEXT_WIDGET",
|
||||||
|
bindingPaths: {
|
||||||
|
text: EvaluationSubstitutionType.TEMPLATE,
|
||||||
|
},
|
||||||
|
validationPaths: {
|
||||||
|
text: { type: ValidationTypes.TEXT },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Text3: {
|
||||||
|
...BASE_WIDGET,
|
||||||
|
widgetName: "Text3",
|
||||||
|
text: "{{Text1.text}}",
|
||||||
|
dynamicBindingPathList: [{ key: "text" }],
|
||||||
|
type: "TEXT_WIDGET",
|
||||||
|
bindingPaths: {
|
||||||
|
text: EvaluationSubstitutionType.TEMPLATE,
|
||||||
|
},
|
||||||
|
validationPaths: {
|
||||||
|
text: { type: ValidationTypes.TEXT },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Text4: {
|
||||||
|
...BASE_WIDGET,
|
||||||
|
widgetName: "Text4",
|
||||||
|
text: "{{Text1.text}}",
|
||||||
|
dynamicBindingPathList: [{ key: "text" }],
|
||||||
|
type: "TEXT_WIDGET",
|
||||||
|
bindingPaths: {
|
||||||
|
text: EvaluationSubstitutionType.TEMPLATE,
|
||||||
|
},
|
||||||
|
validationPaths: {
|
||||||
|
text: { type: ValidationTypes.TEXT },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
List1: {
|
||||||
|
...BASE_WIDGET,
|
||||||
|
privateWidgets: {
|
||||||
|
Text2: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
List2: {
|
||||||
|
...BASE_WIDGET,
|
||||||
|
privateWidgets: {
|
||||||
|
Text3: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
describe("Correctly handle paths", () => {
|
describe("Correctly handle paths", () => {
|
||||||
it("getsAllPaths", () => {
|
it("getsAllPaths", () => {
|
||||||
|
|
@ -39,7 +140,9 @@ describe("Correctly handle paths", () => {
|
||||||
const actual = getAllPaths(myTree);
|
const actual = getAllPaths(myTree);
|
||||||
expect(actual).toStrictEqual(result);
|
expect(actual).toStrictEqual(result);
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("privateWidgets", () => {
|
||||||
it("correctly checks if path is a PrivateEntityPath", () => {
|
it("correctly checks if path is a PrivateEntityPath", () => {
|
||||||
const privateWidgets: PrivateWidgets = {
|
const privateWidgets: PrivateWidgets = {
|
||||||
Button1: true,
|
Button1: true,
|
||||||
|
|
@ -57,4 +160,72 @@ describe("Correctly handle paths", () => {
|
||||||
).toBeFalsy();
|
).toBeFalsy();
|
||||||
expect(isPrivateEntityPath(privateWidgets, "Image2.data")).toBeTruthy();
|
expect(isPrivateEntityPath(privateWidgets, "Image2.data")).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Returns list of all privateWidgets", () => {
|
||||||
|
const expectedPrivateWidgetsList = {
|
||||||
|
Text2: true,
|
||||||
|
Text3: true,
|
||||||
|
};
|
||||||
|
|
||||||
|
const actualPrivateWidgetsList = getAllPrivateWidgetsInDataTree(
|
||||||
|
testDataTree,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(expectedPrivateWidgetsList).toStrictEqual(actualPrivateWidgetsList);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("Returns data tree without privateWidgets", () => {
|
||||||
|
const expectedDataTreeWithoutPrivateWidgets: Record<
|
||||||
|
string,
|
||||||
|
DataTreeWidget
|
||||||
|
> = {
|
||||||
|
Text1: {
|
||||||
|
...BASE_WIDGET,
|
||||||
|
widgetName: "Text1",
|
||||||
|
text: "Label",
|
||||||
|
type: "TEXT_WIDGET",
|
||||||
|
bindingPaths: {
|
||||||
|
text: EvaluationSubstitutionType.TEMPLATE,
|
||||||
|
},
|
||||||
|
validationPaths: {
|
||||||
|
text: { type: ValidationTypes.TEXT },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
Text4: {
|
||||||
|
...BASE_WIDGET,
|
||||||
|
widgetName: "Text4",
|
||||||
|
text: "{{Text1.text}}",
|
||||||
|
dynamicBindingPathList: [{ key: "text" }],
|
||||||
|
type: "TEXT_WIDGET",
|
||||||
|
bindingPaths: {
|
||||||
|
text: EvaluationSubstitutionType.TEMPLATE,
|
||||||
|
},
|
||||||
|
validationPaths: {
|
||||||
|
text: { type: ValidationTypes.TEXT },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
List1: {
|
||||||
|
...BASE_WIDGET,
|
||||||
|
privateWidgets: {
|
||||||
|
Text2: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
List2: {
|
||||||
|
...BASE_WIDGET,
|
||||||
|
privateWidgets: {
|
||||||
|
Text3: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const actualDataTreeWithoutPrivateWidgets = getDataTreeWithoutPrivateWidgets(
|
||||||
|
testDataTree,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(expectedDataTreeWithoutPrivateWidgets).toStrictEqual(
|
||||||
|
actualDataTreeWithoutPrivateWidgets,
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -722,3 +722,27 @@ export const isPrivateEntityPath = (
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getAllPrivateWidgetsInDataTree = (
|
||||||
|
dataTree: DataTree,
|
||||||
|
): PrivateWidgets => {
|
||||||
|
let privateWidgets: PrivateWidgets = {};
|
||||||
|
|
||||||
|
Object.keys(dataTree).forEach((entityName) => {
|
||||||
|
const entity = dataTree[entityName];
|
||||||
|
if (isWidget(entity) && !_.isEmpty(entity.privateWidgets)) {
|
||||||
|
privateWidgets = { ...privateWidgets, ...entity.privateWidgets };
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return privateWidgets;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getDataTreeWithoutPrivateWidgets = (
|
||||||
|
dataTree: DataTree,
|
||||||
|
): DataTree => {
|
||||||
|
const privateWidgets = getAllPrivateWidgetsInDataTree(dataTree);
|
||||||
|
const privateWidgetNames = Object.keys(privateWidgets);
|
||||||
|
const treeWithoutPrivateWidgets = _.omit(dataTree, privateWidgetNames);
|
||||||
|
return treeWithoutPrivateWidgets;
|
||||||
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user