Skip to content

Commit

Permalink
Merge branch 'main' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
joacoc committed Oct 27, 2023
2 parents 36de1ea + 338a447 commit a73fa43
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
15 changes: 8 additions & 7 deletions src/context/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export class Context extends EventEmitter {

// If there is no profile loaded skip, do not load a context.
if (!profile) {
this.loaded = true;
return;
}

Expand Down Expand Up @@ -242,20 +243,20 @@ export class Context extends EventEmitter {
return this.config.getProfileName();
}

addAndSaveProfile(name: string, appPassword: AppPassword, region: string) {
this.config.addAndSaveProfile(name, appPassword, region);
this.loadContext();
async addAndSaveProfile(name: string, appPassword: AppPassword, region: string) {
await this.config.addAndSaveProfile(name, appPassword, region);
await this.loadContext();
}

removeAndSaveProfile(name: string) {
async removeAndSaveProfile(name: string) {
this.config.removeAndSaveProfile(name);
this.loadContext();
await this.loadContext();
}

setProfile(name: string) {
async setProfile(name: string) {
this.config.setProfile(name);
this.environment = undefined;
this.loadContext();
await this.loadContext();
}

handleErr(err: Error) {
Expand Down
7 changes: 7 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ export function activate(vsContext: vscode.ExtensionContext) {
// Register the `Run SQL` command.
let runDisposable = vscode.commands.registerCommand('materialize.run', async () => {
console.log("[RunSQLCommand]", "Firing detected.");

// Check for available profile before proceeding.
if (!context.getProfileName()) {
vscode.window.showErrorMessage('No available profile to run the query.');
return;
}

const activeEditor = vscode.window.activeTextEditor;
if (!activeEditor) {
vscode.window.showErrorMessage('No active editor.');
Expand Down
15 changes: 10 additions & 5 deletions src/providers/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export default class AuthProvider implements vscode.WebviewViewProvider {
* @param name name of the profile.
* @param webviewView webview of the provider.
*/
checkLoginServerResponse(
async checkLoginServerResponse(
appPasswordResponse: AppPasswordResponse | undefined,
name: string,
webviewView: vscode.WebviewView
Expand All @@ -184,7 +184,7 @@ export default class AuthProvider implements vscode.WebviewViewProvider {
// Set the state loading to true. After the new context is loaded
// loading will turn false.
this.state.isLoading = true;
this.context.addAndSaveProfile(name, appPassword, region.toString());
await this.context.addAndSaveProfile(name, appPassword, region.toString());
} else {
// Cancel login process.
webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);
Expand All @@ -211,10 +211,14 @@ export default class AuthProvider implements vscode.WebviewViewProvider {

webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);
loginServer(name).then((appPasswordResponse) => {
this.checkLoginServerResponse(appPasswordResponse, name, webviewView);
this.checkLoginServerResponse(appPasswordResponse, name, webviewView).then(() => {
webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);
});
}).catch((err) => {
console.error("Error setting up the server: ", err);
vscode.window.showErrorMessage('Internal error while waiting for the credentials.');
webviewView.webview.html = this._getHtmlForWebview(webviewView.webview);

});
break;
}
Expand Down Expand Up @@ -261,7 +265,7 @@ export default class AuthProvider implements vscode.WebviewViewProvider {
const name = this.context.getProfileName();

if (name) {
this.context.removeAndSaveProfile(name);
await this.context.removeAndSaveProfile(name);
} else {
console.error("[Auth]", "Profile name is not available.");
}
Expand Down Expand Up @@ -332,9 +336,10 @@ export default class AuthProvider implements vscode.WebviewViewProvider {
// Use a nonce to only allow a specific script to be run.
const nonce = getNonce();

console.log("Is loading: ", this.state.isLoading);
let content = (
`
<vscode-text-field id="profileNameInput">Profile Name</vscode-text-field>
<vscode-text-field id="profileNameInput" ${this.state.isLoading ? "disabled": ""}>Profile Name</vscode-text-field>
<p id="invalidProfileNameErrorMessage">Profile name must contain only ASCII letters, ASCII digits, underscores, and dashes.</p>
<div class="setup-container-actions">
<vscode-button appearence="primary" id="continueProfileButton" class="action_button" disabled=true>Continue</vscode-button>
Expand Down

0 comments on commit a73fa43

Please sign in to comment.