2019-10-31 08:36:04 +00:00
|
|
|
import { createSelector } from "reselect";
|
2019-11-08 11:02:00 +00:00
|
|
|
import { AppState, DataTree } from "../reducers";
|
2019-10-31 08:36:04 +00:00
|
|
|
import { AppViewReduxState } from "../reducers/uiReducers/appViewReducer";
|
|
|
|
|
import { AppViewerProps } from "../pages/AppViewer";
|
2019-11-14 09:28:51 +00:00
|
|
|
import { getDataTree } from "./entitiesSelector";
|
2019-11-14 11:17:36 +00:00
|
|
|
import createCachedSelector from "re-reselect";
|
|
|
|
|
import CanvasWidgetsNormalizer from "normalizers/CanvasWidgetsNormalizer";
|
2019-11-19 12:44:58 +00:00
|
|
|
import { getValidatedDynamicProps } from "./editorSelectors";
|
|
|
|
|
import { CanvasWidgetsReduxState } from "../reducers/entityReducers/canvasWidgetsReducer";
|
2019-10-31 08:36:04 +00:00
|
|
|
|
2019-11-07 04:59:40 +00:00
|
|
|
const getAppViewState = (state: AppState) => state.ui.appView;
|
2019-10-31 08:36:04 +00:00
|
|
|
|
|
|
|
|
export const getCurrentLayoutId = (state: AppState, props: AppViewerProps) =>
|
2019-11-07 04:59:40 +00:00
|
|
|
state.ui.appView.currentLayoutId || props.match.params.layoutId;
|
|
|
|
|
export const getCurrentPageId = (state: AppState, props: AppViewerProps) =>
|
|
|
|
|
state.ui.appView.currentPageId || props.match.params.pageId;
|
2019-11-06 06:21:56 +00:00
|
|
|
export const getCurrentRoutePageId = (state: AppState, props: AppViewerProps) =>
|
|
|
|
|
props.match.params.pageId;
|
2019-10-31 08:36:04 +00:00
|
|
|
|
|
|
|
|
// For the viewer, this does not need to be wrapped in createCachedSelector, as it will not change in subsequent renders.
|
2019-11-14 11:17:36 +00:00
|
|
|
// export const getCurrentPageLayoutDSL = createSelector(
|
|
|
|
|
// getAppViewState,
|
|
|
|
|
// getDataTree,
|
|
|
|
|
// (view: AppViewReduxState, dataTree: DataTree) =>
|
|
|
|
|
// injectDataTreeIntoDsl(dataTree, view.dsl),
|
|
|
|
|
// );
|
2019-10-31 08:36:04 +00:00
|
|
|
|
|
|
|
|
export const getPageList = createSelector(
|
|
|
|
|
getAppViewState,
|
|
|
|
|
(view: AppViewReduxState) => (view.pages.length > 0 ? view.pages : undefined),
|
|
|
|
|
);
|
2019-11-06 06:21:56 +00:00
|
|
|
|
|
|
|
|
export const getIsFetchingPage = createSelector(
|
|
|
|
|
getAppViewState,
|
|
|
|
|
(view: AppViewReduxState) => view.isFetchingPage,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
export const getCurrentDSLPageId = createSelector(
|
|
|
|
|
getAppViewState,
|
|
|
|
|
(view: AppViewReduxState) => view.currentPageId,
|
|
|
|
|
);
|
2019-11-14 11:17:36 +00:00
|
|
|
|
|
|
|
|
export const getPageWidgetId = createSelector(
|
|
|
|
|
getAppViewState,
|
|
|
|
|
(view: AppViewReduxState) => view.pageWidgetId,
|
|
|
|
|
);
|
|
|
|
|
export const getCurrentPageLayoutDSL = createCachedSelector(
|
|
|
|
|
getPageWidgetId,
|
|
|
|
|
getDataTree,
|
2019-11-19 12:44:58 +00:00
|
|
|
getValidatedDynamicProps,
|
|
|
|
|
(
|
|
|
|
|
pageWidgetId: string,
|
|
|
|
|
entities: DataTree,
|
|
|
|
|
validatedDynamicWidgets: CanvasWidgetsReduxState,
|
|
|
|
|
) => {
|
|
|
|
|
return CanvasWidgetsNormalizer.denormalize(pageWidgetId, {
|
|
|
|
|
...entities,
|
|
|
|
|
canvasWidgets: validatedDynamicWidgets,
|
|
|
|
|
});
|
2019-11-14 11:17:36 +00:00
|
|
|
},
|
|
|
|
|
)((pageWidgetId, entities) => entities || 0);
|