Skip to content

Commit 72512da

Browse files
authored
Data extensions editor: Allow users to pick an existing database from their workspace (#2643)
1 parent c2ed98e commit 72512da

File tree

1 file changed

+53
-13
lines changed

1 file changed

+53
-13
lines changed

extensions/ql-vscode/src/data-extensions-editor/data-extensions-editor-view.ts

Lines changed: 53 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,9 @@ export class DataExtensionsEditorView extends AbstractWebview<
312312
// In application mode, we need the database of a specific library to generate
313313
// the modeled methods. In framework mode, we'll use the current database.
314314
if (this.mode === Mode.Application) {
315-
addedDatabase = await this.promptImportDatabase(progress);
315+
addedDatabase = await this.promptChooseNewOrExistingDatabase(
316+
progress,
317+
);
316318
if (!addedDatabase) {
317319
return;
318320
}
@@ -354,17 +356,6 @@ export class DataExtensionsEditorView extends AbstractWebview<
354356
)`Failed to generate flow model: ${getErrorMessage(e)}`,
355357
);
356358
}
357-
358-
if (addedDatabase) {
359-
// After the flow model has been generated, we can remove the temporary database
360-
// which we used for generating the flow model.
361-
progress({
362-
step: 3900,
363-
maxStep: 4000,
364-
message: "Removing temporary database",
365-
});
366-
await this.databaseManager.removeDatabaseItem(addedDatabase);
367-
}
368359
},
369360
{ cancellable: false },
370361
);
@@ -493,7 +484,9 @@ export class DataExtensionsEditorView extends AbstractWebview<
493484

494485
private async modelDependency(): Promise<void> {
495486
return withProgress(async (progress, token) => {
496-
const addedDatabase = await this.promptImportDatabase(progress);
487+
const addedDatabase = await this.promptChooseNewOrExistingDatabase(
488+
progress,
489+
);
497490
if (!addedDatabase || token.isCancellationRequested) {
498491
return;
499492
}
@@ -524,6 +517,53 @@ export class DataExtensionsEditorView extends AbstractWebview<
524517
});
525518
}
526519

520+
private async promptChooseNewOrExistingDatabase(
521+
progress: ProgressCallback,
522+
): Promise<DatabaseItem | undefined> {
523+
const language = this.databaseItem.language;
524+
const databases = this.databaseManager.databaseItems.filter(
525+
(db) => db.language === language,
526+
);
527+
if (databases.length === 0) {
528+
return await this.promptImportDatabase(progress);
529+
} else {
530+
const local = {
531+
label: "$(database) Use existing database",
532+
detail: "Use database from the workspace",
533+
};
534+
const github = {
535+
label: "$(repo) Import database",
536+
detail: "Choose database from GitHub",
537+
};
538+
const newOrExistingDatabase = await window.showQuickPick([local, github]);
539+
540+
if (!newOrExistingDatabase) {
541+
void this.app.logger.log("No database chosen");
542+
return;
543+
}
544+
545+
if (newOrExistingDatabase === local) {
546+
const pickedDatabase = await window.showQuickPick(
547+
databases.map((database) => ({
548+
label: database.name,
549+
description: database.language,
550+
database,
551+
})),
552+
{
553+
placeHolder: "Pick a database",
554+
},
555+
);
556+
if (!pickedDatabase) {
557+
void this.app.logger.log("No database chosen");
558+
return;
559+
}
560+
return pickedDatabase.database;
561+
} else {
562+
return await this.promptImportDatabase(progress);
563+
}
564+
}
565+
}
566+
527567
private async promptImportDatabase(
528568
progress: ProgressCallback,
529569
): Promise<DatabaseItem | undefined> {

0 commit comments

Comments
 (0)