at the end of the day, it was inevitable

This commit is contained in:
Mo Elzubeir
2022-12-09 08:36:26 -06:00
commit 1218570914
1768 changed files with 887087 additions and 0 deletions
@@ -0,0 +1,49 @@
import { fromJS } from 'immutable'
import { createAction, handleActions } from 'redux-actions'
// Action types
const ADD_ALERT_CHART = 'ADD_ALERT_CHART'
const REMOVE_ALERT_CHART = 'REMOVE_ALERT_CHART'
const RESET_ALERT_CHART = 'RESET_ALERT_CHART'
// Actions
const addAlertChart = createAction(ADD_ALERT_CHART, (payload) => payload)
const removeAlertChart = createAction(REMOVE_ALERT_CHART, (payload) => payload)
const resetAlertChart = createAction(RESET_ALERT_CHART, (payload) => payload)
export const analyzeActions = {
addAlertChart,
removeAlertChart,
resetAlertChart
}
// Reducer
const initialState = fromJS({
alertCharts: []
})
export default handleActions(
{
[ADD_ALERT_CHART]: (state, { payload }) => {
const charts = state.getIn(['alertCharts'])
if (charts.find((v) => v.name === payload)) {
return state
}
return state.setIn(['alertCharts'], [...charts, payload])
},
[REMOVE_ALERT_CHART]: (state, { payload }) => {
const charts = state
.getIn(['alertCharts'])
.filter(
(item) =>
item.name !== payload.name ||
(item.id ? item.id !== payload.id : true)
)
return state.setIn(['alertCharts'], charts)
},
[RESET_ALERT_CHART]: (state) => {
return state.setIn(['alertCharts'], [])
}
},
initialState
)