PromucFlow_constructor/app/client/src/selectors/appViewSelectors.tsx

60 lines
2.1 KiB
TypeScript
Raw Normal View History

import { createSelector } from "reselect";
2019-11-08 11:02:00 +00:00
import { AppState, DataTree } from "../reducers";
import { AppViewReduxState } from "../reducers/uiReducers/appViewReducer";
import { PageListReduxState } from "reducers/entityReducers/pageListReducer";
2019-11-14 09:28:51 +00:00
import { getDataTree } from "./entitiesSelector";
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";
const getAppViewState = (state: AppState) => state.ui.appView;
const getPageListState = (state: AppState): PageListReduxState =>
state.entities.pageList;
export const getCurrentPageId = (state: AppState) =>
state.ui.appView.currentPageId;
// For the viewer, this does not need to be wrapped in createCachedSelector, as it will not change in subsequent renders.
// export const getCurrentPageLayoutDSL = createSelector(
// getAppViewState,
// getDataTree,
// (view: AppViewReduxState, dataTree: DataTree) =>
// injectDataTreeIntoDsl(dataTree, view.dsl),
// );
export const getPageList = createSelector(
getPageListState,
(pageList: PageListReduxState) =>
pageList.pages.length > 0 ? pageList.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,
);
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,
});
},
)((pageWidgetId, entities) => entities || 0);