Merge branch 'stable-3.9' * stable-3.9: GitHubOAuthConfigTest: Reformat the code using google-java-format Build github plugin against the v3.8.0-rc5 Gerrit API PullRequestCreateChange: Remove unused import Fix velocity deprecated configuration keys Set plugin version to 3.4.7 Fire git ref update events for all imported refs PluginVelocityRuntimeProvider: Fix warning flagged by error prone Fix default scopes resolution Change-Id: I3f3f559c70378003766916bbf70e8173c3c89109
diff --git a/github-plugin/src/main/ts/gr-github-oauth-progress.ts b/github-plugin/src/main/ts/gr-github-oauth-progress.ts index 3b53d47..292e294 100644 --- a/github-plugin/src/main/ts/gr-github-oauth-progress.ts +++ b/github-plugin/src/main/ts/gr-github-oauth-progress.ts
@@ -10,9 +10,11 @@ @property() plugin!: PluginApi; - @state() authInfo?: AuthInfo + @state() authInfo?: AuthInfo; - @state() loggedIn?: boolean + @state() loggedIn?: boolean; + + @state() currentNavigationPath?: string; override connectedCallback() { super.connectedCallback(); @@ -21,6 +23,13 @@ restApi.getConfig().then(config => this.authInfo = config?.auth); } restApi.getLoggedIn().then(loggedIn => this.loggedIn = loggedIn); + document.addEventListener( + 'nav-report', + // the `nav-report` event is emitted before `window.location` is updated, in order + // to get the current location, we need to delay `this.updateLocationPath` execution + // by putting it on the end of processing queue + () => setTimeout(() => this.updateLocationPath(), 0)); + this.updateLocationPath(); } static override get styles() { @@ -50,11 +59,15 @@ override render() { if (!this.authInfo || this.loggedIn !== false) { - return + return; + } + const loginWithRedirect = new URL(this.authInfo.login_url ?? "/", window.location.origin); + if (this.currentNavigationPath) { + loginWithRedirect.pathname = loginWithRedirect.pathname + this.currentNavigationPath; } return html` - <a class="loginButton" href=${this.authInfo.login_url} @click=${this.showModal}> + <a class="loginButton" href="${loginWithRedirect}" @click=${this.showModal}> ${this.authInfo.login_text} </a> <dialog id="gitHubOAuthProgress"> @@ -66,6 +79,10 @@ ` } + private updateLocationPath() { + this.currentNavigationPath = window.location.pathname; + } + private showModal() { setTimeout(() => this.gitHubOAuthProgress?.showModal(), 550); }