fix(job-status-modal): after user clicked the redirect, closing the dialog no longer navigates back (from the navigated redirect)

This commit is contained in:
as-op
2024-09-04 12:52:04 +02:00
parent 3d739dbbe1
commit 8fe4a22214
3 changed files with 19 additions and 2 deletions
@@ -10,6 +10,7 @@ export default class JobStatusPollingController extends Controller<HTMLElement>
declare readonly frameTarget:FrameElement;
interval:ReturnType<typeof setInterval>;
userInteraction:boolean = false;
connect() {
this.interval = setInterval(() => this.frameTarget.reload(), 2000);
@@ -17,7 +18,7 @@ export default class JobStatusPollingController extends Controller<HTMLElement>
disconnect() {
this.stopPolling();
if (this.backOnCloseValue) {
if (this.backOnCloseValue && !this.userInteraction) {
window.history.back();
}
}
@@ -39,7 +40,14 @@ export default class JobStatusPollingController extends Controller<HTMLElement>
setTimeout(() => element.click(), 50);
}
redirectClick(_:Event) {
this.userInteraction = true;
}
redirectTargetConnected(element:HTMLLinkElement) {
setTimeout(() => { window.location.href = element.href; }, 2000);
setTimeout(() => {
this.userInteraction = true;
window.location.href = element.href;
}, 2000);
}
}
@@ -19,6 +19,7 @@
flex.with_row { render(Primer::Beta::Link.new(
href: redirect_url,
data: {
action: 'job-status-polling#redirectClick',
"job-status-polling-target": job_errors.present? ? nil : "redirect"
}
)) { I18n.t('job_status_dialog.redirect_link') } }
@@ -88,5 +88,13 @@ RSpec.describe "Job status", :js do
expect(page).to have_content "Some error"
expect(page).to have_css("a[href='#{home_url}']", text: "Please click here to continue")
end
it "does not navigate back after user clicked the redirect" do
visit "/projects"
visit "/job_statuses/#{status.job_id}"
click_on I18n.t('job_status_dialog.redirect_link')
expect(page).to have_current_path(home_path, wait: 10)
end
end
end