Add reducer for cell range
parent
5082b5d493
commit
a2159edba5
|
@ -11,6 +11,7 @@ import {
|
|||
renameDashboardCell,
|
||||
syncDashboardCell,
|
||||
templateVariableSelected,
|
||||
editCellRanges,
|
||||
} from 'src/dashboards/actions'
|
||||
|
||||
let state
|
||||
|
@ -59,22 +60,11 @@ const c1 = {
|
|||
w: 4,
|
||||
h: 4,
|
||||
id: 1,
|
||||
i: 'im-a-cell-id-index',
|
||||
isEditing: false,
|
||||
name: 'Gigawatts',
|
||||
}
|
||||
const cells = [c1]
|
||||
const tempVar = {
|
||||
...d1.templates[0],
|
||||
id: '1',
|
||||
type: 'measurement',
|
||||
label: 'test query',
|
||||
tempVar: '$HOSTS',
|
||||
query: {
|
||||
db: 'db1',
|
||||
text: 'SHOW TAGS WHERE HUNTER = "coo"',
|
||||
},
|
||||
values: ['h1', 'h2', 'h3'],
|
||||
}
|
||||
|
||||
describe('DataExplorer.Reducers.UI', () => {
|
||||
it('can load the dashboards', () => {
|
||||
|
@ -180,4 +170,20 @@ 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('an set the range', () => {
|
||||
const dash = {..._.cloneDeep(d1), cells: [c1]}
|
||||
|
||||
state = {
|
||||
dashboards: [dash],
|
||||
}
|
||||
|
||||
const y = [1, 2]
|
||||
const y2 = [null, null]
|
||||
|
||||
const actual = reducer(state, editCellRanges(dash, c1, {y, y2}))
|
||||
|
||||
expect(actual.dashboards[0].cells[0].ranges.y).to.deep.equal(y)
|
||||
expect(actual.dashboards[0].cells[0].ranges.y2).to.deep.equal(y2)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -79,6 +79,15 @@ export const addDashboardCell = (dashboard, cell) => ({
|
|||
},
|
||||
})
|
||||
|
||||
export const editCellRanges = (dashboard, cell, ranges) => ({
|
||||
type: 'EDIT_CELL_RANGES',
|
||||
payload: {
|
||||
dashboard,
|
||||
cell,
|
||||
ranges,
|
||||
},
|
||||
})
|
||||
|
||||
export const editDashboardCell = (dashboard, x, y, isEditing) => ({
|
||||
type: 'EDIT_DASHBOARD_CELL',
|
||||
// x and y coords are used as a alternative to cell ids, which are not
|
||||
|
|
|
@ -239,6 +239,30 @@ export default function ui(state = initialState, action) {
|
|||
|
||||
return {...state, dashboards}
|
||||
}
|
||||
|
||||
case 'EDIT_CELL_RANGES': {
|
||||
const {dashboard, cell, ranges} = action.payload
|
||||
|
||||
const dashboards = state.dashboards.map(
|
||||
d =>
|
||||
(d.id === dashboard.id
|
||||
? {
|
||||
...d,
|
||||
cells: d.cells.map(
|
||||
c =>
|
||||
(c.i === cell.i
|
||||
? {
|
||||
...c,
|
||||
ranges,
|
||||
}
|
||||
: c)
|
||||
),
|
||||
}
|
||||
: d)
|
||||
)
|
||||
|
||||
return {...state, dashboards}
|
||||
}
|
||||
}
|
||||
|
||||
return state
|
||||
|
|
Loading…
Reference in New Issue