Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions frontend/e2e/pages/dev-console/cluster-customization-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import BasePage from '../base-page';
export class ClusterCustomizationPage extends BasePage {
async navigateToCustomize(): Promise<void> {
await this.goTo('/k8s/cluster/operator.openshift.io~v1~Console/cluster');
await this.waitForLoadingComplete(10_000);
await this.robustClick(this.page.getByTestId('actions-menu-button'));
await this.robustClick(this.page.getByTestId('Customize'));
}

Expand Down
1 change: 1 addition & 0 deletions frontend/e2e/pages/secrets-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ export class SecretsPage extends BasePage {
asType: 'environment' | 'volume',
options?: { prefix?: string; mountPath?: string },
): Promise<void> {
await this.robustClick(this.page.getByTestId('actions-menu-button'));
await this.robustClick(this.page.getByTestId('Add Secret to workload'));
await this.modal.waitForOpen();

Expand Down
16 changes: 2 additions & 14 deletions frontend/e2e/pages/web-terminal-config-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,8 @@ export class WebTerminalConfigPage extends BasePage {
async navigateToWebTerminalConfig(): Promise<void> {
await this.goTo('/k8s/cluster/operator.openshift.io~v1~Console/cluster');
await this.waitForLoadingComplete(10_000);
const customizeButton = this.page.getByRole('button', { name: 'Customize' });
// eslint-disable-next-line eslint-js/no-restricted-syntax
await customizeButton
.first()
.waitFor({ state: 'visible', timeout: 30_000 })
.catch(() => {});
if (await customizeButton.first().isVisible()) {
await this.robustClick(customizeButton.first());
} else {
const actionsMenu = this.page.getByTestId('actions-menu-button');
await this.robustClick(actionsMenu);
const customizeAction = this.page.locator('[data-test-action="Customize"]:not([disabled])');
await this.robustClick(customizeAction);
}
await this.robustClick(this.page.getByTestId('actions-menu-button'));
await this.robustClick(this.page.locator('[data-test-action="Customize"]:not([disabled])'));
await this.waitForLoadingComplete(10_000);
await this.clickWebTerminalTab();
}
Expand Down
13 changes: 13 additions & 0 deletions frontend/packages/console-app/console-extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -2840,6 +2840,19 @@
"provider": { "$codeRef": "serviceAccountProvider.useServiceAccountActionsProvider" }
}
},
{
"type": "console.action/resource-provider",
"properties": {
"model": {
"group": "operator.openshift.io",
"version": "v1",
"kind": "Console"
},
"provider": {
"$codeRef": "consoleOperatorConfigProvider.useConsoleOperatorConfigActionsProvider"
}
}
},
{
"type": "console.action/resource-provider",
"properties": {
Expand Down
1 change: 1 addition & 0 deletions frontend/packages/console-app/locales/en/console-app.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"Add new users to group {{name}}": "Add new users to group {{name}}",
"Add PodDisruptionBudget": "Add PodDisruptionBudget",
"Add RoleBinding": "Add RoleBinding",
"Add Secret to workload": "Add Secret to workload",
"Add shared applications, services, event sources, or source-to-image builders to your project. Cluster administrators can customize the content made available in the catalog.": "Add shared applications, services, event sources, or source-to-image builders to your project. Cluster administrators can customize the content made available in the catalog.",
"Add storage": "Add storage",
"Add to favorites": "Add to favorites",
Expand Down
3 changes: 2 additions & 1 deletion frontend/packages/console-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@
"machineConfigPoolProvider": "src/actions/providers/machine-config-pool-provider.ts",
"serviceMonitorProvider": "src/actions/providers/service-monitor-provider.ts",
"userProvider": "src/actions/providers/user-provider.ts",
"serviceAccountProvider": "src/actions/providers/service-account-provider.ts"
"serviceAccountProvider": "src/actions/providers/service-account-provider.ts",
"consoleOperatorConfigProvider": "src/actions/providers/console-operator-config-provider.ts"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { act } from '@testing-library/react';
import type { RoutePage } from '@console/dynamic-plugin-sdk/src/extensions/pages';
import { renderWithProviders } from '@console/shared/src/test-utils/unit-test-utils';
import {
addLoadedPluginFromManifest,
createLocalPluginManifest,
createTestPluginStore,
} from '../../components/console-operator/__tests__/pluginTestUtils';
} from '@console/shared/src/test-utils/plugin-test-utils';
import { renderWithProviders } from '@console/shared/src/test-utils/unit-test-utils';
import {
newPluginCSPViolationEvent,
sameHostname,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { createRoutesFromElements, matchRoutes } from 'react-router';
import type { RoutePage } from '@console/dynamic-plugin-sdk/src/extensions/pages';
import { isRoutePage } from '@console/dynamic-plugin-sdk/src/extensions/pages';
import type { LoadedExtension } from '@console/dynamic-plugin-sdk/src/types';
import { renderWithProviders } from '@console/shared/src/test-utils/unit-test-utils';
import {
addLoadedPluginFromManifest,
createLocalPluginManifest,
createTestPluginStore,
} from '../../components/console-operator/__tests__/pluginTestUtils';
} from '@console/shared/src/test-utils/plugin-test-utils';
import { renderWithProviders } from '@console/shared/src/test-utils/unit-test-utils';
import { useCSPViolationDetector } from '../../hooks/useCSPViolationDetector';
import { mapExtensionToRoutes } from '../../hooks/usePluginRoutes';
import { ToastContext } from '../../providers/toast/ToastContext';
Expand Down
1 change: 0 additions & 1 deletion frontend/packages/console-app/src/actions/hooks/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ export enum CommonActionCreator {
ModifyLabels = 'ModifyLabels',
ModifyAnnotations = 'ModifyAnnotations',
ModifyCount = 'ModifyCount',
ModifyPodSelector = 'ModifyPodSelector',
ModifyTolerations = 'ModifyTolerations',
ModifyTaints = 'ModifyTaints',
AddStorage = 'AddStorage',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { useCommonActions } from './useCommonActions';
* // Getting Build actions for Build resource
* const MyBuildComponent = ({ obj }) => {
* const actions = useBuildsActions(obj);
* return <Kebab actions={actions} />;
* return <ActionMenu actions={actions} />;
* };
*/
export const useBuildsActions = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,10 @@ import { CommonActionCreator } from './types';
*
* @param kind - The K8s model for the resource.
* @param resource - The specific resource instance for which to generate actions.
* @param [filterActions] - Optional. If provided, the returned object will contain only the specified actions.
* Specify which actions to include using CommonActionCreator enum values.
* If omitted, it will contain all common actions.
* @param editPath - Optional URL path used for editing the resource.
* @param filterActions - The actions to include, specified using CommonActionCreator enum values.
* The returned object contains only these actions.
* @param [message] - Optional message to display in the delete modal.
* @param [editPath] - Optional URL path used for editing the resource.
*
* This hook is robust to inline arrays/objects for the `filterActions` argument, so you do not need to memoize or define
* the array outside your component. The actions will only update if the actual contents of `filterActions` change, not just the reference.
Expand All @@ -41,7 +40,7 @@ import { CommonActionCreator } from './types';
export const useCommonActions = <T extends readonly CommonActionCreator[]>(
kind: K8sModel | undefined,
resource: K8sResourceKind | undefined,
filterActions?: T,
filterActions: T,
message?: ReactNode,
editPath?: string,
): [ActionObject<T>, boolean] => {
Expand Down Expand Up @@ -169,13 +168,8 @@ export const useCommonActions = <T extends readonly CommonActionCreator[]>(
return [actions, false];
}

// filter and initialize requested actions or construct list of all CommonActions
const actionsToInclude = memoizedFilterActions || Object.values(CommonActionCreator);

actionsToInclude.forEach((actionType) => {
if (factory[actionType]) {
actions[actionType] = factory[actionType]();
}
memoizedFilterActions.forEach((actionType) => {
actions[actionType] = factory[actionType]();
});

return [actions, true];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ import { useCommonActions } from './useCommonActions';
*
* @param kind - The K8s model for the resource.
* @param resource - The specific resource instance for which to generate the action.
* @param actionCreator - The single action creator to use.
* @param [message] - Optional message to display in the delete modal.
* @param editPath - Optional URL path used for editing the resource.
* @param [editPath] - Optional URL path used for editing the resource.
*
* This hook is robust to inline arguments, thanks to internal deep compare memoization.
*
Expand All @@ -22,8 +21,8 @@ import { useCommonActions } from './useCommonActions';
* @example
* // Getting common resource actions
* const MyResourceComponent = ({ kind, resource }) => {
* const modifyCountAction = useCommonResourceActions(kind, resource);
* return <Kebab actions={ actions } />;
* const actions = useCommonResourceActions(kind, resource);
* return <ActionMenu actions={actions} />;
* };
*/
export const useCommonResourceActions = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const startJobAccessReview = (obj: CronJobKind): AccessReviewResourceAttributes
* // Getting all actions for CronJob resource
* const MyCronJobComponent = ({ obj }) => {
* const actions = useCronJobActions(obj);
* return <Kebab actions={actions} />;
* return <ActionMenu actions={actions} />;
* };
*/
export const useCronJobActions = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const deploymentConfigRollout = (dc: K8sResourceKind): Promise<K8sResourceKind>
* // Getting EditDeployment and RestartRollout actions
* const MyDeploymentComponent = ({ kind, obj }) => {
* const [actions, isReady] = useDeploymentActions(kind, obj, [DeploymentActionCreator.EditDeployment, DeploymentActionCreator.RestartRollout] as const);
* return <Kebab actions={ isReady ? actions : []} />;
* return <ActionMenu actions={isReady ? [actions.EditDeployment, actions.RestartRollout] : []} />;
* };
*/
export const useDeploymentActions = <T extends readonly DeploymentActionCreator[]>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { JobActionCreator } from './types';
* // Getting all actions for Job resource
* const MyJobComponent = ({ obj }) => {
* const actions = useJobActions(obj);
* return <Kebab actions={actions} />;
* return <ActionMenu actions={actions} />;
* };
*/
export const useJobActions = (obj: JobKind, filterActions?: JobActionCreator[]): Action[] => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { MachineSetActionCreator } from './types';
* // Getting all actions for MachineSet resource
* const MyMachineSetComponent = ({ obj }) => {
* const actions = useMachineSetActions(obj);
* return <Kebab actions={actions} />;
* return <ActionMenu actions={actions} />;
* };
*/
export const useMachineSetActions = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { PVCActionCreator } from './types';
* // Getting ExpandPVC and PVCSnapshot actions for PVC resource
* const MyPVCComponent = ({ obj }) => {
* const actions = usePVCActions(obj, [PVCActionCreator.ExpandPVC, PVCActionCreator.PVCSnapshot]);
* return <Kebab actions={actions} />;
* return <ActionMenu actions={actions} />;
* };
*/
export const usePVCActions = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@ import { useOverlay } from '@console/dynamic-plugin-sdk/src/app/modal-support/us
import { useDeepCompareMemoize } from '@console/dynamic-plugin-sdk/src/utils/k8s/hooks/useDeepCompareMemoize';
import { LazyRollbackModalOverlay } from '@console/internal/components/modals';
import { DeploymentModel } from '@console/internal/models';
import type { ReplicaSetKind, K8sModel } from '@console/internal/module/k8s';
import type { ReplicaSetKind } from '@console/internal/module/k8s';
import { getOwnerNameByKind } from '@console/shared/src/utils/resource-utils';
import { ReplicaSetActionCreator } from './types';

/**
* A React hook for retrieving actions related to ReplicaSet resources.
*
* @param {K8sModel} kind - The K8s model for the resource.
* @param {ReplicaSetKind} resource - The specific ReplicaSet resource instance.
* @param {ReplicaSetActionCreator[]} [filterActions] - Optional. If provided, returns only specified actions.
* @returns {Action[]} An array containing the generated actions.
*/
export const useReplicaSetActions = (
kind: K8sModel,
resource: ReplicaSetKind,
filterActions?: ReplicaSetActionCreator[],
): Action[] => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { VolumeSnapshotActionCreator } from './types';
* // Getting all actions for VS resources
* const MyVolumeSnapshotComponent = ({ resource }) => {
* const actions = useVolumeSnapshotActions(resource);
* return <Kebab actions={actions} />;
* return <ActionMenu actions={actions} />;
* };
*/
export const useVolumeSnapshotActions = (
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import type { ExtensionHook } from '@console/dynamic-plugin-sdk/src/api/common-types';
import type { Action } from '@console/dynamic-plugin-sdk/src/extensions/actions';
import { asAccessReview } from '@console/internal/components/utils/rbac';
import { ConsoleOperatorConfigModel } from '@console/internal/models';
import type { K8sResourceKind } from '@console/internal/module/k8s';

export const useConsoleOperatorConfigActionsProvider: ExtensionHook<Action[], K8sResourceKind> = (
resource,
) => {
const { t } = useTranslation('console-app');

const actions = useMemo<Action[]>(
() => [
{
id: 'customize-console',
label: t('Customize'),
cta: { href: '/cluster-configuration' },
accessReview: asAccessReview(ConsoleOperatorConfigModel, resource, 'patch'),
},
],
[resource, t],
);

return [actions, true, undefined];
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import { useCommonActions } from '../hooks/useCommonActions';

export const usePrometheusActionsProvider = (resource: K8sResourceKind) => {
const [kindObj, inFlight] = useK8sModel(referenceFor(resource));
const [commonActions] = useCommonActions<CommonActionCreator[]>(kindObj, resource, [
const [commonActions] = useCommonActions(kindObj, resource, [
CommonActionCreator.ModifyLabels,
CommonActionCreator.ModifyCount,
CommonActionCreator.ModifyAnnotations,
CommonActionCreator.Edit,
CommonActionCreator.Delete,
]);
] as const);

const actions = useMemo(() => Object.values(commonActions), [commonActions]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export const useReplicaSetActionsProvider = (resource: ReplicaSetKind) => {
CommonActionCreator.AddStorage,
] as const);
const commonResourceActions = useCommonResourceActions(kindObj, resource);
const replicaSetActions = useReplicaSetActions(kindObj, resource);
const replicaSetActions = useReplicaSetActions(resource);

const actions = useMemo(
() =>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { useMemo } from 'react';
import { useTranslation } from 'react-i18next';
import type { Action } from '@console/dynamic-plugin-sdk/src/extensions/actions';
import { useAddSecretToWorkloadModalLauncher } from '@console/internal/components/modals/add-secret-to-workload';
import { resourceObjPath } from '@console/internal/components/utils/resource-link';
import type { SecretKind } from '@console/internal/module/k8s';
import { referenceFor } from '@console/internal/module/k8s';
import { useK8sModel } from '@console/shared/src/hooks/useK8sModel';
import { useCommonResourceActions } from '../hooks/useCommonResourceActions';

export const useSecretsActionsProvider = (resource: SecretKind) => {
const { t } = useTranslation('console-app');
const [kindObj, inFlight] = useK8sModel(referenceFor(resource));

const editPath = useMemo(
Expand All @@ -15,5 +19,23 @@ export const useSecretsActionsProvider = (resource: SecretKind) => {

const commonActions = useCommonResourceActions(kindObj, resource, undefined, editPath);

return [commonActions, !inFlight];
const addSecretToWorkloadProps = useMemo(
() => ({ secretName: resource.metadata?.name, namespace: resource.metadata?.namespace }),
[resource.metadata?.name, resource.metadata?.namespace],
);
const launchAddSecretToWorkload = useAddSecretToWorkloadModalLauncher(addSecretToWorkloadProps);

const actions = useMemo<Action[]>(
() => [
{
id: 'add-secret-to-workload',
label: t('Add Secret to workload'),
cta: () => launchAddSecretToWorkload(),
},
...commonActions,
],
[commonActions, launchAddSecretToWorkload, t],
);

return [actions, !inFlight];
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { breadcrumbsForGlobalConfig } from '@console/internal/components/cluster
import { DetailsForKind } from '@console/internal/components/default-resource';
import { DetailsPage } from '@console/internal/components/factory';
import { navFactory } from '@console/internal/components/utils/horizontal-nav';
import type { KebabAction } from '@console/internal/components/utils/kebab';
import { asAccessReview } from '@console/internal/components/utils/rbac';
import { ConsoleOperatorConfigModel } from '@console/internal/models';
import type { K8sResourceKindReference } from '@console/internal/module/k8s';
import { referenceForModel } from '@console/internal/module/k8s';
Expand All @@ -32,27 +30,11 @@ export const ConsoleOperatorConfigDetailsPage: FC<ComponentProps<typeof DetailsP
},
];

const menuActions: KebabAction[] = [
() => ({
// t('console-app~Customize')
labelKey: 'console-app~Customize',
labelKind: { kind: ConsoleOperatorConfigModel.kind },
dataTest: `Customize`,
href: '/cluster-configuration',
accessReview: asAccessReview(
ConsoleOperatorConfigModel,
{ spec: { name: 'cluster' } },
'patch',
),
}),
];

return (
<DetailsPage
{...props}
kind={consoleOperatorConfigReference}
pages={pages}
menuActions={menuActions}
breadcrumbsFor={() =>
breadcrumbsForGlobalConfig(ConsoleOperatorConfigModel.label, location.pathname)
}
Expand Down
Loading