Rename getNested to getDeep

pull/10616/head
Iris Scholten 2018-05-22 10:13:56 -07:00 committed by Jared Scheib
parent 2ec7881c64
commit b980d1a8b3
9 changed files with 29 additions and 37 deletions

View File

@ -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<Props, State> {
const queries: CellQuery[] = queriesWorkingDraft.map(q => {
const timeRange = q.range || {upper: null, lower: TEMP_VAR_DASHBOARD_TIME}
const source = getNested<string | null>(q.source, 'links.self', null)
const source = getDeep<string | null>(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<Props, State> {
private findSelectedSource = (): string => {
const {source} = this.props
const sources = this.formattedSources
const currentSource = getNested<Source | null>(
const currentSource = getDeep<Source | null>(
this.state.queriesWorkingDraft,
'0.source',
null
@ -531,11 +531,7 @@ class CellEditorOverlay extends Component<Props, State> {
sources,
} = this.props
const initialSourceLink: string = getNested<string>(
queries,
'0.source',
null
)
const initialSourceLink: string = getDeep<string>(queries, '0.source', null)
if (initialSourceLink) {
const initialSource = sources.find(
@ -559,7 +555,7 @@ class CellEditorOverlay extends Component<Props, State> {
sources.find(
s =>
s.links.self ===
getNested<string | null>(query, 'source.links.self', null)
getDeep<string | null>(query, 'source.links.self', null)
) || source
)
}

View File

@ -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<Props, State> {
private get isMultipleConfigsSupported(): boolean {
const {configSections} = this.state
const hasPagerDuty2 = getNested<Section>(
const hasPagerDuty2 = getDeep<Section>(
configSections,
AlertTypes.pagerduty2,
undefined
)
const hasOpsGenie2 = getNested<Section>(
const hasOpsGenie2 = getDeep<Section>(
configSections,
AlertTypes.opsgenie2,
undefined
@ -454,13 +454,13 @@ class AlertTabs extends PureComponent<Props, State> {
private getConfigEnabled = (sections: Sections, section: string): boolean => {
if (section === AlertTypes.slack || section === AlertTypes.kafka) {
const configElements = getNested<Section[]>(
const configElements = getDeep<Section[]>(
sections,
`${section}.elements`,
[]
)
const enabledConfigElements = configElements.filter(e => {
const enabled = getNested<boolean>(e, 'options.enabled', false)
const enabled = getDeep<boolean>(e, 'options.enabled', false)
return enabled
})
return enabledConfigElements.length > 0

View File

@ -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<Props, State> {
this.state = {
currentBrokers: brokers || [],
testEnabled: this.props.enabled,
enabled: getNested<boolean>(this.props, 'config.options.enabled', false),
enabled: getDeep<boolean>(this.props, 'config.options.enabled', false),
}
}
@ -244,7 +244,7 @@ class KafkaConfig extends PureComponent<Props, State> {
}
private get isNewConfig(): boolean {
return getNested<boolean>(this.props, 'config.isNewConfig', false)
return getDeep<boolean>(this.props, 'config.isNewConfig', false)
}
private get isDefaultConfig(): boolean {

View File

@ -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<Props, State> {
return (
<div>
{this.configs.map(c => {
const enabled = getNested<boolean>(c, 'options.enabled', false)
const id = getNested<string>(c, 'options.id', '')
const enabled = getDeep<boolean>(c, 'options.enabled', false)
const id = getDeep<string>(c, 'options.id', '')
return (
<KafkaConfig
config={c}
@ -93,7 +93,7 @@ class KafkaConfigs extends Component<Props, State> {
}
private get configs(): Config[] {
return _.sortBy(this.state.configs, c => {
const id = getNested<string>(c, 'options.id', '')
const id = getDeep<string>(c, 'options.id', '')
const {isNewConfig} = c
if (id === 'default') {
return ''

View File

@ -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<Props, State> {
}
private isNewConfig = (config: Config): boolean => {
return getNested(config, 'isNewConfig', false)
return getDeep(config, 'isNewConfig', false)
}
private isDefaultConfig = (config: Config): boolean => {

View File

@ -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<string>(
queryConfig,
'source.links.proxy',
''
)
const queryProxy = getDeep<string>(queryConfig, 'source.links.proxy', '')
const host: string[] = [queryProxy || proxy]
return {

View File

@ -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<TimeSeriesSeries[]>(results, '[0].series', [])
const seriesArray = getDeep<TimeSeriesSeries[]>(results, '[0].series', [])
const accumulatedValues = fastReduce<TimeSeriesSeries, TimeSeriesValue[][]>(
seriesArray,
@ -76,7 +76,7 @@ const flattenGroupBySeries = (
},
[]
)
const firstColumns = getNested<string[]>(results, '[0].series[0]columns', [])
const firstColumns = getDeep<string[]>(results, '[0].series[0]columns', [])
const flattenedSeries: Result[] = [
{
@ -102,7 +102,7 @@ const constructResults = (
const MappedResponse = fastMap<TimeSeriesServerResponse, Result[]>(
raw,
(response, index) => {
const results = getNested<TimeSeriesResult[]>(
const results = getDeep<TimeSeriesResult[]>(
response,
'response.results',
[]

View File

@ -1,5 +1,5 @@
import _ from 'lodash'
export function getNested<T = any>(obj: any, path: string, fallback: T): T {
export function getDeep<T = any>(obj: any, path: string, fallback: T): T {
return _.get<T>(obj, path, fallback)
}

View File

@ -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')
})
})
})