Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix to show CRW icon when CRW operator is installed #7895

Merged
merged 1 commit into from
Jan 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { TFunction } from 'i18next';
import { BitbucketIcon, GitAltIcon, GithubIcon, GitlabIcon } from '@patternfly/react-icons';
import { routeDecoratorIcon } from '../render-utils';
import CheIcon from '../CheIcon';

const t = (key): TFunction => key;

Expand Down Expand Up @@ -63,4 +64,29 @@ describe('Ensure render utils works', () => {
).toEqual(GitlabIcon);
});
});

describe('Ensure we get che icon when che is enabled', () => {
it('expect che icon when che icon url is available', () => {
expect(
routeDecoratorIcon(
'https://codeready-openshift-workspaces.apps.div.devcluster.openshift.com/f?url=https://github.com/divyanshiGupta/nationalparks-py/tree/master&policies.create=peruser',
10,
t,
true,
'https://codeready-openshift-workspaces.apps.div.devcluster.openshift.com/dashboard/assets/branding/loader.svg',
).type,
).toEqual('image');
});

it('expect default che icon when che icon url not available', () => {
expect(
routeDecoratorIcon(
'https://codeready-openshift-workspaces.apps.div.devcluster.openshift.com/f?url=https://github.com/divyanshiGupta/nationalparks-py/tree/master&policies.create=peruser',
10,
t,
true,
).type,
).toEqual(CheIcon);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,14 @@ export const routeDecoratorIcon = (
radius: number,
t: TFunction,
cheEnabled?: boolean,
cheIconURL?: string,
): React.ReactElement => {
if (cheEnabled && routeURL) {
return <CheIcon style={{ fontSize: radius }} />;
return cheIconURL ? (
<image xlinkHref={cheIconURL} width={radius} height={radius} />
) : (
<CheIcon style={{ fontSize: radius }} />
);
}
switch (detectGitType(routeURL)) {
case GitTypes.invalid:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useK8sWatchResource } from '@console/internal/components/utils/k8s-watc
import { K8sResourceKind, referenceForModel } from '@console/internal/module/k8s';
import { ConsoleLinkModel } from '@console/internal/models';
import { routeDecoratorIcon } from '@console/dev-console/src/components/import/render-utils';
import { getCheURL, getEditURL } from '../../../../../utils';
import { getCheDecoratorData, getEditURL } from '../../../../../utils';
import Decorator from './Decorator';

interface DefaultDecoratorProps {
Expand All @@ -23,12 +23,12 @@ const EditDecorator: React.FC<DefaultDecoratorProps> = ({ element, radius, x, y
kind: referenceForModel(ConsoleLinkModel),
optional: true,
});
const cheURL = getCheURL(consoleLinks);
const { cheURL, cheIconURL } = getCheDecoratorData(consoleLinks);
const workloadData = element.getData().data;
const { editURL, vcsURI, vcsRef } = workloadData;
const cheEnabled = !!cheURL;
const editUrl = editURL || getEditURL(vcsURI, vcsRef, cheURL);
const repoIcon = routeDecoratorIcon(editUrl, radius, t, cheEnabled);
const repoIcon = routeDecoratorIcon(editUrl, radius, t, cheEnabled, cheIconURL);

if (!repoIcon) {
return null;
Expand Down
14 changes: 12 additions & 2 deletions frontend/packages/topology/src/utils/topology-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,21 @@ export const WORKLOAD_TYPES = [
'pods',
];

export type CheDecoratorData = {
cheURL?: string;
cheIconURL?: string;
};

export const getServiceBindingStatus = ({ FLAGS }: RootState): boolean =>
FLAGS.get(ALLOW_SERVICE_BINDING_FLAG);

export const getCheURL = (consoleLinks: K8sResourceKind[]) =>
_.get(_.find(consoleLinks, ['metadata.name', 'che']), 'spec.href', '');
export const getCheDecoratorData = (consoleLinks: K8sResourceKind[]): CheDecoratorData => {
const cheConsoleLink = _.find(consoleLinks, ['metadata.name', 'che']);
return {
cheURL: cheConsoleLink?.spec?.href,
cheIconURL: cheConsoleLink?.spec?.applicationMenu?.imageURL,
};
};

export const getEditURL = (vcsURI?: string, gitBranch?: string, cheURL?: string) => {
if (!vcsURI) {
Expand Down