From f895e8be4c386385f7419aded811a1568c231777 Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Thu, 27 Jul 2023 10:57:37 -0300 Subject: [PATCH] Bug 34418: Replace dynamic parameter on unnamed route node Signed-off-by: Jonathan Druart Signed-off-by: Jonathan Druart Signed-off-by: Pedro Amorim Signed-off-by: Tomas Cohen Arazi --- .../prog/js/vue/stores/navigation.js | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/navigation.js b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/navigation.js index 5df32a53e1..1e3ecb58b3 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/vue/stores/navigation.js +++ b/koha-tmpl/intranet-tmpl/prog/js/vue/stores/navigation.js @@ -72,7 +72,11 @@ export const useNavigationStore = defineStore("navigation", { getters: { breadcrumbs() { if (this.current) - return _buildFromCurrentMatches(this.current, this.routeState); + return _buildFromCurrentMatches( + this.current, + this.routeState, + this.params + ); return _getBaseElements(this.routeState); @@ -100,14 +104,18 @@ export const useNavigationStore = defineStore("navigation", { ); } - function _buildFromCurrentMatches(currentMatches, routeState) { + function _buildFromCurrentMatches( + currentMatches, + routeState, + params + ) { return [ { ...routeState, icon: null, children: null, }, - ..._mapMatches(currentMatches), + ..._mapMatches(currentMatches, params), ]; } @@ -119,16 +127,28 @@ export const useNavigationStore = defineStore("navigation", { return !child.is_empty; } - function _mapMatches(currentMatches) { + function _getPath(match, params) { + if (!match.name && match.path && params) { + return match.path.replaceAll(/(:[^/]+)/g, param_name => { + return params[param_name.substr(1)]; + }); + } + return match.path; + } + + function _mapMatches(currentMatches, params) { return currentMatches .filter(match => _isBaseOrNotStub(match.meta.self)) .filter(match => _isEmptyNode(match.meta.self)) - .map(match => ({ - ...match.meta.self, - icon: null, - path: match.path, - children: null, - })); + .map(match => { + let path = _getPath(match, params); + return { + ...match.meta.self, + icon: null, + path, + children: null, + }; + }); } }, leftNavigation() { -- 2.39.5