11import React , { FC , useEffect , useRef } from 'react'
2- import { useDispatch , useSelector } from 'react-redux'
2+ import { useSelector } from 'react-redux'
33import { nanoid } from 'nanoid'
44import { parse , format_from_js_file } from '@influxdata/flux-lsp-browser'
55
66import { getOrg } from 'src/organizations/selectors'
7- import { getBuckets } from 'src/buckets/actions/thunks'
8- import { getSortedBuckets } from 'src/buckets/selectors'
9- import { getStatus } from 'src/resources/selectors'
107import { fromFlux , fastFromFlux } from '@influxdata/giraffe'
118import {
129 FluxResult ,
@@ -25,13 +22,7 @@ import {
2522import { isFlagEnabled } from 'src/shared/utils/featureFlag'
2623
2724// Types
28- import {
29- AppState ,
30- ResourceType ,
31- RemoteDataState ,
32- CancellationError ,
33- File ,
34- } from 'src/types'
25+ import { CancellationError , File } from 'src/types'
3526import { RunQueryResult } from 'src/shared/apis/query'
3627
3728interface CancelMap {
@@ -409,21 +400,9 @@ export const parseQuery = (() => {
409400} ) ( )
410401
411402export const QueryProvider : FC = ( { children} ) => {
412- const buckets = useSelector ( ( state : AppState ) => getSortedBuckets ( state ) )
413- const bucketsLoadingState = useSelector ( ( state : AppState ) =>
414- getStatus ( state , ResourceType . Buckets )
415- )
416403 const pending = useRef ( { } as CancelMap )
417404 const org = useSelector ( getOrg )
418405
419- const dispatch = useDispatch ( )
420-
421- useEffect ( ( ) => {
422- if ( bucketsLoadingState === RemoteDataState . NotStarted ) {
423- dispatch ( getBuckets ( ) )
424- }
425- } , [ bucketsLoadingState , dispatch ] )
426-
427406 // this one cancels all pending queries when you
428407 // navigate away from the query provider
429408 useEffect ( ( ) => {
@@ -432,28 +411,10 @@ export const QueryProvider: FC = ({children}) => {
432411 }
433412 } , [ ] )
434413
435- const _getOrg = ast => {
436- const queryBuckets = find (
437- ast ,
438- node =>
439- node ?. type === 'CallExpression' &&
440- node ?. callee ?. type === 'Identifier' &&
441- node ?. callee ?. name === 'from' &&
442- node ?. arguments [ 0 ] ?. properties [ 0 ] ?. key ?. name === 'bucket'
443- ) . map ( node => node ?. arguments [ 0 ] ?. properties [ 0 ] ?. value . value )
444-
445- return (
446- buckets . find ( buck => queryBuckets . includes ( buck . name ) ) ?. orgID || org . id
447- )
448- }
449-
450414 const basic = ( text : string , override ?: QueryScope ) => {
451415 const query = simplify ( text , override ?. vars || { } )
452416
453- // Here we grab the org from the contents of the query, in case it references a sampledata bucket
454- const orgID =
455- override ?. org ||
456- _getOrg ( isFlagEnabled ( 'fastFlows' ) ? parseQuery ( query ) : parse ( query ) )
417+ const orgID = override ?. org || org . id
457418
458419 const url = `${ override ?. region ||
459420 window . location . origin } /api/v2/query?${ new URLSearchParams ( { orgID} ) } `
@@ -594,10 +555,6 @@ export const QueryProvider: FC = ({children}) => {
594555 return promise
595556 }
596557
597- if ( bucketsLoadingState !== RemoteDataState . Done ) {
598- return null
599- }
600-
601558 return (
602559 < QueryContext . Provider
603560 value = { {
0 commit comments