Allow new cells to be created with a type

pull/10616/head
Alex P 2018-04-18 11:41:04 -07:00
parent 3a4ca66183
commit c2f6338d3d
2 changed files with 13 additions and 5 deletions

View File

@ -289,11 +289,14 @@ export const deleteDashboardAsync = dashboard => async dispatch => {
}
}
export const addDashboardCellAsync = dashboard => async dispatch => {
export const addDashboardCellAsync = (
dashboard,
cellType
) => async dispatch => {
try {
const {data} = await addDashboardCellAJAX(
dashboard,
getNewDashboardCell(dashboard)
getNewDashboardCell(dashboard, cellType)
)
dispatch(addDashboardCell(dashboard, data))
dispatch(notify(notifyCellAdded()))

View File

@ -20,9 +20,14 @@ const getMostCommonValue = values => {
return results.mostCommonValue
}
export const getNewDashboardCell = dashboard => {
export const getNewDashboardCell = (dashboard, cellType) => {
const typedCell = {
...NEW_DEFAULT_DASHBOARD_CELL,
type: cellType || 'line',
}
if (dashboard.cells.length === 0) {
return NEW_DEFAULT_DASHBOARD_CELL
return typedCell
}
const newCellY = dashboard.cells
@ -36,7 +41,7 @@ export const getNewDashboardCell = dashboard => {
const mostCommonCellHeight = getMostCommonValue(existingCellHeights)
return {
...NEW_DEFAULT_DASHBOARD_CELL,
...typedCell,
y: newCellY,
w: mostCommonCellWidth,
h: mostCommonCellHeight,