Bug 29946

Summary: Sort profiles alphabetically when staging MARC records for import
Product: Koha Reporter: Lucas Gass <lucas>
Component: ToolsAssignee: Lucas Gass <lucas>
Status: CLOSED FIXED QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: barbara.johnson, florian.bontemps, kyle, victor
Version: master   
Hardware: All   
OS: All   
Change sponsored?: --- Patch complexity: Trivial patch
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
22.05.00
Attachments: Bug 29946: Sort Marc profiles alphabetically
Bug 29946: Sort Marc profiles alphabetically
Bug 29946: Sort Marc profiles alphabetically
Bug 29946: Sort Marc profiles alphabetically
Bug 29946: Sort Marc profiles alphabetically

Description Lucas Gass 2022-01-25 18:45:19 UTC
If you have a lot of MARC profiles for staging MARC records for import it would be nice if those profiles sorted alphabetically by name, so it would be easier to find the one you are looking for.
Comment 1 Lucas Gass 2022-01-25 18:52:00 UTC
Created attachment 129813 [details] [review]
Bug 29946: Sort Marc profiles alphabetically

To test:
1- Go to Tools > Stage MARC records for import
2- You'll need a MARC file, choose one and hit 'Upload file'
3- Create many Profiles with different names. I used ( ATop, ZTop, JTop, STop, etc. )
4- Notice that the profiles sort in the order in which you create them
5- Apply patch
6- Try steps 1-2 again
7- Now the dropdown should be sorted alphabetically
8- Make a few more profiles and make sure they are being inserted in the right order alphabetically
Comment 2 Biblibre Sandboxes 2022-02-07 19:32:59 UTC
Created attachment 130249 [details] [review]
Bug 29946: Sort Marc profiles alphabetically

To test:
1- Go to Tools > Stage MARC records for import
2- You'll need a MARC file, choose one and hit 'Upload file'
3- Create many Profiles with different names. I used ( ATop, ZTop, JTop, STop, etc. )
4- Notice that the profiles sort in the order in which you create them
5- Apply patch
6- Try steps 1-2 again
7- Now the dropdown should be sorted alphabetically
8- Make a few more profiles and make sure they are being inserted in the right order alphabetically

Signed-off-by: Barbara Johnson  <barbara.johnson@bedfordtx.gov>
Comment 3 Katrin Fischer 2022-02-13 14:33:05 UTC
I am sorry, but while this works for A-z and therefor for English, it doesn't work for other languages like German with Umlauts or French with accents/diacritics. If you enter for example a description starting with Á, it will sort at the end, instead of as A.

I think we need to use a sort that accounts for that and that we already have that in Koha - using cmp instead of >?
Comment 4 Lucas Gass 2022-03-24 21:54:42 UTC
(In reply to Katrin Fischer from comment #3)
> I am sorry, but while this works for A-z and therefor for English, it
> doesn't work for other languages like German with Umlauts or French with
> accents/diacritics. If you enter for example a description starting with Á,
> it will sort at the end, instead of as A.
> 
> I think we need to use a sort that accounts for that and that we already
> have that in Koha - using cmp instead of >?

Since we fetch this profiles from /api/v1/import_batch_profiles I think we need a way to sort these, with accents/diacritics, in JavaScript instead of Perl. 

I think localeCompare might be the answer:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/localeCompare
Comment 5 Lucas Gass 2022-03-24 21:57:14 UTC
Created attachment 132200 [details] [review]
Bug 29946: Sort Marc profiles alphabetically

To test:
1- Go to Tools > Stage MARC records for import
2- You'll need a MARC file, choose one and hit 'Upload file'
3- Create many Profiles with different names. Add some that include accents/diacritics.
4- Notice that the profiles sort in the order in which you create them
5- Apply patch
6- Try steps 1-2 again
7- Now the dropdown should be sorted alphabetically
8- Make a few more profiles and make sure they are being inserted in the right order alphabetically, including the profiles containing accents/diacritics.
Comment 6 Barbara Johnson 2022-03-24 22:50:30 UTC
I was able to create profiles using different accents and diacritics.  And the sorting worked correctly.  

But I did run into problems with the following scenario.  I tried to create several similarly named profiles such as the two sets listed below.  I could only save one profile from each set.  It seems that it isn't able to differentiate between a letter with and without accent marks. 

etest
ètest
étest

abooks
äbooks
ábooks
Comment 7 Lucas Gass 2022-03-25 01:06:00 UTC
(In reply to Barbara Johnson from comment #6)
> I was able to create profiles using different accents and diacritics.  And
> the sorting worked correctly.  
> 
> But I did run into problems with the following scenario.  I tried to create
> several similarly named profiles such as the two sets listed below.  I could
> only save one profile from each set.  It seems that it isn't able to
> differentiate between a letter with and without accent marks. 
> 
> etest
> ètest
> étest
> 
> abooks
> äbooks
> ábooks

I see what you mean. This happens with or without this patch. It also seems unrelated to diacritics as I can add a profile with a name like 'abook' but then I will get the error if I try 'Abook' or 'aBook'. 

In the error logs I see:

[WARN] DBIx::Class::Storage::DBI::_dbh_execute(): DBI Exception: DBD::mysql::st execute failed: Duplicate entry 'abook' for key 'u_import_batch_profiles__name' at /kohadevbox/koha/Koha/Object.pm line 170


Maybe we should file a separate bug for that issue?
Comment 8 ByWater Sandboxes 2022-03-25 12:46:08 UTC
Created attachment 132240 [details] [review]
Bug 29946: Sort Marc profiles alphabetically

To test:
1- Go to Tools > Stage MARC records for import
2- You'll need a MARC file, choose one and hit 'Upload file'
3- Create many Profiles with different names. Add some that include accents/diacritics.
4- Notice that the profiles sort in the order in which you create them
5- Apply patch
6- Try steps 1-2 again
7- Now the dropdown should be sorted alphabetically
8- Make a few more profiles and make sure they are being inserted in the right order alphabetically, including the profiles containing accents/diacritics.

Signed-off-by: Barbara Johnson <barbara.johnson@bedfordtx.gov>
Comment 9 Barbara Johnson 2022-03-25 12:50:23 UTC
Yes, that does sound like a separate issue.  Everything worked as described with this patch so I am signing off on it.
Comment 10 Victor Grousset/tuxayo 2022-04-10 23:51:21 UTC
Created attachment 133139 [details] [review]
Bug 29946: Sort Marc profiles alphabetically

To test:
1- Go to Tools > Stage MARC records for import
2- You'll need a MARC file, choose one and hit 'Upload file'
3- Create many Profiles with different names. Add some that include accents/diacritics.
4- Notice that the profiles sort in the order in which you create them
5- Apply patch
6- Try steps 1-2 again
7- Now the dropdown should be sorted alphabetically
8- Make a few more profiles and make sure they are being inserted in the right order alphabetically, including the profiles containing accents/diacritics.

Signed-off-by: Barbara Johnson <barbara.johnson@bedfordtx.gov>
Signed-off-by: Victor Grousset/tuxayo <victor@tuxayo.net>
Comment 11 Victor Grousset/tuxayo 2022-04-10 23:55:19 UTC
Works, qa script happy, code looks good, passing QA :)
Comment 12 Fridolin Somers 2022-04-13 13:57:09 UTC
Pushed to master for 22.05, thanks to everybody involved 🦄