Add cancel edit cell spec
parent
a746de32ae
commit
e90614e33d
|
@ -11,6 +11,7 @@ import {
|
|||
renameDashboardCell,
|
||||
syncDashboardCell,
|
||||
templateVariableSelected,
|
||||
cancelEditCell,
|
||||
} from 'src/dashboards/actions'
|
||||
|
||||
let state
|
||||
|
@ -62,6 +63,13 @@ const c1 = {
|
|||
isEditing: false,
|
||||
name: 'Gigawatts',
|
||||
}
|
||||
|
||||
const editingCell = {
|
||||
i: 1,
|
||||
isEditing: true,
|
||||
name: 'Edit me',
|
||||
}
|
||||
|
||||
const cells = [c1]
|
||||
const tempVar = {
|
||||
...d1.templates[0],
|
||||
|
@ -180,4 +188,17 @@ describe('DataExplorer.Reducers.UI', () => {
|
|||
expect(actual.dashboards[0].templates[0].values[1].selected).to.equal(false)
|
||||
expect(actual.dashboards[0].templates[0].values[2].selected).to.equal(true)
|
||||
})
|
||||
|
||||
it('can cancel cell editing', () => {
|
||||
const dash = _.cloneDeep(d1)
|
||||
dash.cells = [editingCell]
|
||||
|
||||
const actual = reducer(
|
||||
{dashboards: [dash]},
|
||||
cancelEditCell(dash.id, editingCell.i)
|
||||
)
|
||||
|
||||
expect(actual.dashboards[0].cells[0].isEditing).to.equal(false)
|
||||
expect(actual.dashboards[0].cells[0].name).to.equal(editingCell.name)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -93,6 +93,14 @@ export const editDashboardCell = (dashboard, x, y, isEditing) => ({
|
|||
},
|
||||
})
|
||||
|
||||
export const cancelEditCell = (dashboardID, cellID) => ({
|
||||
type: 'CANCEL_EDIT_CELL',
|
||||
payload: {
|
||||
dashboardID,
|
||||
cellID,
|
||||
},
|
||||
})
|
||||
|
||||
export const renameDashboardCell = (dashboard, x, y, name) => ({
|
||||
type: 'RENAME_DASHBOARD_CELL',
|
||||
payload: {
|
||||
|
|
|
@ -132,6 +132,24 @@ export default function ui(state = initialState, action) {
|
|||
return {...state, ...newState}
|
||||
}
|
||||
|
||||
case 'CANCEL_EDIT_CELL': {
|
||||
const {dashboardID, cellID} = action.payload
|
||||
|
||||
const dashboards = state.dashboards.map(
|
||||
d =>
|
||||
(d.id === dashboardID
|
||||
? {
|
||||
...d,
|
||||
cells: d.cells.map(
|
||||
c => (c.i === cellID ? {...c, isEditing: false} : c)
|
||||
),
|
||||
}
|
||||
: d)
|
||||
)
|
||||
|
||||
return {...state, dashboards}
|
||||
}
|
||||
|
||||
case 'SYNC_DASHBOARD_CELL': {
|
||||
const {cell, dashboard} = action.payload
|
||||
|
||||
|
|
Loading…
Reference in New Issue