Data extensions editor: Allow users to pick an existing database from their workspace (#2643)
This commit is contained in:
@@ -312,7 +312,9 @@ export class DataExtensionsEditorView extends AbstractWebview<
|
||||
// In application mode, we need the database of a specific library to generate
|
||||
// the modeled methods. In framework mode, we'll use the current database.
|
||||
if (this.mode === Mode.Application) {
|
||||
addedDatabase = await this.promptImportDatabase(progress);
|
||||
addedDatabase = await this.promptChooseNewOrExistingDatabase(
|
||||
progress,
|
||||
);
|
||||
if (!addedDatabase) {
|
||||
return;
|
||||
}
|
||||
@@ -354,17 +356,6 @@ export class DataExtensionsEditorView extends AbstractWebview<
|
||||
)`Failed to generate flow model: ${getErrorMessage(e)}`,
|
||||
);
|
||||
}
|
||||
|
||||
if (addedDatabase) {
|
||||
// After the flow model has been generated, we can remove the temporary database
|
||||
// which we used for generating the flow model.
|
||||
progress({
|
||||
step: 3900,
|
||||
maxStep: 4000,
|
||||
message: "Removing temporary database",
|
||||
});
|
||||
await this.databaseManager.removeDatabaseItem(addedDatabase);
|
||||
}
|
||||
},
|
||||
{ cancellable: false },
|
||||
);
|
||||
@@ -493,7 +484,9 @@ export class DataExtensionsEditorView extends AbstractWebview<
|
||||
|
||||
private async modelDependency(): Promise<void> {
|
||||
return withProgress(async (progress, token) => {
|
||||
const addedDatabase = await this.promptImportDatabase(progress);
|
||||
const addedDatabase = await this.promptChooseNewOrExistingDatabase(
|
||||
progress,
|
||||
);
|
||||
if (!addedDatabase || token.isCancellationRequested) {
|
||||
return;
|
||||
}
|
||||
@@ -524,6 +517,53 @@ export class DataExtensionsEditorView extends AbstractWebview<
|
||||
});
|
||||
}
|
||||
|
||||
private async promptChooseNewOrExistingDatabase(
|
||||
progress: ProgressCallback,
|
||||
): Promise<DatabaseItem | undefined> {
|
||||
const language = this.databaseItem.language;
|
||||
const databases = this.databaseManager.databaseItems.filter(
|
||||
(db) => db.language === language,
|
||||
);
|
||||
if (databases.length === 0) {
|
||||
return await this.promptImportDatabase(progress);
|
||||
} else {
|
||||
const local = {
|
||||
label: "$(database) Use existing database",
|
||||
detail: "Use database from the workspace",
|
||||
};
|
||||
const github = {
|
||||
label: "$(repo) Import database",
|
||||
detail: "Choose database from GitHub",
|
||||
};
|
||||
const newOrExistingDatabase = await window.showQuickPick([local, github]);
|
||||
|
||||
if (!newOrExistingDatabase) {
|
||||
void this.app.logger.log("No database chosen");
|
||||
return;
|
||||
}
|
||||
|
||||
if (newOrExistingDatabase === local) {
|
||||
const pickedDatabase = await window.showQuickPick(
|
||||
databases.map((database) => ({
|
||||
label: database.name,
|
||||
description: database.language,
|
||||
database,
|
||||
})),
|
||||
{
|
||||
placeHolder: "Pick a database",
|
||||
},
|
||||
);
|
||||
if (!pickedDatabase) {
|
||||
void this.app.logger.log("No database chosen");
|
||||
return;
|
||||
}
|
||||
return pickedDatabase.database;
|
||||
} else {
|
||||
return await this.promptImportDatabase(progress);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async promptImportDatabase(
|
||||
progress: ProgressCallback,
|
||||
): Promise<DatabaseItem | undefined> {
|
||||
|
||||
Reference in New Issue
Block a user