refactor(ui/dataLoaders): Update dataLoaders bucket dropdowns to be the same component
parent
2265893c37
commit
54353fb964
|
@ -0,0 +1,50 @@
|
||||||
|
// Libraries
|
||||||
|
import React from 'react'
|
||||||
|
import {shallow} from 'enzyme'
|
||||||
|
|
||||||
|
// Components
|
||||||
|
import BucketsDropdown from 'src/dataLoaders/components/BucketsDropdown'
|
||||||
|
import {Dropdown, ComponentStatus} from 'src/clockface'
|
||||||
|
import {bucket} from 'mocks/dummyData'
|
||||||
|
|
||||||
|
// Mocks
|
||||||
|
|
||||||
|
const setup = (override = {}) => {
|
||||||
|
const props = {
|
||||||
|
selected: '',
|
||||||
|
buckets: [],
|
||||||
|
onSelectBucket: jest.fn(),
|
||||||
|
...override,
|
||||||
|
}
|
||||||
|
|
||||||
|
const wrapper = shallow(<BucketsDropdown {...props} />)
|
||||||
|
|
||||||
|
return {wrapper}
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('DataLoading.Components.BucketsDropdown', () => {
|
||||||
|
describe('when no buckets', () => {
|
||||||
|
it('renders disabled dropdown', () => {
|
||||||
|
const {wrapper} = setup()
|
||||||
|
|
||||||
|
const dropdown = wrapper.find(Dropdown)
|
||||||
|
|
||||||
|
expect(wrapper.exists()).toBe(true)
|
||||||
|
expect(dropdown.exists()).toBe(true)
|
||||||
|
expect(dropdown.prop('status')).toBe(ComponentStatus.Disabled)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('if buckets', () => {
|
||||||
|
it('renders dropdown', () => {
|
||||||
|
const buckets = [bucket]
|
||||||
|
const {wrapper} = setup({buckets})
|
||||||
|
|
||||||
|
const dropdown = wrapper.find(Dropdown)
|
||||||
|
|
||||||
|
expect(wrapper.exists()).toBe(true)
|
||||||
|
expect(dropdown.exists()).toBe(true)
|
||||||
|
expect(dropdown.prop('status')).toBe(ComponentStatus.Default)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
|
@ -0,0 +1,75 @@
|
||||||
|
// Libraries
|
||||||
|
import React, {PureComponent} from 'react'
|
||||||
|
|
||||||
|
// Components
|
||||||
|
import {Dropdown, ComponentStatus} from 'src/clockface'
|
||||||
|
|
||||||
|
// Types
|
||||||
|
import {Bucket} from 'src/api'
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
selected: string
|
||||||
|
buckets: Bucket[]
|
||||||
|
onSelectBucket: (bucket: Bucket) => void
|
||||||
|
}
|
||||||
|
|
||||||
|
class BucketsDropdown extends PureComponent<Props> {
|
||||||
|
public render() {
|
||||||
|
return (
|
||||||
|
<Dropdown
|
||||||
|
titleText={this.title}
|
||||||
|
status={this.status}
|
||||||
|
selectedID={this.selectedID}
|
||||||
|
onChange={this.handleSelectBucket}
|
||||||
|
>
|
||||||
|
{this.dropdownBuckets}
|
||||||
|
</Dropdown>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
private get title(): string {
|
||||||
|
if (this.isBucketsEmpty) {
|
||||||
|
return 'No buckets found'
|
||||||
|
}
|
||||||
|
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
|
||||||
|
private get status(): ComponentStatus {
|
||||||
|
if (this.isBucketsEmpty) {
|
||||||
|
return ComponentStatus.Disabled
|
||||||
|
}
|
||||||
|
|
||||||
|
return ComponentStatus.Default
|
||||||
|
}
|
||||||
|
|
||||||
|
private get selectedID(): string {
|
||||||
|
return this.props.selected || ''
|
||||||
|
}
|
||||||
|
|
||||||
|
private get isBucketsEmpty(): boolean {
|
||||||
|
const {buckets} = this.props
|
||||||
|
return !buckets || !buckets.length
|
||||||
|
}
|
||||||
|
|
||||||
|
private get dropdownBuckets(): JSX.Element[] {
|
||||||
|
const {buckets} = this.props
|
||||||
|
if (this.isBucketsEmpty) {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
|
return buckets.map(b => (
|
||||||
|
<Dropdown.Item key={b.name} value={b.name} id={b.name}>
|
||||||
|
{b.name}
|
||||||
|
</Dropdown.Item>
|
||||||
|
))
|
||||||
|
}
|
||||||
|
|
||||||
|
private handleSelectBucket = (bucketName: string) => {
|
||||||
|
const bucket = this.props.buckets.find(b => b.name === bucketName)
|
||||||
|
|
||||||
|
this.props.onSelectBucket(bucket)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BucketsDropdown
|
|
@ -11,7 +11,6 @@ import {
|
||||||
Input,
|
Input,
|
||||||
IconFont,
|
IconFont,
|
||||||
ComponentSize,
|
ComponentSize,
|
||||||
Dropdown,
|
|
||||||
FormElement,
|
FormElement,
|
||||||
Grid,
|
Grid,
|
||||||
Columns,
|
Columns,
|
||||||
|
@ -22,6 +21,7 @@ import {
|
||||||
PLUGIN_BUNDLE_OPTIONS,
|
PLUGIN_BUNDLE_OPTIONS,
|
||||||
BUNDLE_LOGOS,
|
BUNDLE_LOGOS,
|
||||||
} from 'src/dataLoaders/constants/pluginConfigs'
|
} from 'src/dataLoaders/constants/pluginConfigs'
|
||||||
|
import BucketDropdown from 'src/dataLoaders/components/BucketsDropdown'
|
||||||
|
|
||||||
// Types
|
// Types
|
||||||
import {TelegrafPlugin, BundleName} from 'src/types/v2/dataLoaders'
|
import {TelegrafPlugin, BundleName} from 'src/types/v2/dataLoaders'
|
||||||
|
@ -69,6 +69,7 @@ class StreamingSelector extends PureComponent<Props, State> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
|
const {bucket, buckets} = this.props
|
||||||
const {gridSizerUpdateFlag, searchTerm} = this.state
|
const {gridSizerUpdateFlag, searchTerm} = this.state
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -76,12 +77,11 @@ class StreamingSelector extends PureComponent<Props, State> {
|
||||||
<Grid.Row>
|
<Grid.Row>
|
||||||
<Grid.Column widthSM={Columns.Five}>
|
<Grid.Column widthSM={Columns.Five}>
|
||||||
<FormElement label="Bucket">
|
<FormElement label="Bucket">
|
||||||
<Dropdown
|
<BucketDropdown
|
||||||
selectedID={this.selectedBucketID}
|
selected={bucket}
|
||||||
onChange={this.handleSelectBucket}
|
buckets={buckets}
|
||||||
>
|
onSelectBucket={this.handleSelectBucket}
|
||||||
{this.dropdownBuckets}
|
/>
|
||||||
</Dropdown>
|
|
||||||
</FormElement>
|
</FormElement>
|
||||||
</Grid.Column>
|
</Grid.Column>
|
||||||
<Grid.Column widthSM={Columns.Five} offsetSM={Columns.Two}>
|
<Grid.Column widthSM={Columns.Five} offsetSM={Columns.Two}>
|
||||||
|
@ -120,33 +120,10 @@ class StreamingSelector extends PureComponent<Props, State> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleSelectBucket = (bucketName: string) => {
|
private handleSelectBucket = (bucket: Bucket) => {
|
||||||
const bucket = this.props.buckets.find(b => b.name === bucketName)
|
|
||||||
|
|
||||||
this.props.onSelectBucket(bucket)
|
this.props.onSelectBucket(bucket)
|
||||||
}
|
}
|
||||||
|
|
||||||
private get selectedBucketID(): string {
|
|
||||||
return this.props.bucket || 'empty'
|
|
||||||
}
|
|
||||||
|
|
||||||
private get dropdownBuckets(): JSX.Element[] {
|
|
||||||
const {buckets} = this.props
|
|
||||||
if (!buckets || !buckets.length) {
|
|
||||||
return [
|
|
||||||
<Dropdown.Item key={'none'} value={'No buckets found'} id={'empty'}>
|
|
||||||
{'No buckets found'}
|
|
||||||
</Dropdown.Item>,
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
return buckets.map(b => (
|
|
||||||
<Dropdown.Item key={b.name} value={b.name} id={b.name}>
|
|
||||||
{b.name}
|
|
||||||
</Dropdown.Item>
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
private get filteredBundles(): BundleName[] {
|
private get filteredBundles(): BundleName[] {
|
||||||
const {searchTerm} = this.state
|
const {searchTerm} = this.state
|
||||||
|
|
||||||
|
|
|
@ -8,15 +8,16 @@ import {
|
||||||
Columns,
|
Columns,
|
||||||
Grid,
|
Grid,
|
||||||
ComponentSize,
|
ComponentSize,
|
||||||
Dropdown,
|
|
||||||
InputType,
|
InputType,
|
||||||
ComponentStatus,
|
ComponentStatus,
|
||||||
} from 'src/clockface'
|
} from 'src/clockface'
|
||||||
|
import BucketDropdown from 'src/dataLoaders/components/BucketsDropdown'
|
||||||
|
import {Bucket} from 'src/api'
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
bucket: string
|
bucket: string
|
||||||
buckets: string[]
|
buckets: Bucket[]
|
||||||
onSelectBucket: (value: string) => void
|
onSelectBucket: (bucket: Bucket) => void
|
||||||
onChangeURL: (value: string) => void
|
onChangeURL: (value: string) => void
|
||||||
url: string
|
url: string
|
||||||
}
|
}
|
||||||
|
@ -27,18 +28,17 @@ export class ScraperTarget extends PureComponent<Props> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
const {onSelectBucket, url} = this.props
|
const {onSelectBucket, url, bucket, buckets} = this.props
|
||||||
return (
|
return (
|
||||||
<Grid>
|
<Grid>
|
||||||
<Grid.Row>
|
<Grid.Row>
|
||||||
<Grid.Column widthXS={Columns.Eight} offsetXS={Columns.Two}>
|
<Grid.Column widthXS={Columns.Eight} offsetXS={Columns.Two}>
|
||||||
<Form.Element label="Bucket">
|
<Form.Element label="Bucket">
|
||||||
<Dropdown
|
<BucketDropdown
|
||||||
selectedID={this.selectedBucket}
|
selected={bucket}
|
||||||
onChange={onSelectBucket}
|
buckets={buckets}
|
||||||
>
|
onSelectBucket={onSelectBucket}
|
||||||
{this.dropdownBuckets}
|
/>
|
||||||
</Dropdown>
|
|
||||||
</Form.Element>
|
</Form.Element>
|
||||||
</Grid.Column>
|
</Grid.Column>
|
||||||
<Grid.Column widthXS={Columns.Eight} offsetXS={Columns.Two}>
|
<Grid.Column widthXS={Columns.Eight} offsetXS={Columns.Two}>
|
||||||
|
@ -69,32 +69,6 @@ export class ScraperTarget extends PureComponent<Props> {
|
||||||
return ComponentStatus.Default
|
return ComponentStatus.Default
|
||||||
}
|
}
|
||||||
|
|
||||||
private get selectedBucket(): string {
|
|
||||||
const {buckets, bucket} = this.props
|
|
||||||
|
|
||||||
if (!buckets || !buckets.length) {
|
|
||||||
return 'empty'
|
|
||||||
}
|
|
||||||
return bucket
|
|
||||||
}
|
|
||||||
|
|
||||||
private get dropdownBuckets(): JSX.Element[] {
|
|
||||||
const {buckets} = this.props
|
|
||||||
if (!buckets || !buckets.length) {
|
|
||||||
return [
|
|
||||||
<Dropdown.Item key={'none'} value={'No buckets found'} id={'empty'}>
|
|
||||||
{'No buckets found'}
|
|
||||||
</Dropdown.Item>,
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
return buckets.map(b => (
|
|
||||||
<Dropdown.Item key={b} value={b} id={b}>
|
|
||||||
{b}
|
|
||||||
</Dropdown.Item>
|
|
||||||
))
|
|
||||||
}
|
|
||||||
|
|
||||||
private get urlEmpty(): boolean {
|
private get urlEmpty(): boolean {
|
||||||
return !this.props.url
|
return !this.props.url
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ export class Scraping extends PureComponent<Props> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public render() {
|
public render() {
|
||||||
const {scraperBucket, onSetScraperTargetURL, url} = this.props
|
const {scraperBucket, onSetScraperTargetURL, url, buckets} = this.props
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form onSubmit={this.handleSubmit}>
|
<Form onSubmit={this.handleSubmit}>
|
||||||
|
@ -70,7 +70,7 @@ export class Scraping extends PureComponent<Props> {
|
||||||
</h5>
|
</h5>
|
||||||
<ScraperTarget
|
<ScraperTarget
|
||||||
bucket={scraperBucket}
|
bucket={scraperBucket}
|
||||||
buckets={this.buckets}
|
buckets={buckets}
|
||||||
onSelectBucket={this.handleSelectBucket}
|
onSelectBucket={this.handleSelectBucket}
|
||||||
onChangeURL={onSetScraperTargetURL}
|
onChangeURL={onSetScraperTargetURL}
|
||||||
url={url}
|
url={url}
|
||||||
|
@ -87,25 +87,12 @@ export class Scraping extends PureComponent<Props> {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private get buckets(): string[] {
|
private handleSelectBucket = (bucket: Bucket) => {
|
||||||
const {buckets} = this.props
|
const {onSetBucketInfo, onSetScraperTargetBucket} = this.props
|
||||||
|
const {organization, organizationID, id, name} = bucket
|
||||||
|
|
||||||
return buckets.map(b => b.name)
|
onSetBucketInfo(organization, organizationID, name, id)
|
||||||
}
|
onSetScraperTargetBucket(bucket.name)
|
||||||
|
|
||||||
private handleSelectBucket = (bucket: string) => {
|
|
||||||
const {buckets, onSetScraperTargetBucket, onSetBucketInfo} = this.props
|
|
||||||
if (!buckets || !buckets.length) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const findBucket = buckets.find(b => b.name === bucket)
|
|
||||||
const bucketID = findBucket.id
|
|
||||||
const org = findBucket.organization
|
|
||||||
const orgID = findBucket.organizationID
|
|
||||||
|
|
||||||
onSetBucketInfo(org, orgID, bucket, bucketID)
|
|
||||||
onSetScraperTargetBucket(bucket)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private get nextButtonStatus(): ComponentStatus {
|
private get nextButtonStatus(): ComponentStatus {
|
||||||
|
|
|
@ -10,28 +10,11 @@ exports[`ScraperTarget rendering renders! 1`] = `
|
||||||
<FormElement
|
<FormElement
|
||||||
label="Bucket"
|
label="Bucket"
|
||||||
>
|
>
|
||||||
<Dropdown
|
<BucketsDropdown
|
||||||
buttonColor="default"
|
buckets={Array []}
|
||||||
buttonSize="sm"
|
onSelectBucket={[MockFunction]}
|
||||||
maxMenuHeight={250}
|
selected=""
|
||||||
menuColor="sapphire"
|
/>
|
||||||
mode="radio"
|
|
||||||
onChange={[MockFunction]}
|
|
||||||
selectedID="empty"
|
|
||||||
status="default"
|
|
||||||
titleText=""
|
|
||||||
wrapText={false}
|
|
||||||
>
|
|
||||||
<DropdownItem
|
|
||||||
checkbox={false}
|
|
||||||
id="empty"
|
|
||||||
key="none"
|
|
||||||
selected={false}
|
|
||||||
value="No buckets found"
|
|
||||||
>
|
|
||||||
No buckets found
|
|
||||||
</DropdownItem>
|
|
||||||
</Dropdown>
|
|
||||||
</FormElement>
|
</FormElement>
|
||||||
</GridColumn>
|
</GridColumn>
|
||||||
<GridColumn
|
<GridColumn
|
||||||
|
|
Loading…
Reference in New Issue