Skip to content

Commit

Permalink
Migrate Helm actions on topology to use the new extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
debsmita1 committed Jun 22, 2021
1 parent 5909e2e commit 3ea481d
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@ import {
StatusBox,
ActionsMenu,
} from '@console/internal/components/utils';
import { ActionsLoader } from '@console/shared';
import TopologyGroupResourcesPanel from '@console/topology/src/components/side-bar/TopologyGroupResourcesPanel';
import { getResource } from '@console/topology/src/utils/topology-utils';
import HelmReleaseOverview from '../components/details-page/overview/HelmReleaseOverview';
import { helmReleaseActions } from './actions/helmReleaseActions';
import { HelmActionOrigins } from '../types/helm-types';
import TopologyHelmReleaseNotesPanel from './TopologyHelmReleaseNotesPanel';

type PropsFromState = {
Expand Down Expand Up @@ -50,6 +51,12 @@ export const ConnectedTopologyHelmReleasePanel: React.FC<TopologyHelmReleasePane
const name = helmRelease.getLabel();
const { namespace } = getResource(helmRelease).metadata;

const actionsScope = {
releaseName: name,
namespace,
actionOrigin: HelmActionOrigins.topology,
};

const detailsComponent = !secret
? () => (
<StatusBox
Expand All @@ -75,7 +82,6 @@ export const ConnectedTopologyHelmReleasePanel: React.FC<TopologyHelmReleasePane

const releaseNotesComponent = () => <TopologyHelmReleaseNotesPanel releaseNotes={releaseNotes} />;

const actions = helmReleaseActions(helmRelease);
return (
<div className="overview__sidebar-pane resource-overview">
<div className="overview__sidebar-pane-head resource-overview__heading">
Expand All @@ -91,11 +97,11 @@ export const ConnectedTopologyHelmReleasePanel: React.FC<TopologyHelmReleasePane
</Link>
)}
</div>
{actions?.length && (
<div className="co-actions">
<ActionsMenu actions={helmReleaseActions(helmRelease)} />
</div>
)}
<div className="co-actions">
<ActionsLoader contextId="helm-actions" scope={actionsScope}>
{(actions, loaded) => loaded && <ActionsMenu actions={actions} />}
</ActionsLoader>
</div>
</h1>
</div>
<SimpleTabNav
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import * as React from 'react';
import { Node } from '@patternfly/react-topology';
import { kebabOptionsToMenu } from '@console/internal/components/utils';
import { ActionsLoader } from '@console/shared';
import { createMenuItems } from '@console/topology/src/components/graph-view';
import { getResource } from '@console/topology/src/utils';
import { HelmActionOrigins } from '../../types/helm-types';

export const helmReleaseContextMenu = (element: Node): any => {
const { namespace } = getResource(element).metadata;
const actionsScope = {
releaseName: element.getLabel(),
namespace,
actionOrigin: HelmActionOrigins.topology,
};

return (
<ActionsLoader contextId="helm-actions" scope={actionsScope}>
{(actions, loaded) => loaded && createMenuItems(kebabOptionsToMenu(actions))}
</ActionsLoader>
);
};
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
import * as React from 'react';
import {
Node,
GraphElement,
withDragNode,
withSelection,
withDndDrop,
withCreateConnector,
} from '@patternfly/react-topology';
import { kebabOptionsToMenu } from '@console/internal/components/utils';
import {
WorkloadNode,
noRegroupWorkloadContextMenu,
createMenuItems,
createConnectorCallback,
NodeComponentProps,
nodeDragSourceSpec,
Expand All @@ -21,13 +18,10 @@ import {
CreateConnector,
} from '@console/topology/src/components/graph-view';
import { withEditReviewAccess } from '@console/topology/src/utils';
import { helmReleaseActions } from '../actions/helmReleaseActions';
import { helmReleaseContextMenu } from '../actions/helmReleaseContextMenu';
import { TYPE_HELM_RELEASE, TYPE_HELM_WORKLOAD } from './const';
import HelmRelease from './HelmRelease';

export const helmReleaseContextMenu = (element: Node) =>
createMenuItems(kebabOptionsToMenu(helmReleaseActions(element)));

export const getHelmComponentFactory = (
kind,
type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
isGraph,
} from '@patternfly/react-topology';
import i18next from 'i18next';
import * as _ from 'lodash';
import {
history,
KebabItem,
Expand All @@ -32,6 +33,16 @@ const onKebabOptionClick = (option: KebabOption) => {
if (option.href) {
history.push(option.href);
}
if (_.isFunction(option.cta)) {
option.cta();
} else if (_.isObject(option.cta)) {
const { href, external } = option.cta;
if (external) {
window.open(href);
} else {
history.push(href);
}
}
};

export const createMenuItems = (actions: KebabMenuOption[]) =>
Expand Down
11 changes: 11 additions & 0 deletions frontend/public/components/utils/dropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,17 @@ class ActionsMenuDropdown_ extends DropdownMixin {
history.push(option.href);
}

if (_.isFunction(option.cta)) {
option.cta();
} else if (_.isObject(option.cta)) {
const { href, external } = option.cta;
if (external) {
window.open(href);
} else {
history.push(href);
}
}

this.hide();
};
return (
Expand Down
1 change: 1 addition & 0 deletions frontend/public/components/utils/kebab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ export type KebabOption = {
path?: string;
pathKey?: string;
icon?: React.ReactNode;
cta?: (() => void) | { href: string; external?: boolean };
};

export type KebabAction = (
Expand Down

0 comments on commit 3ea481d

Please sign in to comment.