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

add Channels, EventSources, OperatorBacked, HelmCharts menu action to Add To Project context menu #6838

Merged
merged 2 commits into from
Oct 14, 2020
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
22 changes: 21 additions & 1 deletion frontend/packages/dev-console/src/actions/add-resources.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import {
CatalogIcon,
CubeIcon,
DatabaseIcon,
LaptopCodeIcon,
BoltIcon,
} from '@patternfly/react-icons';
import { ImportOptions } from '../components/import/import-types';
import { KebabAction, createKebabAction } from '../utils/add-resources-menu-utils';
import HelmChartsIcon from '../components/helm/HelmChartsIcon';

export const allImportResourceAccess = 'allImportResourceAccess';
export const allCatalogImageResourceAccess = 'allCatalogImageResourceAccess';
Expand Down Expand Up @@ -45,12 +48,29 @@ export const fromDatabaseCatalog = createKebabAction(
ImportOptions.DATABASE,
);

export const fromSamples = createKebabAction('Samples', <LaptopCodeIcon />, ImportOptions.SAMPLES);

export const fromOperatorBacked = createKebabAction(
'Operator Backed',
<BoltIcon />,
ImportOptions.OPERATORBACKED,
);

export const fromHelmCharts = createKebabAction(
'Helm Charts',
<HelmChartsIcon style={{ height: '1em', width: '1em' }} />,
ImportOptions.HELMCHARTS,
);

export const addResourceMenu: KebabAction[] = [
fromSamples,
fromGit,
containerImage,
fromCatalog,
fromDockerfile,
fromCatalog,
fromDatabaseCatalog,
fromOperatorBacked,
fromHelmCharts,
];

export const addResourceMenuWithoutCatalog: KebabAction[] = [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import * as React from 'react';
import * as helmIcon from '@console/internal/imgs/logos/helm.svg';

type HelmChartsIconProps = {
className?: string;
style?: React.CSSProperties;
};

const HelmChartsIcon: React.FC<HelmChartsIconProps> = ({ className, style }) => (
<img className={className} style={style} src={helmIcon} alt="Helm Charts Logo" />
);

export default HelmChartsIcon;
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,10 @@ export enum ImportOptions {
DATABASE = 'DATABASE',
EVENTSOURCE = 'EVENTSOURCE',
EVENTPUBSUB = 'EVENTPUBSUB',
OPERATORBACKED = 'OPERATORBACKED',
HELMCHARTS = 'HELMCHARTS',
SAMPLES = 'SAMPLES',
EVENTCHANNEL = 'EVENTCHANNEL',
}

export interface HealthChecksData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('graphActions: ', () => {
createResourceAccess: [allCatalogImageResourceAccess, allImportResourceAccess],
};
const actions = graphActions(graphData);
expect(actions).toHaveLength(5);
expect(actions).toHaveLength(8);
});

it('should return the correct menu items when all only import resources are allowed', () => {
Expand All @@ -26,7 +26,7 @@ describe('graphActions: ', () => {
createResourceAccess: [allImportResourceAccess],
};
const actions = graphActions(graphData);
expect(actions).toHaveLength(4);
expect(actions).toHaveLength(7);
});

it('should return the correct menu items when minimal resources are allowed', () => {
Expand All @@ -36,7 +36,7 @@ describe('graphActions: ', () => {
createResourceAccess: [],
};
const actions = graphActions(graphData);
expect(actions).toHaveLength(2);
expect(actions).toHaveLength(5);
});

it('should return the correct menu items when connector source is passed and event source is disabled', () => {
Expand Down Expand Up @@ -65,4 +65,24 @@ describe('graphActions: ', () => {
expect(actions).toHaveLength(4);
expect(actions.filter((action) => action.label === 'Event Source')).toHaveLength(1);
});

it('should return the correct number of items when all permission are allowed and eventSource is enabled', () => {
const graphData: GraphData = {
eventSourceEnabled: true,
namespace: 'namespace',
createResourceAccess: [allCatalogImageResourceAccess, allImportResourceAccess],
};
const actions = graphActions(graphData);
expect(actions).toHaveLength(10);
});

it('should return the correct number of items when all permission are not allowed and eventSource is enabled', () => {
const graphData: GraphData = {
eventSourceEnabled: true,
namespace: 'namespace',
createResourceAccess: [],
};
const actions = graphActions(graphData);
expect(actions).toHaveLength(7);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,20 @@ export const getAddPageUrl = (
case ImportOptions.EVENTPUBSUB:
pageUrl = `/add/ns/${ns}`;
break;
case ImportOptions.OPERATORBACKED:
pageUrl = `/catalog/ns/${ns}`;
params.append('kind', JSON.stringify(['ClusterServiceVersion']));
break;
case ImportOptions.HELMCHARTS:
pageUrl = `/catalog/ns/${ns}`;
params.append('kind', JSON.stringify(['HelmChart']));
break;
case ImportOptions.SAMPLES:
pageUrl = `/samples/ns/${ns}`;
break;
case ImportOptions.EVENTCHANNEL:
pageUrl = `/channel/ns/${ns}`;
break;
default:
throw new Error('Invalid Import option provided');
}
Expand Down
21 changes: 21 additions & 0 deletions frontend/packages/knative-plugin/src/actions/add-channel.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as React from 'react';
import {
createKebabAction,
KebabAction,
} from '@console/dev-console/src/utils/add-resources-menu-utils';
import { ImportOptions } from '@console/dev-console/src/components/import/import-types';
import * as channelIcon from '../imgs/channel.svg';

const eventChannelStyles = {
width: '1em',
height: '1em',
};
const EventChannelIcon: React.FC = () => (
<img style={eventChannelStyles} src={channelIcon} alt="" />
);

export const addChannels: KebabAction = createKebabAction(
'Channel',
<EventChannelIcon />,
ImportOptions.EVENTCHANNEL,
);
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { Node } from '@patternfly/react-topology';
import { MenuOptions } from '@console/dev-console/src/utils/add-resources-menu-utils';
import { addResourceMenuWithoutCatalog } from '@console/dev-console/src/actions/add-resources';
import {
addResourceMenuWithoutCatalog,
addResourceMenu,
} from '@console/dev-console/src/actions/add-resources';
import { GraphData, getResource } from '@console/dev-console/src/components/topology';
import { referenceForModel } from '@console/internal/module/k8s';
import { addEventSource } from '../actions/add-event-source';
import { addTrigger } from '../actions/add-trigger';
import { addChannels } from '../actions/add-channel';
import { addSubscription } from '../actions/add-subscription';
import { addPubSubConnectionModal } from '../components/pub-sub/PubSubModalLauncher';
import { isEventingChannelResourceKind } from '../utils/fetch-dynamic-eventsources-utils';
Expand All @@ -21,6 +25,9 @@ export const getKnativeContextMenuAction = (
connectorSource?: Node,
): MenuOptions => {
if (!connectorSource) {
if (graphData.eventSourceEnabled) {
return [...addResourceMenu, addEventSource, addChannels];
}
return menu;
}
const sourceKind = connectorSource?.getData().data.kind;
Expand Down