@@ -23,7 +23,7 @@ import { MetabaseTableOrModel } from './metabaseAPITypes';
2323
2424const { modifySqlForMxModels} = catalogAsModels
2525
26- interface ExtractedDataBase {
26+ export interface ExtractedDataBase {
2727 name : string ;
2828 description ?: string ;
2929 id : number ;
@@ -106,7 +106,7 @@ export { type MetabasePageType } from '../defaultState'
106106
107107export type MetabaseAppState = MetabaseAppStateSQLEditor | MetabaseAppStateDashboard | MetabaseSemanticQueryAppState | MetabaseAppStateMBQLEditor ;
108108
109- async function getRelevantEntitiesWithFields ( sqlQuery : string ) : Promise < FormattedTable [ ] > {
109+ async function getRelevantEntitiesWithFields ( sqlQuery : string ) : Promise < MetabaseTableOrModel [ ] > {
110110 const appSettings = RPCs . getAppSettings ( ) ;
111111
112112 // Early return if conditions not met
@@ -146,23 +146,22 @@ async function getRelevantEntitiesWithFields(sqlQuery: string): Promise<Formatte
146146 const relevantModelsWithFields = await getModelsWithFields ( relevantModels ) ;
147147
148148 // Transform and combine tables and models with type annotations
149- const relevantTablesWithFieldsAndType = relevantTablesWithFields . map ( table => ( {
150- ...table ,
149+ const relevantTablesWithFieldsAndType : MetabaseTableOrModel [ ] = relevantTablesWithFields . map ( table => ( {
151150 type : 'table' ,
151+ id : table . id ,
152+ name : table . name ,
153+ schema : table . schema ,
154+ description : table . description ,
152155 } ) ) ;
153156
154- const relevantModelsWithFieldsAndType = relevantModelsWithFields . map ( model => ( {
155- ...model ,
157+ const relevantModelsWithFieldsAndType : MetabaseTableOrModel [ ] = relevantModelsWithFields . map ( model => ( {
156158 type : 'model' ,
157- name : model . modelName || '' ,
158159 id : model . modelId || 0 ,
159- schema : '' ,
160- table : undefined ,
161- modelId : undefined ,
162- modelName : undefined ,
160+ name : model . name ,
161+ description : model . description ,
163162 } ) ) ;
164163
165- return [ ...relevantTablesWithFieldsAndType , ...relevantModelsWithFieldsAndType ] as FormattedTable [ ] ;
164+ return [ ...relevantTablesWithFieldsAndType , ...relevantModelsWithFieldsAndType ] ;
166165}
167166
168167export async function convertDOMtoStateSQLQueryV2 ( ) : Promise < MetabaseAppStateSQLEditorV2 > {
@@ -178,6 +177,8 @@ export async function convertDOMtoStateSQLQueryV2() : Promise<MetabaseAppStateSQ
178177 const limitedEntities = await getRelevantEntitiesWithFields (
179178 get ( currentCard , 'dataset_query.native.query' , '' ) || ''
180179 ) ;
180+ const dbId = await getSelectedDbId ( ) ;
181+ const selectedDatabaseInfo = dbId ? await getDatabaseInfo ( dbId ) : undefined ;
181182 return {
182183 type : MetabaseAppStateType . SQLEditor ,
183184 version : '2' ,
@@ -188,6 +189,7 @@ export async function convertDOMtoStateSQLQueryV2() : Promise<MetabaseAppStateSQ
188189 currentCard,
189190 outputMarkdown,
190191 parameterValues,
192+ selectedDatabaseInfo
191193 }
192194}
193195
0 commit comments