Skip to content

Commit

Permalink
chore(query Builder): fix query builder state (#18649)
Browse files Browse the repository at this point in the history
* fix(query-builder): added function call to editActiveQueryWithBuilder to change redux state to queryBuilder

* fix(query-Builder): resets query builder state after switching to script editor and navigating to another page

* fix(query-Builder): added tests to ensure navigating from the buckets list leads to the data explorer page with query builder

* fix(query-Builder): updated change log

* fix(query-Builder): fixed prettier issue)

* fix(query-Builder): fixed formatting in queryBuilder.ts and simplified test in explorer.test.ts

Co-authored-by: Russ Savage <[email protected]>
  • Loading branch information
rbose22 and russorat authored Jun 25, 2020
1 parent cc28e2f commit 449d475
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
1. [18602](https://github.com/influxdata/influxdb/pull/18602): Fix uint overflow during setup on 32bit systems
1. [18623](https://github.com/influxdata/influxdb/pull/18623): Drop support for --local flag within influx CLI
1. [18632](https://github.com/influxdata/influxdb/pull/18632): Prevents undefined queries in cells from erroring out in dashboards
1. [18649](https://github.com/influxdata/influxdb/pull/18649): Fixes bucket selection issue and query builder state
1. [18658](https://github.com/influxdata/influxdb/pull/18658): Add support for 'd' day and 'w' week time identifiers in the CLI for bucket and setup commands
1. [18581](https://github.com/influxdata/influxdb/pull/18581): Cache dashboard cell query results to use as a reference for cell configurations
1. [18707](https://github.com/influxdata/influxdb/pull/18707): Validate host-url for influx config create/set commands
Expand Down
26 changes: 26 additions & 0 deletions ui/cypress/e2e/explorer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,32 @@ describe('DataExplorer', () => {
})
})

describe('data-explorer state', () => {
it('should persist and display last submitted script editor script ', () => {
const fluxCode = 'from(bucket: "_monitoring")'
cy.getByTestID('switch-to-script-editor').click()
cy.get('.flux-editor').within(() => {
cy.get('.view-lines').type(fluxCode)
})
cy.contains('Submit').click()
cy.getByTestID('nav-item-tasks').click()
cy.getByTestID('nav-item-data-explorer').click()
cy.contains(fluxCode)
})

it('can navigate to data explorer from buckets list and override state', () => {
const fluxCode = 'from(bucket: "_monitoring")'
cy.getByTestID('switch-to-script-editor').click()
cy.get('.flux-editor').within(() => {
cy.get('.view-lines').type(fluxCode)
})
cy.contains('Submit').click()
cy.getByTestID('nav-item-load-data').click()
cy.getByTestID('bucket--card--name _tasks').click()
cy.getByTestID('query-builder').should('exist')
})
})

describe('numeric input using custom bin sizes in Histograms', () => {
beforeEach(() => {
cy.getByTestID('view-type--dropdown').click()
Expand Down
9 changes: 7 additions & 2 deletions ui/src/timeMachine/actions/queryBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ import {
import {getOrg} from 'src/organizations/selectors'
import {getAll} from 'src/resources/selectors'

//Actions
import {editActiveQueryWithBuilderSync} from 'src/timeMachine/actions'

// Constants
import {LIMIT} from 'src/resources/constants'

Expand Down Expand Up @@ -153,7 +156,6 @@ export const loadBuckets = () => async (
) => {
const startTime = Date.now()
const orgID = getOrg(getState()).id

dispatch(setBuilderBucketsStatus(RemoteDataState.Loading))

try {
Expand Down Expand Up @@ -455,11 +457,14 @@ export const reloadTagSelectors = () => (dispatch: Dispatch<Action>) => {
}

export const setBuilderBucketIfExists = (bucketName: string) => (
dispatch: Dispatch<Action>,
dispatch: Dispatch<
Action | ReturnType<typeof editActiveQueryWithBuilderSync>
>,
getState: GetState
) => {
const buckets = getAll<Bucket>(getState(), ResourceType.Buckets)
if (buckets.find(b => b.name === bucketName)) {
dispatch(editActiveQueryWithBuilderSync())
dispatch(setBuilderBucket(bucketName, true))
}
}

0 comments on commit 449d475

Please sign in to comment.