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 Jul 6, 2021
1 parent 8135af4 commit 3516f7c
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ const SubMenuContent: React.FC<GroupMenuContentProps> = ({ option, onClick }) =>

type ActionMenuContentProps = {
options: MenuOption[];
onClick: () => void;
onClick?: () => void;
focusItem?: MenuOption;
};

Expand Down Expand Up @@ -151,12 +151,14 @@ const ActionMenuContent: React.FC<ActionMenuContentProps> = ({ options, onClick,
);
default:
return (
<ActionMenuItem
key={option.id}
action={option as Action}
onClick={onClick}
autoFocus={focusItem ? option === focusItem : undefined}
/>
<div className="pf-c-dropdown__menu-item">
<ActionMenuItem
key={option.id}
action={option as Action}
onClick={onClick}
autoFocus={focusItem ? option === focusItem : undefined}
/>
</div>
);
}
})}
Expand Down
10 changes: 10 additions & 0 deletions frontend/packages/helm-plugin/console-extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@
"required": ["OPENSHIFT_HELM"]
}
},
{
"type": "console.action/provider",
"properties": {
"contextId": "topology-actions",
"provider": { "$codeRef": "actions.useHelmActionProviderForTopology" }
},
"flags": {
"required": ["OPENSHIFT_HELM"]
}
},
{
"type": "console.navigation/href",
"properties": {
Expand Down
19 changes: 19 additions & 0 deletions frontend/packages/helm-plugin/src/actions/providers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import * as React from 'react';
import { GraphElement, Node } from '@patternfly/react-topology';
import { useTranslation } from 'react-i18next';
import { getResource } from '@console/topology/src/utils';
import { TYPE_HELM_RELEASE } from '../topology/components/const';
import { getHelmDeleteAction, getHelmRollbackAction, getHelmUpgradeAction } from './creators';
import { HelmActionsScope } from './types';

Expand All @@ -16,3 +19,19 @@ export const useHelmActionProvider = (scope: HelmActionsScope) => {

return [actions, true, undefined];
};

export const useHelmActionProviderForTopology = (element: GraphElement) => {
const nodeType = element.getType();
const scope = React.useMemo(() => {
const releaseName = element.getLabel();
const { namespace } = getResource(element as Node).metadata;
return {
releaseName,
namespace,
actionOrigin: 'topology',
};
}, [element]);
const actions = useHelmActionProvider(scope);
if (nodeType !== TYPE_HELM_RELEASE) return [[], true, undefined];
return actions;
};
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import * as React from 'react';
import {
Node,
GraphElement,
withDragNode,
withSelection,
withDndDrop,
withCreateConnector,
} from '@patternfly/react-topology';
import { kebabOptionsToMenu } from '@console/internal/components/utils';
import { contextMenuActions } from '@console/topology/src/actions/contextMenuActions';
import {
WorkloadNode,
noRegroupWorkloadContextMenu,
createMenuItems,
createConnectorCallback,
NodeComponentProps,
nodeDragSourceSpec,
Expand All @@ -21,21 +19,17 @@ import {
CreateConnector,
} from '@console/topology/src/components/graph-view';
import { withEditReviewAccess } from '@console/topology/src/utils';
import { helmReleaseActions } from '../actions/helmReleaseActions';
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,
): React.ComponentType<{ element: GraphElement }> | undefined => {
switch (type) {
case TYPE_HELM_RELEASE:
return withSelection({ controlled: true })(
withContextMenu(helmReleaseContextMenu)(withNoDrop()(HelmRelease)),
withContextMenu(contextMenuActions)(withNoDrop()(HelmRelease)),
);
case TYPE_HELM_WORKLOAD:
return withCreateConnector(
Expand Down
14 changes: 14 additions & 0 deletions frontend/packages/topology/src/actions/contextMenuActions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import * as React from 'react';
import { Node } from '@patternfly/react-topology';
import { ActionsLoader } from '@console/shared';
import ActionMenuContent from '@console/shared/src/components/actions/menu/ActionMenuContent';

export const contextMenuActions = (element: Node): React.ReactElement[] => {
return [
<ActionsLoader contextId="topology-actions" scope={element}>
{(loader) => {
return loader.loaded && <ActionMenuContent options={loader.options} />;
}}
</ActionsLoader>,
];
};

0 comments on commit 3516f7c

Please sign in to comment.