fix(queryBuilder): display loading text (#17963)

* fix(queryBuilder): display loading text

* fix: add loading text to dropdown
pull/17967/head
Andrew Watkins 2020-05-05 20:52:00 -07:00 committed by GitHub
parent 3fd731511a
commit 4243bca075
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 6 deletions

View File

@ -75,7 +75,9 @@ export default class SearchableDropdown extends Component<Props> {
size={buttonSize} size={buttonSize}
status={buttonStatus} status={buttonStatus}
> >
{selectedOption} {buttonStatus === ComponentStatus.Loading
? 'Loading...'
: selectedOption}
</Dropdown.Button> </Dropdown.Button>
)} )}
menu={onCollapse => ( menu={onCollapse => (

View File

@ -82,7 +82,10 @@ const setBuilderTagKeys = (index: number, keys: string[]) => ({
payload: {index, keys}, payload: {index, keys},
}) })
const setBuilderTagKeysStatus = (index: number, status: RemoteDataState) => ({ export const setBuilderTagKeysStatus = (
index: number,
status: RemoteDataState
) => ({
type: 'SET_BUILDER_TAG_KEYS_STATUS' as 'SET_BUILDER_TAG_KEYS_STATUS', type: 'SET_BUILDER_TAG_KEYS_STATUS' as 'SET_BUILDER_TAG_KEYS_STATUS',
payload: {index, status}, payload: {index, status},
}) })
@ -204,6 +207,7 @@ export const loadTagSelector = (index: number) => async (
if (!tags[index] || !buckets[0]) { if (!tags[index] || !buckets[0]) {
return return
} }
dispatch(setBuilderTagKeysStatus(index, RemoteDataState.Loading)) dispatch(setBuilderTagKeysStatus(index, RemoteDataState.Loading))
const state = getState() const state = getState()

View File

@ -198,7 +198,10 @@ class TagSelector extends PureComponent<Props> {
) )
} }
if (valuesStatus === RemoteDataState.Loading) { if (
valuesStatus === RemoteDataState.Loading ||
valuesStatus === RemoteDataState.NotStarted
) {
return ( return (
<BuilderCard.Empty> <BuilderCard.Empty>
<WaitingText text="Loading tag values" /> <WaitingText text="Loading tag values" />

View File

@ -5,14 +5,16 @@ import {
initialState, initialState,
initialStateHelper, initialStateHelper,
timeMachinesReducer, timeMachinesReducer,
timeMachineReducer,
} from 'src/timeMachine/reducers' } from 'src/timeMachine/reducers'
import {setBuilderTagKeysStatus} from 'src/timeMachine/actions/queryBuilder'
import {RemoteDataState, TableViewProperties} from 'src/types' import {RemoteDataState, TableViewProperties} from 'src/types'
describe('the Time Machine reducer', () => { describe('the Time Machine reducer', () => {
describe('setting the default aggregateFunctionType', () => { describe('setting the default aggregateFunctionType', () => {
const store = createStore(timeMachinesReducer, initialState()) const store = createStore(timeMachinesReducer, initialState())
const expectedAggregatefunctionType = initialStateHelper().queryBuilder const expectedAggregateFunctionType = initialStateHelper().queryBuilder
.tags[0].aggregateFunctionType .tags[0].aggregateFunctionType
it('is set when setting a builder bucket selection', () => { it('is set when setting a builder bucket selection', () => {
@ -26,7 +28,7 @@ describe('the Time Machine reducer', () => {
.aggregateFunctionType .aggregateFunctionType
expect(defaultAggregateFunctionType).toEqual( expect(defaultAggregateFunctionType).toEqual(
expectedAggregatefunctionType expectedAggregateFunctionType
) )
}) })
@ -38,11 +40,28 @@ describe('the Time Machine reducer', () => {
.aggregateFunctionType .aggregateFunctionType
expect(defaultAggregateFunctionType).toEqual( expect(defaultAggregateFunctionType).toEqual(
expectedAggregatefunctionType expectedAggregateFunctionType
) )
}) })
}) })
describe('setBuilderTagKeyStatus', () => {
it('sets tagValues "status" to "NotStarted" when tagKeys are "Loading"', () => {
const {Loading, NotStarted} = RemoteDataState
const dataExplorer = initialState().timeMachines.de
dataExplorer.queryBuilder.tags[0].keysStatus = RemoteDataState.Done
dataExplorer.queryBuilder.tags[0].valuesStatus = RemoteDataState.Done
const state = timeMachineReducer(
dataExplorer,
setBuilderTagKeysStatus(0, Loading)
)
expect(state.queryBuilder.tags[0].keysStatus).toBe(Loading)
expect(state.queryBuilder.tags[0].valuesStatus).toBe(NotStarted)
})
})
describe('buildActiveQuery', () => { describe('buildActiveQuery', () => {
let draftState let draftState

View File

@ -764,6 +764,7 @@ export const timeMachineReducer = (
tags[index].keysStatus = status tags[index].keysStatus = status
if (status === RemoteDataState.Loading) { if (status === RemoteDataState.Loading) {
tags[index].valuesStatus = RemoteDataState.NotStarted
for (let i = index + 1; i < tags.length; i++) { for (let i = index + 1; i < tags.length; i++) {
tags[i].keysStatus = RemoteDataState.NotStarted tags[i].keysStatus = RemoteDataState.NotStarted
} }