Skip to content

Commit 811f494

Browse files
shrabantipaul-collateShrabanti Paul
authored andcommitted
Fixes 25794: Global Domain Filter translation (#25982)
* Global Domain Filter translation * remove repeated code for domainDisplayName * memoize domainDisplayName * add unit test for util function * fix failing jest test --------- Co-authored-by: Shrabanti Paul <shrabantipaul@Shrabantis-MacBook-Pro.local> (cherry picked from commit db104e5)
1 parent 8baf489 commit 811f494

5 files changed

Lines changed: 102 additions & 8 deletions

File tree

openmetadata-ui/src/main/resources/ui/src/components/MyData/CustomizableComponents/CustomiseLandingPageHeader/CustomiseLandingPageHeader.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ import {
3939
CustomPrevArrow,
4040
} from '../../../../utils/CustomizableLandingPageUtils';
4141
import entityUtilClassBase from '../../../../utils/EntityUtilClassBase';
42-
import { getEntityName } from '../../../../utils/EntityUtils';
42+
import { getDomainDisplayName } from '../../../../utils/EntityUtils';
4343
import serviceUtilClassBase from '../../../../utils/ServiceUtilClassBase';
4444
import { showErrorToast } from '../../../../utils/ToastUtils';
4545
import DomainSelectableList from '../../../common/DomainSelectableList/DomainSelectableList.component';
@@ -138,6 +138,11 @@ const CustomiseLandingPageHeader = ({
138138
[updateActiveDomain, navigate]
139139
);
140140

141+
const domainDisplayName = useMemo(
142+
() => getDomainDisplayName(activeDomainEntityRef, activeDomain),
143+
[activeDomainEntityRef, activeDomain, t]
144+
);
145+
141146
const navigateToEntity = (data: {
142147
entityType: string;
143148
fullyQualifiedName: string;
@@ -221,9 +226,7 @@ const CustomiseLandingPageHeader = ({
221226
width={22}
222227
/>
223228
<Typography.Text className="text-sm font-medium domain-title">
224-
{activeDomainEntityRef
225-
? getEntityName(activeDomainEntityRef)
226-
: activeDomain}
229+
{domainDisplayName}
227230
</Typography.Text>
228231
<DropdownIcon
229232
className="dropdown-icon"

openmetadata-ui/src/main/resources/ui/src/components/NavBar/NavBar.test.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ jest.mock('../../utils/EntityUtilClassBase', () => ({
174174

175175
jest.mock('../../utils/EntityUtils', () => ({
176176
getEntityName: jest.fn().mockReturnValue('MockedEntityName'),
177+
getDomainDisplayName: jest.fn().mockReturnValue('All Domains'),
177178
}));
178179

179180
jest.mock(

openmetadata-ui/src/main/resources/ui/src/components/NavBar/NavBar.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ import {
6666
} from '../../utils/BrowserNotificationUtils';
6767
import { getCustomPropertyEntityPathname } from '../../utils/CustomProperty.utils';
6868
import entityUtilClassBase from '../../utils/EntityUtilClassBase';
69-
import { getEntityName } from '../../utils/EntityUtils';
69+
import { getDomainDisplayName } from '../../utils/EntityUtils';
7070
import {
7171
getEntityFQN,
7272
getEntityType,
@@ -431,6 +431,11 @@ const NavBar = () => {
431431
[]
432432
);
433433

434+
const domainDisplayName = useMemo(
435+
() => getDomainDisplayName(activeDomainEntityRef, activeDomain),
436+
[activeDomainEntityRef, activeDomain, t]
437+
);
438+
434439
const handleLanguageChange = useCallback(({ key }: MenuInfo) => {
435440
i18next.changeLanguage(key);
436441
setPreference({ language: key as SupportedLocales });
@@ -498,9 +503,7 @@ const NavBar = () => {
498503
width={20}
499504
/>
500505
<Typography.Text ellipsis className="domain-text">
501-
{activeDomainEntityRef
502-
? getEntityName(activeDomainEntityRef)
503-
: activeDomain}
506+
{domainDisplayName}
504507
</Typography.Text>
505508
<DropDownIcon width={12} />
506509
</Button>

openmetadata-ui/src/main/resources/ui/src/utils/EntityUtils.test.tsx

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
*/
1313
import { render } from '@testing-library/react';
1414
import { startCase } from 'lodash';
15+
import { DEFAULT_DOMAIN_VALUE } from '../constants/constants';
1516
import { EntityTabs, EntityType } from '../enums/entity.enum';
1617
import { ExplorePageTabs } from '../enums/Explore.enum';
1718
import { ServiceCategory } from '../enums/service.enum';
@@ -22,6 +23,7 @@ import {
2223
columnSorter,
2324
getBreadcrumbForTestSuite,
2425
getColumnSorter,
26+
getDomainDisplayName,
2527
getEntityBreadcrumbs,
2628
getEntityLinkFromType,
2729
getEntityOverview,
@@ -56,6 +58,7 @@ import { getServiceRouteFromServiceType } from './ServiceUtils';
5658
import { getTierTags } from './TableUtils';
5759

5860
jest.mock('../constants/constants', () => ({
61+
DEFAULT_DOMAIN_VALUE: 'All Domains',
5962
getEntityDetailsPath: jest.fn(),
6063
getServiceDetailsPath: jest.fn(),
6164
}));
@@ -83,6 +86,16 @@ jest.mock('./ExportUtilClassBase', () => ({
8386
},
8487
}));
8588

89+
jest.mock('i18next', () => ({
90+
t: jest.fn((key) => {
91+
const translations: Record<string, string> = {
92+
'label.all-domain-plural': 'All Domains',
93+
};
94+
95+
return translations[key] || key;
96+
}),
97+
}));
98+
8699
jest.mock('../components/Tag/TagsV1/TagsV1.component', () => ({
87100
__esModule: true,
88101
default: jest.fn(),
@@ -595,4 +608,64 @@ describe('EntityUtils unit tests', () => {
595608
});
596609
});
597610
});
611+
612+
describe('getDomainDisplayName', () => {
613+
it('should return entity name when activeDomainEntityRef is provided', () => {
614+
const mockEntityRef = {
615+
id: '123',
616+
name: 'Engineering',
617+
displayName: 'Engineering Domain',
618+
type: 'domain',
619+
};
620+
621+
const result = getDomainDisplayName(mockEntityRef);
622+
623+
expect(result).toBe('Engineering Domain');
624+
});
625+
626+
it('should return entity name without displayName when activeDomainEntityRef has only name', () => {
627+
const mockEntityRef = {
628+
id: '123',
629+
name: 'Engineering',
630+
type: 'domain',
631+
};
632+
633+
const result = getDomainDisplayName(mockEntityRef);
634+
635+
expect(result).toBe('Engineering');
636+
});
637+
638+
it('should return translated "All Domains" when activeDomain is DEFAULT_DOMAIN_VALUE', () => {
639+
const result = getDomainDisplayName(undefined, DEFAULT_DOMAIN_VALUE);
640+
641+
expect(result).toBe('All Domains');
642+
});
643+
644+
it('should return custom domain name when activeDomain is a custom value', () => {
645+
const customDomain = 'custom-domain';
646+
647+
const result = getDomainDisplayName(undefined, customDomain);
648+
649+
expect(result).toBe(customDomain);
650+
});
651+
652+
it('should return undefined when both parameters are undefined', () => {
653+
const result = getDomainDisplayName();
654+
655+
expect(result).toBe(undefined);
656+
});
657+
658+
it('should prioritize activeDomainEntityRef over activeDomain', () => {
659+
const mockEntityRef = {
660+
id: '123',
661+
name: 'Engineering',
662+
displayName: 'Engineering Domain',
663+
type: 'domain',
664+
};
665+
666+
const result = getDomainDisplayName(mockEntityRef, DEFAULT_DOMAIN_VALUE);
667+
668+
expect(result).toBe('Engineering Domain');
669+
});
670+
});
598671
});

openmetadata-ui/src/main/resources/ui/src/utils/EntityUtils.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import {
4949
import TagsV1 from '../components/Tag/TagsV1/TagsV1.component';
5050
import { FQN_SEPARATOR_CHAR } from '../constants/char.constants';
5151
import {
52+
DEFAULT_DOMAIN_VALUE,
5253
NO_DATA,
5354
PLACEHOLDER_ROUTE_ENTITY_TYPE,
5455
PLACEHOLDER_ROUTE_FQN,
@@ -176,6 +177,19 @@ export const getEntityName = (entity?: {
176177
return entity?.displayName || entity?.name || '';
177178
};
178179

180+
export const getDomainDisplayName = (
181+
activeDomainEntityRef?: EntityReference,
182+
activeDomain?: string
183+
) => {
184+
if (activeDomainEntityRef) {
185+
return getEntityName(activeDomainEntityRef);
186+
}
187+
188+
return activeDomain === DEFAULT_DOMAIN_VALUE
189+
? t('label.all-domain-plural')
190+
: activeDomain;
191+
};
192+
179193
export const getEntityLabel = (entity: {
180194
displayName?: string;
181195
name?: string;

0 commit comments

Comments
 (0)