List databases for publish quickpick (#16368)

* List databases for publish quickpick

* missed word
This commit is contained in:
Charles Gagnon
2021-07-21 08:36:34 -07:00
committed by GitHub
parent d1892b514f
commit efa82650f8
2 changed files with 29 additions and 11 deletions

View File

@@ -69,14 +69,26 @@ export async function launchPublishDatabaseQuickpick(project: Project): Promise<
// so exit the flow. // so exit the flow.
return; return;
} }
quickPick.hide(); // Hide the quickpick immediately so it isn't showing while the API loads
// 2. Select connection // 2. Select connection
const api = await getVscodeMssqlApi(); const vscodeMssqlApi = await getVscodeMssqlApi();
const connectionProfile = await api.promptForConnection(); let dbs: string[] | undefined = undefined;
while (!dbs) {
const connectionProfile = await vscodeMssqlApi.promptForConnection(true);
if (!connectionProfile) { if (!connectionProfile) {
return; return;
} }
const dbs = ['db1', 'db2']; // Get the list of databases now to validate that the connection is valid and re-prompt them if it isn't
try {
dbs = await vscodeMssqlApi.listDatabases(connectionProfile);
} catch (err) {
// no-op, the mssql extension handles showing the error to the user. We'll just go
// back and prompt the user for a connection again
}
}
// 3. Select database
const dbQuickpicks = dbs.map(db => { const dbQuickpicks = dbs.map(db => {
return { return {
label: db, label: db,
@@ -93,10 +105,9 @@ export async function launchPublishDatabaseQuickpick(project: Project): Promise<
} }
dbQuickpicks.push({ label: constants.createNew, dbName: '', isCreateNew: true }); dbQuickpicks.push({ label: constants.createNew, dbName: '', isCreateNew: true });
// 3. Select database
// TODO@chgagnon: Hook up to MSSQL let databaseName: string | undefined = undefined;
let databaseName = ''; while (!databaseName) {
while (databaseName === '') {
const selectedDatabase = await vscode.window.showQuickPick( const selectedDatabase = await vscode.window.showQuickPick(
dbQuickpicks, dbQuickpicks,
{ title: constants.selectDatabase, ignoreFocusOut: true }); { title: constants.selectDatabase, ignoreFocusOut: true });
@@ -117,7 +128,6 @@ export async function launchPublishDatabaseQuickpick(project: Project): Promise<
} }
} }
// 4. Modify sqlcmd vars // 4. Modify sqlcmd vars
// If a publish profile is provided then the values from there will overwrite the ones in the // If a publish profile is provided then the values from there will overwrite the ones in the
// project file (if they exist) // project file (if they exist)

View File

@@ -28,8 +28,16 @@ declare module 'vscode-mssql' {
/** /**
* Prompts the user to select an existing connection or create a new one, and then returns the result * Prompts the user to select an existing connection or create a new one, and then returns the result
* @param ignoreFocusOut Whether the quickpick prompt ignores focus out (default false)
*/ */
promptForConnection(): Promise<IConnectionInfo | undefined> promptForConnection(ignoreFocusOut?: boolean): Promise<IConnectionInfo | undefined>;
/**
* Lists the databases for a given connection. An error is thrown and displayed to the user if an
* error occurs while connecting
* @param connection The connection to list the databases for
*/
listDatabases(connection: IConnectionInfo): Promise<string[]>;
} }
/** /**