1- import React , { type FC , useCallback , useMemo , useState } from 'react' ;
2- import { useNavigate } from 'react-router-dom' ;
1+ import React , { type FC , useCallback , useMemo , useState , useEffect } from 'react' ;
2+ import { matchPath , useLocation , useNavigate , useResolvedPath } from 'react-router-dom' ;
33import { useTranslation } from 'react-i18next' ;
44import { useCreateSearch , useQueryParams } from 'lib/hooks' ;
55import {
@@ -12,6 +12,7 @@ import AppTabs, { type AppTabItem } from 'components/shared/elements/AppTabs/App
1212import {
1313 activityPath ,
1414 alertsPath ,
15+ dataEntitiesPath ,
1516 dataQualityPath ,
1617 directoryPath ,
1718 lookupTablesPath ,
@@ -20,17 +21,17 @@ import {
2021 searchPath ,
2122 termsSearchPath ,
2223} from 'routes' ;
23- import useSetSelectedTab from '../../AppTabs/useSetSelectedTab' ;
2424
2525const ToolbarTabs : FC = ( ) => {
2626 const dispatch = useAppDispatch ( ) ;
2727 const { t } = useTranslation ( ) ;
2828 const navigate = useNavigate ( ) ;
2929 const createSearch = useCreateSearch ( ) ;
30+ const { pathname } = useResolvedPath ( useLocation ( ) ) ;
3031 const { defaultQueryString : activityQueryString } =
3132 useQueryParams < ActivityQuery > ( defaultActivityQuery ) ;
3233
33- const tabs = useMemo < AppTabItem [ ] > (
34+ const tabs = useMemo < AppTabItem < string > [ ] > (
3435 ( ) => [
3536 {
3637 name : t ( 'Catalog' ) ,
@@ -39,49 +40,74 @@ const ToolbarTabs: FC = () => {
3940 {
4041 name : t ( 'Directory' ) ,
4142 link : directoryPath ( ) ,
43+ value : 'directory' ,
4244 } ,
4345 {
4446 name : t ( 'Data Quality' ) ,
4547 link : dataQualityPath ( ) ,
48+ value : 'data-quality' ,
4649 } ,
4750 {
4851 name : t ( 'Data Modelling' ) ,
4952 link : queryExamplesPath ( ) ,
5053 hint : t ( 'BETA' ) ,
5154 hintType : 'secondary' ,
55+ value : 'data-modelling' ,
5256 } ,
5357 {
5458 name : t ( 'Master Data' ) ,
5559 link : lookupTablesPath ( ) ,
60+ value : 'master-data' ,
5661 } ,
5762 {
5863 name : t ( 'Management' ) ,
5964 link : managementPath ( ) ,
65+ value : 'management' ,
6066 } ,
6167 {
6268 name : t ( 'Dictionary' ) ,
6369 link : termsSearchPath ( ) ,
70+ value : 'dictionary' ,
6471 } ,
6572 {
6673 name : t ( 'Alerts' ) ,
6774 link : alertsPath ( 'all' ) ,
75+ value : 'alerts' ,
6876 } ,
6977 {
7078 name : t ( 'Activity' ) ,
7179 link : activityPath ( activityQueryString ) ,
80+ value : 'activity' ,
7281 } ,
7382 ] ,
7483 [ activityQueryString , t ]
7584 ) ;
7685
7786 const [ selectedTab , setSelectedTab ] = useState ( - 1 ) ;
7887
79- useSetSelectedTab ( tabs , setSelectedTab ) ;
88+ useEffect ( ( ) => {
89+ if ( matchPath ( '/' , pathname ) ) {
90+ setSelectedTab ( - 1 ) ;
91+ return ;
92+ }
93+
94+ if (
95+ matchPath ( `${ searchPath ( ) } /*` , pathname ) ||
96+ matchPath ( `${ dataEntitiesPath ( ) } /*` , pathname )
97+ ) {
98+ setSelectedTab ( 0 ) ;
99+ return ;
100+ }
101+
102+ tabs . forEach ( ( tab , idx ) => {
103+ if ( tab . value && pathname . includes ( tab . value ) ) {
104+ setSelectedTab ( idx ) ;
105+ }
106+ } ) ;
107+ } , [ pathname ] ) ;
80108
81109 const handleTabClick = useCallback (
82110 ( idx : number ) => {
83- setSelectedTab ( idx ) ;
84-
85111 const initialParams = { query : '' , pageSize : 30 , filters : { } } ;
86112
87113 if ( tabs [ idx ] . name === t ( 'Dictionary' ) ) {
0 commit comments