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 8, 2021
1 parent fec42d0 commit cd76a8c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
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
12 changes: 12 additions & 0 deletions frontend/packages/topology/src/actions/contextMenuActions.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import * as React from 'react';
import { Node } from '@patternfly/react-topology';
import { ActionsLoader } from '@console/shared';
import { createContextMenuItems } from '../components/graph-view';

export const contextMenuActions = (element: Node): React.ReactElement[] => {
return [
<ActionsLoader key="topology" contextId="topology-actions" scope={element}>
{(loader) => loader.loaded && createContextMenuItems(loader.options)}
</ActionsLoader>,
];
};
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 { Action } from '@console/dynamic-plugin-sdk/src';
import {
history,
KebabItem,
Expand All @@ -15,6 +16,14 @@ import {
kebabOptionsToMenu,
isKebabSubMenu,
} from '@console/internal/components/utils';
import {
GroupedMenuOption,
MenuOption,
MenuOptionType,
orderExtensionBasedOnInsertBeforeAndAfter,
} from '@console/shared/src';
import ActionMenuItem from '@console/shared/src/components/actions/menu/ActionMenuItem';
import { getMenuOptionType } from '@console/shared/src/components/actions/menu/menu-utils';
import { graphActions } from '../../../actions/graphActions';
import { groupActions } from '../../../actions/groupActions';
import { workloadActions } from '../../../actions/workloadActions';
Expand Down Expand Up @@ -51,6 +60,39 @@ export const createMenuItems = (actions: KebabMenuOption[]) =>
),
);

export const createContextMenuItems = (actions: MenuOption[]) => {
const sortedOptions = orderExtensionBasedOnInsertBeforeAndAfter(actions);
return sortedOptions.map((option: MenuOption) => {
const optionType = getMenuOptionType(option);
switch (optionType) {
case MenuOptionType.SUB_MENU:
return (
<ContextSubMenuItem label={option.label} key={option.id}>
{createContextMenuItems((option as GroupedMenuOption).children)}
</ContextSubMenuItem>
);
case MenuOptionType.GROUP_MENU:
return (
<>
<div className="pf-c-dropdown__group-title">{option.label}</div>
{createContextMenuItems((option as GroupedMenuOption).children)}
</>
);
default:
return (
<ContextMenuItem
key={option.id}
component={
<div className="pf-c-dropdown__menu-item">
<ActionMenuItem action={option as Action} />
</div>
}
/>
);
}
});
};

export const workloadContextMenu = (element: Node) =>
createMenuItems(
kebabOptionsToMenu(
Expand Down

0 comments on commit cd76a8c

Please sign in to comment.