Skip to content

Commit

Permalink
fix: pass variables into a function (#16291)
Browse files Browse the repository at this point in the history
  • Loading branch information
drdelambre authored Dec 19, 2019
1 parent 48b8cb8 commit 6c33488
Showing 1 changed file with 27 additions and 7 deletions.
34 changes: 27 additions & 7 deletions ui/src/telegrafs/components/TelegrafOutputOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,24 +71,38 @@ class TelegrafOutputOverlay extends PureComponent<Props> {
return <>{this.overlay}</>
}

private get overlay(): JSX.Element {
const {server, org, orgID, buckets} = this.props
const _buckets = (buckets || [])
private get buckets() {
const {buckets} = this.props
return (buckets || [])
.filter(item => item.type !== 'system')
.sort((a, b) => {
const _a = a.name.toLowerCase()
const _b = b.name.toLowerCase()
return _a > _b ? 1 : _a < _b ? -1 : 0
})
}

private get currentBucket() {
const _buckets = this.buckets
const {selectedBucket} = this.state

if (_buckets.length) {
return selectedBucket ? selectedBucket : _buckets[0]
}

return null
}

private get overlay(): JSX.Element {
const {server, org, orgID} = this.props
const _buckets = this.buckets
const bucket = this.currentBucket
let bucket_dd = null
let bucket = null

if (_buckets.length) {
bucket = selectedBucket ? selectedBucket : _buckets[0]
bucket_dd = (
<BucketDropdown
selectedBucketID={bucket.id}
selectedBucketID={this.currentBucket.id}
buckets={_buckets}
onSelectBucket={this.handleSelectBucket}
/>
Expand Down Expand Up @@ -144,9 +158,15 @@ class TelegrafOutputOverlay extends PureComponent<Props> {
}

private handleDownloadConfig = () => {
const {server, org} = this.props
const bucket = this.currentBucket
const config = transform(
TELEGRAF_OUTPUT,
Object.assign({}, OUTPUT_DEFAULTS, {})
Object.assign({}, OUTPUT_DEFAULTS, {
server,
org,
bucket: bucket ? bucket.name : OUTPUT_DEFAULTS.bucket,
})
)
downloadTextFile(config, 'outputs.influxdb_v2', '.conf')
}
Expand Down

0 comments on commit 6c33488

Please sign in to comment.