Bug 37930

Summary: Change how we handle authorised values in Vue
Product: Koha Reporter: Matt Blenkinsop <matt.blenkinsop>
Component: ERMAssignee: Matt Blenkinsop <matt.blenkinsop>
Status: Failed QA --- QA Contact: Testopia <testopia>
Severity: enhancement    
Priority: P5 - low CC: esther.melander, jonathan.druart, jonathan.field, martin.renvoize, matt.blenkinsop, pedro.amorim, tomascohen
Version: Main   
Hardware: All   
OS: All   
See Also: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=38201
Change sponsored?: --- Patch complexity: ---
Documentation contact: Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:
Attachments: Bug 37930: Add a method to initialise the AV store
Bug 37930: Update the ERM and Preservation apps
Bug 37930: Update cypress tests
Bug 37930: [DO NOT PUSH] Alternate concept
Bug 37930: Change how we load authorised values in Vue
Bug 37930: Restore AV store to hold methods
Bug 37930: Modify AgreementsList and FormAdd to support new AV concept
Bug 37930: Change how we load authorised values in Vue
Bug 37930: Modify AgreementsList and FormAdd to support new AV concept
Bug 37930: Modify AgreementsList and FormAdd to support new AV concept
Bug 37930: Modify AgreementsList and FormAdd to support new AV concept
Bug 37930: Modify AgreementsList and FormAdd to support new AV concept

Description Matt Blenkinsop 2024-09-16 11:16:12 UTC
A concept for abstracting the import of authorised values to make it much easier to set them up in new vue apps throughout Koha
Comment 1 Matt Blenkinsop 2024-09-16 15:31:39 UTC
Created attachment 171556 [details] [review]
Bug 37930: Add a method to initialise the AV store

This patch adds a method to initialise the authorised values in a vue app. It will automatically load authorised values into the app and store them in the authorised values store based on the entries in a matrix file. The intent behind this is to make adding authorised values into a Vue app much simpler and more DRY, especially when creating a new vue app. You will just need to add your app into the avMatrix.js file and add a call to the initialisation method in your app.
Comment 2 Matt Blenkinsop 2024-09-16 15:31:41 UTC
Created attachment 171557 [details] [review]
Bug 37930: Update the ERM and Preservation apps
Comment 3 Matt Blenkinsop 2024-09-16 15:31:44 UTC
Created attachment 171558 [details] [review]
Bug 37930: Update cypress tests

Test plan:
1) Run the cypress tests for ERM and Preservation
2) All tests should still pass
Comment 4 Matt Blenkinsop 2024-09-16 15:35:50 UTC
This is an idea for discussion - the main intent is to make the handling of authorised values DRY across all Vue apps and to make it much easier to inject them into both existing and new apps

The avMatrix file controls which authorised values are injected into the app so to use an additional value category in your app you would just need to add a line into that file under the relevant module

For new apps, you would just add an entry into the matrix file and call the initialisation method somewhere in your home component and the front loading of all the authorised values would be handled for you
Comment 5 Jonathan Druart 2024-09-17 07:18:53 UTC
I think we should keep one file per app. Otherwise we will end up with a big ugly and hard-to-maintain authorisedValues/avMatrix.js.

Why not simply have the av list in the store of the app (eg. stores/erm.js)?

That would mean we could remove useAVStore and use the mainStore instead. We would retrieve the AVs from the config:
  this.config.avs.get("my_av")
  this.config.avs.get_lib_from_av("my_av", value)

Also for discussion :)
Comment 6 Matt Blenkinsop 2024-09-17 14:34:36 UTC
Created attachment 171628 [details] [review]
Bug 37930: [DO NOT PUSH] Alternate concept

Alternative patch taking into account feedback in comment 5 on the bug. This patch removes the authorised values store and migrates the methods to the main store. Authorised values are now added into the module specific store and replaced on module load with the actual values

To test I've added a console log of the values in the store to the AgreementsList component so apply all patches on the bug and then navigate to the agreements table in ERM. The module will throw errors as I haven't been through and changed all the instances where we would need to swap the AV store for the ERM store (there are a lot of instances and this is just a proof of concept for discussion for now). Check that the logged values are as expected. If you have the Vue devtools you'll be able to see the store values and check them directly in there
Comment 7 Matt Blenkinsop 2024-09-17 14:36:51 UTC
(In reply to Jonathan Druart from comment #5)
> I think we should keep one file per app. Otherwise we will end up with a big
> ugly and hard-to-maintain authorisedValues/avMatrix.js.
> 
> Why not simply have the av list in the store of the app (eg. stores/erm.js)?
> 
> That would mean we could remove useAVStore and use the mainStore instead. We
> would retrieve the AVs from the config:
>   this.config.avs.get("my_av")
>   this.config.avs.get_lib_from_av("my_av", value)
> 
> Also for discussion :)

I like the idea of using the module specific store so the new patch uses that methodology. I've opted not to include them in the config object as we overwrite that when we fetch the config and that wipes the existing authorised values we would have fetched

Have a look at the patch above and see what you think - I've not changed all of the places we would need to remove the AV store yet as this may need changes and that would take time to keep repeating.
Comment 8 Jonathan Druart 2024-09-23 09:41:06 UTC
That seems better to me.

