File tree Expand file tree Collapse file tree 3 files changed +31
-8
lines changed
web/src/components/common Expand file tree Collapse file tree 3 files changed +31
-8
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,9 @@ export abstract class AppState<T extends InternalState, K> {
3535 public async getQuerySelectorMap ( ) {
3636 return this . useStore ( ) . getState ( ) . querySelectorMap ;
3737 }
38+
39+ public async triggerStateUpdate ( ) {
40+ }
3841}
3942
4043export abstract class DefaultAppState < T > extends AppState < InternalState , T > {
Original file line number Diff line number Diff line change @@ -137,6 +137,19 @@ function minifyDbs(allDBs: any) {
137137 return Object . values ( allDBs || { } ) . map ( ( db : any ) => ( { id : db . id , name : db . name } ) )
138138}
139139
140+ async function fetchAllDBsIfEmpty ( ) {
141+ let minifiedDBs = minifyDbs ( await RPCs . getMetabaseState ( 'entities.databases' ) )
142+ let _tries = 0
143+ while ( isEmpty ( minifiedDBs ) ) {
144+ await new Promise ( resolve => setTimeout ( resolve , 500 ) )
145+ minifiedDBs = minifyDbs ( await RPCs . getMetabaseState ( 'entities.databases' ) )
146+ if ( _tries ++ > 50 ) {
147+ break
148+ }
149+ }
150+ return minifiedDBs
151+ }
152+
140153export class MetabaseState extends DefaultAppState < MetabaseAppState > {
141154 initialInternalState = metabaseInternalState ;
142155 actionController = new MetabaseController ( this ) ;
@@ -150,13 +163,8 @@ export class MetabaseState extends DefaultAppState<MetabaseAppState> {
150163
151164 const getState = this . useStore ( ) . getState
152165 let minifiedDBs = minifyDbs ( allDBs )
153- let _tries = 0
154- while ( isEmpty ( minifiedDBs ) ) {
155- await new Promise ( resolve => setTimeout ( resolve , 500 ) )
156- minifiedDBs = minifyDbs ( await RPCs . getMetabaseState ( 'entities.databases' ) ) ;
157- if ( _tries ++ > 50 ) {
158- break
159- }
166+ if ( isEmpty ( minifiedDBs ) ) {
167+ minifiedDBs = await fetchAllDBsIfEmpty ( )
160168 }
161169
162170 let toolEnabledNew = shouldEnable ( elements , url ) ;
Original file line number Diff line number Diff line change @@ -764,7 +764,19 @@ const TaskUI = forwardRef<HTMLTextAreaElement>((_props, ref) => {
764764 < Text fontSize = { "sm" } color = { "gray.500" } mb = { 3 } > We're unable to auto-select your Database. Pick one to get started</ Text >
765765 < Box display = "flex" justifyContent = "center" >
766766 < Menu placement = "bottom" >
767- < MenuButton as = { Button } rightIcon = { < BiChevronDown /> } size = "xs" variant = "solid" colorScheme = 'minusxGreen' >
767+ < MenuButton
768+ as = { Button }
769+ rightIcon = { < BiChevronDown /> }
770+ size = "xs"
771+ variant = "solid"
772+ colorScheme = 'minusxGreen'
773+ onClick = { ( ) => {
774+ const allDBs = get ( toolContext , 'allDBs' , [ ] )
775+ if ( isEmpty ( allDBs ) ) {
776+ app . triggerStateUpdate ( )
777+ }
778+ } }
779+ >
768780 Choose a Database
769781 </ MenuButton >
770782 < MenuList maxH = "200px" overflowY = "auto" >
You can’t perform that action at this time.
0 commit comments