grafana/public/app/core/reducers/appNotification.ts

20 lines
727 B
TypeScript
Raw Normal View History

2018-10-24 07:33:53 -05:00
import { AppNotification, AppNotificationsState } from 'app/types/';
2018-10-24 03:23:11 -05:00
import { Action, ActionTypes } from '../actions/appNotification';
2018-10-22 07:22:40 -05:00
2018-10-23 09:00:04 -05:00
export const initialState: AppNotificationsState = {
appNotifications: [] as AppNotification[],
2018-10-22 07:22:40 -05:00
};
2018-10-23 09:00:04 -05:00
export const appNotificationsReducer = (state = initialState, action: Action): AppNotificationsState => {
2018-10-22 07:22:40 -05:00
switch (action.type) {
2018-10-23 06:34:27 -05:00
case ActionTypes.AddAppNotification:
2018-10-23 09:00:04 -05:00
return { ...state, appNotifications: state.appNotifications.concat([action.payload]) };
2018-10-23 06:34:27 -05:00
case ActionTypes.ClearAppNotification:
2018-10-22 07:22:40 -05:00
return {
...state,
2018-10-23 09:00:04 -05:00
appNotifications: state.appNotifications.filter(appNotification => appNotification.id !== action.payload),
2018-10-22 07:22:40 -05:00
};
}
return state;
};