Skip to content

Commit

Permalink
Merge pull request #1909 from influxdata/chore/switch-buckets-ui-gene…
Browse files Browse the repository at this point in the history
…rated

Switch buckets ui to use generated client
  • Loading branch information
bthesorceror authored Dec 14, 2018
2 parents 909fb6e + 816e5de commit f5a035b
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 27 deletions.
6 changes: 6 additions & 0 deletions http/cur_swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3625,6 +3625,12 @@ components:
$ref: "#/components/schemas/Owners"
name:
type: string
organization:
type: string
rp:
type: string
organizationID:
type: string
retentionRules:
type: array
description: rules to expire or retain data. No rules means data never expires.
Expand Down
18 changes: 18 additions & 0 deletions ui/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,18 @@ export interface Bucket {
* @memberof Bucket
*/
name: string;
/**
*
* @type {string}
* @memberof Bucket
*/
organization?: string;
/**
*
* @type {string}
* @memberof Bucket
*/
organizationID?: string;
/**
*
* @type {Owners}
Expand All @@ -260,6 +272,12 @@ export interface Bucket {
* @memberof Bucket
*/
retentionRules: Array<BucketRetentionRules>;
/**
*
* @type {string}
* @memberof Bucket
*/
rp?: string;
}

/**
Expand Down
28 changes: 11 additions & 17 deletions ui/src/logs/actions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {logViewData as defaultLogView} from 'src/logs/data/logViewData'
// Types
import {Dispatch} from 'redux'
import {ThunkDispatch} from 'redux-thunk'
import {View} from 'src/api'
import {View, Bucket, Source} from 'src/api'
import {NewView, TimeSeriesValue} from 'src/types/v2/dashboards'
import {
Filter,
Expand All @@ -37,7 +37,6 @@ import {
TableData,
LogQuery,
} from 'src/types/logs'
import {Source, Bucket} from 'src/types/v2'
import {QueryConfig} from 'src/types'

// Constants
Expand Down Expand Up @@ -303,12 +302,11 @@ export const setBuckets = (buckets: Bucket[]): SetBucketsAction => ({
},
})

export const populateBucketsAsync = (
bucketsLink: string,
source: Source = null
) => async (dispatch): Promise<void> => {
export const populateBucketsAsync = (source: Source = null) => async (
dispatch
): Promise<void> => {
try {
const buckets = await getBuckets(bucketsLink)
const buckets = await getBuckets(source)

if (buckets && buckets.length > 0) {
dispatch(setBuckets(buckets))
Expand All @@ -334,17 +332,13 @@ export const getSourceAndPopulateBucketsAsync = (id: string) => async (
): Promise<void> => {
const source = await readSource(id)

const bucketsLink = getDeep<string | null>(source, 'links.buckets', null)

if (bucketsLink) {
dispatch(setSource(source))
dispatch(setSource(source))

try {
await dispatch(populateBucketsAsync(bucketsLink, source))
await dispatch(clearSearchData(SearchStatus.UpdatingSource))
} catch (e) {
await dispatch(clearSearchData(SearchStatus.SourceError))
}
try {
await dispatch(populateBucketsAsync(source))
await dispatch(clearSearchData(SearchStatus.UpdatingSource))
} catch (e) {
await dispatch(clearSearchData(SearchStatus.SourceError))
}
}

Expand Down
2 changes: 1 addition & 1 deletion ui/src/logs/components/LogsHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import _ from 'lodash'
import React, {PureComponent} from 'react'
import {Source, Bucket} from 'src/types/v2'
import {Source, Bucket} from 'src/api'

import {
Dropdown,
Expand Down
3 changes: 2 additions & 1 deletion ui/src/logs/containers/logs_page/LogsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import {getSources} from 'src/sources/selectors'
import {NOW} from 'src/logs/constants'

// Types
import {Source, Links, Bucket, AppState} from 'src/types/v2'
import {Bucket} from 'src/api'
import {Source, Links, AppState} from 'src/types/v2'
import {
Filter,
LogConfig,
Expand Down
2 changes: 1 addition & 1 deletion ui/src/logs/utils/logQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {buildFluxQuery} from 'src/logs/utils/v2/queryBuilder'
import {buildInfluxQLQuery} from 'src/logs/utils/v1/queryBuilder'

// Types
import {Bucket} from 'src/types/v2/buckets'
import {Bucket} from 'src/api'
import {InfluxLanguage} from 'src/types/v2/dashboards'
import {QueryConfig} from 'src/types'
import {
Expand Down
11 changes: 6 additions & 5 deletions ui/src/shared/apis/v2/buckets.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import AJAX from 'src/utils/ajax'
import {Bucket} from 'src/types/v2/buckets'
import {Bucket, Source} from 'src/api'
import {bucketsAPI} from 'src/utils/api'

export const getBuckets = async (url: string): Promise<Bucket[]> => {
export const getBuckets = async (source: Source): Promise<Bucket[]> => {
try {
const {data} = await AJAX({url})
return data
const {data} = await bucketsAPI.sourcesSourceIDBucketsGet(source.id, null)

return data.buckets
} catch (error) {
console.error(error)
throw error
Expand Down
3 changes: 1 addition & 2 deletions ui/src/types/logs.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import {Index} from 'react-virtualized'

import {Bucket} from 'src/types/v2'
import {QueryConfig} from 'src/types'
import {Source} from 'src/api'
import {Bucket, Source} from 'src/api'

import {FieldOption, TimeSeriesValue} from 'src/types/v2/dashboards'

Expand Down
2 changes: 2 additions & 0 deletions ui/src/utils/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
WriteApi,
SourcesApi,
DefaultApi,
BucketsApi,
} from 'src/api'

const basePath = '/api/v2'
Expand All @@ -23,3 +24,4 @@ export const telegrafsAPI = new TelegrafsApi({basePath})
export const authorizationsAPI = new AuthorizationsApi({basePath})
export const writeAPI = new WriteApi({basePath})
export const sourcesAPI = new SourcesApi({basePath})
export const bucketsAPI = new BucketsApi({basePath})

0 comments on commit f5a035b

Please sign in to comment.