Bug 37226 - Authority hierarchy tree broken when a child (narrower) term appears under more than one parent (greater) term
Summary: Authority hierarchy tree broken when a child (narrower) term appears under mo...
Status: Pushed to oldstable
Alias: None
Product: Koha
Classification: Unclassified
Component: MARC Authority data support (show other bugs)
Version: Main
Hardware: All All
: P5 - low normal
Assignee: Andreas Roussos
QA Contact: Marcel de Rooy
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-07-01 14:05 UTC by Andreas Roussos
Modified: 2024-09-18 04:00 UTC (History)
5 users (show)

See Also:
Change sponsored?: ---
Patch complexity: Trivial patch
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
24.11.00,24.05.04,23.11.09
Circulation function:


Attachments
short screen recording that shows the bug in action (239.64 KB, video/mp4)
2024-07-01 14:05 UTC, Andreas Roussos
Details
Sample MARC data in ISO2709 format (contains three authority records) (740 bytes, application/marc)
2024-07-01 14:18 UTC, Andreas Roussos
Details
Bug 37226: append a random number to the `id` attribute of each <li> (4.00 KB, patch)
2024-07-01 14:30 UTC, Andreas Roussos
Details | Diff | Splinter Review
Bug 37226: append a random number to the `id` attribute of each <li> (4.15 KB, patch)
2024-07-01 14:33 UTC, Andreas Roussos
Details | Diff | Splinter Review
Bug 37226: append a random number to the `id` attribute of each <li> (4.20 KB, patch)
2024-07-02 01:26 UTC, David Nind
Details | Diff | Splinter Review
Bug 37226: append a random number to the `id` attribute of each <li> (4.29 KB, patch)
2024-07-19 09:50 UTC, Marcel de Rooy
Details | Diff | Splinter Review

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Roussos 2024-07-01 14:05:50 UTC
Created attachment 168314 [details]
short screen recording that shows the bug in action

With AuthDisplayHierarchy enabled and the following MARC21 authority data:

001 1
151 $a Europe
551 $a Athens
    $w h
    $9 3
942 $a GEOGR_NAME

001 2
151 $a Greece
551 $a Athens
    $w h
    $9 3
942 $a GEOGR_NAME

001 3
151 $a Athens
551 $a Europe
    $w g
    $9 1
551 $a Greece
    $w g
    $9 2
942 $a GEOGR_NAME

In the authority details page for 'Athens' (authid=3), clicking on the
expand/collapse arrows next to the top-level terms in the hierarchy tree
('Europe' and 'Greece') will not work properly, i.e. *only one* broader
term will show 'Athens' as its narrower term at any given time.

I attach a small screen recording that shows this in action.
Comment 1 Andreas Roussos 2024-07-01 14:08:45 UTC
This is happening because in the HTML source of the page the individual
<li> elements associated with each node do not have unique `id` values,
which confuses the JavaScript library (jsTree) responsible for rendering
the hierarchy tree.

The simple fix is to append a random number to each `id` attribute.
Comment 2 Andreas Roussos 2024-07-01 14:18:01 UTC
Created attachment 168318 [details]
Sample MARC data in ISO2709 format (contains three authority records)

I upload an .mrc file containing some sample MARC authority data,
this is meant to be used in the test plan.
Comment 3 Andreas Roussos 2024-07-01 14:30:33 UTC Comment hidden (obsolete)
Comment 4 Andreas Roussos 2024-07-01 14:33:59 UTC
Created attachment 168320 [details] [review]
Bug 37226: append a random number to the `id` attribute of each <li>

When you view the authority details page for a term that contains more
than one terms with broader relationship, clicking on the expand/collapse
arrows next to the top-level terms in the hierarchy tree will not work
properly, i.e. *only one* broader term will show the narrower term under
it at any given time.

This is affecting both the OPAC and the Staff interface.

