Dashboard comes from params, not Redux (#1218)

We removed the `dashboard` key from Redux in favor
of `dashboards`, which contains an array of all
dashboards. This means we have to pass the current
dashboard around to action creators.
pull/1221/head
lukevmorris 2017-04-06 17:07:13 -07:00 committed by GitHub
parent e9c5f836b8
commit b1b3279396
2 changed files with 6 additions and 7 deletions

View File

@ -64,9 +64,10 @@ export const syncDashboardCell = (dashboard, cell) => ({
},
})
export const addDashboardCell = (cell) => ({
export const addDashboardCell = (dashboard, cell) => ({
type: 'ADD_DASHBOARD_CELL',
payload: {
dashboard,
cell,
},
})
@ -141,7 +142,7 @@ export const deleteDashboardAsync = (dashboard) => async (dispatch) => {
export const addDashboardCellAsync = (dashboard) => async (dispatch) => {
try {
const {data} = await addDashboardCellAJAX(dashboard, NEW_DEFAULT_DASHBOARD_CELL)
dispatch(addDashboardCell(data))
dispatch(addDashboardCell(dashboard, data))
} catch (error) {
console.error(error)
throw error

View File

@ -72,15 +72,13 @@ export default function ui(state = initialState, action) {
}
case 'ADD_DASHBOARD_CELL': {
const {cell} = action.payload
const {dashboard, dashboards} = state
const {cell, dashboard} = action.payload
const {dashboards} = state
const newCells = [cell, ...dashboard.cells]
const newDashboard = {...dashboard, cells: newCells}
const newDashboards = dashboards.map((d) => d.id === dashboard.id ? newDashboard : d)
const newState = {
dashboards: newDashboards,
}
const newState = {dashboards: newDashboards}
return {...state, ...newState}
}