Skip to content

Commit

Permalink
Merge pull request openshift#8816 from jerolimov/i18n-pinned-resources
Browse files Browse the repository at this point in the history
Bug 1941669: Translate pinned resources when labelPluralKey is available
  • Loading branch information
openshift-merge-robot authored Apr 29, 2021
2 parents a732db7 + da41e4e commit 74170af
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions frontend/public/components/nav/perspective-nav.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as React from 'react';
import { useTranslation } from 'react-i18next';
import { NavItemSeparator, NavGroup, Button } from '@patternfly/react-core';
import { MinusCircleIcon } from '@patternfly/react-icons';
import {
Expand All @@ -11,7 +12,7 @@ import {
isSeparatorNavItem,
} from '@console/plugin-sdk';
import { useActivePerspective, usePinnedResources } from '@console/shared';
import { modelFor, referenceForModel } from '../../module/k8s';
import { K8sKind, modelFor, referenceForModel } from '../../module/k8s';
import { getSortedNavItems } from './navSortUtils';
import confirmNavUnpinModal from './confirmNavUnpinModal';
import { NavSection } from './section';
Expand All @@ -26,12 +27,8 @@ import {

import './_perspective-nav.scss';

const getLabelForResource = (resource: string): string => {
const model = modelFor(resource);
return model ? model.labelPlural : '';
};

const PerspectiveNav: React.FC<{}> = () => {
const { t } = useTranslation();
const [perspective] = useActivePerspective();
const allItems = useExtensions<PluginNavSection | NavItem | SeparatorNavItem>(
isNavSection,
Expand All @@ -56,6 +53,17 @@ const PerspectiveNav: React.FC<{}> = () => {
return <AdminNav />;
}

const getLabelForResource = (resource: string): string => {
const model: K8sKind | undefined = modelFor(resource);
if (model) {
if (model.labelPluralKey) {
return t(model.labelPluralKey);
}
return model.labelPlural || model.plural;
}
return '';
};

const getPinnedItems = (rootNavLink: boolean = false): React.ReactElement[] =>
pinnedResourcesLoaded
? pinnedResources
Expand All @@ -64,14 +72,15 @@ const PerspectiveNav: React.FC<{}> = () => {
if (!model) {
return null;
}
const { labelPlural, apiVersion, apiGroup, namespaced, crd, plural } = model;
const { apiVersion, apiGroup, namespaced, crd, plural } = model;
const label = getLabelForResource(resource);
const duplicates =
pinnedResources.filter((res) => getLabelForResource(res) === labelPlural).length > 1;
pinnedResources.filter((res) => getLabelForResource(res) === label).length > 1;
const props = {
key: `pinned-${resource}`,
name: labelPlural,
name: label,
resource: crd ? referenceForModel(model) : plural,
tipText: duplicates ? `${labelPlural}: ${apiGroup || 'core'}/${apiVersion}` : null,
tipText: duplicates ? `${label}: ${apiGroup || 'core'}/${apiVersion}` : null,
id: resource,
};
const Component: NavLinkComponent = namespaced ? ResourceNSLink : ResourceClusterLink;
Expand Down

0 comments on commit 74170af

Please sign in to comment.