@@ -62,6 +62,27 @@ export const CippBreadcrumbNav = () => {
6262 const titleCheckCountRef = useRef ( 0 ) ;
6363 const titleCheckIntervalRef = useRef ( null ) ;
6464
65+ // Helper function to filter out unnecessary query parameters
66+ const getCleanQueryParams = ( query ) => {
67+ const cleaned = { ...query } ;
68+ // Remove tenantFilter if it's "AllTenants" or not explicitly needed
69+ if ( cleaned . tenantFilter === "AllTenants" || cleaned . tenantFilter === undefined ) {
70+ delete cleaned . tenantFilter ;
71+ }
72+ return cleaned ;
73+ } ;
74+
75+ // Helper function to clean page titles
76+ const cleanPageTitle = ( title ) => {
77+ if ( ! title ) return title ;
78+ // Remove AllTenants and any surrounding separators
79+ return title
80+ . replace ( / \s * - \s * A l l T e n a n t s \s * / , "" )
81+ . replace ( / A l l T e n a n t s \s * - \s * / , "" )
82+ . replace ( / A l l T e n a n t s / , "" )
83+ . trim ( ) ;
84+ } ;
85+
6586 // Load tab options on mount
6687 useEffect ( ( ) => {
6788 loadTabOptions ( ) . then ( setTabOptions ) ;
@@ -109,6 +130,9 @@ export const CippBreadcrumbNav = () => {
109130 pageTitle = parts . slice ( 0 , - 1 ) . join ( " - " ) . trim ( ) ;
110131 }
111132
133+ // Clean AllTenants from title
134+ pageTitle = cleanPageTitle ( pageTitle ) ;
135+
112136 // Skip if title is empty, generic, or error page
113137 if (
114138 ! pageTitle ||
@@ -155,7 +179,10 @@ export const CippBreadcrumbNav = () => {
155179 if ( samePath && ! sameTitle ) {
156180 // Same URL but title changed - update the entry
157181 const updated = [ ...prevHistory ] ;
158- updated [ prevHistory . length - 1 ] = currentPage ;
182+ updated [ prevHistory . length - 1 ] = {
183+ ...currentPage ,
184+ query : getCleanQueryParams ( currentPage . query ) ,
185+ } ;
159186 if ( titleCheckIntervalRef . current ) {
160187 clearInterval ( titleCheckIntervalRef . current ) ;
161188 titleCheckIntervalRef . current = null ;
@@ -173,7 +200,11 @@ export const CippBreadcrumbNav = () => {
173200
174201 // URL not in history (except possibly as last entry which we handled) - add as new entry
175202 if ( existingIndex === - 1 ) {
176- const newHistory = [ ...prevHistory , currentPage ] ;
203+ const cleanedCurrentPage = {
204+ ...currentPage ,
205+ query : getCleanQueryParams ( currentPage . query ) ,
206+ } ;
207+ const newHistory = [ ...prevHistory , cleanedCurrentPage ] ;
177208
178209 // Keep only the last MAX_HISTORY_STORAGE pages
179210 const trimmedHistory =
@@ -192,7 +223,10 @@ export const CippBreadcrumbNav = () => {
192223 titleCheckIntervalRef . current = null ;
193224 }
194225 const updated = prevHistory . slice ( 0 , existingIndex + 1 ) ;
195- updated [ existingIndex ] = currentPage ;
226+ updated [ existingIndex ] = {
227+ ...currentPage ,
228+ query : getCleanQueryParams ( currentPage . query ) ,
229+ } ;
196230 return updated ;
197231 } ) ;
198232 } ;
@@ -211,9 +245,10 @@ export const CippBreadcrumbNav = () => {
211245 const handleBreadcrumbClick = ( index ) => {
212246 const page = history [ index ] ;
213247 if ( page ) {
248+ const cleanedQuery = getCleanQueryParams ( page . query ) ;
214249 router . push ( {
215250 pathname : page . path ,
216- query : page . query ,
251+ query : cleanedQuery ,
217252 } ) ;
218253 }
219254 } ;
@@ -247,15 +282,18 @@ export const CippBreadcrumbNav = () => {
247282 return ;
248283 }
249284
250- const pageTitle = document . title . replace ( " - CIPP" , "" ) . trim ( ) ;
285+ let pageTitle = document . title . replace ( " - CIPP" , "" ) . trim ( ) ;
251286 const parts = pageTitle . split ( " - " ) ;
252287 const cleanTitle =
253288 parts . length > 1 && parts [ parts . length - 1 ] . includes ( "." )
254289 ? parts . slice ( 0 , - 1 ) . join ( " - " ) . trim ( )
255290 : pageTitle ;
256291
257- if ( cleanTitle && cleanTitle !== "CIPP" && ! cleanTitle . toLowerCase ( ) . includes ( "loading" ) ) {
258- setCurrentPageTitle ( cleanTitle ) ;
292+ // Clean AllTenants from title
293+ const finalTitle = cleanPageTitle ( cleanTitle ) ;
294+
295+ if ( finalTitle && finalTitle !== "CIPP" && ! finalTitle . toLowerCase ( ) . includes ( "loading" ) ) {
296+ setCurrentPageTitle ( finalTitle ) ;
259297 // Stop checking once we have a valid title
260298 if ( hierarchicalTitleCheckRef . current ) {
261299 clearInterval ( hierarchicalTitleCheckRef . current ) ;
@@ -316,11 +354,11 @@ export const CippBreadcrumbNav = () => {
316354
317355 // Check if this item matches the current path
318356 if ( item . path && pathsMatch ( item . path , currentPath ) ) {
319- // If this is the current page, include current query params
357+ // If this is the current page, include current query params (cleaned)
320358 if ( item . path === currentPath ) {
321359 const lastItem = currentBreadcrumb [ currentBreadcrumb . length - 1 ] ;
322360 if ( lastItem ) {
323- lastItem . query = { ... router . query } ;
361+ lastItem . query = getCleanQueryParams ( router . query ) ;
324362 }
325363 }
326364 return currentBreadcrumb ;
@@ -339,6 +377,32 @@ export const CippBreadcrumbNav = () => {
339377
340378 let result = findPathInMenu ( nativeMenuItems ) ;
341379
380+ // If we found a menu item, check if the current path matches any tab
381+ // If so, tabOptions wins and we use its label
382+ if ( result . length > 0 && tabOptions . length > 0 ) {
383+ const normalizedCurrentPath = currentPath . replace ( / \/ $ / , "" ) ;
384+
385+ // Check if current path matches any tab (exact match)
386+ const matchingTab = tabOptions . find ( ( tab ) => {
387+ const normalizedTabPath = tab . path . replace ( / \/ $ / , "" ) ;
388+ return normalizedTabPath === normalizedCurrentPath ;
389+ } ) ;
390+
391+ if ( matchingTab ) {
392+ // Tab matches the current path - use tab's label instead of config's
393+ result = result . map ( ( item , idx ) => {
394+ if ( idx === result . length - 1 ) {
395+ return {
396+ ...item ,
397+ title : matchingTab . title ,
398+ type : "tab" ,
399+ } ;
400+ }
401+ return item ;
402+ } ) ;
403+ }
404+ }
405+
342406 // If not found in main menu, check if it's a tab page
343407 if ( result . length === 0 && tabOptions . length > 0 ) {
344408 const normalizedCurrentPath = currentPath . replace ( / \/ $ / , "" ) ;
@@ -395,12 +459,12 @@ export const CippBreadcrumbNav = () => {
395459 if ( basePagePath . length > 0 ) {
396460 result = basePagePath ;
397461
398- // Add the tab as the final breadcrumb with current query params
462+ // Add the tab as the final breadcrumb with current query params (cleaned)
399463 result . push ( {
400464 title : matchingTab . title ,
401465 path : matchingTab . path ,
402466 type : "tab" ,
403- query : { ... router . query } , // Include current query params for tab page
467+ query : getCleanQueryParams ( router . query ) , // Include current query params for tab page
404468 } ) ;
405469 }
406470 }
@@ -411,7 +475,10 @@ export const CippBreadcrumbNav = () => {
411475 const lastItem = result [ result . length - 1 ] ;
412476 if ( lastItem . path && lastItem . path !== currentPath && currentPath . startsWith ( lastItem . path ) ) {
413477 // Use the tracked page title if available, otherwise fall back to document.title
414- const tabTitle = currentPageTitle || document . title . replace ( " - CIPP" , "" ) . trim ( ) ;
478+ let tabTitle = currentPageTitle || document . title . replace ( " - CIPP" , "" ) . trim ( ) ;
479+
480+ // Clean AllTenants from title
481+ tabTitle = cleanPageTitle ( tabTitle ) ;
415482
416483 // Add tab as an additional breadcrumb item
417484 if (
@@ -423,7 +490,7 @@ export const CippBreadcrumbNav = () => {
423490 title : tabTitle ,
424491 path : currentPath ,
425492 type : "tab" ,
426- query : { ... router . query } , // Include current query params
493+ query : getCleanQueryParams ( router . query ) , // Include current query params (cleaned)
427494 } ) ;
428495 }
429496 }
@@ -435,10 +502,11 @@ export const CippBreadcrumbNav = () => {
435502 // Handle click for hierarchical breadcrumbs
436503 const handleHierarchicalClick = ( path , query ) => {
437504 if ( path ) {
438- if ( query && Object . keys ( query ) . length > 0 ) {
505+ const cleanedQuery = getCleanQueryParams ( query ) ;
506+ if ( cleanedQuery && Object . keys ( cleanedQuery ) . length > 0 ) {
439507 router . push ( {
440508 pathname : path ,
441- query : query ,
509+ query : cleanedQuery ,
442510 } ) ;
443511 } else {
444512 router . push ( path ) ;
@@ -478,7 +546,7 @@ export const CippBreadcrumbNav = () => {
478546 title,
479547 path,
480548 type : "fallback" ,
481- query : index === pathSegments . length - 1 ? { ... router . query } : { } ,
549+ query : index === pathSegments . length - 1 ? getCleanQueryParams ( router . query ) : { } ,
482550 } ;
483551 } ) ;
484552
@@ -488,7 +556,7 @@ export const CippBreadcrumbNav = () => {
488556 currentPageTitle !== "CIPP" &&
489557 ! currentPageTitle . toLowerCase ( ) . includes ( "loading" )
490558 ) {
491- breadcrumbs [ breadcrumbs . length - 1 ] . title = currentPageTitle ;
559+ breadcrumbs [ breadcrumbs . length - 1 ] . title = cleanPageTitle ( currentPageTitle ) ;
492560 }
493561 }
494562 }
0 commit comments