A couple of notes:
* "loaded" is not called when the pref is off (and so "loading..." is displayed on the screen)

* it would be nice to still have the av related functions (get_lib_from_av, map_av_dt_filter, loadAuthorisedValues) in a dedicated file. They were isolated and it was good. We should try to keep that in mind, to keep stores/main.js short and clean. But I would not consider it blocker.
Comment 9 Matt Blenkinsop 2024-10-17 11:37:45 UTC
Created attachment 172863 [details] [review]
Bug 37930: Change how we load authorised values in Vue

This patch adds a method to initialise the authorised values in a vue app. It will automatically load authorised values into the app and store them in the store for your app. The intent behind this is to make adding authorised values into a Vue app much simpler and more DRY, especially when creating a new vue app. You will just need to add your desired authorised values into the store for your app and they will be loaded automatically
Comment 10 Matt Blenkinsop 2024-10-17 11:37:48 UTC
Created attachment 172864 [details] [review]
Bug 37930: Restore AV store to hold methods
Comment 11 Matt Blenkinsop 2024-10-17 11:37:50 UTC
Created attachment 172865 [details] [review]
Bug 37930: Modify AgreementsList and FormAdd to support new AV concept

Test plan
1) Navigate to ERM module
2) Click into agreements, page should load as normal
3) Click New agreement, form should load as expected
4) Fill in the required fields - note that the Status field is correctly populated with authorised values
5) Save new agreeement
6) Note that the status column in the table is correctly populated
Comment 12 Matt Blenkinsop 2024-10-17 11:39:19 UTC
I've restored the AVstore to hold the methods - this means we now need to pass the authorised values into the methods themselves rather than accessing them using "this" in the store

I've made the changes to AgreementsList and FormAdd to show the new concept working, if we're happy with this I'll update the rest of the instances and the cypress tests :)

I've also fixed the loading issue
Comment 13 Matt Blenkinsop 2024-10-17 14:21:53 UTC
Created attachment 172886 [details] [review]
Bug 37930: Change how we load authorised values in Vue

This patch adds a method to initialise the authorised values in a vue app. It will automatically load authorised values into the app and store them in the store for your app. The intent behind this is to make adding authorised values into a Vue app much simpler and more DRY, especially when creating a new vue app. You will just need to add your desired authorised values into the store for your app and they will be loaded automatically
Comment 14 Matt Blenkinsop 2024-10-17 14:21:55 UTC
Created attachment 172887 [details] [review]
Bug 37930: Modify AgreementsList and FormAdd to support new AV concept

Test plan
1) Navigate to ERM module
2) Click into agreements, page should load as normal
3) Click New agreement, form should load as expected
4) Fill in the required fields - note that the Status field is correctly populated with authorised values
5) Save new agreeement
6) Note that the status column in the table is correctly populated
Comment 15 Matt Blenkinsop 2024-10-17 14:23:34 UTC
Having the methods outside of mainstore involved a lot more passing data back and forth so I've moved them back into main store and the AVs are loaded into there. This means it is much easier to access them in the components
Comment 16 Matt Blenkinsop 2024-10-17 14:24:23 UTC
Created attachment 172888 [details] [review]
Bug 37930: Modify AgreementsList and FormAdd to support new AV concept

Test plan
1) Navigate to ERM module
2) Click into agreements, page should load as normal
3) Click New agreement, form should load as expected
4) Fill in the required fields - note that the Status field is correctly populated with authorised values
5) Save new agreeement
6) Note that the status column in the table is correctly populated
Comment 17 Matt Blenkinsop 2024-10-18 13:50:17 UTC
Created attachment 172979 [details] [review]
Bug 37930: Modify AgreementsList and FormAdd to support new AV concept

Test plan
1) Navigate to ERM module
2) Click into agreements, page should load as normal
3) Click New agreement, form should load as expected
4) Fill in the required fields - note that the Status field is correctly populated with authorised values
5) Save new agreeement
6) Note that the status column in the table is correctly populated
Comment 18 PTFS Europe Sandboxes 2024-10-21 16:14:11 UTC
Created attachment 173069 [details] [review]
Bug 37930: Modify AgreementsList and FormAdd to support new AV concept

Test plan
1) Navigate to ERM module
2) Click into agreements, page should load as normal
3) Click New agreement, form should load as expected
4) Fill in the required fields - note that the Status field is correctly populated with authorised values
5) Save new agreeement
6) Note that the status column in the table is correctly populated

Signed-off-by: esther <esther@bywatersolutions.com>
Comment 19 Jonathan Druart 2024-10-23 08:20:15 UTC
1. The code in beforeCreate needs to be adjusted. There could be a race: we should not have this.loaded() called twice.

2. functions are defined in 2 different places (store/main and store/authorised-values)

3. Other apps need to be adjusted.

4. 
(In reply to Matt Blenkinsop from comment #15)
> Having the methods outside of mainstore involved a lot more passing data
> back and forth so I've moved them back into main store and the AVs are
> loaded into there. This means it is much easier to access them in the
> components

Could you push a branch with this version and explain exactly what was the problematic part? Moving av code to main is not ideal IMO.

We are still in the discussion step here it seems, not ready for inclusion.