From ca69c452b05a27a5921b16a8335f0f33e47908b3 Mon Sep 17 00:00:00 2001 From: Agustin Moyano Date: Wed, 26 Jul 2023 17:02:36 -0300 Subject: [PATCH] Bug 34425: fix Breadcrumbs vue component This patch fixes Breadcrumbs component when there is no title in a node in the routes tree, and fixes the links when there are parameters and the node has no name defined --- .../prog/js/vue/stores/navigation.js | 52 +++++++++++++++---- 1 file changed, 41 insertions(+), 11 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 b252923f10..8dcaee6d84 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), ]; } @@ -115,15 +123,37 @@ export const useNavigationStore = defineStore("navigation", { return child.is_base || (child.path && child.path !== ""); } - function _mapMatches(currentMatches) { + function _hasTitle(child) { + return !!child.title; + } + + function _getPath(match, params) { + if (match.path && params) { + return match.path.replaceAll( + /(:(\w+))/g, + (text, first_match, second_match) => { + return params[second_match]; + } + ); + } + } + + function _mapMatches(currentMatches, params) { return currentMatches - .filter(match => _isBaseOrNotStub(match.meta.self)) - .map(match => ({ - ...match.meta.self, - icon: null, - path: match.path, - children: null, - })); + .filter( + match => + _isBaseOrNotStub(match.meta.self) && + _hasTitle(match.meta.self) + ) + .map(match => { + let path = _getPath(match, params); + return { + ...match.meta.self, + icon: null, + path, + children: null, + }; + }); } }, leftNavigation() { -- 2.25.1