This is happening because in the HTML source of the page the individual
<li> elements associated with each node do not have unique `id` values,
which confuses the JavaScript library (jsTree) responsible for rendering
the hierarchy tree.

This patch fixes that by appending a random number to each `id` attribute.

Test plan:

0) Enable the AuthDisplayHierarchy System Preference (set to 'Show').

1) Copy the provided MARC21 Authority sample data (sample-data.mrc)
   to your KTD Koha container (it must have MARC21 marc flavour):

   docker cp sample-data.mrc koha-koha-1:/kohadevbox/

2) Import the provided authorities (the sample file contains three
   Geographic Name records):

   WARNING! the --delete switch is passed to bulkmarcimport.pl
   WARNING! this will erase any authority data you have in your instance!
   (this is done to retain the broader/narrower authid associations)

   misc/migration_tools/bulkmarcimport.pl --authorities --file=/kohadevbox/sample-data.mrc --verbose -c=MARC21 --delete -m=ISO2709

3) Visit the authority details page for 'Athens' in OPAC/Staff:

   http://localhost:8080/cgi-bin/koha/opac-authoritiesdetail.pl?authid=3
   http://localhost:8081/cgi-bin/koha/authorities/detail.pl?authid=3

   In the authority hierarchy tree, click the arrows next to 'Europe'
   and 'Greece' to expand and show the narrower term: notice how only
   one item works at any given time.

4) Apply the patch.

5) Repeat step 3) (refresh the pages) -- this time you should be able
   to view 'Athens' as a narrower term of both 'Europe' and 'Greece'
   at the same time.
Comment 5 David Nind 2024-07-02 01:26:21 UTC
Created attachment 168335 [details] [review]
Bug 37226: append a random number to the `id` attribute of each <li>

When you view the authority details page for a term that contains more
than one terms with broader relationship, clicking on the expand/collapse
arrows next to the top-level terms in the hierarchy tree will not work
properly, i.e. *only one* broader term will show the narrower term under
it at any given time.

This is affecting both the OPAC and the Staff interface.

This is happening because in the HTML source of the page the individual
<li> elements associated with each node do not have unique `id` values,
which confuses the JavaScript library (jsTree) responsible for rendering
the hierarchy tree.

This patch fixes that by appending a random number to each `id` attribute.

Test plan:

0) Enable the AuthDisplayHierarchy System Preference (set to 'Show').

1) Copy the provided MARC21 Authority sample data (sample-data.mrc)
   to your KTD Koha container (it must have MARC21 marc flavour):

   docker cp sample-data.mrc koha-koha-1:/kohadevbox/

2) Import the provided authorities (the sample file contains three
   Geographic Name records):

   WARNING! the --delete switch is passed to bulkmarcimport.pl
   WARNING! this will erase any authority data you have in your instance!
   (this is done to retain the broader/narrower authid associations)

   misc/migration_tools/bulkmarcimport.pl --authorities --file=/kohadevbox/sample-data.mrc --verbose -c=MARC21 --delete -m=ISO2709

3) Visit the authority details page for 'Athens' in OPAC/Staff:

   http://localhost:8080/cgi-bin/koha/opac-authoritiesdetail.pl?authid=3
   http://localhost:8081/cgi-bin/koha/authorities/detail.pl?authid=3

   In the authority hierarchy tree, click the arrows next to 'Europe'
   and 'Greece' to expand and show the narrower term: notice how only
   one item works at any given time.

4) Apply the patch.

5) Repeat step 3) (refresh the pages) -- this time you should be able
   to view 'Athens' as a narrower term of both 'Europe' and 'Greece'
   at the same time.

