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

35 lines
1.0 KiB
TypeScript
Raw Normal View History

import { AppState } from "../reducers";
import { FlattenedWidgetProps } from "../reducers/entityReducers/canvasWidgetsReducer";
import { WidgetProps } from "../widgets/BaseWidget";
import { WidgetType } from "../constants/WidgetConstants";
export const getWidgets = (
state: AppState,
): { [widgetId: string]: FlattenedWidgetProps } => {
return state.entities.canvasWidgets;
};
export const getWidget = (state: AppState, widgetId: string): WidgetProps => {
return state.entities.canvasWidgets[widgetId];
};
export const getEditorConfigs = (
state: AppState,
): { pageId: string; layoutId: string } => {
const { currentLayoutId, currentPageId } = state.ui.editor;
return {
pageId: currentPageId,
layoutId: currentLayoutId,
};
};
export const getDefaultWidgetConfig = (
state: AppState,
type: WidgetType,
): Partial<WidgetProps> => {
const configs = state.entities.widgetConfig.config;
const widgetConfig = { ...configs[type] };
delete widgetConfig.rows;
delete widgetConfig.columns;
return widgetConfig;
};