Open CEO before saving new cell to dashboard
parent
f0bfa08c15
commit
ddaf1dfcaa
|
@ -8,6 +8,7 @@ import {
|
||||||
ThresholdType,
|
ThresholdType,
|
||||||
TableOptions,
|
TableOptions,
|
||||||
} from 'src/types/dashboards'
|
} from 'src/types/dashboards'
|
||||||
|
import {NewDefaultCell} from '../constants'
|
||||||
|
|
||||||
export enum ActionType {
|
export enum ActionType {
|
||||||
ShowCellEditorOverlay = 'SHOW_CELL_EDITOR_OVERLAY',
|
ShowCellEditorOverlay = 'SHOW_CELL_EDITOR_OVERLAY',
|
||||||
|
@ -43,7 +44,7 @@ export type Action =
|
||||||
export interface ShowCellEditorOverlayAction {
|
export interface ShowCellEditorOverlayAction {
|
||||||
type: ActionType.ShowCellEditorOverlay
|
type: ActionType.ShowCellEditorOverlay
|
||||||
payload: {
|
payload: {
|
||||||
cell: Cell
|
cell: Cell | NewDefaultCell
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -129,7 +130,7 @@ export interface UpdateFieldOptionsAction {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const showCellEditorOverlay = (
|
export const showCellEditorOverlay = (
|
||||||
cell: Cell
|
cell: Cell | NewDefaultCell
|
||||||
): ShowCellEditorOverlayAction => ({
|
): ShowCellEditorOverlayAction => ({
|
||||||
type: ActionType.ShowCellEditorOverlay,
|
type: ActionType.ShowCellEditorOverlay,
|
||||||
payload: {
|
payload: {
|
||||||
|
|
|
@ -26,10 +26,7 @@ import {
|
||||||
templateSelectionsFromTemplates,
|
templateSelectionsFromTemplates,
|
||||||
} from 'src/dashboards/utils/tempVars'
|
} from 'src/dashboards/utils/tempVars'
|
||||||
import {validTimeRange, validAbsoluteTimeRange} from 'src/dashboards/utils/time'
|
import {validTimeRange, validAbsoluteTimeRange} from 'src/dashboards/utils/time'
|
||||||
import {
|
import {getClonedDashboardCell} from 'src/dashboards/utils/cellGetters'
|
||||||
getNewDashboardCell,
|
|
||||||
getClonedDashboardCell,
|
|
||||||
} from 'src/dashboards/utils/cellGetters'
|
|
||||||
import {
|
import {
|
||||||
notifyDashboardDeleted,
|
notifyDashboardDeleted,
|
||||||
notifyDashboardDeleteFailed,
|
notifyDashboardDeleteFailed,
|
||||||
|
@ -53,13 +50,13 @@ import {defaultTimeRange} from 'src/shared/data/timeRanges'
|
||||||
import {
|
import {
|
||||||
Dashboard,
|
Dashboard,
|
||||||
Cell,
|
Cell,
|
||||||
CellType,
|
|
||||||
TimeRange,
|
TimeRange,
|
||||||
Source,
|
Source,
|
||||||
Template,
|
Template,
|
||||||
TemplateValue,
|
TemplateValue,
|
||||||
TemplateType,
|
TemplateType,
|
||||||
} from 'src/types'
|
} from 'src/types'
|
||||||
|
import {NewDefaultCell} from '../constants'
|
||||||
|
|
||||||
export enum ActionType {
|
export enum ActionType {
|
||||||
LoadDashboards = 'LOAD_DASHBOARDS',
|
LoadDashboards = 'LOAD_DASHBOARDS',
|
||||||
|
@ -482,9 +479,10 @@ export const putDashboardByID = (dashboardID: number) => async (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const updateDashboardCell = (dashboard: Dashboard, cell: Cell) => async (
|
export const updateDashboardCell = (
|
||||||
dispatch: Dispatch<Action>
|
dashboard: Dashboard,
|
||||||
): Promise<void> => {
|
cell: Cell | NewDefaultCell
|
||||||
|
) => async (dispatch: Dispatch<Action>): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const {data} = await updateDashboardCellAJAX(cell)
|
const {data} = await updateDashboardCellAJAX(cell)
|
||||||
dispatch(syncDashboardCell(dashboard, data))
|
dispatch(syncDashboardCell(dashboard, data))
|
||||||
|
@ -514,16 +512,12 @@ export const deleteDashboardAsync = (dashboard: Dashboard) => async (
|
||||||
|
|
||||||
export const addDashboardCellAsync = (
|
export const addDashboardCellAsync = (
|
||||||
dashboard: Dashboard,
|
dashboard: Dashboard,
|
||||||
cellType?: CellType
|
cell: NewDefaultCell
|
||||||
) => async (dispatch: Dispatch<Action>): Promise<void> => {
|
) => async (dispatch: Dispatch<Action>): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
const {data} = await addDashboardCellAJAX(
|
const {data} = await addDashboardCellAJAX(dashboard, cell)
|
||||||
dashboard,
|
|
||||||
getNewDashboardCell(dashboard, cellType)
|
|
||||||
)
|
|
||||||
dispatch(addDashboardCell(dashboard, data))
|
dispatch(addDashboardCell(dashboard, data))
|
||||||
dispatch(notify(notifyCellAdded(data.name)))
|
dispatch(notify(notifyCellAdded(data.name)))
|
||||||
dispatch(showCellEditorOverlay(data))
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error)
|
console.error(error)
|
||||||
dispatch(errorThrown(error))
|
dispatch(errorThrown(error))
|
||||||
|
|
|
@ -45,6 +45,7 @@ import * as QueriesModels from 'src/types/queries'
|
||||||
import * as SourcesModels from 'src/types/sources'
|
import * as SourcesModels from 'src/types/sources'
|
||||||
import {Service} from 'src/types'
|
import {Service} from 'src/types'
|
||||||
import {Template} from 'src/types/tempVars'
|
import {Template} from 'src/types/tempVars'
|
||||||
|
import {NewDefaultCell} from 'src/dashboards/constants/index'
|
||||||
|
|
||||||
type QueryTransitions = typeof queryTransitions
|
type QueryTransitions = typeof queryTransitions
|
||||||
type EditRawTextAsyncFunc = (
|
type EditRawTextAsyncFunc = (
|
||||||
|
@ -75,7 +76,7 @@ interface Props {
|
||||||
services: Service[]
|
services: Service[]
|
||||||
editQueryStatus: typeof editCellQueryStatus
|
editQueryStatus: typeof editCellQueryStatus
|
||||||
onCancel: () => void
|
onCancel: () => void
|
||||||
onSave: (cell: DashboardsModels.Cell) => void
|
onSave: (cell: DashboardsModels.Cell | NewDefaultCell) => void
|
||||||
source: SourcesModels.Source
|
source: SourcesModels.Source
|
||||||
dashboardID: number
|
dashboardID: number
|
||||||
queryStatus: QueryStatus
|
queryStatus: QueryStatus
|
||||||
|
@ -86,7 +87,7 @@ interface Props {
|
||||||
thresholdsListColors: ColorsModels.ColorNumber[]
|
thresholdsListColors: ColorsModels.ColorNumber[]
|
||||||
gaugeColors: ColorsModels.ColorNumber[]
|
gaugeColors: ColorsModels.ColorNumber[]
|
||||||
lineColors: ColorsModels.ColorString[]
|
lineColors: ColorsModels.ColorString[]
|
||||||
cell: DashboardsModels.Cell
|
cell: DashboardsModels.Cell | NewDefaultCell
|
||||||
}
|
}
|
||||||
|
|
||||||
interface State {
|
interface State {
|
||||||
|
@ -359,7 +360,7 @@ class CellEditorOverlay extends Component<Props, State> {
|
||||||
lineColors,
|
lineColors,
|
||||||
})
|
})
|
||||||
|
|
||||||
const newCell: DashboardsModels.Cell = {
|
const newCell: DashboardsModels.Cell | NewDefaultCell = {
|
||||||
...cell,
|
...cell,
|
||||||
queries,
|
queries,
|
||||||
colors,
|
colors,
|
||||||
|
|
|
@ -48,6 +48,7 @@ import {
|
||||||
} from 'src/shared/constants'
|
} from 'src/shared/constants'
|
||||||
import {FORMAT_INFLUXQL, defaultTimeRange} from 'src/shared/data/timeRanges'
|
import {FORMAT_INFLUXQL, defaultTimeRange} from 'src/shared/data/timeRanges'
|
||||||
import {EMPTY_LINKS} from 'src/dashboards/constants/dashboardHeader'
|
import {EMPTY_LINKS} from 'src/dashboards/constants/dashboardHeader'
|
||||||
|
import {getNewDashboardCell} from 'src/dashboards/utils/cellGetters'
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import {WithRouterProps} from 'react-router'
|
import {WithRouterProps} from 'react-router'
|
||||||
|
@ -62,6 +63,7 @@ import * as QueriesModels from 'src/types/queries'
|
||||||
import * as SourcesModels from 'src/types/sources'
|
import * as SourcesModels from 'src/types/sources'
|
||||||
import * as TempVarsModels from 'src/types/tempVars'
|
import * as TempVarsModels from 'src/types/tempVars'
|
||||||
import * as NotificationsActions from 'src/types/actions/notifications'
|
import * as NotificationsActions from 'src/types/actions/notifications'
|
||||||
|
import {NewDefaultCell} from 'src/dashboards/constants/index'
|
||||||
import {Service} from 'src/types'
|
import {Service} from 'src/types'
|
||||||
|
|
||||||
interface Props extends ManualRefreshProps, WithRouterProps {
|
interface Props extends ManualRefreshProps, WithRouterProps {
|
||||||
|
@ -412,11 +414,21 @@ class DashboardPage extends Component<Props, State> {
|
||||||
return topInView && bottomInView
|
return topInView && bottomInView
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private isExistingCell(cell: DashboardsModels.Cell | NewDefaultCell) {
|
||||||
|
return (cell as DashboardsModels.Cell).i !== undefined
|
||||||
|
}
|
||||||
|
|
||||||
private handleSaveEditedCell = async (
|
private handleSaveEditedCell = async (
|
||||||
newCell: DashboardsModels.Cell
|
newCell: DashboardsModels.Cell | NewDefaultCell
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
const {dashboard, handleHideCellEditorOverlay} = this.props
|
const {dashboard, handleHideCellEditorOverlay} = this.props
|
||||||
await this.props.updateDashboardCell(dashboard, newCell)
|
|
||||||
|
if (this.isExistingCell(newCell)) {
|
||||||
|
await this.props.updateDashboardCell(dashboard, newCell)
|
||||||
|
} else if (!this.isExistingCell(newCell)) {
|
||||||
|
this.props.addDashboardCellAsync(dashboard, newCell)
|
||||||
|
}
|
||||||
|
|
||||||
handleHideCellEditorOverlay()
|
handleHideCellEditorOverlay()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,7 +471,8 @@ class DashboardPage extends Component<Props, State> {
|
||||||
|
|
||||||
private handleAddCell = (): void => {
|
private handleAddCell = (): void => {
|
||||||
const {dashboard} = this.props
|
const {dashboard} = this.props
|
||||||
this.props.addDashboardCellAsync(dashboard)
|
const emptyCell = getNewDashboardCell(dashboard)
|
||||||
|
this.props.handleShowCellEditorOverlay(emptyCell)
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleCloneCell = (cell: DashboardsModels.Cell): void => {
|
private handleCloneCell = (cell: DashboardsModels.Cell): void => {
|
||||||
|
|
|
@ -18,9 +18,10 @@ import {Action, ActionType} from 'src/dashboards/actions/cellEditorOverlay'
|
||||||
import {CellType, Cell} from 'src/types'
|
import {CellType, Cell} from 'src/types'
|
||||||
import {ThresholdType, TableOptions} from 'src/types/dashboards'
|
import {ThresholdType, TableOptions} from 'src/types/dashboards'
|
||||||
import {ThresholdColor, GaugeColor, LineColor} from 'src/types/colors'
|
import {ThresholdColor, GaugeColor, LineColor} from 'src/types/colors'
|
||||||
|
import {NewDefaultCell} from 'src/dashboards/constants/index'
|
||||||
|
|
||||||
interface CEOInitialState {
|
interface CEOInitialState {
|
||||||
cell: Cell | null
|
cell: Cell | NewDefaultCell | null
|
||||||
thresholdsListType: ThresholdType
|
thresholdsListType: ThresholdType
|
||||||
thresholdsListColors: ThresholdColor[]
|
thresholdsListColors: ThresholdColor[]
|
||||||
gaugeColors: GaugeColor[]
|
gaugeColors: GaugeColor[]
|
||||||
|
@ -38,17 +39,7 @@ export const initialState = {
|
||||||
export default (state = initialState, action: Action): CEOInitialState => {
|
export default (state = initialState, action: Action): CEOInitialState => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
case ActionType.ShowCellEditorOverlay: {
|
case ActionType.ShowCellEditorOverlay: {
|
||||||
const {
|
const {cell} = action.payload
|
||||||
cell,
|
|
||||||
cell: {colors},
|
|
||||||
} = action.payload
|
|
||||||
|
|
||||||
const thresholdsListType = getThresholdsListType(colors)
|
|
||||||
const thresholdsListColors = validateThresholdsListColors(
|
|
||||||
colors,
|
|
||||||
thresholdsListType
|
|
||||||
)
|
|
||||||
const gaugeColors = validateGaugeColors(colors)
|
|
||||||
|
|
||||||
const tableOptions = getDeep<TableOptions>(
|
const tableOptions = getDeep<TableOptions>(
|
||||||
cell,
|
cell,
|
||||||
|
@ -56,15 +47,29 @@ export default (state = initialState, action: Action): CEOInitialState => {
|
||||||
initializeOptions(CellType.Table)
|
initializeOptions(CellType.Table)
|
||||||
)
|
)
|
||||||
|
|
||||||
const lineColors = validateLineColors(colors)
|
const colors = (cell as any).colors
|
||||||
|
if (colors !== undefined) {
|
||||||
|
const thresholdsListType = getThresholdsListType(colors)
|
||||||
|
const thresholdsListColors = validateThresholdsListColors(
|
||||||
|
colors,
|
||||||
|
thresholdsListType
|
||||||
|
)
|
||||||
|
const gaugeColors = validateGaugeColors(colors)
|
||||||
|
|
||||||
|
const lineColors = validateLineColors(colors)
|
||||||
|
|
||||||
|
return {
|
||||||
|
...state,
|
||||||
|
cell: {...cell, tableOptions},
|
||||||
|
thresholdsListType,
|
||||||
|
thresholdsListColors,
|
||||||
|
gaugeColors,
|
||||||
|
lineColors,
|
||||||
|
}
|
||||||
|
}
|
||||||
return {
|
return {
|
||||||
...state,
|
...state,
|
||||||
cell: {...cell, tableOptions},
|
cell: {...cell, tableOptions},
|
||||||
thresholdsListType,
|
|
||||||
thresholdsListColors,
|
|
||||||
gaugeColors,
|
|
||||||
lineColors,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue