diff --git a/ui/src/dashboards/components/CellEditorOverlay.tsx b/ui/src/dashboards/components/CellEditorOverlay.tsx index dd19917b87..737ac2dfad 100644 --- a/ui/src/dashboards/components/CellEditorOverlay.tsx +++ b/ui/src/dashboards/components/CellEditorOverlay.tsx @@ -2,7 +2,7 @@ import React, {Component} from 'react' import _ from 'lodash' import uuid from 'uuid' -import {getNested} from 'src/utils/wrappers' +import {getDeep} from 'src/utils/wrappers' import ResizeContainer from 'src/shared/components/ResizeContainer' import QueryMaker from 'src/dashboards/components/QueryMaker' @@ -306,7 +306,7 @@ class CellEditorOverlay extends Component { const queries: CellQuery[] = queriesWorkingDraft.map(q => { const timeRange = q.range || {upper: null, lower: TEMP_VAR_DASHBOARD_TIME} - const source = getNested(q.source, 'links.self', null) + const source = getDeep(q.source, 'links.self', null) return { queryConfig: q, query: q.rawText || buildQuery(TYPE_QUERY_CONFIG, timeRange, q), @@ -449,7 +449,7 @@ class CellEditorOverlay extends Component { private findSelectedSource = (): string => { const {source} = this.props const sources = this.formattedSources - const currentSource = getNested( + const currentSource = getDeep( this.state.queriesWorkingDraft, '0.source', null @@ -531,11 +531,7 @@ class CellEditorOverlay extends Component { sources, } = this.props - const initialSourceLink: string = getNested( - queries, - '0.source', - null - ) + const initialSourceLink: string = getDeep(queries, '0.source', null) if (initialSourceLink) { const initialSource = sources.find( @@ -559,7 +555,7 @@ class CellEditorOverlay extends Component { sources.find( s => s.links.self === - getNested(query, 'source.links.self', null) + getDeep(query, 'source.links.self', null) ) || source ) } diff --git a/ui/src/kapacitor/components/AlertTabs.tsx b/ui/src/kapacitor/components/AlertTabs.tsx index 20fffcd67b..4cda960e8c 100644 --- a/ui/src/kapacitor/components/AlertTabs.tsx +++ b/ui/src/kapacitor/components/AlertTabs.tsx @@ -1,7 +1,7 @@ import React, {PureComponent, MouseEvent} from 'react' import _ from 'lodash' -import {getNested} from 'src/utils/wrappers' +import {getDeep} from 'src/utils/wrappers' import { Tab, @@ -431,12 +431,12 @@ class AlertTabs extends PureComponent { private get isMultipleConfigsSupported(): boolean { const {configSections} = this.state - const hasPagerDuty2 = getNested
( + const hasPagerDuty2 = getDeep
( configSections, AlertTypes.pagerduty2, undefined ) - const hasOpsGenie2 = getNested
( + const hasOpsGenie2 = getDeep
( configSections, AlertTypes.opsgenie2, undefined @@ -454,13 +454,13 @@ class AlertTabs extends PureComponent { private getConfigEnabled = (sections: Sections, section: string): boolean => { if (section === AlertTypes.slack || section === AlertTypes.kafka) { - const configElements = getNested( + const configElements = getDeep( sections, `${section}.elements`, [] ) const enabledConfigElements = configElements.filter(e => { - const enabled = getNested(e, 'options.enabled', false) + const enabled = getDeep(e, 'options.enabled', false) return enabled }) return enabledConfigElements.length > 0 diff --git a/ui/src/kapacitor/components/config/KafkaConfig.tsx b/ui/src/kapacitor/components/config/KafkaConfig.tsx index 025bce6995..024c4114f0 100644 --- a/ui/src/kapacitor/components/config/KafkaConfig.tsx +++ b/ui/src/kapacitor/components/config/KafkaConfig.tsx @@ -8,7 +8,7 @@ import {Notification, NotificationFunc} from 'src/types' import {KafkaProperties} from 'src/types/kapacitor' import {notifyInvalidBatchSizeValue} from 'src/shared/copy/notifications' -import {getNested} from 'src/utils/wrappers' +import {getDeep} from 'src/utils/wrappers' interface Config { options: KafkaProperties @@ -62,7 +62,7 @@ class KafkaConfig extends PureComponent { this.state = { currentBrokers: brokers || [], testEnabled: this.props.enabled, - enabled: getNested(this.props, 'config.options.enabled', false), + enabled: getDeep(this.props, 'config.options.enabled', false), } } @@ -244,7 +244,7 @@ class KafkaConfig extends PureComponent { } private get isNewConfig(): boolean { - return getNested(this.props, 'config.isNewConfig', false) + return getDeep(this.props, 'config.isNewConfig', false) } private get isDefaultConfig(): boolean { diff --git a/ui/src/kapacitor/components/config/KafkaConfigs.tsx b/ui/src/kapacitor/components/config/KafkaConfigs.tsx index 750e3d2a65..df87293ff5 100644 --- a/ui/src/kapacitor/components/config/KafkaConfigs.tsx +++ b/ui/src/kapacitor/components/config/KafkaConfigs.tsx @@ -7,7 +7,7 @@ import {ErrorHandling} from 'src/shared/decorators/errors' import {KafkaProperties} from 'src/types/kapacitor' import {Notification, NotificationFunc} from 'src/types' -import {getNested} from 'src/utils/wrappers' +import {getDeep} from 'src/utils/wrappers' const DEFAULT_CONFIG = { options: { @@ -63,8 +63,8 @@ class KafkaConfigs extends Component { return (
{this.configs.map(c => { - const enabled = getNested(c, 'options.enabled', false) - const id = getNested(c, 'options.id', '') + const enabled = getDeep(c, 'options.enabled', false) + const id = getDeep(c, 'options.id', '') return ( { } private get configs(): Config[] { return _.sortBy(this.state.configs, c => { - const id = getNested(c, 'options.id', '') + const id = getDeep(c, 'options.id', '') const {isNewConfig} = c if (id === 'default') { return '' diff --git a/ui/src/kapacitor/components/config/SlackConfigs.tsx b/ui/src/kapacitor/components/config/SlackConfigs.tsx index 4ac217e303..815454b747 100644 --- a/ui/src/kapacitor/components/config/SlackConfigs.tsx +++ b/ui/src/kapacitor/components/config/SlackConfigs.tsx @@ -1,6 +1,6 @@ import React, {PureComponent, MouseEvent} from 'react' import _ from 'lodash' -import {getNested} from 'src/utils/wrappers' +import {getDeep} from 'src/utils/wrappers' import {ErrorHandling} from 'src/shared/decorators/errors' import SlackConfig from 'src/kapacitor/components/config/SlackConfig' @@ -98,7 +98,7 @@ class SlackConfigs extends PureComponent { } private isNewConfig = (config: Config): boolean => { - return getNested(config, 'isNewConfig', false) + return getDeep(config, 'isNewConfig', false) } private isDefaultConfig = (config: Config): boolean => { diff --git a/ui/src/utils/buildQueriesForGraphs.ts b/ui/src/utils/buildQueriesForGraphs.ts index 318cb23346..66133fa2c0 100644 --- a/ui/src/utils/buildQueriesForGraphs.ts +++ b/ui/src/utils/buildQueriesForGraphs.ts @@ -1,5 +1,5 @@ import _ from 'lodash' -import {getNested} from 'src/utils/wrappers' +import {getDeep} from 'src/utils/wrappers' import {buildQuery} from 'src/utils/influxql' import {TYPE_QUERY_CONFIG, TYPE_SHIFTED} from 'src/dashboards/constants' @@ -42,11 +42,7 @@ const buildQueries = ( const queries: Query[] = statements .filter(s => s.text !== null) .map(({queryConfig, text, id}) => { - const queryProxy = getNested( - queryConfig, - 'source.links.proxy', - '' - ) + const queryProxy = getDeep(queryConfig, 'source.links.proxy', '') const host: string[] = [queryProxy || proxy] return { diff --git a/ui/src/utils/groupByTimeSeriesTransform.ts b/ui/src/utils/groupByTimeSeriesTransform.ts index 08b64c32c9..4fb2474dd9 100644 --- a/ui/src/utils/groupByTimeSeriesTransform.ts +++ b/ui/src/utils/groupByTimeSeriesTransform.ts @@ -16,7 +16,7 @@ import { TimeSeriesSuccessfulResult, TimeSeries, } from 'src/types/series' -import {getNested} from 'src/utils/wrappers' +import {getDeep} from 'src/utils/wrappers' interface Result { series: TimeSeriesSeries[] @@ -60,7 +60,7 @@ const flattenGroupBySeries = ( } const tagsKeys = _.keys(tags) - const seriesArray = getNested(results, '[0].series', []) + const seriesArray = getDeep(results, '[0].series', []) const accumulatedValues = fastReduce( seriesArray, @@ -76,7 +76,7 @@ const flattenGroupBySeries = ( }, [] ) - const firstColumns = getNested(results, '[0].series[0]columns', []) + const firstColumns = getDeep(results, '[0].series[0]columns', []) const flattenedSeries: Result[] = [ { @@ -102,7 +102,7 @@ const constructResults = ( const MappedResponse = fastMap( raw, (response, index) => { - const results = getNested( + const results = getDeep( response, 'response.results', [] diff --git a/ui/src/utils/wrappers.ts b/ui/src/utils/wrappers.ts index 90c2eeb558..8a64f0d761 100644 --- a/ui/src/utils/wrappers.ts +++ b/ui/src/utils/wrappers.ts @@ -1,5 +1,5 @@ import _ from 'lodash' -export function getNested(obj: any, path: string, fallback: T): T { +export function getDeep(obj: any, path: string, fallback: T): T { return _.get(obj, path, fallback) } diff --git a/ui/test/utils/wrappers.test.ts b/ui/test/utils/wrappers.test.ts index 25fff02622..61409216fb 100644 --- a/ui/test/utils/wrappers.test.ts +++ b/ui/test/utils/wrappers.test.ts @@ -1,17 +1,17 @@ -import {getNested} from 'src/utils/wrappers' +import {getDeep} from 'src/utils/wrappers' describe('utils.wrappers', () => { describe('get', () => { it('gets a nested value', () => { const example = {a: {b: 'hello'}} - expect(getNested(example, 'a.b', 'default')).toEqual('hello') + expect(getDeep(example, 'a.b', 'default')).toEqual('hello') }) it('gets the default value when key is empty', () => { const example = {a: {b: 'hello'}} - expect(getNested(example, 'a.c', 'default')).toEqual('default') + expect(getDeep(example, 'a.c', 'default')).toEqual('default') }) }) })