Type dashTimeV1 reducer
parent
044e9920af
commit
3fd4090cea
|
@ -99,7 +99,7 @@ interface LoadDashboardAction {
|
|||
interface RetainRangesDashTimeV1Action {
|
||||
type: ActionType.RetainRangesDashboardTimeV1
|
||||
payload: {
|
||||
dashboardIDs: string[]
|
||||
dashboardIDs: number[]
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -260,7 +260,7 @@ export const setDashTimeV1 = (
|
|||
})
|
||||
|
||||
export const retainRangesDashTimeV1 = (
|
||||
dashboardIDs: string[]
|
||||
dashboardIDs: number[]
|
||||
): RetainRangesDashTimeV1Action => ({
|
||||
type: ActionType.RetainRangesDashboardTimeV1,
|
||||
payload: {dashboardIDs},
|
||||
|
|
|
@ -1,17 +1,30 @@
|
|||
import _ from 'lodash'
|
||||
const initialState = {
|
||||
|
||||
import {TimeRange} from 'src/types'
|
||||
import {Action, ActionType} from 'src/dashboards/actions'
|
||||
|
||||
interface Range extends TimeRange {
|
||||
dashboardID: number
|
||||
}
|
||||
|
||||
interface State {
|
||||
ranges: Range[]
|
||||
}
|
||||
|
||||
const initialState: State = {
|
||||
ranges: [],
|
||||
}
|
||||
|
||||
const dashTimeV1 = (state = initialState, action) => {
|
||||
export default (state: State = initialState, action: Action) => {
|
||||
switch (action.type) {
|
||||
case 'DELETE_DASHBOARD': {
|
||||
case ActionType.DeleteDashboard: {
|
||||
const {dashboard} = action.payload
|
||||
const ranges = state.ranges.filter(r => r.dashboardID !== dashboard.id)
|
||||
|
||||
return {...state, ranges}
|
||||
}
|
||||
case 'RETAIN_RANGES_DASHBOARD_TIME_V1': {
|
||||
|
||||
case ActionType.RetainRangesDashboardTimeV1: {
|
||||
const {dashboardIDs} = action.payload
|
||||
const ranges = state.ranges.filter(r =>
|
||||
dashboardIDs.includes(r.dashboardID)
|
||||
|
@ -19,7 +32,7 @@ const dashTimeV1 = (state = initialState, action) => {
|
|||
return {...state, ranges}
|
||||
}
|
||||
|
||||
case 'SET_DASHBOARD_TIME_V1': {
|
||||
case ActionType.SetDashboardTimeV1: {
|
||||
const {dashboardID, timeRange} = action.payload
|
||||
const newTimeRange = [{dashboardID, ...timeRange}]
|
||||
const ranges = _.unionBy(newTimeRange, state.ranges, 'dashboardID')
|
||||
|
@ -30,5 +43,3 @@ const dashTimeV1 = (state = initialState, action) => {
|
|||
|
||||
return state
|
||||
}
|
||||
|
||||
export default dashTimeV1
|
Loading…
Reference in New Issue