chore(ui): label client refactor complete (#16361)
Chore(ui): label client refactor completepull/16380/head
parent
7eb04a0690
commit
cffcdf3519
|
@ -60,7 +60,7 @@ import {DEFAULT_DASHBOARD_NAME} from 'src/dashboards/constants/index'
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import {RemoteDataState} from 'src/types'
|
import {RemoteDataState} from 'src/types'
|
||||||
import {CreateCell, ILabel} from '@influxdata/influx'
|
import {CreateCell} from '@influxdata/influx'
|
||||||
import {
|
import {
|
||||||
Dashboard,
|
Dashboard,
|
||||||
NewView,
|
NewView,
|
||||||
|
@ -68,6 +68,7 @@ import {
|
||||||
GetState,
|
GetState,
|
||||||
View,
|
View,
|
||||||
DashboardTemplate,
|
DashboardTemplate,
|
||||||
|
Label,
|
||||||
} from 'src/types'
|
} from 'src/types'
|
||||||
|
|
||||||
export enum ActionTypes {
|
export enum ActionTypes {
|
||||||
|
@ -141,7 +142,7 @@ interface AddDashboardLabelsAction {
|
||||||
type: ActionTypes.AddDashboardLabels
|
type: ActionTypes.AddDashboardLabels
|
||||||
payload: {
|
payload: {
|
||||||
dashboardID: string
|
dashboardID: string
|
||||||
labels: ILabel[]
|
labels: Label[]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,7 +150,7 @@ interface RemoveDashboardLabelsAction {
|
||||||
type: ActionTypes.RemoveDashboardLabels
|
type: ActionTypes.RemoveDashboardLabels
|
||||||
payload: {
|
payload: {
|
||||||
dashboardID: string
|
dashboardID: string
|
||||||
labels: ILabel[]
|
labels: Label[]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,7 +216,7 @@ export const removeCell = (
|
||||||
|
|
||||||
export const addDashboardLabels = (
|
export const addDashboardLabels = (
|
||||||
dashboardID: string,
|
dashboardID: string,
|
||||||
labels: ILabel[]
|
labels: Label[]
|
||||||
): AddDashboardLabelsAction => ({
|
): AddDashboardLabelsAction => ({
|
||||||
type: ActionTypes.AddDashboardLabels,
|
type: ActionTypes.AddDashboardLabels,
|
||||||
payload: {dashboardID, labels},
|
payload: {dashboardID, labels},
|
||||||
|
@ -223,7 +224,7 @@ export const addDashboardLabels = (
|
||||||
|
|
||||||
export const removeDashboardLabels = (
|
export const removeDashboardLabels = (
|
||||||
dashboardID: string,
|
dashboardID: string,
|
||||||
labels: ILabel[]
|
labels: Label[]
|
||||||
): RemoveDashboardLabelsAction => ({
|
): RemoveDashboardLabelsAction => ({
|
||||||
type: ActionTypes.RemoveDashboardLabels,
|
type: ActionTypes.RemoveDashboardLabels,
|
||||||
payload: {dashboardID, labels},
|
payload: {dashboardID, labels},
|
||||||
|
@ -527,7 +528,7 @@ export const copyDashboardCellAsync = (dashboard: Dashboard, cell: Cell) => (
|
||||||
|
|
||||||
export const addDashboardLabelsAsync = (
|
export const addDashboardLabelsAsync = (
|
||||||
dashboardID: string,
|
dashboardID: string,
|
||||||
labels: ILabel[]
|
labels: Label[]
|
||||||
) => async (dispatch: Dispatch<Action | PublishNotificationAction>) => {
|
) => async (dispatch: Dispatch<Action | PublishNotificationAction>) => {
|
||||||
try {
|
try {
|
||||||
const newLabels = await client.dashboards.addLabels(
|
const newLabels = await client.dashboards.addLabels(
|
||||||
|
@ -544,7 +545,7 @@ export const addDashboardLabelsAsync = (
|
||||||
|
|
||||||
export const removeDashboardLabelsAsync = (
|
export const removeDashboardLabelsAsync = (
|
||||||
dashboardID: string,
|
dashboardID: string,
|
||||||
labels: ILabel[]
|
labels: Label[]
|
||||||
) => async (dispatch: Dispatch<Action | PublishNotificationAction>) => {
|
) => async (dispatch: Dispatch<Action | PublishNotificationAction>) => {
|
||||||
try {
|
try {
|
||||||
await client.dashboards.removeLabels(dashboardID, labels.map(l => l.id))
|
await client.dashboards.removeLabels(dashboardID, labels.map(l => l.id))
|
||||||
|
|
|
@ -9,10 +9,11 @@ import {
|
||||||
ILabelProperties,
|
ILabelProperties,
|
||||||
} from '@influxdata/influx'
|
} from '@influxdata/influx'
|
||||||
import {createAuthorization} from 'src/authorizations/apis'
|
import {createAuthorization} from 'src/authorizations/apis'
|
||||||
import {postWrite} from 'src/client'
|
import {postWrite as apiPostWrite, postLabel as apiPostLabel} from 'src/client'
|
||||||
|
|
||||||
// Utils
|
// Utils
|
||||||
import {createNewPlugin} from 'src/dataLoaders/utils/pluginConfigs'
|
import {createNewPlugin} from 'src/dataLoaders/utils/pluginConfigs'
|
||||||
|
import {addLabelDefaults} from 'src/labels/utils/'
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
import {
|
import {
|
||||||
|
@ -30,8 +31,7 @@ import {
|
||||||
BundleName,
|
BundleName,
|
||||||
ConfigurationState,
|
ConfigurationState,
|
||||||
} from 'src/types/dataLoaders'
|
} from 'src/types/dataLoaders'
|
||||||
import {AppState} from 'src/types'
|
import {AppState, RemoteDataState} from 'src/types'
|
||||||
import {RemoteDataState} from 'src/types'
|
|
||||||
import {
|
import {
|
||||||
WritePrecision,
|
WritePrecision,
|
||||||
TelegrafRequest,
|
TelegrafRequest,
|
||||||
|
@ -452,12 +452,20 @@ const createTelegraf = async (dispatch, getState, plugins) => {
|
||||||
tokenID: createdToken.id,
|
tokenID: createdToken.id,
|
||||||
} as ILabelProperties // hack to make compiler work
|
} as ILabelProperties // hack to make compiler work
|
||||||
|
|
||||||
const createdLabel = await client.labels.create({
|
const resp = await apiPostLabel({
|
||||||
orgID: org.id,
|
data: {
|
||||||
name: `@influxdata.token-${new Date().getTime()}`, // fix for https://github.com/influxdata/influxdb/issues/15730
|
orgID: org.id,
|
||||||
properties,
|
name: `@influxdata.token-${new Date().getTime()}`, // fix for https://github.com/influxdata/influxdb/issues/15730
|
||||||
|
properties,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (resp.status !== 201) {
|
||||||
|
throw new Error(resp.data.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
const createdLabel = addLabelDefaults(resp.data.label)
|
||||||
|
|
||||||
// add label to telegraf config
|
// add label to telegraf config
|
||||||
const label = await client.telegrafConfigs.addLabel(tc.id, createdLabel)
|
const label = await client.telegrafConfigs.addLabel(tc.id, createdLabel)
|
||||||
|
|
||||||
|
@ -554,7 +562,10 @@ export const writeLineProtocolAction = (
|
||||||
try {
|
try {
|
||||||
dispatch(setLPStatus(RemoteDataState.Loading))
|
dispatch(setLPStatus(RemoteDataState.Loading))
|
||||||
|
|
||||||
const resp = await postWrite({data: body, query: {org, bucket, precision}})
|
const resp = await apiPostWrite({
|
||||||
|
data: body,
|
||||||
|
query: {org, bucket, precision},
|
||||||
|
})
|
||||||
|
|
||||||
if (resp.status === 204) {
|
if (resp.status === 204) {
|
||||||
dispatch(setLPStatus(RemoteDataState.Done))
|
dispatch(setLPStatus(RemoteDataState.Done))
|
||||||
|
|
|
@ -1,11 +1,14 @@
|
||||||
// API
|
// API
|
||||||
import {client} from 'src/utils/api'
|
import {
|
||||||
|
getLabels as apiGetLabels,
|
||||||
|
postLabel as apiPostLabel,
|
||||||
|
patchLabel as apiPatchLabel,
|
||||||
|
deleteLabel as apiDeleteLabel,
|
||||||
|
} from 'src/client'
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import {Dispatch} from 'react'
|
import {Dispatch} from 'react'
|
||||||
import {RemoteDataState, AppThunk} from 'src/types'
|
import {RemoteDataState, AppThunk, LabelProperties} from 'src/types'
|
||||||
import {ILabel, ILabelProperties} from '@influxdata/influx'
|
|
||||||
import {LabelProperties} from 'src/types/labels'
|
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
import {notify, Action as NotifyAction} from 'src/shared/actions/notifications'
|
import {notify, Action as NotifyAction} from 'src/shared/actions/notifications'
|
||||||
|
@ -15,7 +18,10 @@ import {
|
||||||
updateLabelFailed,
|
updateLabelFailed,
|
||||||
deleteLabelFailed,
|
deleteLabelFailed,
|
||||||
} from 'src/shared/copy/notifications'
|
} from 'src/shared/copy/notifications'
|
||||||
import {GetState} from 'src/types'
|
import {GetState, Label} from 'src/types'
|
||||||
|
|
||||||
|
// Utils
|
||||||
|
import {addLabelDefaults} from 'src/labels/utils/'
|
||||||
|
|
||||||
export type Action =
|
export type Action =
|
||||||
| SetLabels
|
| SetLabels
|
||||||
|
@ -28,13 +34,13 @@ interface SetLabels {
|
||||||
type: 'SET_LABELS'
|
type: 'SET_LABELS'
|
||||||
payload: {
|
payload: {
|
||||||
status: RemoteDataState
|
status: RemoteDataState
|
||||||
list: ILabel[]
|
list: Label[]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setLabels = (
|
export const setLabels = (
|
||||||
status: RemoteDataState,
|
status: RemoteDataState,
|
||||||
list?: ILabel[]
|
list?: Label[]
|
||||||
): SetLabels => ({
|
): SetLabels => ({
|
||||||
type: 'SET_LABELS',
|
type: 'SET_LABELS',
|
||||||
payload: {status, list},
|
payload: {status, list},
|
||||||
|
@ -43,11 +49,11 @@ export const setLabels = (
|
||||||
interface AddLabel {
|
interface AddLabel {
|
||||||
type: 'ADD_LABEL'
|
type: 'ADD_LABEL'
|
||||||
payload: {
|
payload: {
|
||||||
label: ILabel
|
label: Label
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const addLabel = (label: ILabel): AddLabel => ({
|
export const addLabel = (label: Label): AddLabel => ({
|
||||||
type: 'ADD_LABEL',
|
type: 'ADD_LABEL',
|
||||||
payload: {label},
|
payload: {label},
|
||||||
})
|
})
|
||||||
|
@ -57,7 +63,7 @@ interface EditLabel {
|
||||||
payload: {label}
|
payload: {label}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const editLabel = (label: ILabel): EditLabel => ({
|
export const editLabel = (label: Label): EditLabel => ({
|
||||||
type: 'EDIT_LABEL',
|
type: 'EDIT_LABEL',
|
||||||
payload: {label},
|
payload: {label},
|
||||||
})
|
})
|
||||||
|
@ -82,7 +88,13 @@ export const getLabels = () => async (
|
||||||
} = getState()
|
} = getState()
|
||||||
dispatch(setLabels(RemoteDataState.Loading))
|
dispatch(setLabels(RemoteDataState.Loading))
|
||||||
|
|
||||||
const labels = await client.labels.getAll(org.id)
|
const resp = await apiGetLabels({query: {orgID: org.id}})
|
||||||
|
|
||||||
|
if (resp.status !== 200) {
|
||||||
|
throw new Error(resp.data.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
const labels = resp.data.labels.map(l => addLabelDefaults(l))
|
||||||
|
|
||||||
dispatch(setLabels(RemoteDataState.Done, labels))
|
dispatch(setLabels(RemoteDataState.Done, labels))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -104,12 +116,20 @@ export const createLabel = (
|
||||||
} = getState()
|
} = getState()
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const createdLabel = await client.labels.create({
|
const resp = await apiPostLabel({
|
||||||
orgID: org.id,
|
data: {
|
||||||
name,
|
orgID: org.id,
|
||||||
properties: properties as ILabelProperties,
|
name,
|
||||||
|
properties,
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (resp.status !== 201) {
|
||||||
|
throw new Error(resp.data.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
const createdLabel = addLabelDefaults(resp.data.label)
|
||||||
|
|
||||||
dispatch(addLabel(createdLabel))
|
dispatch(addLabel(createdLabel))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e)
|
console.error(e)
|
||||||
|
@ -117,11 +137,17 @@ export const createLabel = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const updateLabel = (id: string, l: ILabel) => async (
|
export const updateLabel = (id: string, l: Label) => async (
|
||||||
dispatch: Dispatch<Action>
|
dispatch: Dispatch<Action>
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
const label = await client.labels.update(id, l)
|
const resp = await apiPatchLabel({labelID: id, data: l})
|
||||||
|
|
||||||
|
if (resp.status !== 200) {
|
||||||
|
throw new Error(resp.data.message)
|
||||||
|
}
|
||||||
|
|
||||||
|
const label = addLabelDefaults(resp.data.label)
|
||||||
|
|
||||||
dispatch(editLabel(label))
|
dispatch(editLabel(label))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
@ -134,7 +160,7 @@ export const deleteLabel = (id: string) => async (
|
||||||
dispatch: Dispatch<Action>
|
dispatch: Dispatch<Action>
|
||||||
) => {
|
) => {
|
||||||
try {
|
try {
|
||||||
await client.labels.delete(id)
|
await apiDeleteLabel({labelID: id})
|
||||||
|
|
||||||
dispatch(removeLabel(id))
|
dispatch(removeLabel(id))
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
|
|
@ -7,7 +7,7 @@ import LabelOverlayForm from 'src/labels/components/LabelOverlayForm'
|
||||||
import {Overlay, ComponentStatus} from '@influxdata/clockface'
|
import {Overlay, ComponentStatus} from '@influxdata/clockface'
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import {ILabel} from '@influxdata/influx'
|
import {Label} from 'src/types'
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
import {EMPTY_LABEL} from 'src/labels/constants'
|
import {EMPTY_LABEL} from 'src/labels/constants'
|
||||||
|
@ -18,12 +18,12 @@ import {ErrorHandling} from 'src/shared/decorators/errors'
|
||||||
interface Props {
|
interface Props {
|
||||||
isVisible: boolean
|
isVisible: boolean
|
||||||
onDismiss: () => void
|
onDismiss: () => void
|
||||||
onCreateLabel: (label: ILabel) => void
|
onCreateLabel: (label: Label) => void
|
||||||
onNameValidation: (name: string) => string | null
|
onNameValidation: (name: string) => string | null
|
||||||
overrideDefaultName?: string
|
overrideDefaultName?: string
|
||||||
}
|
}
|
||||||
interface State {
|
interface State {
|
||||||
label: ILabel
|
label: Label
|
||||||
colorStatus: ComponentStatus
|
colorStatus: ComponentStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,6 @@ import {validateLabelUniqueness} from 'src/labels/utils/'
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import {AppState, Label} from 'src/types'
|
import {AppState, Label} from 'src/types'
|
||||||
import {ILabel} from '@influxdata/influx'
|
|
||||||
import {
|
import {
|
||||||
IconFont,
|
IconFont,
|
||||||
ComponentSize,
|
ComponentSize,
|
||||||
|
@ -145,7 +144,7 @@ class Labels extends PureComponent<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleUpdateLabel = (label: Label) => {
|
private handleUpdateLabel = (label: Label) => {
|
||||||
this.props.updateLabel(label.id, label as ILabel)
|
this.props.updateLabel(label.id, label)
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleDelete = (id: string) => {
|
private handleDelete = (id: string) => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// Labels can use a different set of brand colors than single stats or gauges
|
// Labels can use a different set of brand colors than single stats or gauges
|
||||||
import {ILabel} from '@influxdata/influx'
|
import {Label} from 'src/types'
|
||||||
import {LabelColor, LabelColorType} from 'src/types/colors'
|
import {LabelColor, LabelColorType} from 'src/types/colors'
|
||||||
|
|
||||||
export const INFLUX_LABEL_PREFIX = '@influxdata'
|
export const INFLUX_LABEL_PREFIX = '@influxdata'
|
||||||
|
@ -9,7 +9,7 @@ export const HEX_CODE_CHAR_LENGTH = 7
|
||||||
|
|
||||||
export const DEFAULT_LABEL_COLOR_HEX = '#326BBA'
|
export const DEFAULT_LABEL_COLOR_HEX = '#326BBA'
|
||||||
|
|
||||||
export const EMPTY_LABEL: ILabel = {
|
export const EMPTY_LABEL: Label = {
|
||||||
name: '',
|
name: '',
|
||||||
properties: {
|
properties: {
|
||||||
description: '',
|
description: '',
|
||||||
|
|
|
@ -23,7 +23,7 @@ import {createTaskFromTemplate as createTaskFromTemplateAJAX} from 'src/template
|
||||||
import {addLabelDefaults} from 'src/labels/utils'
|
import {addLabelDefaults} from 'src/labels/utils'
|
||||||
import {
|
import {
|
||||||
deleteTask as apiDeleteTask,
|
deleteTask as apiDeleteTask,
|
||||||
deleteTasksLabel,
|
deleteTasksLabel as apiDeleteTasksLabel,
|
||||||
getTask as apiGetTask,
|
getTask as apiGetTask,
|
||||||
getTasks as apiGetTasks,
|
getTasks as apiGetTasks,
|
||||||
getTasksRuns as apiGetTasksRuns,
|
getTasksRuns as apiGetTasksRuns,
|
||||||
|
@ -295,7 +295,7 @@ export const removeTaskLabelAsync = (taskID: string, label: Label) => async (
|
||||||
dispatch
|
dispatch
|
||||||
): Promise<void> => {
|
): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
await deleteTasksLabel({taskID, labelID: label.id})
|
await apiDeleteTasksLabel({taskID, labelID: label.id})
|
||||||
const resp = await apiGetTask({taskID})
|
const resp = await apiGetTask({taskID})
|
||||||
if (resp.status !== 200) {
|
if (resp.status !== 200) {
|
||||||
throw new Error(resp.data.message)
|
throw new Error(resp.data.message)
|
||||||
|
|
|
@ -25,8 +25,7 @@ import {viewableLabels} from 'src/labels/selectors'
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import {ComponentColor} from '@influxdata/clockface'
|
import {ComponentColor} from '@influxdata/clockface'
|
||||||
import {ILabel} from '@influxdata/influx'
|
import {AppState, Task, Label} from 'src/types'
|
||||||
import {AppState, Task} from 'src/types'
|
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
import {DEFAULT_TASK_NAME} from 'src/dashboards/constants'
|
import {DEFAULT_TASK_NAME} from 'src/dashboards/constants'
|
||||||
|
@ -43,7 +42,7 @@ interface PassedProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface StateProps {
|
interface StateProps {
|
||||||
labels: ILabel[]
|
labels: Label[]
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DispatchProps {
|
interface DispatchProps {
|
||||||
|
@ -184,19 +183,19 @@ export class TaskCard extends PureComponent<Props & WithRouterProps> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleAddLabel = (label: ILabel) => {
|
private handleAddLabel = (label: Label) => {
|
||||||
const {task, onAddTaskLabel} = this.props
|
const {task, onAddTaskLabel} = this.props
|
||||||
|
|
||||||
onAddTaskLabel(task.id, label)
|
onAddTaskLabel(task.id, label)
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleRemoveLabel = (label: ILabel) => {
|
private handleRemoveLabel = (label: Label) => {
|
||||||
const {task, onRemoveTaskLabel} = this.props
|
const {task, onRemoveTaskLabel} = this.props
|
||||||
|
|
||||||
onRemoveTaskLabel(task.id, label)
|
onRemoveTaskLabel(task.id, label)
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleCreateLabel = (label: ILabel) => {
|
private handleCreateLabel = (label: Label) => {
|
||||||
this.props.onCreateLabel(label.name, label.properties)
|
this.props.onCreateLabel(label.name, label.properties)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,6 @@ import {
|
||||||
ITaskTemplate,
|
ITaskTemplate,
|
||||||
TemplateType,
|
TemplateType,
|
||||||
ITemplate,
|
ITemplate,
|
||||||
ILabel as Label,
|
|
||||||
} from '@influxdata/influx'
|
} from '@influxdata/influx'
|
||||||
import {
|
import {
|
||||||
RemoteDataState,
|
RemoteDataState,
|
||||||
|
@ -20,6 +19,7 @@ import {
|
||||||
DashboardTemplate,
|
DashboardTemplate,
|
||||||
VariableTemplate,
|
VariableTemplate,
|
||||||
Template,
|
Template,
|
||||||
|
Label,
|
||||||
} from 'src/types'
|
} from 'src/types'
|
||||||
|
|
||||||
// Actions
|
// Actions
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import _ from 'lodash'
|
import _, {get} from 'lodash'
|
||||||
import {
|
import {
|
||||||
DashboardTemplate,
|
DashboardTemplate,
|
||||||
TemplateType,
|
TemplateType,
|
||||||
|
@ -24,11 +24,14 @@ import {
|
||||||
getLabelRelationships,
|
getLabelRelationships,
|
||||||
} from 'src/templates/utils/'
|
} from 'src/templates/utils/'
|
||||||
import {addDefaults} from 'src/tasks/actions'
|
import {addDefaults} from 'src/tasks/actions'
|
||||||
|
import {addLabelDefaults} from 'src/labels/utils'
|
||||||
// API
|
// API
|
||||||
import {
|
import {
|
||||||
getTask as apiGetTask,
|
getTask as apiGetTask,
|
||||||
postTask as apiPostTask,
|
postTask as apiPostTask,
|
||||||
postTasksLabel as apiPostTasksLabel,
|
postTasksLabel as apiPostTasksLabel,
|
||||||
|
getLabels as apiGetLabels,
|
||||||
|
postLabel as apiPostLabel,
|
||||||
} from 'src/client'
|
} from 'src/client'
|
||||||
// Create Dashboard Templates
|
// Create Dashboard Templates
|
||||||
|
|
||||||
|
@ -107,17 +110,33 @@ const createLabelsFromTemplate = async <T extends TemplateBase>(
|
||||||
labelRelationships
|
labelRelationships
|
||||||
)
|
)
|
||||||
|
|
||||||
const existingLabels = await client.labels.getAll(orgID)
|
const resp = await apiGetLabels({query: {orgID}})
|
||||||
|
|
||||||
const labelsToCreate = findLabelsToCreate(existingLabels, includedLabels).map(
|
if (resp.status !== 200) {
|
||||||
l => ({
|
throw new Error(resp.data.message)
|
||||||
orgID,
|
}
|
||||||
name: _.get(l, 'attributes.name', ''),
|
|
||||||
properties: _.get(l, 'attributes.properties', {}),
|
const existingLabels = resp.data.labels.map(l => addLabelDefaults(l))
|
||||||
|
|
||||||
|
const foundLabelsToCreate = findLabelsToCreate(
|
||||||
|
existingLabels,
|
||||||
|
includedLabels
|
||||||
|
).map(l => ({
|
||||||
|
orgID,
|
||||||
|
name: _.get(l, 'attributes.name', ''),
|
||||||
|
properties: _.get(l, 'attributes.properties', {}),
|
||||||
|
}))
|
||||||
|
|
||||||
|
const promisedLabels = foundLabelsToCreate.map(async lab => {
|
||||||
|
return apiPostLabel({
|
||||||
|
data: lab,
|
||||||
})
|
})
|
||||||
)
|
.then(res => get(res, 'res.data.label', ''))
|
||||||
|
.then(lab => addLabelDefaults(lab))
|
||||||
|
})
|
||||||
|
|
||||||
|
const createdLabels = await Promise.all(promisedLabels)
|
||||||
|
|
||||||
const createdLabels = await client.labels.createAll(labelsToCreate)
|
|
||||||
const allLabels = [...createdLabels, ...existingLabels]
|
const allLabels = [...createdLabels, ...existingLabels]
|
||||||
|
|
||||||
const labelMap: LabelMap = {}
|
const labelMap: LabelMap = {}
|
||||||
|
|
|
@ -21,9 +21,9 @@ import {createResourceFromStaticTemplate} from 'src/templates/actions'
|
||||||
import {viewableLabels} from 'src/labels/selectors'
|
import {viewableLabels} from 'src/labels/selectors'
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import {TemplateSummary, ILabel} from '@influxdata/influx'
|
import {TemplateSummary} from '@influxdata/influx'
|
||||||
import {ComponentColor} from '@influxdata/clockface'
|
import {ComponentColor} from '@influxdata/clockface'
|
||||||
import {AppState, Organization} from 'src/types'
|
import {AppState, Organization, Label} from 'src/types'
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
interface OwnProps {
|
interface OwnProps {
|
||||||
|
@ -37,7 +37,7 @@ interface DispatchProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface StateProps {
|
interface StateProps {
|
||||||
labels: ILabel[]
|
labels: Label[]
|
||||||
org: Organization
|
org: Organization
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,9 +31,9 @@ import {createLabel as createLabelAsync} from 'src/labels/actions'
|
||||||
import {viewableLabels} from 'src/labels/selectors'
|
import {viewableLabels} from 'src/labels/selectors'
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import {TemplateSummary, ILabel} from '@influxdata/influx'
|
import {TemplateSummary} from '@influxdata/influx'
|
||||||
import {ComponentColor} from '@influxdata/clockface'
|
import {ComponentColor} from '@influxdata/clockface'
|
||||||
import {AppState, Organization} from 'src/types'
|
import {AppState, Organization, Label} from 'src/types'
|
||||||
|
|
||||||
// Constants
|
// Constants
|
||||||
import {DEFAULT_TEMPLATE_NAME} from 'src/templates/constants'
|
import {DEFAULT_TEMPLATE_NAME} from 'src/templates/constants'
|
||||||
|
@ -54,7 +54,7 @@ interface DispatchProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface StateProps {
|
interface StateProps {
|
||||||
labels: ILabel[]
|
labels: Label[]
|
||||||
org: Organization
|
org: Organization
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -203,19 +203,19 @@ class TemplateCard extends PureComponent<Props & WithRouterProps> {
|
||||||
router.push(`/orgs/${org.id}/settings/templates/${template.id}/view`)
|
router.push(`/orgs/${org.id}/settings/templates/${template.id}/view`)
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleAddLabel = (label: ILabel): void => {
|
private handleAddLabel = (label: Label): void => {
|
||||||
const {template, onAddTemplateLabels} = this.props
|
const {template, onAddTemplateLabels} = this.props
|
||||||
|
|
||||||
onAddTemplateLabels(template.id, [label])
|
onAddTemplateLabels(template.id, [label])
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleRemoveLabel = (label: ILabel): void => {
|
private handleRemoveLabel = (label: Label): void => {
|
||||||
const {template, onRemoveTemplateLabels} = this.props
|
const {template, onRemoveTemplateLabels} = this.props
|
||||||
|
|
||||||
onRemoveTemplateLabels(template.id, [label])
|
onRemoveTemplateLabels(template.id, [label])
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleCreateLabel = (label: ILabel) => {
|
private handleCreateLabel = (label: Label) => {
|
||||||
this.props.onCreateLabel(label.name, label.properties)
|
this.props.onCreateLabel(label.name, label.properties)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,8 @@ import {
|
||||||
Relationships,
|
Relationships,
|
||||||
LabelRelationship,
|
LabelRelationship,
|
||||||
} from 'src/types'
|
} from 'src/types'
|
||||||
import {ILabel, IVariable as Variable} from '@influxdata/influx'
|
import {IVariable as Variable} from '@influxdata/influx'
|
||||||
|
import {Label} from 'src/types'
|
||||||
|
|
||||||
export function findIncludedsFromRelationships<
|
export function findIncludedsFromRelationships<
|
||||||
T extends {id: string; type: TemplateType}
|
T extends {id: string; type: TemplateType}
|
||||||
|
@ -33,7 +34,7 @@ export function findIncludedFromRelationship<
|
||||||
}
|
}
|
||||||
|
|
||||||
export const findLabelsToCreate = (
|
export const findLabelsToCreate = (
|
||||||
currentLabels: ILabel[],
|
currentLabels: Label[],
|
||||||
labels: LabelIncluded[]
|
labels: LabelIncluded[]
|
||||||
): LabelIncluded[] => {
|
): LabelIncluded[] => {
|
||||||
return labels.filter(
|
return labels.filter(
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
import {
|
import {
|
||||||
ILabel,
|
|
||||||
IVariable as Variable,
|
IVariable as Variable,
|
||||||
IDashboard,
|
IDashboard,
|
||||||
DocumentListEntry,
|
DocumentListEntry,
|
||||||
Document,
|
Document,
|
||||||
DocumentMeta,
|
DocumentMeta,
|
||||||
} from '@influxdata/influx'
|
} from '@influxdata/influx'
|
||||||
import {View, Cell} from './index'
|
import {View, Cell, Label} from './index'
|
||||||
|
|
||||||
export enum TemplateType {
|
export enum TemplateType {
|
||||||
Label = 'label',
|
Label = 'label',
|
||||||
|
@ -29,7 +28,7 @@ interface DocumentMetaWithTemplateID extends DocumentMeta {
|
||||||
export interface TemplateBase extends Document {
|
export interface TemplateBase extends Document {
|
||||||
meta: DocumentMetaWithTemplateID
|
meta: DocumentMetaWithTemplateID
|
||||||
content: {data: TemplateData; included: TemplateIncluded[]}
|
content: {data: TemplateData; included: TemplateIncluded[]}
|
||||||
labels: ILabel[]
|
labels: Label[]
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: be more specific about what attributes can be
|
// TODO: be more specific about what attributes can be
|
||||||
|
@ -98,7 +97,7 @@ export interface CellIncluded extends TemplateIncluded {
|
||||||
|
|
||||||
export interface LabelIncluded extends TemplateIncluded {
|
export interface LabelIncluded extends TemplateIncluded {
|
||||||
type: TemplateType.Label
|
type: TemplateType.Label
|
||||||
attributes: ILabel
|
attributes: Label
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface VariableIncluded extends TemplateIncluded {
|
export interface VariableIncluded extends TemplateIncluded {
|
||||||
|
@ -172,5 +171,5 @@ export interface VariableTemplate extends TemplateBase {
|
||||||
export type Template = TaskTemplate | DashboardTemplate | VariableTemplate
|
export type Template = TaskTemplate | DashboardTemplate | VariableTemplate
|
||||||
|
|
||||||
export interface TemplateSummary extends DocumentListEntry {
|
export interface TemplateSummary extends DocumentListEntry {
|
||||||
labels: ILabel[]
|
labels: Label[]
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,8 +38,9 @@ import {
|
||||||
QueryArguments,
|
QueryArguments,
|
||||||
MapArguments,
|
MapArguments,
|
||||||
CSVArguments,
|
CSVArguments,
|
||||||
|
Label,
|
||||||
} from 'src/types'
|
} from 'src/types'
|
||||||
import {IVariable as Variable, ILabel as Label} from '@influxdata/influx'
|
import {IVariable as Variable} from '@influxdata/influx'
|
||||||
import {VariableValuesByID} from 'src/variables/types'
|
import {VariableValuesByID} from 'src/variables/types'
|
||||||
import {
|
import {
|
||||||
addVariableLabelFailed,
|
addVariableLabelFailed,
|
||||||
|
|
|
@ -9,8 +9,8 @@ import InlineLabels from 'src/shared/components/inlineLabels/InlineLabels'
|
||||||
import VariableContextMenu from 'src/variables/components/VariableContextMenu'
|
import VariableContextMenu from 'src/variables/components/VariableContextMenu'
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import {IVariable as Variable, ILabel} from '@influxdata/influx'
|
import {IVariable as Variable} from '@influxdata/influx'
|
||||||
import {AppState} from 'src/types'
|
import {AppState, Label} from 'src/types'
|
||||||
|
|
||||||
// Selectors
|
// Selectors
|
||||||
import {viewableLabels} from 'src/labels/selectors'
|
import {viewableLabels} from 'src/labels/selectors'
|
||||||
|
@ -31,7 +31,7 @@ interface OwnProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
interface StateProps {
|
interface StateProps {
|
||||||
labels: ILabel[]
|
labels: Label[]
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DispatchProps {
|
interface DispatchProps {
|
||||||
|
@ -95,19 +95,19 @@ class VariableCard extends PureComponent<Props & WithRouterProps> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleAddLabel = (label: ILabel): void => {
|
private handleAddLabel = (label: Label): void => {
|
||||||
const {variable, onAddVariableLabels} = this.props
|
const {variable, onAddVariableLabels} = this.props
|
||||||
|
|
||||||
onAddVariableLabels(variable.id, [label])
|
onAddVariableLabels(variable.id, [label])
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleRemoveLabel = (label: ILabel): void => {
|
private handleRemoveLabel = (label: Label): void => {
|
||||||
const {variable, onRemoveVariableLabels} = this.props
|
const {variable, onRemoveVariableLabels} = this.props
|
||||||
|
|
||||||
onRemoveVariableLabels(variable.id, [label])
|
onRemoveVariableLabels(variable.id, [label])
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleCreateLabel = (label: ILabel): void => {
|
private handleCreateLabel = (label: Label): void => {
|
||||||
const {name, properties} = label
|
const {name, properties} = label
|
||||||
this.props.onCreateLabel(name, properties)
|
this.props.onCreateLabel(name, properties)
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ class VariableCard extends PureComponent<Props & WithRouterProps> {
|
||||||
|
|
||||||
const mstp = ({labels}: AppState): StateProps => {
|
const mstp = ({labels}: AppState): StateProps => {
|
||||||
return {
|
return {
|
||||||
labels: viewableLabels(labels.list as ILabel[]),
|
labels: viewableLabels(labels.list),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue