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";
|
2022-01-28 11:10:05 +00:00
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
};
|
2022-01-28 11:10:05 +00:00
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
};
|