Skip to content

Commit 651fc9f

Browse files
Merge pull request #1228 from NASA-IMPACT/3228-bugfix-preserve-scroll-position--document-type-selection-behavior-on-individual-urls
changes js code to preserve y scroll position while saving
2 parents 1dd1a63 + bf84557 commit 651fc9f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ For each PR made, an entry should be added to this changelog. It should contain
4646
- Used regex to catch any HTML content comming in as an input to form fields
4747
- Called this class within the serializer for necessary fields
4848

49+
- 3228-bugfix-preserve-scroll-position--document-type-selection-behavior-on-individual-urls
50+
- Description: Upon selecting a document type on any individual URL, the page refreshes and returns to the top. This is not necessarily a bug but an inconvenience, especially when working at the bottom of the page. Fix the JS code.
51+
- Changes:
52+
- Added a constant `scrollPosition` within `postDocumentTypePatterns` to store the y coordinate postion on the page
53+
- Modified the ajax relaod to navigate to this position upon posting/saving the document type changes.
54+
4955
- 3227-bugfix-title-patterns-selecting-multi-url-pattern-does-nothing
5056
- Description: When selecting options from the match pattern type filter, the system does not filter the results as expected. Instead of displaying only the chosen variety of patterns, it continues to show all patterns.
5157
- Changes:

sde_indexing_helper/static/js/delta_url_list.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,7 +1400,8 @@ function handleHideorShowSubmitButton() {
14001400
}
14011401

14021402
function handleDocumentTypeSelect() {
1403-
$("body").on("click", ".document_type_select", function () {
1403+
$("body").on("click", ".document_type_select", function (e) {
1404+
e.preventDefault();
14041405
$match_pattern = $(this)
14051406
.parents(".document_type_dropdown")
14061407
.data("match-pattern");
@@ -1581,6 +1582,8 @@ function postDocumentTypePatterns(
15811582
return;
15821583
}
15831584

1585+
const scrollPosition = window.scrollY;
1586+
15841587
$.ajax({
15851588
url: "/api/document-type-patterns/",
15861589
type: "POST",
@@ -1592,7 +1595,9 @@ function postDocumentTypePatterns(
15921595
csrfmiddlewaretoken: csrftoken,
15931596
},
15941597
success: function (data) {
1595-
$("#delta_urls_table").DataTable().ajax.reload(null, false);
1598+
$("#delta_urls_table").DataTable().ajax.reload(function() {
1599+
window.scrollTo(0, scrollPosition);
1600+
}, false);
15961601
$("#document_type_patterns_table").DataTable().ajax.reload(null, false);
15971602
if (currentTab === "") { //Only add a notification if we are on the first tab
15981603
newDocumentTypePatternsCount = newDocumentTypePatternsCount + 1;

0 commit comments

Comments
 (0)