Merge pull request #12623 from influxdata/death-to-v2-folders-dashboards

Death to v2 folders dashboards
pull/12661/head
Deniz Kusefoglu 2019-03-15 14:13:16 -07:00 committed by GitHub
commit 0e5e2a5703
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 198 additions and 130 deletions

View File

@ -16,7 +16,7 @@ import {
removeDashboardLabels as removeDashboardLabelsAJAX,
getView as getViewAJAX,
updateView as updateViewAJAX,
} from 'src/dashboards/apis/v2'
} from 'src/dashboards/apis'
import {client} from 'src/utils/api'
// Actions
@ -25,12 +25,12 @@ import {
deleteTimeRange,
updateTimeRangeFromQueryParams,
DeleteTimeRangeAction,
} from 'src/dashboards/actions/v2/ranges'
} from 'src/dashboards/actions/ranges'
import {
importDashboardSucceeded,
importDashboardFailed,
} from 'src/shared/copy/notifications'
import {setView, SetViewAction, setViews} from 'src/dashboards/actions/v2/views'
import {setView, SetViewAction, setViews} from 'src/dashboards/actions/views'
import {getVariables, refreshVariableValues} from 'src/variables/actions'
// Utils

View File

@ -2,8 +2,8 @@
import {get, isUndefined} from 'lodash'
// Actions
import {createCellWithView} from 'src/dashboards/actions/v2'
import {updateView} from 'src/dashboards/actions/v2/views'
import {createCellWithView} from 'src/dashboards/actions'
import {updateView} from 'src/dashboards/actions/views'
// Utils
import {createView} from 'src/shared/utils/view'
@ -11,7 +11,7 @@ import {createView} from 'src/shared/utils/view'
// Types
import {GetState} from 'src/types/v2'
import {NoteEditorMode, MarkdownView, ViewType} from 'src/types/v2/dashboards'
import {NoteEditorState} from 'src/dashboards/reducers/v2/notes'
import {NoteEditorState} from 'src/dashboards/reducers/notes'
export type Action =
| OpenNoteEditorAction

View File

@ -2,7 +2,7 @@
import {
getView as getViewAJAX,
updateView as updateViewAJAX,
} from 'src/dashboards/apis/v2/'
} from 'src/dashboards/apis/'
// Types
import {RemoteDataState} from 'src/types'

View File

