PromucFlow_constructor/app/client/src/selectors/dataTreeSelectors.ts

70 lines
2.0 KiB
TypeScript
Raw Normal View History

2020-02-18 10:41:52 +00:00
import { createSelector } from "reselect";
import {
getActionsForCurrentPage,
getAppData,
getPluginEditorConfigs,
} from "./entitiesSelector";
2020-02-18 10:41:52 +00:00
import { ActionDataState } from "reducers/entityReducers/actionsReducer";
2020-04-07 08:01:34 +00:00
import { DataTree, DataTreeFactory } from "entities/DataTree/dataTreeFactory";
import { getWidgets, getWidgetsMeta } from "sagas/selectors";
2020-04-01 08:09:57 +00:00
import "url-search-params-polyfill";
2020-04-20 05:42:46 +00:00
import { getPageList } from "./appViewSelectors";
import { AppState } from "reducers";
2020-04-01 08:09:57 +00:00
export const getUnevaluatedDataTree = createSelector(
getActionsForCurrentPage,
getWidgets,
getWidgetsMeta,
getPageList,
getAppData,
getPluginEditorConfigs,
(actions, widgets, widgetsMeta, pageListPayload, appData, editorConfigs) => {
const pageList = pageListPayload || [];
2021-03-31 07:40:59 +00:00
return DataTreeFactory.create({
actions,
widgets,
widgetsMeta,
pageList,
appData,
editorConfigs,
});
},
);
2020-02-18 10:41:52 +00:00
export const getEvaluationInverseDependencyMap = (state: AppState) =>
state.evaluations.dependencies.inverseDependencyMap;
2021-01-14 14:37:21 +00:00
export const getLoadingEntities = (state: AppState) =>
state.evaluations.loadingEntities;
/**
* returns evaluation tree object
*
* @param state
*/
export const getDataTree = (state: AppState) => state.evaluations.tree;
2020-02-18 10:41:52 +00:00
// For autocomplete. Use actions cached responses if
// there isn't a response already
export const getDataTreeForAutocomplete = createSelector(
getDataTree,
getActionsForCurrentPage,
(tree: DataTree, actions: ActionDataState) => {
2020-02-18 10:41:52 +00:00
const cachedResponses: Record<string, any> = {};
if (actions && actions.length) {
2020-12-24 04:32:25 +00:00
actions.forEach((action) => {
if (!(action.config.name in tree) && action.config.cacheResponse) {
2020-02-18 10:41:52 +00:00
try {
cachedResponses[action.config.name] = JSON.parse(
action.config.cacheResponse,
);
} catch (e) {
cachedResponses[action.config.name] = action.config.cacheResponse;
}
}
});
}
2020-06-04 13:49:22 +00:00
return tree;
2020-02-18 10:41:52 +00:00
},
);