Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(ui): Add the ability to name a scraper target #11809

Merged
merged 1 commit into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## v2.0.0-alpha.3 [unreleased]

### Features
1. [11809](https://github.com/influxdata/influxdb/pull/11809): Add the ability to name a scraper target

### Bug Fixes

Expand Down
6 changes: 3 additions & 3 deletions ui/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
},
"dependencies": {
"@influxdata/react-custom-scrollbars": "4.3.8",
"@influxdata/influx": "^0.2.3",
"@influxdata/influx": "^0.2.5",
"axios": "^0.18.0",
"babel-polyfill": "^6.26.0",
"bignumber.js": "^4.0.2",
Expand Down
15 changes: 13 additions & 2 deletions ui/src/dataLoaders/actions/dataLoaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export type Action =
| SetConfigArrayValue
| SetScraperTargetBucket
| SetScraperTargetURL
| SetScraperTargetName
| SetScraperTargetID
| ClearDataLoaders
| SetTelegrafConfigName
Expand Down Expand Up @@ -246,6 +247,16 @@ export const setScraperTargetURL = (url: string): SetScraperTargetURL => ({
payload: {url},
})

interface SetScraperTargetName {
type: 'SET_SCRAPER_TARGET_NAME'
payload: {name: string}
}

export const setScraperTargetName = (name: string): SetScraperTargetName => ({
type: 'SET_SCRAPER_TARGET_NAME',
payload: {name},
})

interface SetScraperTargetID {
type: 'SET_SCRAPER_TARGET_ID'
payload: {id: string}
Expand Down Expand Up @@ -426,7 +437,7 @@ export const saveScraperTarget = () => async (
const {
dataLoading: {
dataLoaders: {
scraperTarget: {url, id},
scraperTarget: {url, id, name},
},
steps: {bucketID, orgID},
},
Expand All @@ -437,7 +448,7 @@ export const saveScraperTarget = () => async (
await client.scrapers.update(id, {url, bucketID})
} else {
const newTarget = await client.scrapers.create({
name: 'new target',
name,
type: ScraperTargetRequest.TypeEnum.Prometheus,
url,
bucketID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class ConfigureDataSourceSwitcher extends PureComponent<Props> {
<Scraping onClickNext={onClickNext} buckets={buckets} />
</div>
)
case DataLoaderType.CSV:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rip

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i cant believe that was in there for so long. oops

return <div>{DataLoaderType.CSV}</div>
default:
return <EmptyDataSourceState />
}
Expand Down
31 changes: 0 additions & 31 deletions ui/src/dataLoaders/components/configureStep/Scraper.test.tsx

This file was deleted.

54 changes: 54 additions & 0 deletions ui/src/dataLoaders/components/configureStep/ScraperTarget.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// Libraries
import React from 'react'
import {shallow} from 'enzyme'

// Components
import {ScraperTarget} from 'src/dataLoaders/components/configureStep/ScraperTarget'

const setup = (override = {}) => {
const props = {
bucket: '',
buckets: [],
onSelectBucket: jest.fn(),
onChangeURL: jest.fn(),
onChangeName: jest.fn(),
url: '',
name: '',
...override,
}
const wrapper = shallow(<ScraperTarget {...props} />)

return {wrapper}
}

describe('ScraperTarget', () => {
describe('rendering', () => {
it('renders correctly with no bucket, url, name', () => {
const {wrapper} = setup()
expect(wrapper.exists()).toBe(true)

expect(wrapper).toMatchSnapshot()
})

it('renders correctly with bucket', () => {
const {wrapper} = setup({bucket: 'defbuck'})
expect(wrapper.exists()).toBe(true)

expect(wrapper).toMatchSnapshot()
})

it('renders correctly with url', () => {
const {wrapper} = setup({url: 'http://url.com'})
expect(wrapper.exists()).toBe(true)

expect(wrapper).toMatchSnapshot()
})

it('renders correctly with name', () => {
const {wrapper} = setup({name: 'MyScraper'})
expect(wrapper.exists()).toBe(true)

expect(wrapper).toMatchSnapshot()
})
})
})
36 changes: 33 additions & 3 deletions ui/src/dataLoaders/components/configureStep/ScraperTarget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ interface Props {
buckets: Bucket[]
onSelectBucket: (bucket: Bucket) => void
onChangeURL: (value: string) => void
onChangeName: (value: string) => void
url: string
name: string
}

export class ScraperTarget extends PureComponent<Props> {
Expand All @@ -28,11 +30,25 @@ export class ScraperTarget extends PureComponent<Props> {
}

public render() {
const {onSelectBucket, url, bucket, buckets} = this.props
const {onSelectBucket, url, name, bucket, buckets} = this.props
return (
<Grid>
<Grid.Row>
<Grid.Column widthXS={Columns.Eight} offsetXS={Columns.Two}>
<Form.Element
label="Name"
errorMessage={this.nameEmpty && 'Target name is empty'}
>
<Input
ischolten marked this conversation as resolved.
Show resolved Hide resolved
type={InputType.Text}
value={name}
onChange={this.handleChangeName}
titleText="Name"
size={ComponentSize.Medium}
autoFocus={true}
status={this.nameStatus}
/>
</Form.Element>
<Form.Element label="Bucket">
<BucketDropdown
selected={bucket}
Expand All @@ -44,15 +60,14 @@ export class ScraperTarget extends PureComponent<Props> {
<Grid.Column widthXS={Columns.Eight} offsetXS={Columns.Two}>
<Form.Element
label="Target URL"
errorMessage={this.urlEmpty && 'target URL is empty'}
errorMessage={this.urlEmpty && 'Target URL is empty'}
>
<Input
type={InputType.Text}
value={url}
onChange={this.handleChangeURL}
titleText="Target URL"
size={ComponentSize.Medium}
autoFocus={true}
status={this.urlStatus}
/>
</Form.Element>
Expand All @@ -73,10 +88,25 @@ export class ScraperTarget extends PureComponent<Props> {
return !this.props.url
}

private get nameStatus(): ComponentStatus {
if (this.nameEmpty) {
return ComponentStatus.Error
}
return ComponentStatus.Default
}
private get nameEmpty(): boolean {
return !this.props.name
}

private handleChangeURL = (e: ChangeEvent<HTMLInputElement>) => {
const value = e.target.value
this.props.onChangeURL(value)
}

private handleChangeName = (e: ChangeEvent<HTMLInputElement>) => {
const value = e.target.value
this.props.onChangeName(value)
}
}

export default ScraperTarget
19 changes: 17 additions & 2 deletions ui/src/dataLoaders/components/configureStep/Scraping.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import ScraperTarget from 'src/dataLoaders/components/configureStep/ScraperTarge
import {
setScraperTargetBucket,
setScraperTargetURL,
setScraperTargetName,
saveScraperTarget,
} from 'src/dataLoaders/actions/dataLoaders'
import {setBucketInfo} from 'src/dataLoaders/actions/steps'
Expand All @@ -29,6 +30,7 @@ interface OwnProps {
interface DispatchProps {
onSetScraperTargetBucket: typeof setScraperTargetBucket
onSetScraperTargetURL: typeof setScraperTargetURL
onSetScraperTargetName: typeof setScraperTargetName
onSaveScraperTarget: typeof saveScraperTarget
onSetBucketInfo: typeof setBucketInfo
}
Expand All @@ -37,6 +39,7 @@ interface StateProps {
scraperBucket: string
url: string
currentBucket: string
name: string
}

type Props = OwnProps & DispatchProps & StateProps
Expand All @@ -56,7 +59,14 @@ export class Scraping extends PureComponent<Props> {
}

public render() {
const {scraperBucket, onSetScraperTargetURL, url, buckets} = this.props
const {
scraperBucket,
onSetScraperTargetURL,
onSetScraperTargetName,
url,
buckets,
name,
} = this.props

return (
<Form onSubmit={this.handleSubmit}>
Expand All @@ -73,7 +83,9 @@ export class Scraping extends PureComponent<Props> {
buckets={buckets}
onSelectBucket={this.handleSelectBucket}
onChangeURL={onSetScraperTargetURL}
onChangeName={onSetScraperTargetName}
url={url}
name={name}
/>
</div>
</FancyScrollbar>
Expand All @@ -97,7 +109,8 @@ export class Scraping extends PureComponent<Props> {

private get nextButtonStatus(): ComponentStatus {
if (
this.props.url === '' ||
!this.props.url ||
!this.props.name ||
!this.props.buckets ||
!this.props.buckets.length
) {
Expand All @@ -123,6 +136,7 @@ const mstp = ({
currentBucket: bucket,
scraperBucket: scraperTarget.bucket,
url: scraperTarget.url,
name: scraperTarget.name,
}
}

Expand All @@ -131,6 +145,7 @@ const mdtp: DispatchProps = {
onSetScraperTargetURL: setScraperTargetURL,
onSaveScraperTarget: saveScraperTarget,
onSetBucketInfo: setBucketInfo,
onSetScraperTargetName: setScraperTargetName,
}

export default connect<StateProps, DispatchProps, OwnProps>(
Expand Down

This file was deleted.

Loading