Bug 38201: Allow the breadcrumb to be dynamic in the show component
Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu> Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org> Signed-off-by: Lucas Gass <lucas@bywatersolutions.com>
This commit is contained in:
parent
f34565f958
commit
0b80976cb3
|
|
@ -9,6 +9,8 @@ export function useBaseResource(instancedResource) {
|
|||
const route = useRoute();
|
||||
const { setConfirmationDialog, setMessage, setError, setWarning } =
|
||||
inject("mainStore");
|
||||
const navigationStore = inject("navigationStore");
|
||||
const { breadcrumbMetadata } = storeToRefs(navigationStore);
|
||||
|
||||
const moduleStoreUtils = {};
|
||||
if (instancedResource.moduleStore) {
|
||||
|
|
@ -363,6 +365,7 @@ export function useBaseResource(instancedResource) {
|
|||
//TODO: Rename this 'resource' to 'fetchedResource'. Needs to also be renamed in ResourceFormAdd and ResourceShow
|
||||
// This is to make it clear that this is the fetchedResource (data), not the resource component class
|
||||
componentData.resource.value = resource;
|
||||
breadcrumbMetadata.value = resource;
|
||||
if (componentData.instancedResource.afterResourceFetch) {
|
||||
componentData.instancedResource.afterResourceFetch(
|
||||
componentData,
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ export const routes = [
|
|||
path: ":agreement_id",
|
||||
name: "AgreementsShow",
|
||||
component: markRaw(ResourceWrapper),
|
||||
title: $__("Show agreement"),
|
||||
title: $__("Show {name}"),
|
||||
},
|
||||
{
|
||||
path: "add",
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ export const useNavigationStore = defineStore("navigation", () => {
|
|||
params: {},
|
||||
from: null,
|
||||
query: {},
|
||||
breadcrumbMetadata: null,
|
||||
});
|
||||
const actions = {
|
||||
setRoutes(routesDef) {
|
||||
|
|
@ -79,7 +80,8 @@ export const useNavigationStore = defineStore("navigation", () => {
|
|||
return _buildFromCurrentMatches(
|
||||
store.current,
|
||||
store.routeState,
|
||||
store.params
|
||||
store.params,
|
||||
store.breadcrumbMetadata
|
||||
);
|
||||
|
||||
return _getBaseElements(store.routeState);
|
||||
|
|
@ -111,7 +113,8 @@ export const useNavigationStore = defineStore("navigation", () => {
|
|||
function _buildFromCurrentMatches(
|
||||
currentMatches,
|
||||
routeState,
|
||||
params
|
||||
params,
|
||||
breadcrumbMetadata
|
||||
) {
|
||||
return [
|
||||
{
|
||||
|
|
@ -119,7 +122,7 @@ export const useNavigationStore = defineStore("navigation", () => {
|
|||
icon: null,
|
||||
children: null,
|
||||
},
|
||||
..._mapMatches(currentMatches, params),
|
||||
..._mapMatches(currentMatches, params, breadcrumbMetadata),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -140,7 +143,7 @@ export const useNavigationStore = defineStore("navigation", () => {
|
|||
return match.path;
|
||||
}
|
||||
|
||||
function _mapMatches(currentMatches, params) {
|
||||
function _mapMatches(currentMatches, params, breadcrumbMetadata) {
|
||||
const matches = currentMatches
|
||||
.filter(match => _isBaseOrNotStub(match.meta.self))
|
||||
.filter(match => _isEmptyNode(match.meta.self))
|
||||
|
|
@ -158,13 +161,24 @@ export const useNavigationStore = defineStore("navigation", () => {
|
|||
});
|
||||
}
|
||||
const breadcrumbInfo = {
|
||||
...match.meta.self,
|
||||
...self,
|
||||
icon: null,
|
||||
...(externalPath
|
||||
? { href: path, path: null }
|
||||
: { path }),
|
||||
children: null,
|
||||
};
|
||||
if (
|
||||
breadcrumbMetadata &&
|
||||
/(?:{([^}]+)})/.test(self.title)
|
||||
) {
|
||||
breadcrumbInfo.title = self.title.replaceAll(
|
||||
/(?:{([^}]+)})/g,
|
||||
(match, paramName) => {
|
||||
return breadcrumbMetadata[paramName];
|
||||
}
|
||||
);
|
||||
}
|
||||
return breadcrumbInfo;
|
||||
});
|
||||
return matches;
|
||||
|
|
|
|||
Loading…
Reference in New Issue