@@ -14,7 +14,11 @@ import {
1414 FromDataExtensionsEditorMessage ,
1515 ToDataExtensionsEditorMessage ,
1616} from "../common/interface-types" ;
17- import { ProgressUpdate } from "../common/vscode/progress" ;
17+ import {
18+ ProgressCallback ,
19+ ProgressUpdate ,
20+ withProgress ,
21+ } from "../common/vscode/progress" ;
1822import { QueryRunner } from "../query-server" ;
1923import {
2024 showAndLogExceptionWithTelemetry ,
@@ -44,6 +48,7 @@ import { getAutoModelUsages } from "./auto-model-usages-query";
4448import { Mode } from "./shared/mode" ;
4549import { loadModeledMethods , saveModeledMethods } from "./modeled-method-fs" ;
4650import { join } from "path" ;
51+ import { pickExtensionPack } from "./extension-pack-picker" ;
4752
4853export class DataExtensionsEditorView extends AbstractWebview <
4954 ToDataExtensionsEditorMessage ,
@@ -139,6 +144,10 @@ export class DataExtensionsEditorView extends AbstractWebview<
139144 msg . modeledMethods ,
140145 ) ;
141146
147+ break ;
148+ case "modelDependency" :
149+ await this . modelDependency ( ) ;
150+
142151 break ;
143152 case "switchMode" :
144153 this . mode = msg . mode ;
@@ -284,29 +293,12 @@ export class DataExtensionsEditorView extends AbstractWebview<
284293 // In application mode, we need the database of a specific library to generate
285294 // the modeled methods. In framework mode, we'll use the current database.
286295 if ( this . mode === Mode . Application ) {
287- const selectedDatabase = this . databaseManager . currentDatabaseItem ;
288-
289- // The external API methods are in the library source code, so we need to ask
290- // the user to import the library database. We need to have the database
291- // imported to the query server, so we need to register it to our workspace.
292- addedDatabase = await promptImportGithubDatabase (
293- this . app . commands ,
294- this . databaseManager ,
295- this . app . workspaceStoragePath ?? this . app . globalStoragePath ,
296- this . app . credentials ,
297- ( update ) => this . showProgress ( update ) ,
298- this . cliServer ,
296+ addedDatabase = await this . promptImportAndResetDatabase ( ( update ) =>
297+ this . showProgress ( update ) ,
299298 ) ;
300299 if ( ! addedDatabase ) {
301- await this . clearProgress ( ) ;
302- void this . app . logger . log ( "No database chosen" ) ;
303-
304300 return ;
305301 }
306-
307- // The library database was set as the current database by importing it,
308- // but we need to set it back to the originally selected database.
309- await this . databaseManager . setCurrentDatabaseItem ( selectedDatabase ) ;
310302 }
311303
312304 await this . showProgress ( {
@@ -429,6 +421,68 @@ export class DataExtensionsEditorView extends AbstractWebview<
429421 await this . clearProgress ( ) ;
430422 }
431423
424+ private async modelDependency ( ) : Promise < void > {
425+ return withProgress ( async ( progress , token ) => {
426+ const addedDatabase = await this . promptImportAndResetDatabase ( progress ) ;
427+ if ( ! addedDatabase || token . isCancellationRequested ) {
428+ return ;
429+ }
430+
431+ const modelFile = await pickExtensionPack (
432+ this . cliServer ,
433+ addedDatabase ,
434+ this . app . logger ,
435+ progress ,
436+ token ,
437+ ) ;
438+ if ( ! modelFile ) {
439+ return ;
440+ }
441+
442+ const view = new DataExtensionsEditorView (
443+ this . ctx ,
444+ this . app ,
445+ this . databaseManager ,
446+ this . cliServer ,
447+ this . queryRunner ,
448+ this . queryStorageDir ,
449+ addedDatabase ,
450+ modelFile ,
451+ Mode . Framework ,
452+ ) ;
453+ await view . openView ( ) ;
454+ } ) ;
455+ }
456+
457+ private async promptImportAndResetDatabase (
458+ progress : ProgressCallback ,
459+ ) : Promise < DatabaseItem | undefined > {
460+ const selectedDatabase = this . databaseManager . currentDatabaseItem ;
461+
462+ // The external API methods are in the library source code, so we need to ask
463+ // the user to import the library database. We need to have the database
464+ // imported to the query server, so we need to register it to our workspace.
465+ const addedDatabase = await promptImportGithubDatabase (
466+ this . app . commands ,
467+ this . databaseManager ,
468+ this . app . workspaceStoragePath ?? this . app . globalStoragePath ,
469+ this . app . credentials ,
470+ progress ,
471+ this . cliServer ,
472+ this . databaseItem . language ,
473+ ) ;
474+ if ( ! addedDatabase ) {
475+ void this . app . logger . log ( "No database chosen" ) ;
476+ return undefined ;
477+ }
478+
479+ // The library database was set as the current database by importing it,
480+ // but we need to set it back to the originally selected database.
481+ await this . databaseManager . setCurrentDatabaseItem ( selectedDatabase ) ;
482+
483+ return addedDatabase ;
484+ }
485+
432486 /*
433487 * Progress in this class is a bit weird. Most of the progress is based on running the query.
434488 * Query progress is always between 0 and 1000. However, we still have some steps that need
0 commit comments