From b5c30e693049c5e98a93c5ad39eb60b16c452de6 Mon Sep 17 00:00:00 2001 From: Deniz Kusefoglu Date: Fri, 12 Apr 2019 16:45:06 -0700 Subject: [PATCH 1/7] Remove unused FetchLabels component --- ui/src/shared/components/FetchLabels.tsx | 81 ------------------------ 1 file changed, 81 deletions(-) delete mode 100644 ui/src/shared/components/FetchLabels.tsx diff --git a/ui/src/shared/components/FetchLabels.tsx b/ui/src/shared/components/FetchLabels.tsx deleted file mode 100644 index bc87a6197f..0000000000 --- a/ui/src/shared/components/FetchLabels.tsx +++ /dev/null @@ -1,81 +0,0 @@ -// Libraries -import React, {PureComponent} from 'react' -import {withRouter, WithRouterProps} from 'react-router' -import _ from 'lodash' - -// Components -import { - EmptyState, - TechnoSpinner, - SpinnerContainer, -} from '@influxdata/clockface' - -// APIs -import {client} from 'src/utils/api' - -// Types -import {RemoteDataState} from 'src/types' -import {Label} from 'src/types/labels' - -// Decorators -import {ErrorHandling} from 'src/shared/decorators/errors' - -interface PassedInProps { - children: (labels: Label[]) => JSX.Element -} - -interface RouterProps extends WithRouterProps { - params: { - orgID: string - } -} - -type Props = PassedInProps & RouterProps - -interface State { - labels: Label[] - loading: RemoteDataState -} - -@ErrorHandling -class FetchLabels extends PureComponent { - constructor(props: Props) { - super(props) - - this.state = { - labels: [], - loading: RemoteDataState.NotStarted, - } - } - - public async componentDidMount() { - const { - params: {orgID}, - } = this.props - const labels = await client.labels.getAll(orgID) - this.setState({ - loading: RemoteDataState.Done, - labels: _.orderBy(labels, ['name']), - }) - } - - public render() { - const {loading} = this.state - - if (loading === RemoteDataState.Error) { - return ( - - - - ) - } - - return ( - }> - {this.props.children(this.state.labels)} - - ) - } -} - -export default withRouter(FetchLabels) From a446f413a307d56a7de71545afb6767e9c015955 Mon Sep 17 00:00:00 2001 From: Deniz Kusefoglu Date: Fri, 12 Apr 2019 16:45:22 -0700 Subject: [PATCH 2/7] Remove inconsistencies around getAll --- ui/src/buckets/actions/index.ts | 2 +- ui/src/labels/actions/index.ts | 6 ++---- ui/src/scrapers/actions/index.ts | 7 +++---- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/ui/src/buckets/actions/index.ts b/ui/src/buckets/actions/index.ts index 3a50eeaf32..61feb0b526 100644 --- a/ui/src/buckets/actions/index.ts +++ b/ui/src/buckets/actions/index.ts @@ -78,7 +78,7 @@ export const getBuckets = () => async ( orgs: {org}, } = getState() - const buckets = (await client.buckets.getAll(org.id)) as Bucket[] + const buckets = await client.buckets.getAll(org.id) dispatch(setBuckets(RemoteDataState.Done, buckets)) } catch (e) { diff --git a/ui/src/labels/actions/index.ts b/ui/src/labels/actions/index.ts index ae08630422..7fd56ef160 100644 --- a/ui/src/labels/actions/index.ts +++ b/ui/src/labels/actions/index.ts @@ -73,13 +73,11 @@ export const getLabels = () => async ( ) => { try { const { - orgs: { - org: {id}, - }, + orgs: {org}, } = getState() dispatch(setLabels(RemoteDataState.Loading)) - const labels = await client.labels.getAll(id) + const labels = await client.labels.getAll(org.id) dispatch(setLabels(RemoteDataState.Done, labels)) } catch (e) { diff --git a/ui/src/scrapers/actions/index.ts b/ui/src/scrapers/actions/index.ts index 303dbad6c6..9afd031bbd 100644 --- a/ui/src/scrapers/actions/index.ts +++ b/ui/src/scrapers/actions/index.ts @@ -76,13 +76,12 @@ export const getScrapers = () => async ( ) => { try { const { - orgs: { - org: {id}, - }, + orgs: {org}, } = getState() + dispatch(setScrapers(RemoteDataState.Loading)) - const scrapers = await client.scrapers.getAll(id) + const scrapers = await client.scrapers.getAll(org.id) dispatch(setScrapers(RemoteDataState.Done, scrapers)) } catch (e) { From 4b9305a47392d445ba80c005a3d4fba38a7403c8 Mon Sep 17 00:00:00 2001 From: Deniz Kusefoglu Date: Fri, 12 Apr 2019 16:51:20 -0700 Subject: [PATCH 3/7] Remove src/influxql folder --- ui/src/influxql/ast.ts | 129 --------- ui/src/influxql/astToString.test.ts | 406 ---------------------------- ui/src/influxql/index.ts | 9 - 3 files changed, 544 deletions(-) delete mode 100644 ui/src/influxql/ast.ts delete mode 100644 ui/src/influxql/astToString.test.ts delete mode 100644 ui/src/influxql/index.ts diff --git a/ui/src/influxql/ast.ts b/ui/src/influxql/ast.ts deleted file mode 100644 index 1f3911e616..0000000000 --- a/ui/src/influxql/ast.ts +++ /dev/null @@ -1,129 +0,0 @@ -import _ from 'lodash' - -// TODO make recursive -const exprStr = ({expr, val, type}) => { - if (expr === 'reference') { - if (val === 'time') { - return val - } - return `"${val}"` - } else if (expr === 'literal' || expr === '"string"') { - if (type === 'regex') { - return `${val}` // TODO add slashes `/${val}/` - } else if (type === 'list') { - throw new Error() // TODO list - } else if (type === 'string') { - return `'${val}'` - } else { - // types: boolean, number, integer, duration, time - return val - } - } else if (expr === 'wildcard') { - return val - } -} - -const recurse = root => { - const {expr} = root - - if (expr === 'binary') { - const {op, lhs, rhs} = root - return `${recurse(lhs)} ${op} ${recurse(rhs)}` - } else if (expr === 'call') { - const {name, args} = root - if (!args) { - return `${name}()` - } - return `${name}(${args.map(recurse).join(', ')})` - } - - return exprStr(root) -} - -export const toString = ast => { - const {fields, sources, condition, groupBy, orderbys, limits} = ast - - const strs = ['SELECT'] - - // SELECT - const flds = [] - for (const field of fields) { - const {column, alias} = field - const result = recurse(column) - flds.push(alias ? `${result} AS "${alias}"` : result) - } - strs.push(flds.join(', ')) - - // FROM - if (sources.length) { - strs.push('FROM') - const srcs = [] - for (const source of sources) { - // TODO subquery (type) - const {database, retentionPolicy, name} = source - srcs.push(`"${_.compact([database, retentionPolicy, name]).join('"."')}"`) - } - strs.push(srcs.join(', ')) - } - - // WHERE - if (condition) { - strs.push('WHERE') - const result = recurse(condition) - strs.push(result) - } - - // GROUP BY - if (groupBy) { - strs.push('GROUP BY') - - const dimensions = [] - const {time, tags, fill} = groupBy - if (time) { - const {interval, offset} = time - // _.compact([interval, offset]).join(', ') - dimensions.push(`time(${_.compact([interval, offset]).join(', ')})`) - } - - if (tags) { - strs.push(dimensions.concat(tags).join(',')) - } else { - strs.push(dimensions.join(',')) - } - - if (fill) { - strs.push(`fill(${fill})`) - } - } - - // ORDER BY - if (orderbys && orderbys.length) { - strs.push('ORDER BY') - strs.push( - orderbys - .map(({name, order}) => { - return `${name} ${order === 'descending' ? 'DESC' : 'ASC'}` - }) - .join(',') - ) - } - - // LIMIT - if (limits) { - const {limit, offset, slimit, soffset} = limits - if (limit) { - strs.push(`LIMIT ${limit}`) - } - if (offset) { - strs.push(`OFFSET ${offset}`) - } - if (slimit) { - strs.push(`SLIMIT ${slimit}`) - } - if (soffset) { - strs.push(`SOFFSET ${soffset}`) - } - } - - return strs.join(' ') -} diff --git a/ui/src/influxql/astToString.test.ts b/ui/src/influxql/astToString.test.ts deleted file mode 100644 index 374f0e6f08..0000000000 --- a/ui/src/influxql/astToString.test.ts +++ /dev/null @@ -1,406 +0,0 @@ -import InfluxQL from 'src/influxql' - -describe('influxql astToString', () => { - it('simple query', () => { - const ast = InfluxQL({ - fields: [ - { - column: { - expr: 'binary', - op: '+', - lhs: { - expr: 'literal', - val: '1', - type: 'integer', - }, - rhs: { - expr: 'reference', - val: 'A', - }, - }, - }, - ], - sources: [ - { - database: '', - retentionPolicy: '', - name: 'howdy', - type: 'measurement', - }, - ], - }) - - const expected = `SELECT 1 + "A" FROM "howdy"` - const actual = ast.toString() - - // console.log(actual) - - expect(actual).toBe(expected) - }) - - it('simple query w/ multiple sources', () => { - const ast = InfluxQL({ - fields: [ - { - column: { - expr: 'binary', - op: '+', - lhs: { - expr: 'literal', - val: '1', - type: 'integer', - }, - rhs: { - expr: 'reference', - val: 'A', - }, - }, - }, - ], - sources: [ - { - database: '', - retentionPolicy: '', - name: 'howdy', - type: 'measurement', - }, - { - database: 'telegraf', - retentionPolicy: 'autogen', - name: 'doody', - type: 'measurement', - }, - ], - }) - - const expected = `SELECT 1 + "A" FROM "howdy", "telegraf"."autogen"."doody"` - const actual = ast.toString() - - // console.log('actual ', actual) - // console.log('expected', expected) - - expect(actual).toBe(expected) - }) - - it('query with AS', () => { - const ast = InfluxQL({ - fields: [ - { - alias: 'B', - column: { - expr: 'binary', - op: '+', - lhs: { - expr: 'literal', - val: '1', - type: 'integer', - }, - rhs: { - expr: 'reference', - val: 'A', - }, - }, - }, - ], - sources: [ - { - database: '', - retentionPolicy: '', - name: 'howdy', - type: 'measurement', - }, - ], - }) - - const expected = `SELECT 1 + "A" AS "B" FROM "howdy"` - const actual = ast.toString() - - // console.log(actual) - - expect(actual).toBe(expected) - }) - - it('query with 2x func', () => { - const ast = InfluxQL({ - fields: [ - { - column: { - expr: 'binary', - op: '/', - lhs: { - expr: 'call', - name: 'derivative', - args: [ - { - expr: 'reference', - val: 'field1', - }, - { - expr: 'literal', - val: '1h', - type: 'duration', - }, - ], - }, - rhs: { - expr: 'call', - name: 'derivative', - args: [ - { - expr: 'reference', - val: 'field2', - }, - { - expr: 'literal', - val: '1h', - type: 'duration', - }, - ], - }, - }, - }, - ], - sources: [ - { - database: '', - retentionPolicy: '', - name: 'myseries', - type: 'measurement', - }, - ], - }) - - const expected = `SELECT derivative("field1", 1h) / derivative("field2", 1h) FROM "myseries"` - const actual = ast.toString() - - expect(actual).toBe(expected) - }) - - it('query with where and groupby', () => { - const ast = InfluxQL({ - condition: { - expr: 'binary', - op: 'AND', - lhs: { - expr: 'binary', - op: 'AND', - lhs: { - expr: 'binary', - op: '=~', - lhs: { - expr: 'reference', - val: 'cluster_id', - }, - rhs: { - expr: 'literal', - val: '/^23/', - type: 'regex', - }, - }, - rhs: { - expr: 'binary', - op: '=', - lhs: { - expr: 'reference', - val: 'host', - }, - rhs: { - expr: 'literal', - val: 'prod-2ccccc04-us-east-1-data-3', - type: 'string', - }, - }, - }, - rhs: { - expr: 'binary', - op: '\u003e', - lhs: { - expr: 'reference', - val: 'time', - }, - rhs: { - expr: 'binary', - op: '-', - lhs: { - expr: 'call', - name: 'now', - }, - rhs: { - expr: 'literal', - val: '15m', - type: 'duration', - }, - }, - }, - }, - fields: [ - { - alias: 'max_cpus', - column: { - expr: 'call', - name: 'max', - args: [ - { - expr: 'reference', - val: 'n_cpus', - }, - ], - }, - }, - { - column: { - expr: 'call', - name: 'non_negative_derivative', - args: [ - { - expr: 'call', - name: 'median', - args: [ - { - expr: 'reference', - val: 'n_users', - }, - ], - }, - { - expr: 'literal', - val: '5m', - type: 'duration', - }, - ], - }, - }, - ], - groupBy: { - time: { - interval: '15m', - offset: '10s', - }, - tags: ['host', 'tag_x'], - fill: '10', - }, - sources: [ - { - database: '', - retentionPolicy: '', - name: 'system', - type: 'measurement', - }, - ], - }) - - const expected = - 'SELECT max("n_cpus") AS "max_cpus", non_negative_derivative(median("n_users"), 5m) FROM "system" WHERE "cluster_id" =~ /^23/ AND "host" = \'prod-2ccccc04-us-east-1-data-3\' AND time > now() - 15m GROUP BY time(15m, 10s),host,tag_x fill(10)' - const actual = ast.toString() - - // console.log('actual ', actual) - // console.log('expected', expected) - - expect(actual).toBe(expected) - }) - - it('query with orderby and limit', () => { - const ast = InfluxQL({ - condition: { - expr: 'binary', - op: 'AND', - lhs: { - expr: 'binary', - op: '=', - lhs: { - expr: 'reference', - val: 'host', - }, - rhs: { - expr: 'literal', - val: 'hosta.influxdb.org', - type: 'string', - }, - }, - rhs: { - expr: 'binary', - op: '\u003e', - lhs: { - expr: 'reference', - val: 'time', - }, - rhs: { - expr: 'literal', - val: '2017-02-07T01:43:02.245407693Z', - type: 'string', - }, - }, - }, - fields: [ - { - column: { - expr: 'call', - name: 'mean', - args: [ - { - expr: 'reference', - val: 'field1', - }, - ], - }, - }, - { - column: { - expr: 'call', - name: 'sum', - args: [ - { - expr: 'reference', - val: 'field2', - }, - ], - }, - }, - { - alias: 'field_x', - column: { - expr: 'call', - name: 'count', - args: [ - { - expr: 'reference', - val: 'field3', - }, - ], - }, - }, - ], - groupBy: { - time: { - interval: '10h', - }, - }, - limits: { - limit: 20, - offset: 10, - }, - orderbys: [ - { - name: 'time', - order: 'descending', - }, - ], - sources: [ - { - database: '', - retentionPolicy: '', - name: 'myseries', - type: 'measurement', - }, - ], - }) - - const expected = `SELECT mean("field1"), sum("field2"), count("field3") AS "field_x" FROM "myseries" WHERE "host" = 'hosta.influxdb.org' AND time > '2017-02-07T01:43:02.245407693Z' GROUP BY time(10h) ORDER BY time DESC LIMIT 20 OFFSET 10` - const actual = ast.toString() - - // console.log('actual ', actual) - // console.log('expected', expected) - - expect(actual).toBe(expected) - }) -}) diff --git a/ui/src/influxql/index.ts b/ui/src/influxql/index.ts deleted file mode 100644 index 49525d5d6e..0000000000 --- a/ui/src/influxql/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import {toString} from './ast' - -const InfluxQL = ast => { - return { - toString: () => toString(ast), - } -} - -export default InfluxQL From de25e696cda68cde50173a8fb11143fa3282a956 Mon Sep 17 00:00:00 2001 From: Deniz Kusefoglu Date: Fri, 12 Apr 2019 16:53:40 -0700 Subject: [PATCH 4/7] Remove v2 actions and reducer folder in shared --- ui/src/shared/actions/{v2 => }/me.ts | 2 +- ui/src/shared/containers/GetMe.tsx | 2 +- ui/src/shared/reducers/{v2 => }/me.ts | 2 +- ui/src/store/configureStore.ts | 2 +- ui/src/types/stores.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) rename ui/src/shared/actions/{v2 => }/me.ts (90%) rename ui/src/shared/reducers/{v2 => }/me.ts (87%) diff --git a/ui/src/shared/actions/v2/me.ts b/ui/src/shared/actions/me.ts similarity index 90% rename from ui/src/shared/actions/v2/me.ts rename to ui/src/shared/actions/me.ts index 9192674343..608f4a7cb6 100644 --- a/ui/src/shared/actions/v2/me.ts +++ b/ui/src/shared/actions/me.ts @@ -1,4 +1,4 @@ -import {MeState} from 'src/shared/reducers/v2/me' +import {MeState} from 'src/shared/reducers/me' import {client} from 'src/utils/api' export enum ActionTypes { diff --git a/ui/src/shared/containers/GetMe.tsx b/ui/src/shared/containers/GetMe.tsx index 86b9c6e006..3a5a708b94 100644 --- a/ui/src/shared/containers/GetMe.tsx +++ b/ui/src/shared/containers/GetMe.tsx @@ -9,7 +9,7 @@ import {SpinnerContainer, TechnoSpinner} from '@influxdata/clockface' import {RemoteDataState} from 'src/types' // Actions -import {getMe} from 'src/shared/actions/v2/me' +import {getMe} from 'src/shared/actions/me' // Decorators import {ErrorHandling} from 'src/shared/decorators/errors' diff --git a/ui/src/shared/reducers/v2/me.ts b/ui/src/shared/reducers/me.ts similarity index 87% rename from ui/src/shared/reducers/v2/me.ts rename to ui/src/shared/reducers/me.ts index a1df16c621..432d9cbc37 100644 --- a/ui/src/shared/reducers/v2/me.ts +++ b/ui/src/shared/reducers/me.ts @@ -1,4 +1,4 @@ -import {Actions, ActionTypes} from 'src/shared/actions/v2/me' +import {Actions, ActionTypes} from 'src/shared/actions/me' export interface MeLinks { self: string diff --git a/ui/src/store/configureStore.ts b/ui/src/store/configureStore.ts index 2b7e80cf22..db9dd29870 100644 --- a/ui/src/store/configureStore.ts +++ b/ui/src/store/configureStore.ts @@ -10,7 +10,7 @@ import sharedReducers from 'src/shared/reducers' import persistStateEnhancer from './persistStateEnhancer' // v2 reducers -import meReducer from 'src/shared/reducers/v2/me' +import meReducer from 'src/shared/reducers/me' import tasksReducer from 'src/tasks/reducers' import rangesReducer from 'src/dashboards/reducers/ranges' import {dashboardsReducer} from 'src/dashboards/reducers/dashboards' diff --git a/ui/src/types/stores.ts b/ui/src/types/stores.ts index 2c1f9a037e..e192daebb6 100644 --- a/ui/src/types/stores.ts +++ b/ui/src/types/stores.ts @@ -5,7 +5,7 @@ import {TimeMachinesState} from 'src/timeMachine/reducers' import {AppState as AppPresentationState} from 'src/shared/reducers/app' import {TasksState} from 'src/tasks/reducers' import {RouterState} from 'react-router-redux' -import {MeState} from 'src/shared/reducers/v2/me' +import {MeState} from 'src/shared/reducers/me' import {NoteEditorState} from 'src/dashboards/reducers/notes' import {DataLoadingState} from 'src/dataLoaders/reducers' import {OnboardingState} from 'src/onboarding/reducers' From d4788217e31f1a25e89d45ad1679e1f0f5710021 Mon Sep 17 00:00:00 2001 From: Deniz Kusefoglu Date: Fri, 12 Apr 2019 17:01:51 -0700 Subject: [PATCH 5/7] Remove cloud feature flag for cloud exclude --- ui/src/buckets/components/BucketRow.tsx | 6 ++--- .../components/AccountNavSubItem.tsx | 6 ++--- .../components/SettingsNavigation.tsx | 6 ++--- ui/src/shared/components/CloudFeatureFlag.tsx | 23 ------------------- 4 files changed, 9 insertions(+), 32 deletions(-) delete mode 100644 ui/src/shared/components/CloudFeatureFlag.tsx diff --git a/ui/src/buckets/components/BucketRow.tsx b/ui/src/buckets/components/BucketRow.tsx index e5b2fe91bf..00a7b376b1 100644 --- a/ui/src/buckets/components/BucketRow.tsx +++ b/ui/src/buckets/components/BucketRow.tsx @@ -5,8 +5,8 @@ import _ from 'lodash' // Components import {IndexList, ConfirmationButton, Context} from 'src/clockface' -import CloudFeatureFlag from 'src/shared/components/CloudFeatureFlag' import EditableName from 'src/shared/components/EditableName' +import CloudExclude from 'src/shared/components/cloud/CloudExclude' // Constants import {DEFAULT_BUCKET_NAME} from 'src/dashboards/constants' @@ -77,13 +77,13 @@ class BucketRow extends PureComponent { description="Quickly load an existing line protocol file." action={this.handleAddLineProtocol} /> - + - + diff --git a/ui/src/pageLayout/components/AccountNavSubItem.tsx b/ui/src/pageLayout/components/AccountNavSubItem.tsx index 6ebb28b379..d6a3995111 100644 --- a/ui/src/pageLayout/components/AccountNavSubItem.tsx +++ b/ui/src/pageLayout/components/AccountNavSubItem.tsx @@ -5,8 +5,8 @@ import {Link} from 'react-router' // Components import {NavMenu} from '@influxdata/clockface' import {Organization} from '@influxdata/influx' -import CloudFeatureFlag from 'src/shared/components/CloudFeatureFlag' import SortingHat from 'src/shared/components/sorting_hat/SortingHat' +import CloudExclude from 'src/shared/components/cloud/CloudExclude' interface Props { orgs: Organization[] @@ -29,7 +29,7 @@ class AccountNavSubItem extends PureComponent { return ( <> - + {orgs.length > 1 && ( ( @@ -50,7 +50,7 @@ class AccountNavSubItem extends PureComponent { )} active={false} /> - + ( diff --git a/ui/src/settings/components/SettingsNavigation.tsx b/ui/src/settings/components/SettingsNavigation.tsx index 8c6b245551..e9f0c7eb45 100644 --- a/ui/src/settings/components/SettingsNavigation.tsx +++ b/ui/src/settings/components/SettingsNavigation.tsx @@ -7,7 +7,7 @@ import {Tabs} from 'src/clockface' // Decorators import {ErrorHandling} from 'src/shared/decorators/errors' -import CloudFeatureFlag from 'src/shared/components/CloudFeatureFlag' +import CloudExclude from 'src/shared/components/cloud/CloudExclude' interface Props { tab: string @@ -41,14 +41,14 @@ class SettingsNavigation extends PureComponent { url={`${route}/telegrafs`} active={'telegrafs' === tab} /> - + - + { - public render() { - if (this.isHidden) { - return null - } - - return this.props.children - } - - private get isHidden(): boolean { - return CLOUD - } -} From c469a1b716ec9b6dc694abbb5667e5c5ce81d3d5 Mon Sep 17 00:00:00 2001 From: Deniz Kusefoglu Date: Fri, 12 Apr 2019 17:02:10 -0700 Subject: [PATCH 6/7] Remove subsections --- ui/src/shared/components/SubSections.test.tsx | 86 ------------------- ui/src/shared/components/SubSections.tsx | 65 -------------- ui/src/shared/components/SubSectionsTab.tsx | 25 ------ 3 files changed, 176 deletions(-) delete mode 100644 ui/src/shared/components/SubSections.test.tsx delete mode 100644 ui/src/shared/components/SubSections.tsx delete mode 100644 ui/src/shared/components/SubSectionsTab.tsx diff --git a/ui/src/shared/components/SubSections.test.tsx b/ui/src/shared/components/SubSections.test.tsx deleted file mode 100644 index a555b611e0..0000000000 --- a/ui/src/shared/components/SubSections.test.tsx +++ /dev/null @@ -1,86 +0,0 @@ -import {shallow} from 'enzyme' -import React from 'react' -import SubSections from 'src/shared/components/SubSections' -import SubSectionsTab from 'src/shared/components/SubSectionsTab' - -const Guava = () => { - return
-} - -const Mango = () => { - return
-} - -const Pineapple = () => { - return
-} - -const guavaURL = 'guava' -const mangoURL = 'mango' -const pineappleURL = 'pineapple' - -const defaultProps = { - router: { - push: () => {}, - replace: () => {}, - go: () => {}, - goBack: () => {}, - goForward: () => {}, - setRouteLeaveHook: () => {}, - isActive: () => {}, - }, - sourceID: 'fruitstand', - parentUrl: 'fred-the-fruit-guy', - activeSection: guavaURL, - sections: [ - { - url: guavaURL, - name: 'Guava', - component: , - enabled: true, - }, - { - url: mangoURL, - name: 'Mango', - component: , - enabled: true, - }, - { - url: pineappleURL, - name: 'Pineapple', - component: , - enabled: false, - }, - ], -} - -const setup = (override?: {}) => { - const props = { - ...defaultProps, - ...override, - } - - return shallow() -} - -describe('SubSections', () => { - describe('render', () => { - it('renders the currently active tab', () => { - const wrapper = setup() - const content = wrapper.dive().find({'data-testid': 'subsectionContent'}) - - expect(content.find(Guava).exists()).toBe(true) - }) - - it('only renders enabled tabs', () => { - const wrapper = setup() - const nav = wrapper.dive().find({'data-testid': 'subsectionNav'}) - - const tabs = nav.find(SubSectionsTab) - - tabs.forEach(tab => { - expect(tab.exists()).toBe(tab.props().section.enabled) - }) - }) - }) -}) diff --git a/ui/src/shared/components/SubSections.tsx b/ui/src/shared/components/SubSections.tsx deleted file mode 100644 index 8387bf4024..0000000000 --- a/ui/src/shared/components/SubSections.tsx +++ /dev/null @@ -1,65 +0,0 @@ -import React, {Component, ReactNode} from 'react' -import uuid from 'uuid' -import {withRouter, InjectedRouter} from 'react-router' - -import SubSectionsTab from 'src/shared/components/SubSectionsTab' -import {ErrorHandling} from 'src/shared/decorators/errors' -import {PageSection} from 'src/types/shared' - -interface Props { - sections: PageSection[] - activeSection: string - sourceID: string - router: InjectedRouter - parentUrl: string -} - -@ErrorHandling -class SubSections extends Component { - constructor(props) { - super(props) - } - - public render() { - const {sections, activeSection} = this.props - - return ( -
-
-
- {sections.map( - section => - section.enabled && ( - - ) - )} -
-
-
- {this.activeSectionComponent} -
-
- ) - } - - private get activeSectionComponent(): ReactNode { - const {sections, activeSection} = this.props - const {component} = sections.find(section => section.url === activeSection) - return component - } - - public handleTabClick = url => () => { - const {router, sourceID, parentUrl} = this.props - router.push(`/sources/${sourceID}/${parentUrl}/${url}`) - } -} - -export default withRouter(SubSections) diff --git a/ui/src/shared/components/SubSectionsTab.tsx b/ui/src/shared/components/SubSectionsTab.tsx deleted file mode 100644 index 399a46a41d..0000000000 --- a/ui/src/shared/components/SubSectionsTab.tsx +++ /dev/null @@ -1,25 +0,0 @@ -import React, {SFC} from 'react' -import {PageSection} from 'src/types/shared' - -interface TabProps { - handleClick: () => void - section: PageSection - activeSection: string -} - -const SubSectionsTab: SFC = ({ - handleClick, - section, - activeSection, -}) => ( -
- {section.name} -
-) - -export default SubSectionsTab From 09751d7c5994771ae04f5442b64f8f360eff13da Mon Sep 17 00:00:00 2001 From: Deniz Kusefoglu Date: Fri, 12 Apr 2019 17:10:04 -0700 Subject: [PATCH 7/7] Remove GetLabels in favor of GetResources with labels resource --- .../DashboardsIndexContents.tsx | 6 +- ui/src/labels/components/GetLabels.tsx | 57 ------------------- ui/src/tasks/containers/TasksPage.tsx | 5 +- ui/src/telegrafs/components/Collectors.tsx | 6 +- ui/src/templates/components/TemplatesPage.tsx | 6 +- ui/src/variables/components/VariablesTab.tsx | 6 +- 6 files changed, 14 insertions(+), 72 deletions(-) delete mode 100644 ui/src/labels/components/GetLabels.tsx diff --git a/ui/src/dashboards/components/dashboard_index/DashboardsIndexContents.tsx b/ui/src/dashboards/components/dashboard_index/DashboardsIndexContents.tsx index e43f295d80..4adb03477a 100644 --- a/ui/src/dashboards/components/dashboard_index/DashboardsIndexContents.tsx +++ b/ui/src/dashboards/components/dashboard_index/DashboardsIndexContents.tsx @@ -5,7 +5,7 @@ import _ from 'lodash' // Components import Table from 'src/dashboards/components/dashboard_index/Table' import FilterList from 'src/shared/components/Filter' -import GetLabels from 'src/labels/components/GetLabels' +import GetResources, {ResourceTypes} from 'src/shared/components/GetResources' // Decorators import {ErrorHandling} from 'src/shared/decorators/errors' @@ -43,7 +43,7 @@ export default class DashboardsIndexContents extends Component { } = this.props return ( - + list={dashboards} searchTerm={searchTerm} @@ -64,7 +64,7 @@ export default class DashboardsIndexContents extends Component { /> )} - + ) } } diff --git a/ui/src/labels/components/GetLabels.tsx b/ui/src/labels/components/GetLabels.tsx deleted file mode 100644 index c8d99cb5a9..0000000000 --- a/ui/src/labels/components/GetLabels.tsx +++ /dev/null @@ -1,57 +0,0 @@ -// Libraries -import React, {PureComponent} from 'react' -import _ from 'lodash' -import {connect} from 'react-redux' - -// Actions -import {getLabels} from 'src/labels/actions' - -// Types -import {RemoteDataState} from 'src/types' -import {AppState} from 'src/types' - -// Decorators -import {ErrorHandling} from 'src/shared/decorators/errors' -import {TechnoSpinner} from '@influxdata/clockface' - -interface StateProps { - status: RemoteDataState -} - -interface DispatchProps { - getLabels: typeof getLabels -} - -type Props = StateProps & DispatchProps - -@ErrorHandling -class GetLabels extends PureComponent { - public async componentDidMount() { - await this.props.getLabels() - } - - public render() { - const {status, children} = this.props - - if (status != RemoteDataState.Done) { - return - } - - return children - } -} - -const mstp = ({labels}: AppState): StateProps => { - return { - status: labels.status, - } -} - -const mdtp = { - getLabels: getLabels, -} - -export default connect( - mstp, - mdtp -)(GetLabels) diff --git a/ui/src/tasks/containers/TasksPage.tsx b/ui/src/tasks/containers/TasksPage.tsx index 91f3012d66..7f96072835 100644 --- a/ui/src/tasks/containers/TasksPage.tsx +++ b/ui/src/tasks/containers/TasksPage.tsx @@ -10,7 +10,6 @@ import {Page} from 'src/pageLayout' import {ErrorHandling} from 'src/shared/decorators/errors' import FilterList from 'src/shared/components/Filter' import SearchWidget from 'src/shared/components/search_widget/SearchWidget' -import GetLabels from 'src/labels/components/GetLabels' import GetResources, {ResourceTypes} from 'src/shared/components/GetResources' // Actions @@ -106,7 +105,7 @@ class TasksPage extends PureComponent {
- + list={this.filteredTasks} searchTerm={searchTerm} @@ -133,7 +132,7 @@ class TasksPage extends PureComponent { )} {this.hiddenTaskAlert} - +
diff --git a/ui/src/telegrafs/components/Collectors.tsx b/ui/src/telegrafs/components/Collectors.tsx index fef110a023..aae783891a 100644 --- a/ui/src/telegrafs/components/Collectors.tsx +++ b/ui/src/telegrafs/components/Collectors.tsx @@ -11,7 +11,7 @@ import CollectorList from 'src/telegrafs/components/CollectorList' import TelegrafExplainer from 'src/telegrafs/components/TelegrafExplainer' import FilterList from 'src/shared/components/Filter' import NoBucketsWarning from 'src/buckets/components/NoBucketsWarning' -import GetLabels from 'src/labels/components/GetLabels' +import GetResources, {ResourceTypes} from 'src/shared/components/GetResources' // Actions import {setBucketInfo} from 'src/dataLoaders/actions/steps' @@ -102,7 +102,7 @@ class Collectors extends PureComponent { visible={this.hasNoBuckets} resourceName="Telegraf Configurations" /> - + searchTerm={searchTerm} searchKeys={['plugins.0.config.bucket', 'labels[].name']} @@ -119,7 +119,7 @@ class Collectors extends PureComponent { /> )} - + { isFullPage={false} filterComponent={() => this.filterComponent} /> - + searchTerm={searchTerm} searchKeys={['meta.name', 'labels[].name']} @@ -65,7 +65,7 @@ class TemplatesPage extends PureComponent { /> )} - + ) } diff --git a/ui/src/variables/components/VariablesTab.tsx b/ui/src/variables/components/VariablesTab.tsx index 13a909c446..6c096c61ef 100644 --- a/ui/src/variables/components/VariablesTab.tsx +++ b/ui/src/variables/components/VariablesTab.tsx @@ -14,7 +14,7 @@ import TabbedPageHeader from 'src/shared/components/tabbed_page/TabbedPageHeader import VariableList from 'src/variables/components/VariableList' import FilterList from 'src/shared/components/Filter' import AddResourceDropdown from 'src/shared/components/AddResourceDropdown' -import GetLabels from 'src/labels/components/GetLabels' +import GetResources, {ResourceTypes} from 'src/shared/components/GetResources' // Types import {OverlayState} from 'src/types' @@ -65,7 +65,7 @@ class VariablesTab extends PureComponent { onSelectNew={this.handleOpenCreateOverlay} /> - + searchTerm={searchTerm} searchKeys={['name', 'labels[].name']} @@ -82,7 +82,7 @@ class VariablesTab extends PureComponent { /> )} - + ) }