PromucFlow_constructor/app/client/src/actions/metaActions.ts

65 lines
1.6 KiB
TypeScript
Raw Normal View History

2020-02-07 02:32:52 +00:00
import { ReduxActionTypes, ReduxAction } from "constants/ReduxActionConstants";
2020-04-13 08:24:13 +00:00
import { BatchAction, batchAction } from "actions/batchActions";
import { DataTree } from "entities/DataTree/dataTreeFactory";
import { isWidget } from "../workers/evaluationUtils";
import { MetaState } from "../reducers/entityReducers/metaReducer";
import isEmpty from "lodash/isEmpty";
2020-02-07 02:32:52 +00:00
2020-03-06 09:45:21 +00:00
export interface UpdateWidgetMetaPropertyPayload {
widgetId: string;
propertyName: string;
propertyValue: any;
}
2020-02-07 02:32:52 +00:00
export const updateWidgetMetaProperty = (
widgetId: string,
propertyName: string,
propertyValue: any,
2020-04-13 08:24:13 +00:00
): BatchAction<UpdateWidgetMetaPropertyPayload> => {
return batchAction({
2020-02-07 02:32:52 +00:00
type: ReduxActionTypes.SET_META_PROP,
payload: {
widgetId,
propertyName,
propertyValue,
},
2020-04-13 08:24:13 +00:00
});
2020-02-07 02:32:52 +00:00
};
2020-03-06 09:45:21 +00:00
export const resetWidgetMetaProperty = (
widgetId: string,
2020-04-13 08:24:13 +00:00
): BatchAction<{ widgetId: string }> => {
return batchAction({
2020-03-06 09:45:21 +00:00
type: ReduxActionTypes.RESET_WIDGET_META,
payload: {
widgetId,
},
2020-04-13 08:24:13 +00:00
});
2020-03-06 09:45:21 +00:00
};
export const resetChildrenMetaProperty = (
widgetId: string,
): ReduxAction<{ widgetId: string }> => {
return {
type: ReduxActionTypes.RESET_CHILDREN_WIDGET_META,
payload: {
widgetId,
},
};
};
export const updateMetaState = (evaluatedDataTree: DataTree) => {
const updatedWidgetMetaState: MetaState = {};
Object.values(evaluatedDataTree).forEach((entity) => {
if (isWidget(entity) && entity.widgetId && !isEmpty(entity.meta)) {
updatedWidgetMetaState[entity.widgetId] = entity.meta;
}
});
return {
type: ReduxActionTypes.UPDATE_META_STATE,
payload: {
updatedWidgetMetaState,
},
};
};