PromucFlow_constructor/app/client/src/selectors/nameBindingsWithDataSelector.ts
Hetu Nandu 005c00a145 Revert "Selected Option is now available in dropdown widget."
This reverts commit c45198e9927dbb520ef1f3c26f9cfeddbd76995e.
2019-12-19 15:03:27 +05:30

25 lines
790 B
TypeScript

import { DataTree } from "reducers";
import { JSONPath } from "jsonpath-plus";
import { createSelector } from "reselect";
import { getDataTree } from "./entitiesSelector";
export type NameBindingsWithData = Record<string, object>;
export const getNameBindingsWithData = createSelector(
getDataTree,
(dataTree: DataTree): NameBindingsWithData => {
const nameBindingsWithData: Record<string, object> = {};
Object.keys(dataTree.nameBindings).forEach(key => {
const nameBindings = dataTree.nameBindings[key];
const evaluatedValue = JSONPath({
path: nameBindings,
json: dataTree,
})[0];
if (evaluatedValue && key !== "undefined") {
nameBindingsWithData[key] = evaluatedValue;
}
});
return nameBindingsWithData;
},
);