Bug 27725 - Use JavaScript to set history state during patron search
Summary: Use JavaScript to set history state during patron search
Status: CLOSED FIXED
Alias: None
Product: Koha
Classification: Unclassified
Component: Patrons (show other bugs)
Version: Main
Hardware: All All
: P5 - low enhancement
Assignee: Owen Leonard
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks: 28867
  Show dependency treegraph
 
Reported: 2021-02-18 16:29 UTC by Owen Leonard
Modified: 2022-06-06 20:25 UTC (History)
6 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Small patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
This patch modifies the process of searching patrons by the first letter of their surname so that the search is added to the browser's history. This allows the user to use the back button to return to the search after clicking one of the results.
Version(s) released in:
21.11.00
Circulation function:


Attachments
Bug 27725: Use JavaScript to set history state during patron search (3.85 KB, patch)
2021-02-18 17:48 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 27725: Use JavaScript to set history state during patron search (4.58 KB, patch)
2021-02-21 15:34 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 27725: Use JavaScript to set history state during patron search (5.86 KB, patch)
2021-08-17 18:41 UTC, Owen Leonard
Details | Diff | Splinter Review
Bug 27725: Use JavaScript to set history state during patron search (5.91 KB, patch)
2021-08-17 20:15 UTC, David Nind
Details | Diff | Splinter Review
Bug 27725: Use JavaScript to set history state during patron search (5.97 KB, patch)
2021-10-03 14:35 UTC, Katrin Fischer
Details | Diff | Splinter Review
Bug 27725: (follow-up) Remove code for clearing search results (1.28 KB, patch)
2021-10-06 14:32 UTC, Owen Leonard
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Owen Leonard 2021-02-18 16:29:11 UTC
The patron search page can be annoying because it never remembers where you left off. If I click a letter to browse by last name, follow a link, and then back up, the page doesn't remember that I was in the middle of a search.

There are a lot of aspects which can be improved, but I have a patch which will address the specific case of the first letter search ("Browse by last name").
Comment 1 Owen Leonard 2021-02-18 17:48:56 UTC Comment hidden (obsolete)
Comment 2 David Nind 2021-02-20 02:13:10 UTC
I like this!

The only place it doesn't work is when a letter only has one patron. For example in koha-testing-docker with the letter O.

In that case the first time you click on the letter it doesn't give a list of results, it goes straight to the patron.

When you press the back button it quickly goes back to the list and then the patron page is loaded again.

Not sure whether this can be fixed, or the likelihood of a normal library only having one patron for a letter.

I think it would be better to list patrons even if there is only one result, rather than the back button not working as expected - not sure what others think though!
Comment 3 Owen Leonard 2021-02-21 15:34:17 UTC
Created attachment 117123 [details] [review]
Bug 27725: Use JavaScript to set history state during patron search

This patch modifies the patron search page so that clicks on the "Browse
by last name" letters add an entry to the browser history, allowing the
user to click back and forth from results while preserving their search.

To test, apply the patch and go to Patrons in the staff interface.

- Click one of the "Browse by last name" letters.
- The table of search results should load the correct data.
- In the browser's location bar you should see a query string added to
  the URL, e.g. /cgi-bin/koha/members/members-home.pl?firstletter=Q
- Click another letter.
- Click the back button. You should be returned to the search results
  for your first letter choice.
- Clicking the forward button should work correctly as well.
- Other patron searches (header search, sidebar search) should continue
  to work as expected.

EDIT: Clear single-letter querystring history item if only one result
was returned.
Comment 4 David Nind 2021-02-21 20:02:59 UTC
This now works if there is only one result. Thanks for updating to address that behaviour!

