PromucFlow_constructor/app/client/src/reducers/entityReducers/metaReducer.ts
Rishabh Rathod a9f16d75bd
Enable Autocomplete for Static Objects (#6302)
* Remove type from COLORS constant

* Remove type from InputTypes in InputWidget

* Remove type from ReduxActionTypes

* Remove type from ReduxErrorActionTypes

* Remove type from SocialLoginTypes

* Fix widget actions issues

* Remove OPEN_SUB_PANE commented redux action
2021-08-03 13:36:48 +05:30

92 lines
2.3 KiB
TypeScript

import { set, cloneDeep } from "lodash";
import { createReducer } from "utils/AppsmithUtils";
import { UpdateWidgetMetaPropertyPayload } from "actions/metaActions";
import {
ReduxActionTypes,
ReduxAction,
WidgetReduxActionTypes,
} from "constants/ReduxActionConstants";
export type MetaState = Record<string, Record<string, unknown>>;
const initialState: MetaState = {};
export const metaReducer = createReducer(initialState, {
[ReduxActionTypes.SET_META_PROP]: (
state: MetaState,
action: ReduxAction<UpdateWidgetMetaPropertyPayload>,
) => {
const next = cloneDeep(state);
set(
next,
`${action.payload.widgetId}.${action.payload.propertyName}`,
action.payload.propertyValue,
);
return next;
},
[ReduxActionTypes.TABLE_PANE_MOVED]: (
state: MetaState,
action: ReduxAction<TableFilterPanePositionConfig>,
) => {
const next = { ...state };
let widgetMetaProps: Record<string, any> = next[action.payload.widgetId];
if (widgetMetaProps === undefined) {
widgetMetaProps = {
isMoved: true,
position: { ...action.payload.position },
};
} else {
widgetMetaProps = {
...widgetMetaProps,
isMoved: true,
position: { ...action.payload.position },
};
}
next[action.payload.widgetId] = widgetMetaProps;
return next;
},
[WidgetReduxActionTypes.WIDGET_DELETE]: (
state: MetaState,
action: ReduxAction<{ widgetId: string }>,
) => {
const next = { ...state };
delete next[action.payload.widgetId];
return next;
},
[ReduxActionTypes.RESET_WIDGET_META]: (
state: MetaState,
action: ReduxAction<{ widgetId: string }>,
) => {
const widgetId = action.payload.widgetId;
if (widgetId in state) {
const resetData: Record<string, any> = {
...state[widgetId],
};
Object.keys(resetData).forEach((key: string) => {
resetData[key] = undefined;
});
return { ...state, [widgetId]: { ...resetData } };
}
return state;
},
[ReduxActionTypes.FETCH_PAGE_SUCCESS]: () => {
return initialState;
},
[ReduxActionTypes.FETCH_PUBLISHED_PAGE_SUCCESS]: () => {
return initialState;
},
});
interface TableFilterPanePositionConfig {
widgetId: string;
isMoved: boolean;
position: {
left: number;
top: number;
};
}
export default metaReducer;