Skip to content

Conversation

@Eashana0104
Copy link
Contributor

Closes #2232

Changes Made -

  • Extracted inline back-navigation JS into an external file for CSP compliance.
  • Added a new back-navigation handler with proper history and fallback behavior.
  • Updated all templates that previously relied on inline JavaScript for the Back to previous page link to use the new external script.

Clicking on Back to previous page
Screenshot 2025-11-19 at 11 50 18 AM

No more CSP compliance errors on clicking Back to previous page
Screenshot 2025-11-19 at 2 09 41 PM

Leads back to the previous page in history.
Screenshot 2025-11-19 at 2 11 25 PM

@Eashana0104 Eashana0104 changed the title Dev/issue 2232 fix csp violation breaking “back to previous page” link Fix csp violation breaking “back to previous page” link Nov 19, 2025
@sarah-mason sarah-mason added the Community Pull requests that have been contributed from community members outside Artefactual label Nov 20, 2025
@sarah-mason
Copy link
Contributor

Hi @Eashana0104! Thank you so much for your contribution and congratulations on your first PR to AtoM! I'm know you are getting your development environment set up still, but the Prettier test failed. Everything else passed!

Copy link
Contributor

@melaniekung melaniekung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @Eashana0104 , thanks for the contribution! Just added some small feedback, but otherwise looks great!

<a href="javascript:history.go(-1)">
<?php echo __('Back to previous page.'); ?>
</a><br>
<a href="#" class="js-back-link" data-fallback-url="<?php echo url_for('@homepage'); ?>"><?php echo __('Back to previous page'); ?></a><br>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use a data-action like data-action="back" instead of a class to call the js function for better readability. (Same for all the other php classes)

Copy link
Contributor Author

@Eashana0104 Eashana0104 Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does increase the readability. I have resolved this in my commits and formatted the closing tags properly to increase readability further!

});

function historyNavigation() {
document.querySelectorAll('.js-back-link').forEach(function (el) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a data-action will require updating the querySelectorAll here, but should work with the rest of the function as is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense in accordance to the change on selector. Resolved by 52deaf9

import "/js/deletePhysicalStorage";
import "/js/settingsFindingAid";
import "/js/refreshJobs";
import "/js/historyNavigation";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Daniel has mentioned to us that you are having troubles setting up prettier checks so I thought it may be useful to add this - I believe the Prettier test may be failing due to the missing empty line here.

Copy link
Contributor Author

@Eashana0104 Eashana0104 Nov 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Prettier check was failing due to some formatting requirement failing in historyNavigation.js. i have fixed that using the command prettier --write js/historyNavigation.js. Now all the .js files are formatted according to Prettier rules. Resolved by 5f7db10

Copy link
Contributor

@melaniekung melaniekung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates @Eashana0104 , this looks good to me! Congrats on completing your first PR to AtoM!

Copy link
Contributor

@anvit anvit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a couple small comments

"use strict";

$(() => {
historyNavigation();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would suggest putting the body of the entire function here instead of a single named function call

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved by b84114c

Comment on lines 14 to 15
window.history.back();
} else {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be cleaner to just return; after the window.history.back(); and skip the else entirely.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved by 0476724

@Eashana0104 Eashana0104 requested a review from anvit December 1, 2025 18:20
Copy link
Contributor

@anvit anvit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Eashana0104 ! This looks good!

@anvit anvit merged commit eb3187a into artefactual:qa/2.x Dec 2, 2025
6 checks passed
@anvit anvit added this to the 2.10.1 milestone Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Community Pull requests that have been contributed from community members outside Artefactual

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Problem: CSP Violation: Previous Page Link Not Functioning

4 participants