However, pressing the back button after multiple results for a letter now results in:
- the URL changing to members-home.pl
- the page remaining with "Patrons found for: begins with 'D'" 
- the current list of results remaining 
(D used in this example)
Comment 5 Owen Leonard 2021-02-22 12:49:52 UTC
(In reply to David Nind from comment #4)

> - the page remaining with "Patrons found for: begins with 'D'" 

This is a bug in master.
Comment 6 David Nind 2021-08-03 20:46:54 UTC
Hi Owen.

I've finally had another go at this one.

For some reason the forward button no longer works (after using the back button).

I tested this in Firefox and Google Chrome (latest versions on Ubuntu 18.04).

David
Comment 7 Lucas Gass (lukeg) 2021-08-10 22:00:06 UTC
I also cannot get the forward button to work after using the back button.

Also, if I click "A", then "B" then "C", then "D" it takes me to each of those pages correctly. But if I start pressing the back button I can go back to "C" but no further. If I try to go back any further I see the 'Processing...' box for a split second but noting happens. 

I am testing in Chrome and FF on MacOS.
Comment 8 Owen Leonard 2021-08-17 18:41:11 UTC
Created attachment 123881 [details] [review]
Bug 27725: Use JavaScript to set history state during patron search

This patch modifies the patron search page so that clicks on the "Browse
by last name" letters add an entry to the browser history, allowing the
user to click back and forth from results while preserving their search.

To test, apply the patch and go to Patrons in the staff interface.

- Click one of the "Browse by last name" letters.
- The table of search results should load the correct data.
- In the browser's location bar you should see a query string added to
  the URL, e.g. /cgi-bin/koha/members/members-home.pl?firstletter=Q
- Click another letter.
- Click the back button. You should be returned to the search results
  for your first letter choice.
- Clicking the forward button should work correctly as well.
- Other patron searches (header search, sidebar search) should continue
  to work as expected.

EDIT: Clear single-letter querystring history item if only one result
was returned.

EDIT 2: Fixed handling of history state changes so that forward and back
buttons work correctly.
Comment 9 David Nind 2021-08-17 20:15:07 UTC
Created attachment 123913 [details] [review]
Bug 27725: Use JavaScript to set history state during patron search

This patch modifies the patron search page so that clicks on the "Browse
by last name" letters add an entry to the browser history, allowing the
user to click back and forth from results while preserving their search.

To test, apply the patch and go to Patrons in the staff interface.

- Click one of the "Browse by last name" letters.
- The table of search results should load the correct data.
- In the browser's location bar you should see a query string added to
  the URL, e.g. /cgi-bin/koha/members/members-home.pl?firstletter=Q
- Click another letter.
- Click the back button. You should be returned to the search results
  for your first letter choice.
- Clicking the forward button should work correctly as well.
- Other patron searches (header search, sidebar search) should continue
  to work as expected.

EDIT: Clear single-letter querystring history item if only one result
was returned.

EDIT 2: Fixed handling of history state changes so that forward and back
buttons work correctly.

Signed-off-by: David Nind <david@davidnind.com>
Comment 10 David Nind 2021-08-17 20:19:38 UTC
Testing notes:
- Tested using Firefox 91 and Google Chrome 91.0.4472.114 on Ubuntu 18.04 (64 bit)
- Back and forward buttons work and display previous results
- everything else seems to work as expected
Comment 11 Katrin Fischer 2021-10-03 14:35:37 UTC
Created attachment 125683 [details] [review]
Bug 27725: Use JavaScript to set history state during patron search

This patch modifies the patron search page so that clicks on the "Browse
by last name" letters add an entry to the browser history, allowing the
user to click back and forth from results while preserving their search.

To test, apply the patch and go to Patrons in the staff interface.

- Click one of the "Browse by last name" letters.
- The table of search results should load the correct data.
- In the browser's location bar you should see a query string added to
  the URL, e.g. /cgi-bin/koha/members/members-home.pl?firstletter=Q
- Click another letter.
- Click the back button. You should be returned to the search results
  for your first letter choice.
- Clicking the forward button should work correctly as well.
- Other patron searches (header search, sidebar search) should continue
  to work as expected.

EDIT: Clear single-letter querystring history item if only one result
was returned.

EDIT 2: Fixed handling of history state changes so that forward and back
buttons work correctly.

Signed-off-by: David Nind <david@davidnind.com>

Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de>
Comment 12 Katrin Fischer 2021-10-03 14:36:07 UTC
Nice improvement!
Comment 13 Jonathan Druart 2021-10-04 13:08:46 UTC
Regression found: if you are using the patron search in the header, the search is not triggered.
Comment 14 Owen Leonard 2021-10-06 14:32:22 UTC
Created attachment 125821 [details] [review]
Bug 27725: (follow-up) Remove code for clearing search results

This patch removes code which cleared search results if there was no
first-letter search. It was unnecessary for the letter search
functionality and made all other searches fail.
Comment 15 Jonathan Druart 2021-10-07 09:15:47 UTC
Patches will be squashed when pushed.
Comment 16 Jonathan Druart 2021-10-07 09:20:30 UTC
Pushed to master for 21.11, thanks to everybody involved!