From f900234590f5e5a0b8e85eb48de03b77b2475bcb Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Mon, 7 Apr 2025 12:50:09 +0200 Subject: [PATCH] Bug 37930: Return actions from the composable file --- .../js/vue/composables/authorisedValues.js | 26 ++++++++++++++++--- .../intranet-tmpl/prog/js/vue/stores/erm.js | 15 +++-------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/composables/authorisedValues.js b/koha-tmpl/intranet-tmpl/prog/js/vue/composables/authorisedValues.js index 3bfdb9ac305..c6861e9245f 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/composables/authorisedValues.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/composables/authorisedValues.js @@ -1,6 +1,6 @@ import { APIClient } from "../fetch/api-client.js"; -export const get_lib_from_av_handler = (arr_name, av, store) => { +const get_lib_from_av_handler = (arr_name, av, store) => { if (store.authorisedValues[arr_name] === undefined) { console.warn( "The authorised value category for '%s' is not defined.".format( @@ -12,14 +12,17 @@ export const get_lib_from_av_handler = (arr_name, av, store) => { let o = store.authorisedValues[arr_name].find(e => e.value == av); return o ? o.description : av; }; -export const map_av_dt_filter_handler = (arr_name, store) => { +const map_av_dt_filter_handler = (arr_name, store) => { return store.authorisedValues[arr_name].map(e => { e["_id"] = e["value"]; e["_str"] = e["description"]; return e; }); }; -export const loadAuthorisedValues = async (authorisedValues, targetStore) => { +const load_authorised_values_handler = async ( + authorisedValues, + targetStore +) => { const AVsToFetch = Object.keys(authorisedValues).reduce((acc, avKey) => { if (Array.isArray(authorisedValues[avKey])) return acc; acc[avKey] = authorisedValues[avKey]; @@ -48,3 +51,20 @@ export const loadAuthorisedValues = async (authorisedValues, targetStore) => { return Promise.all(promises); }; + +export function withAuthorisedValueActions(store) { + return { + loadAuthorisedValues(authorisedValues, targetStore) { + return load_authorised_values_handler( + authorisedValues, + targetStore + ); + }, + get_lib_from_av(arr_name, av) { + return get_lib_from_av_handler(arr_name, av, store); + }, + map_av_dt_filter(arr_name) { + return map_av_dt_filter_handler(arr_name, store); + }, + }; +} diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/erm.js b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/erm.js index 244501ea158..3a32409c99f 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/erm.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/erm.js @@ -1,9 +1,6 @@ import { defineStore } from "pinia"; -import { - loadAuthorisedValues, - get_lib_from_av_handler, - map_av_dt_filter_handler, -} from "../composables/authorisedValues"; + +import { withAuthorisedValueActions } from "../composables/authorisedValues"; export const useERMStore = defineStore("erm", { state: () => ({ @@ -65,12 +62,6 @@ export const useERMStore = defineStore("erm", { }, }), actions: { - loadAuthorisedValues, - get_lib_from_av(arr_name, av) { - return get_lib_from_av_handler(arr_name, av, this); - }, - map_av_dt_filter(arr_name) { - return map_av_dt_filter_handler(arr_name, this); - }, + ...withAuthorisedValueActions(this), }, }); -- 2.34.1