From 5596254e6a58f0a7503e697ecdafa378581e0a46 Mon Sep 17 00:00:00 2001 From: Deniz Kusefoglu Date: Thu, 9 Aug 2018 13:55:33 -0700 Subject: [PATCH] Remove unused SourcePage --- ui/src/index.tsx | 4 +- ui/src/sources/components/SourceForm.tsx | 229 --------------- ui/src/sources/containers/SourcePage.tsx | 267 ------------------ ui/src/sources/index.ts | 3 +- .../sources/components/SourceForm.test.tsx | 37 --- 5 files changed, 2 insertions(+), 538 deletions(-) delete mode 100644 ui/src/sources/components/SourceForm.tsx delete mode 100644 ui/src/sources/containers/SourcePage.tsx delete mode 100644 ui/test/sources/components/SourceForm.test.tsx diff --git a/ui/src/index.tsx b/ui/src/index.tsx index 81a1e3894..2be8a9b48 100644 --- a/ui/src/index.tsx +++ b/ui/src/index.tsx @@ -35,7 +35,7 @@ import { TickscriptPage, } from 'src/kapacitor' import {AdminChronografPage, AdminInfluxDBPage} from 'src/admin' -import {SourcePage, ManageSources, OnboardingWizard} from 'src/sources' +import {ManageSources, OnboardingWizard} from 'src/sources' import {CheckServices, FluxConnectionPage} from 'src/flux' import NotFound from 'src/shared/components/NotFound' @@ -166,8 +166,6 @@ class Root extends PureComponent<{}, State> { /> - - diff --git a/ui/src/sources/components/SourceForm.tsx b/ui/src/sources/components/SourceForm.tsx deleted file mode 100644 index 921df039d..000000000 --- a/ui/src/sources/components/SourceForm.tsx +++ /dev/null @@ -1,229 +0,0 @@ -import React, {PureComponent, FocusEvent, MouseEvent, ChangeEvent} from 'react' -import classnames from 'classnames' -import {connect} from 'react-redux' -import _ from 'lodash' - -import {insecureSkipVerifyText} from 'src/shared/copy/tooltipText' - -import {SUPERADMIN_ROLE} from 'src/auth/Authorized' -import {Source, Role, Organization} from 'src/types' - -interface Me { - role: Role - currentOrganization: Organization -} - -interface Props { - me: Me - source: Partial - editMode: boolean - isUsingAuth: boolean - gotoPurgatory: () => void - isInitialSource: boolean - onSubmit: (e: MouseEvent) => void - onInputChange: (e: ChangeEvent) => void - onBlurSourceURL: (e: FocusEvent) => void -} - -export class SourceForm extends PureComponent { - public render() { - const { - source, - onSubmit, - isUsingAuth, - onInputChange, - gotoPurgatory, - onBlurSourceURL, - isInitialSource, - } = this.props - return ( -
- {isUsingAuth && isInitialSource && this.authIndicator} -
-
- - -
-
- - -
-
- - -
-
- - -
- {this.isEnterprise && ( -
- - -
- )} -
- - -
-
- - -
-
-
- - -
-
- {this.isHTTPS && ( -
-
- - -
- -
- )} -
- - -
- {isUsingAuth && ( - - )} -
-
-
- ) - } - - private get authIndicator(): JSX.Element { - const {me} = this.props - return ( -
- {me.role.name === SUPERADMIN_ROLE ? ( -

- {me.currentOrganization.name} has no connections -

- ) : ( -

- {me.currentOrganization.name} has no connections - available to {me.role}s -

- )} -
Add a Connection below:
-
- ) - } - - private get submitText(): string { - const {editMode} = this.props - if (editMode) { - return 'Save Changes' - } - - return 'Add Connection' - } - - private get submitIconClass(): string { - const {editMode} = this.props - return `icon ${editMode ? 'checkmark' : 'plus'}` - } - - private get submitClass(): string { - const {editMode} = this.props - return classnames('btn btn-block', { - 'btn-primary': editMode, - 'btn-success': !editMode, - }) - } - - private get isEnterprise(): boolean { - const {source} = this.props - return _.get(source, 'type', '').includes('enterprise') - } - - private get isHTTPS(): boolean { - const {source} = this.props - return _.get(source, 'url', '').startsWith('https') - } -} - -const mapStateToProps = ({auth: {isUsingAuth, me}}) => ({isUsingAuth, me}) - -export default connect(mapStateToProps)(SourceForm) diff --git a/ui/src/sources/containers/SourcePage.tsx b/ui/src/sources/containers/SourcePage.tsx deleted file mode 100644 index 3d626f1d8..000000000 --- a/ui/src/sources/containers/SourcePage.tsx +++ /dev/null @@ -1,267 +0,0 @@ -import React, {PureComponent, MouseEvent, ChangeEvent} from 'react' -import {withRouter, WithRouterProps} from 'react-router' -import _ from 'lodash' -import {getSource} from 'src/shared/apis' -import {createSource, updateSource} from 'src/shared/apis' -import { - addSource as addSourceAction, - updateSource as updateSourceAction, - AddSource, - UpdateSource, -} from 'src/shared/actions/sources' -import {notify as notifyAction} from 'src/shared/actions/notifications' -import {connect} from 'react-redux' - -import Notifications from 'src/shared/components/Notifications' -import SourceForm from 'src/sources/components/SourceForm' -import FancyScrollbar from 'src/shared/components/FancyScrollbar' -import PageHeader from 'src/reusable_ui/components/page_layout/PageHeader' -import {DEFAULT_SOURCE} from 'src/shared/constants' - -const INITIAL_PATH = '/sources/new' - -import { - notifySourceUdpated, - notifySourceUdpateFailed, - notifySourceCreationFailed, - notifyErrorConnectingToSource, - notifySourceCreationSucceeded, -} from 'src/shared/copy/notifications' -import {ErrorHandling} from 'src/shared/decorators/errors' - -import * as SourcesModels from 'src/types/sources' -import * as NotificationsActions from 'src/types/actions/notifications' - -interface Props extends WithRouterProps { - notify: NotificationsActions.PublishNotificationActionCreator - addSource: AddSource - updateSource: UpdateSource -} - -interface State { - isCreated: boolean - isLoading: boolean - source: Partial - editMode: boolean - isInitialSource: boolean -} - -@ErrorHandling -class SourcePage extends PureComponent { - constructor(props) { - super(props) - - this.state = { - isLoading: true, - isCreated: false, - source: DEFAULT_SOURCE, - editMode: props.params.id !== undefined, - isInitialSource: props.router.location.pathname === INITIAL_PATH, - } - } - - public async componentDidMount() { - const {editMode} = this.state - const {params, notify} = this.props - - if (!editMode) { - return this.setState({isLoading: false}) - } - - try { - const source = await getSource(params.id) - this.setState({ - source: {...DEFAULT_SOURCE, ...source}, - isLoading: false, - }) - } catch (error) { - notify(notifyErrorConnectingToSource(this.parseError(error))) - this.setState({isLoading: false}) - } - } - - public render() { - const {isLoading, source, editMode, isInitialSource} = this.state - - if (isLoading) { - return
- } - - return ( -
- - - -
-
-
-
- -
-
-
-
-
-
- ) - } - - private handleSubmit = (e: MouseEvent): void => { - e.preventDefault() - const {isCreated, editMode} = this.state - const isNewSource = !editMode - if (!isCreated && isNewSource) { - return this.setState(this.normalizeSource, this.createSource) - } - this.setState(this.normalizeSource, this.updateSource) - } - - private gotoPurgatory = (): void => { - const {router} = this.props - router.push('/purgatory') - } - - private normalizeSource({source}) { - const url = source.url.trim() - if (source.url.startsWith('http')) { - return {source: {...source, url}} - } - return {source: {...source, url: `http://${url}`}} - } - - private createSourceOnBlur = async () => { - const {source} = this.state - // if there is a type on source it has already been created - if (source.type) { - return - } - - try { - const sourceFromServer = await createSource(source) - this.props.addSource(sourceFromServer) - this.setState({ - source: {...DEFAULT_SOURCE, ...sourceFromServer}, - isCreated: true, - }) - } catch (err) { - // dont want to flash this until they submit - const error = this.parseError(err) - console.error('Error creating InfluxDB connection: ', error) - } - } - - private createSource = async () => { - const {source} = this.state - const {notify} = this.props - try { - const sourceFromServer = await createSource(source) - this.props.addSource(sourceFromServer) - this.redirect(sourceFromServer) - notify(notifySourceCreationSucceeded(source.name)) - } catch (err) { - // dont want to flash this until they submit - notify(notifySourceCreationFailed(source.name, this.parseError(err))) - } - } - - private updateSource = async () => { - const {source} = this.state - const {notify} = this.props - try { - const sourceFromServer = await updateSource(source) - this.props.updateSource(sourceFromServer) - this.redirect(sourceFromServer) - notify(notifySourceUdpated(source.name)) - } catch (error) { - notify(notifySourceUdpateFailed(source.name, this.parseError(error))) - } - } - - private redirect = source => { - const {isInitialSource} = this.state - const {params, router} = this.props - - if (isInitialSource) { - return this.redirectToApp(source) - } - - router.push(`/sources/${params.sourceID}/manage-sources`) - } - - private parseError = (error): string => { - return _.get(error, ['data', 'message'], error) - } - - private redirectToApp = source => { - const {location, router} = this.props - const {redirectPath} = location.query - - if (!redirectPath) { - return router.push(`/sources/${source.id}/hosts`) - } - - const fixedPath = redirectPath.replace( - /\/sources\/[^/]*/, - `/sources/${source.id}` - ) - return router.push(fixedPath) - } - - private handleInputChange = (e: ChangeEvent) => { - let val = e.target.value - const name = e.target.name - - if (e.target.type === 'checkbox') { - val = e.target.checked as any - } - - this.setState(prevState => { - const source = { - ...prevState.source, - [name]: val, - } - - return {...prevState, source} - }) - } - - private handleBlurSourceURL = () => { - const {source, editMode} = this.state - if (editMode) { - this.setState(this.normalizeSource) - return - } - - if (!source.url) { - return - } - - this.setState(this.normalizeSource, this.createSourceOnBlur) - } - - private get pageTitle(): string { - const {editMode} = this.state - - if (editMode) { - return 'Configure InfluxDB Connection' - } - - return 'Add a New InfluxDB Connection' - } -} - -const mdtp = { - notify: notifyAction, - addSource: addSourceAction, - updateSource: updateSourceAction, -} - -export default connect(null, mdtp)(withRouter(SourcePage)) diff --git a/ui/src/sources/index.ts b/ui/src/sources/index.ts index b9c6ea2c8..08fee8c25 100644 --- a/ui/src/sources/index.ts +++ b/ui/src/sources/index.ts @@ -1,4 +1,3 @@ -import SourcePage from './containers/SourcePage' import ManageSources from './containers/ManageSources' import OnboardingWizard from './containers/OnboardingWizard' -export {SourcePage, ManageSources, OnboardingWizard} +export {ManageSources, OnboardingWizard} diff --git a/ui/test/sources/components/SourceForm.test.tsx b/ui/test/sources/components/SourceForm.test.tsx deleted file mode 100644 index 1e7f9e4e8..000000000 --- a/ui/test/sources/components/SourceForm.test.tsx +++ /dev/null @@ -1,37 +0,0 @@ -import React from 'react' -import {shallow} from 'enzyme' - -import {SourceForm} from 'src/sources/components/SourceForm' -import {me} from 'test/resources' -import {source} from 'test/fixtures/index' - -const setup = (override = {}) => { - const noop = () => {} - const props = { - source, - editMode: false, - onSubmit: noop, - onInputChange: noop, - onBlurSourceURL: noop, - isUsingAuth: false, - gotoPurgatory: noop, - isInitialSource: false, - me, - ...override, - } - - const wrapper = shallow() - return {wrapper, props} -} - -describe('Sources.Components.SourceForm', () => { - describe('rendering', () => { - it('renders default retention policy field', () => { - const {wrapper} = setup() - const inputs = wrapper.find('input') - const defaultRP = inputs.find({id: 'defaultRP'}) - - expect(defaultRP.exists()).toBe(true) - }) - }) -})