Signed-off-by: David Nind <david@davidnind.com>
Comment 6 David Nind 2024-07-02 01:27:59 UTC
I think the commit message title needs amending (to follow the commit message guidelines https://wiki.koha-community.org/wiki/Commit_messages).
Comment 7 Andreas Roussos 2024-07-19 06:08:13 UTC
(In reply to David Nind from comment #6)
> I think the commit message title needs amending (to follow the commit
> message guidelines https://wiki.koha-community.org/wiki/Commit_messages).
Hi David, and thanks for the speedy Sign Off!

The current commit message title is:
"Bug 37226: append a random number to the `id` attribute of each <li>"

I think it meets the guidelines given in the wiki page you refer to?

If not, can you elaborate on what needs changing? Thank you!
Comment 8 Marcel de Rooy 2024-07-19 09:49:04 UTC
(In reply to Andreas Roussos from comment #7)
> (In reply to David Nind from comment #6)
> > I think the commit message title needs amending (to follow the commit
> > message guidelines https://wiki.koha-community.org/wiki/Commit_messages).
> Hi David, and thanks for the speedy Sign Off!
> 
> The current commit message title is:
> "Bug 37226: append a random number to the `id` attribute of each <li>"
> 
> I think it meets the guidelines given in the wiki page you refer to?
> 
> If not, can you elaborate on what needs changing? Thank you!

I cant see the problem either with that title.
Comment 9 Marcel de Rooy 2024-07-19 09:50:07 UTC
Created attachment 169188 [details] [review]
Bug 37226: append a random number to the `id` attribute of each <li>

When you view the authority details page for a term that contains more
than one terms with broader relationship, clicking on the expand/collapse
arrows next to the top-level terms in the hierarchy tree will not work
properly, i.e. *only one* broader term will show the narrower term under
it at any given time.

This is affecting both the OPAC and the Staff interface.

This is happening because in the HTML source of the page the individual
<li> elements associated with each node do not have unique `id` values,
which confuses the JavaScript library (jsTree) responsible for rendering
the hierarchy tree.

This patch fixes that by appending a random number to each `id` attribute.

Test plan:

0) Enable the AuthDisplayHierarchy System Preference (set to 'Show').

1) Copy the provided MARC21 Authority sample data (sample-data.mrc)
   to your KTD Koha container (it must have MARC21 marc flavour):

   docker cp sample-data.mrc koha-koha-1:/kohadevbox/

2) Import the provided authorities (the sample file contains three
   Geographic Name records):

   WARNING! the --delete switch is passed to bulkmarcimport.pl
   WARNING! this will erase any authority data you have in your instance!
   (this is done to retain the broader/narrower authid associations)

   misc/migration_tools/bulkmarcimport.pl --authorities --file=/kohadevbox/sample-data.mrc --verbose -c=MARC21 --delete -m=ISO2709

3) Visit the authority details page for 'Athens' in OPAC/Staff:

   http://localhost:8080/cgi-bin/koha/opac-authoritiesdetail.pl?authid=3
   http://localhost:8081/cgi-bin/koha/authorities/detail.pl?authid=3

   In the authority hierarchy tree, click the arrows next to 'Europe'
   and 'Greece' to expand and show the narrower term: notice how only
   one item works at any given time.

4) Apply the patch.

5) Repeat step 3) (refresh the pages) -- this time you should be able
   to view 'Athens' as a narrower term of both 'Europe' and 'Greece'
   at the same time.

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

Signed-off-by: Marcel de Rooy <m.de.rooy@rijksmuseum.nl>
Comment 10 Martin Renvoize (ashimema) 2024-07-22 09:40:58 UTC
Thanks for all the hard work!

Pushed to main for the next 24.11.00 release as RM Assistant
Comment 11 Lucas Gass (lukeg) 2024-08-28 19:45:22 UTC
Backported to 24.05.x for upcoming 24.05.04
Comment 12 Fridolin Somers 2024-09-10 13:14:15 UTC
Pushed to 23.11.x for 23.11.09
Comment 13 Fridolin Somers 2024-09-10 13:14:50 UTC
Maybe we could create a TT template to generate the random number (without dot)
Comment 14 Wainui Witika-Park 2024-09-18 04:00:22 UTC
Not backporting to 23.05.x unless requested