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

Migrate Helm actions on topology to use the new extensions #9313

Merged
merged 1 commit into from
Jul 9, 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,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