chore(schemaExplorer): simplify fetchMeasurements

pull/5858/head
Pavel Zavora 2022-02-09 10:26:02 +01:00
parent 733527698d
commit 5f30d8ab4f
2 changed files with 14 additions and 16 deletions

View File

@ -2,8 +2,7 @@
import {PureComponent} from 'react'
// Utils
import {measurements as fetchMeasurementsAsync} from 'src/shared/apis/flux/metaQueries'
import parseValuesColumn from 'src/shared/parsing/flux/values'
import {fetchMeasurements} from 'src/shared/apis/flux/metaQueries'
// Types
import {Source, RemoteDataState} from 'src/types'
@ -19,14 +18,6 @@ interface State {
loading: RemoteDataState
}
export async function fetchFluxMeasurements(
source: Source,
bucket: string
): Promise<string[]> {
const measurementResults = await fetchMeasurementsAsync(source, bucket)
return parseValuesColumn(measurementResults)
}
class FetchMeasurements extends PureComponent<Props, State> {
constructor(props) {
super(props)
@ -36,18 +27,18 @@ class FetchMeasurements extends PureComponent<Props, State> {
}
}
public componentDidMount() {
this.fetchMeasurements()
this.fetchData()
}
public render() {
return this.props.children(this.state.measurements, this.state.loading)
}
private async fetchMeasurements() {
private async fetchData() {
const {source, bucket} = this.props
this.setState({loading: RemoteDataState.Loading})
try {
const measurements = await fetchFluxMeasurements(source, bucket)
const measurements = await fetchMeasurements(source, bucket)
this.setState({measurements, loading: RemoteDataState.Done})
} catch (error) {
this.setState({loading: RemoteDataState.Error})

View File

@ -4,12 +4,19 @@ import AJAX from 'src/utils/ajax'
import {Source, SchemaFilter} from 'src/types'
import recordProperty from 'src/flux/helpers/recordProperty'
import fluxString from 'src/flux/helpers/fluxString'
import parseValuesColumn from 'src/shared/parsing/flux/values'
export const measurements = async (
export const fetchMeasurements = async (
source: Source,
bucket: string
): Promise<any> => {
return tagValues({bucket, source, tagKey: '_measurement', limit: 0})
): Promise<string[]> => {
const csvResponse = await tagValues({
bucket,
source,
tagKey: '_measurement',
limit: 0,
})
return parseValuesColumn(csvResponse)
}
export const fields = async (