Skip to content

Commit

Permalink
Merge pull request #9240 from openshift-cherrypick-robot/cherry-pick-…
Browse files Browse the repository at this point in the history
…9228-to-release-4.8

[release-4.8] Bug 1971911: Do not render samples column and helm link when add page customization disabled them
  • Loading branch information
openshift-ci[bot] committed Aug 7, 2021
2 parents a9e55c8 + edc87de commit 3c9fb22
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ export const GettingStartedCard: React.FC<GettingStartedCardProps> = ({
onClick={link.onClick}
>
{link.title}
{link.external}
</SimpleListItem>
),
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,43 @@ import {
GettingStartedCard,
} from '@console/shared/src/components/getting-started';

import { getDisabledAddActions } from '../../utils/useAddActionExtensions';
import { fromHelmCharts } from '../../actions/add-resources';

export const DeveloperFeaturesGettingStartedCard: React.FC = () => {
const { t } = useTranslation();
const [activeNamespace] = useActiveNamespace();
const parsed = semver.parse(useOpenShiftVersion());
// Show only major and minor version.
const version = parsed ? `${parsed.major}.${parsed.minor}` : '';

const links: GettingStartedLink[] = [
{
const links: GettingStartedLink[] = [];

const disabledAddActions = getDisabledAddActions();
if (!disabledAddActions?.includes(fromHelmCharts.id)) {
links.push({
id: 'helm-charts',
title: t('devconsole~Discover certified Helm Charts'),
href:
activeNamespace && activeNamespace !== ALL_NAMESPACES_KEY
? `/catalog/ns/${activeNamespace}?catalogType=HelmChart`
: '/catalog/all-namespaces?catalogType=HelmChart',
},
{
id: 'topology',
title: t('devconsole~Start building your application quickly in topology'),
href:
activeNamespace && activeNamespace !== ALL_NAMESPACES_KEY
? `/topology/ns/${activeNamespace}?catalogSearch=`
: '/topology/all-namespaces?catalogSearch=',
},
];
});
}

links.push({
id: 'topology',
title: t('devconsole~Start building your application quickly in topology'),
href:
activeNamespace && activeNamespace !== ALL_NAMESPACES_KEY
? `/topology/ns/${activeNamespace}?catalogSearch=`
: '/topology/all-namespaces?catalogSearch=',
});

const moreLink: GettingStartedLink = {
id: 'whats-new',
title: t("devconsole~What's new in OpenShift {{version}}", { version }),
href: 'https://developers.redhat.com/products/openshift/getting-started',
href: 'https://developers.redhat.com/products/openshift/whats-new',
external: true,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import { useActiveNamespace } from '@console/shared/src/hooks/useActiveNamespace
import { CatalogItem } from '@console/dynamic-plugin-sdk';

import CatalogServiceProvider from '../catalog/service/CatalogServiceProvider';
import { getDisabledAddActions } from '../../utils/useAddActionExtensions';
import { fromSamples } from '../../actions/add-resources';

interface SampleGettingStartedCardProps {
featured?: string[];
Expand Down Expand Up @@ -46,6 +48,11 @@ export const SampleGettingStartedCard: React.FC<SampleGettingStartedCardProps> =
const { t } = useTranslation();
const [activeNamespace] = useActiveNamespace();

const disabledAddActions = getDisabledAddActions();
if (disabledAddActions?.includes(fromSamples.id)) {
return null;
}

const moreLink: GettingStartedLink = {
id: 'all-samples',
title: t('devconsole~View all samples'),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ jest.mock(

const useActiveNamespaceMock = useActiveNamespace as jest.Mock;

afterEach(() => {
delete window.SERVER_FLAGS.addPage;
});

describe('DeveloperFeaturesGettingStartedCard', () => {
it('should contain links to current active namespace', () => {
useActiveNamespaceMock.mockReturnValue(['active-namespace']);
Expand All @@ -59,7 +63,32 @@ describe('DeveloperFeaturesGettingStartedCard', () => {
expect(wrapper.find(GettingStartedCard).props().moreLink).toEqual({
id: 'whats-new',
title: "What's new in OpenShift 4.8",
href: 'https://developers.redhat.com/products/openshift/getting-started',
href: 'https://developers.redhat.com/products/openshift/whats-new',
external: true,
});
});

it('should not show helm link when helm card is disabled', () => {
window.SERVER_FLAGS.addPage = '{ "disabledActions": "helm" }';

useActiveNamespaceMock.mockReturnValue(['active-namespace']);

const wrapper = shallow(<DeveloperFeaturesGettingStartedCard />);

expect(wrapper.find(GettingStartedCard).props().title).toEqual(
'Explore new developer features',
);
expect(wrapper.find(GettingStartedCard).props().links).toEqual([
{
id: 'topology',
title: 'Start building your application quickly in topology',
href: '/topology/ns/active-namespace?catalogSearch=',
},
]);
expect(wrapper.find(GettingStartedCard).props().moreLink).toEqual({
id: 'whats-new',
title: "What's new in OpenShift 4.8",
href: 'https://developers.redhat.com/products/openshift/whats-new',
external: true,
});
});
Expand Down Expand Up @@ -87,7 +116,7 @@ describe('DeveloperFeaturesGettingStartedCard', () => {
expect(wrapper.find(GettingStartedCard).props().moreLink).toEqual({
id: 'whats-new',
title: "What's new in OpenShift 4.8",
href: 'https://developers.redhat.com/products/openshift/getting-started',
href: 'https://developers.redhat.com/products/openshift/whats-new',
external: true,
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,22 @@ jest.mock(
const useActiveNamespaceMock = useActiveNamespace as jest.Mock;
const CatalogServiceProviderMock = CatalogServiceProvider as jest.Mock;

afterEach(() => {
delete window.SERVER_FLAGS.addPage;
});

describe('SampleGettingStartedCard', () => {
it('should not render when Samples add card is disabled', () => {
window.SERVER_FLAGS.addPage = '{ "disabledActions": "import-from-samples" }';

useActiveNamespaceMock.mockReturnValue(['active-namespace']);
CatalogServiceProviderMock.mockImplementation((props) => props.children(loadedCatalogService));

const wrapper = shallow(<SampleGettingStartedCard />);

expect(wrapper.text()).toEqual('');
});

it('should render loading links until catalog service is loaded', () => {
useActiveNamespaceMock.mockReturnValue(['active-namespace']);
CatalogServiceProviderMock.mockImplementation((props) => props.children(loadingCatalogService));
Expand Down

0 comments on commit 3c9fb22

Please sign in to comment.