2020-02-18 10:41:52 +00:00
|
|
|
import { createSelector } from "reselect";
|
2020-08-07 14:24:26 +00:00
|
|
|
import {
|
|
|
|
|
getActionsForCurrentPage,
|
|
|
|
|
getAuthUser,
|
|
|
|
|
getUrl,
|
|
|
|
|
} from "./entitiesSelector";
|
2020-02-18 10:41:52 +00:00
|
|
|
import { ActionDataState } from "reducers/entityReducers/actionsReducer";
|
|
|
|
|
import { getEvaluatedDataTree } from "utils/DynamicBindingUtils";
|
2020-04-07 08:01:34 +00:00
|
|
|
import { DataTree, DataTreeFactory } from "entities/DataTree/dataTreeFactory";
|
2020-03-19 03:25:52 +00:00
|
|
|
import { getWidgets, getWidgetsMeta } from "sagas/selectors";
|
2020-03-23 12:40:17 +00:00
|
|
|
import * as log from "loglevel";
|
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";
|
2020-04-01 08:09:57 +00:00
|
|
|
|
2020-06-19 13:06:45 +00:00
|
|
|
export const getUnevaluatedDataTree = (withFunctions?: boolean) =>
|
|
|
|
|
createSelector(
|
|
|
|
|
getActionsForCurrentPage,
|
|
|
|
|
getWidgets,
|
|
|
|
|
getWidgetsMeta,
|
|
|
|
|
getPageList,
|
2020-08-07 14:24:26 +00:00
|
|
|
getAuthUser,
|
|
|
|
|
getUrl,
|
|
|
|
|
(actions, widgets, widgetsMeta, pageListPayload, authUser, url) => {
|
2020-06-19 13:06:45 +00:00
|
|
|
const pageList = pageListPayload || [];
|
|
|
|
|
return DataTreeFactory.create(
|
|
|
|
|
{
|
|
|
|
|
actions,
|
|
|
|
|
widgets,
|
|
|
|
|
widgetsMeta,
|
|
|
|
|
pageList,
|
2020-08-07 14:24:26 +00:00
|
|
|
authUser,
|
|
|
|
|
url,
|
2020-06-19 13:06:45 +00:00
|
|
|
},
|
|
|
|
|
withFunctions,
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
2020-02-18 10:41:52 +00:00
|
|
|
|
2020-06-19 13:06:45 +00:00
|
|
|
export const evaluateDataTree = (withFunctions?: boolean) =>
|
|
|
|
|
createSelector(
|
|
|
|
|
getUnevaluatedDataTree(withFunctions),
|
|
|
|
|
(dataTree: DataTree): DataTree => {
|
|
|
|
|
return getEvaluatedDataTree(dataTree);
|
|
|
|
|
},
|
|
|
|
|
);
|
2020-02-18 10:41:52 +00:00
|
|
|
|
2020-07-06 13:35:31 +00:00
|
|
|
export const evaluateDataTreeWithFunctions = evaluateDataTree(true);
|
|
|
|
|
export const evaluateDataTreeWithoutFunctions = evaluateDataTree(true);
|
|
|
|
|
|
2020-02-18 10:41:52 +00:00
|
|
|
// For autocomplete. Use actions cached responses if
|
|
|
|
|
// there isn't a response already
|
2020-02-26 12:44:56 +00:00
|
|
|
export const getDataTreeForAutocomplete = createSelector(
|
2020-07-06 13:35:31 +00:00
|
|
|
evaluateDataTreeWithoutFunctions,
|
2020-03-19 03:25:52 +00:00
|
|
|
getActionsForCurrentPage,
|
2020-02-26 12:44:56 +00:00
|
|
|
(tree: DataTree, actions: ActionDataState) => {
|
2020-03-23 12:40:17 +00:00
|
|
|
log.debug("Evaluating data tree to get autocomplete values");
|
2020-02-18 10:41:52 +00:00
|
|
|
const cachedResponses: Record<string, any> = {};
|
|
|
|
|
if (actions && actions.length) {
|
|
|
|
|
actions.forEach(action => {
|
2020-02-26 12:44:56 +00:00
|
|
|
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
|
|
|
},
|
2020-02-26 12:44:56 +00:00
|
|
|
);
|