@ -1,102 +1,176 @@
import AJAX from 'src/utils/ajax'
// Libraries
import _ from 'lodash'
import {AxiosResponse} from 'axios'
import {DashboardsResponse, GetDashboards} from 'src/types/apis/dashboards'
// Utils
import {addLabelDefaults} from 'src/shared/utils/labels'
import {incrementCloneName} from 'src/utils/naming'
export const getDashboards: GetDashboards = () => {
return AJAX<DashboardsResponse>({
method: 'GET',
resource: 'dashboards',
}) as Promise<AxiosResponse<DashboardsResponse>>
}
// Types
import {Cell, NewCell, Dashboard, View} from 'src/types/v2'
import {ILabel} from '@influxdata/influx'
export const getDashboard = async dashboardID => {
try {
return await AJAX({
method: 'GET',
url: `/chronograf/v1/dashboards/${dashboardID}`,
})
} catch (error) {
console.error(error)
throw error
}
}
import {Cell as CellAPI, CreateDashboardRequest} from '@influxdata/influx'
import {client} from 'src/utils/api'
export const updateDashboard = dashboard => {
return AJAX({
method: 'PUT',
url: dashboard.links.self,
data: dashboard,
export const addDashboardIDToCells = (
cells: CellAPI[],
dashboardID: string
): Cell[] => {
return cells.map(c => {
return {...c, dashboardID}
})
}
export const updateDashboardCell = cell => {
return AJAX({
method: 'PUT',
url: cell.links.self,
data: cell,
})
// TODO(desa): what to do about getting dashboards from another v2 source
export const getDashboards = async (): Promise<Dashboard[]> => {
const dashboards = await client.dashboards.getAll()
return dashboards.map(d => ({
...d,
labels: d.labels.map(addLabelDefaults),
cells: addDashboardIDToCells(d.cells, d.id),
}))
}
export const createDashboard = async dashboard => {
try {
return await AJAX({
method: 'POST',
resource: 'dashboards',
data: dashboard,
})
} catch (error) {
console.error(error)
throw error
export const getDashboard = async (id: string): Promise<Dashboard> => {
const dashboard = await client.dashboards.get(id)
return {
...dashboard,
labels: dashboard.labels.map(addLabelDefaults),
cells: addDashboardIDToCells(dashboard.cells, dashboard.id),
}
}
export const deleteDashboard = async dashboard => {
try {
return await AJAX({
method: 'DELETE',
url: dashboard.links.self,
})
} catch (error) {
console.error(error)
throw error
export const getDashboardsByOrgID = async (
orgID: string
): Promise<Dashboard[]> => {
const dashboards = await client.dashboards.getAllByOrgID(orgID)
return dashboards.map(d => ({
...d,
labels: d.labels.map(addLabelDefaults),
cells: addDashboardIDToCells(d.cells, d.id),
}))
}
export const createDashboard = async (
props: CreateDashboardRequest
): Promise<Dashboard> => {
const dashboard = await client.dashboards.create(props)
return {
...dashboard,
labels: dashboard.labels.map(addLabelDefaults),
cells: addDashboardIDToCells(dashboard.cells, dashboard.id),
}
}
export const addDashboardCell = async (dashboard, cell) => {
try {
return await AJAX({
method: 'POST',
url: dashboard.links.cells,
data: cell,
})
} catch (error) {
console.error(error)
throw error
export const deleteDashboard = async (dashboard: Dashboard): Promise<void> => {
await client.dashboards.delete(dashboard.id)
}
export const updateDashboard = async (
dashboard: Dashboard
): Promise<Dashboard> => {
const updated = await client.dashboards.update(dashboard.id, dashboard)
return {
...updated,
labels: updated.labels.map(addLabelDefaults),
cells: addDashboardIDToCells(updated.cells, updated.id),
}
}
export const deleteDashboardCell = async cell => {
try {
return await AJAX({
method: 'DELETE',
url: cell.links.self,
})
} catch (error) {
console.error(error)
throw error
}
export const addCell = async (
dashboardID: string,
cell: NewCell
): Promise<Cell> => {
const result = await client.dashboards.createCell(dashboardID, cell)
const cellWithID = {...result, dashboardID}
return cellWithID
}
export const editTemplateVariables = async templateVariable => {
try {
return await AJAX({
method: 'PUT',
url: templateVariable.links.self,
data: templateVariable,
})
} catch (error) {
console.error(error)
throw error
}
export const updateCells = async (
id: string,
cells: Cell[]
): Promise<Cell[]> => {
const result = await client.dashboards.updateAllCells(id, cells)
return addDashboardIDToCells(result, id)
}
export const deleteCell = async (
dashboardID: string,
cell: Cell
): Promise<void> => {
await client.dashboards.deleteCell(dashboardID, cell.id)
}
export const addDashboardLabels = async (
dashboardID: string,
labels: ILabel[]
): Promise<ILabel[]> => {
const addedLabels = await Promise.all(
labels.map(async label => {
return client.dashboards.addLabel(dashboardID, label.id)
})
)
return addedLabels as ILabel[]
}
export const removeDashboardLabels = async (
dashboardID: string,
labels: ILabel[]
): Promise<void> => {
await Promise.all(
labels.map(label => {
return client.dashboards.removeLabel(dashboardID, label.id)
})
)
}
export const getView = async (
dashboardID: string,
cellID: string
): Promise<View> => {
const data = await client.dashboards.getView(dashboardID, cellID)
const view: View = {...data, dashboardID, cellID}
return view
}
export const updateView = async (
dashboardID: string,
cellID: string,
view: Partial<View>
): Promise<View> => {
const data = await client.dashboards.updateView(dashboardID, cellID, view)
const viewWithIDs: View = {...data, dashboardID, cellID}
return viewWithIDs
}
export const cloneDashboard = async (
dashboardToClone: Dashboard,
dashboards: Dashboard[]
) => {
const allDashboardNames = dashboards.map(d => d.name)
const clonedName = incrementCloneName(
allDashboardNames,
dashboardToClone.name
)
const clonedDashboard = await client.dashboards.clone(
dashboardToClone.id,
clonedName
)
return clonedDashboard
}

View File

@ -2,7 +2,6 @@
import _ from 'lodash'
// Utils
import {addLabelDefaults} from 'src/shared/utils/labels'
import {incrementCloneName} from 'src/utils/naming'
// Types
@ -27,7 +26,6 @@ export const getDashboards = async (): Promise<Dashboard[]> => {
return dashboards.map(d => ({
...d,
labels: d.labels.map(addLabelDefaults),
cells: addDashboardIDToCells(d.cells, d.id),
}))
}
@ -39,9 +37,8 @@ export const getDashboardsByOrgID = async (
return dashboards.map(d => ({
...d,
labels: d.labels.map(addLabelDefaults),
cells: addDashboardIDToCells(d.cells, d.id),
}))
})) as Dashboard[]
}
export const getDashboard = async (id: string): Promise<Dashboard> => {
@ -49,7 +46,6 @@ export const getDashboard = async (id: string): Promise<Dashboard> => {
return {
...dashboard,
labels: dashboard.labels.map(addLabelDefaults),
cells: addDashboardIDToCells(dashboard.cells, dashboard.id),
}
}
@ -61,7 +57,6 @@ export const createDashboard = async (
return {
...dashboard,
labels: dashboard.labels.map(addLabelDefaults),
cells: addDashboardIDToCells(dashboard.cells, dashboard.id),
}
}
@ -77,7 +72,6 @@ export const updateDashboard = async (
return {
...updated,
labels: updated.labels.map(addLabelDefaults),
cells: addDashboardIDToCells(updated.cells, updated.id),
}
}

View File

@ -8,7 +8,7 @@ import ExportOverlay from 'src/shared/components/ExportOverlay'
import {dashboardToTemplate} from 'src/shared/utils/resourceToTemplate'
// APIs
import {getDashboard, getView} from 'src/dashboards/apis/v2'
import {getDashboard, getView} from 'src/dashboards/apis'
// Types
import {ITemplate} from '@influxdata/influx'

View File

@ -22,7 +22,7 @@ import {
} from 'src/dashboards/constants/index'
// Actions
import {addNote} from 'src/dashboards/actions/v2/notes'
import {addNote} from 'src/dashboards/actions/notes'
// Types
import * as AppActions from 'src/types/actions/app'

View File

@ -5,8 +5,8 @@ import _ from 'lodash'
import {connect} from 'react-redux'
// Actions
import {getDashboardsAsync} from 'src/dashboards/actions/v2'
import {createDashboardFromTemplate as createDashboardFromTemplateAction} from 'src/dashboards/actions/v2'
import {getDashboardsAsync} from 'src/dashboards/actions'
import {createDashboardFromTemplate as createDashboardFromTemplateAction} from 'src/dashboards/actions'
// Types
import ImportOverlay from 'src/shared/components/ImportOverlay'

View File

@ -16,8 +16,8 @@ import {HoverTimeProvider} from 'src/dashboards/utils/hoverTime'
import NoteEditorContainer from 'src/dashboards/components/NoteEditorContainer'
// Actions
import * as dashboardActions from 'src/dashboards/actions/v2'
import * as rangesActions from 'src/dashboards/actions/v2/ranges'
import * as dashboardActions from 'src/dashboards/actions'
import * as rangesActions from 'src/dashboards/actions/ranges'
import * as appActions from 'src/shared/actions/app'
import * as notifyActions from 'src/shared/actions/notifications'
import {setActiveTimeMachine} from 'src/timeMachine/actions'

View File

@ -18,7 +18,7 @@ import {
setIsPreviewing,
toggleShowNoteWhenEmpty,
setNote,
} from 'src/dashboards/actions/v2/notes'
} from 'src/dashboards/actions/notes'
// Styles
import 'src/dashboards/components/NoteEditor.scss'

View File

@ -13,7 +13,7 @@ import {
closeNoteEditor,
createNoteCell,
updateViewNote,
} from 'src/dashboards/actions/v2/notes'
} from 'src/dashboards/actions/notes'
import {notify} from 'src/shared/actions/notifications'
// Utils

View File

@ -12,7 +12,7 @@ import InlineLabels from 'src/shared/components/inlineLabels/InlineLabels'
import {
addDashboardLabelsAsync,
removeDashboardLabelsAsync,
} from 'src/dashboards/actions/v2'
} from 'src/dashboards/actions'
import {createLabel as createLabelAsync} from 'src/labels/actions'
// Types

View File

@ -10,7 +10,7 @@ import SearchWidget from 'src/shared/components/search_widget/SearchWidget'
import AddResourceDropdown from 'src/shared/components/AddResourceDropdown'
// APIs
import {createDashboard, cloneDashboard} from 'src/dashboards/apis/v2/'
import {createDashboard, cloneDashboard} from 'src/dashboards/apis/'
// Actions
import {
@ -19,8 +19,8 @@ import {
updateDashboardAsync,
addDashboardLabelsAsync,
removeDashboardLabelsAsync,
} from 'src/dashboards/actions/v2'
import {retainRangesDashTimeV1 as retainRangesDashTimeV1Action} from 'src/dashboards/actions/v2/ranges'
} from 'src/dashboards/actions'
import {retainRangesDashTimeV1 as retainRangesDashTimeV1Action} from 'src/dashboards/actions/ranges'
import {notify as notifyAction} from 'src/shared/actions/notifications'
// Constants

View File

@ -1,5 +1,5 @@
// Reducer
import reducer from 'src/dashboards/reducers/v2/dashboards'
import reducer from 'src/dashboards/reducers/dashboards'
// Actions
import {
@ -10,7 +10,7 @@ import {
deleteCell,
addDashboardLabels,
removeDashboardLabels,
} from 'src/dashboards/actions/v2/'
} from 'src/dashboards/actions/'
// Resources
import {dashboard} from 'src/dashboards/resources'

View File

@ -1,4 +1,4 @@
import {Action, ActionTypes} from 'src/dashboards/actions/v2'
import {Action, ActionTypes} from 'src/dashboards/actions'
import {Dashboard} from 'src/types/v2'
import _ from 'lodash'

View File

@ -1,4 +1,4 @@
import {Action} from 'src/dashboards/actions/v2/notes'
import {Action} from 'src/dashboards/actions/notes'
import {NoteEditorMode} from 'src/types/v2/dashboards'
export interface NoteEditorState {

View File

@ -1,6 +1,6 @@
import reducer from 'src/dashboards/reducers/v2/ranges'
import reducer from 'src/dashboards/reducers/ranges'
import {setDashTimeV1, deleteTimeRange} from 'src/dashboards/actions/v2/ranges'
import {setDashTimeV1, deleteTimeRange} from 'src/dashboards/actions/ranges'
const emptyState = undefined
const dashboardID = '1'

View File

@ -1,7 +1,7 @@
import _ from 'lodash'
import {TimeRange} from 'src/types'
import {Action, ActionTypes} from 'src/dashboards/actions/v2/ranges'
import {Action, ActionTypes} from 'src/dashboards/actions/ranges'
export interface Range extends TimeRange {
dashboardID: string

View File

@ -1,5 +1,5 @@
// Types
import {Action} from 'src/dashboards/actions/v2/views'
import {Action} from 'src/dashboards/actions/views'
import {RemoteDataState} from 'src/types'
import {View} from 'src/types/v2'

View File

@ -20,8 +20,8 @@ import DashboardsDropdown from 'src/dataExplorer/components/DashboardsDropdown'
import {cellAddFailed, cellAdded} from 'src/shared/copy/notifications'
// actions
import {getDashboardsAsync, createCellWithView} from 'src/dashboards/actions/v2'
import {createDashboard} from 'src/dashboards/apis/v2'
import {getDashboardsAsync, createCellWithView} from 'src/dashboards/actions'
import {createDashboard} from 'src/dashboards/apis'
import {notify} from 'src/shared/actions/notifications'
// types

View File

@ -1,5 +1,5 @@
import _ from 'lodash'
import {Range} from 'src/dashboards/reducers/v2/ranges'
import {Range} from 'src/dashboards/reducers/ranges'
const dashtime = (ranges: Range[]): Range[] => {
if (!Array.isArray(ranges)) {

View File

@ -11,13 +11,13 @@ import {IconFont} from '@influxdata/clockface'
import AddResourceDropdown from 'src/shared/components/AddResourceDropdown'
// APIs
import {createDashboard, cloneDashboard} from 'src/dashboards/apis/v2/'
import {createDashboard, cloneDashboard} from 'src/dashboards/apis/'
// Actions
import {
deleteDashboardAsync,
updateDashboardAsync,
} from 'src/dashboards/actions/v2'
} from 'src/dashboards/actions/'
import {notify as notifyAction} from 'src/shared/actions/notifications'
// Constants

View File

@ -4,11 +4,11 @@ import {Dispatch} from 'redux'
import {client} from 'src/utils/api'
// Utils
import {addDashboardIDToCells} from 'src/dashboards/apis/v2/'
import {addDashboardIDToCells} from 'src/dashboards/apis/'
import {addLabelDefaults} from 'src/shared/utils/labels'
// Actions
import {loadDashboard} from 'src/dashboards/actions/v2/'
import {loadDashboard} from 'src/dashboards/actions/'
import {notify} from 'src/shared/actions/notifications'
// Types

View File

@ -8,7 +8,7 @@ import {Context} from 'src/clockface'
import {ErrorHandling} from 'src/shared/decorators/errors'
// Actions
import {openNoteEditor} from 'src/dashboards/actions/v2/notes'
import {openNoteEditor} from 'src/dashboards/actions/notes'
// Types
import {IconFont, ComponentColor} from '@influxdata/clockface'

View File

@ -12,14 +12,14 @@ import persistStateEnhancer from './persistStateEnhancer'
// v2 reducers
import meReducer from 'src/shared/reducers/v2/me'
import tasksReducer from 'src/tasks/reducers/v2'
import rangesReducer from 'src/dashboards/reducers/v2/ranges'
import dashboardsReducer from 'src/dashboards/reducers/v2/dashboards'
import viewsReducer from 'src/dashboards/reducers/v2/views'
import rangesReducer from 'src/dashboards/reducers/ranges'
import dashboardsReducer from 'src/dashboards/reducers/dashboards'
import viewsReducer from 'src/dashboards/reducers/views'
import {timeMachinesReducer} from 'src/timeMachine/reducers'
import orgsReducer from 'src/organizations/reducers/orgs'
import orgViewReducer from 'src/organizations/reducers/orgView'
import onboardingReducer from 'src/onboarding/reducers'
import noteEditorReducer from 'src/dashboards/reducers/v2/notes'
import noteEditorReducer from 'src/dashboards/reducers/notes'
import dataLoadingReducer from 'src/dataLoaders/reducers'
import protosReducer from 'src/protos/reducers'
import {variablesReducer} from 'src/variables/reducers'

View File

@ -1,7 +1,7 @@
import {SourceType} from 'src/types/v2/sources'
import {Bucket, RetentionRule, RetentionRuleTypes} from 'src/types/v2/buckets'
import {RangeState} from 'src/dashboards/reducers/v2/ranges'
import {ViewsState} from 'src/dashboards/reducers/v2/views'
import {RangeState} from 'src/dashboards/reducers/ranges'
import {ViewsState} from 'src/dashboards/reducers/views'
import {
DashboardSwitcherLinks,
NewCell,
@ -30,7 +30,7 @@ import {AppState as AppPresentationState} from 'src/shared/reducers/app'
import {State as TaskState} from 'src/tasks/reducers/v2'
import {RouterState} from 'react-router-redux'
import {MeState} from 'src/shared/reducers/v2/me'
import {NoteEditorState} from 'src/dashboards/reducers/v2/notes'
import {NoteEditorState} from 'src/dashboards/reducers/notes'
import {DataLoadingState} from 'src/dataLoaders/reducers'
import {OnboardingState} from 'src/onboarding/reducers'
import {ProtosState} from 'src/protos/reducers'