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

Fixes #37895 - Handle version removal for multi-CV activation key #11246

Merged
merged 1 commit into from
Dec 19, 2024
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ def plan(content_view_environment, options)
end

content_view_environment.activation_keys.each do |key|
plan_action(ActivationKey::Reassign, key, options[:key_content_view_id], options[:key_environment_id])
if key.multi_content_view_environment?
key.content_view_environments = key.content_view_environments - [content_view_environment]
else
plan_action(ActivationKey::Reassign, key, options[:key_content_view_id], options[:key_environment_id])
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import React, { useState, useContext } from 'react';
import { useDispatch, useSelector } from 'react-redux';
import useDeepCompareEffect from 'use-deep-compare-effect';
import { ExpandableSection, SelectOption } from '@patternfly/react-core';
import { ExpandableSection, SelectOption, Alert, AlertActionCloseButton } from '@patternfly/react-core';
import { STATUS } from 'foremanReact/constants';
import { translate as __ } from 'foremanReact/common/I18n';
import EnvironmentPaths from '../../../../components/EnvironmentPaths/EnvironmentPaths';
import getContentViews from '../../../../ContentViewsActions';
import { selectContentViewError, selectContentViews, selectContentViewStatus } from '../../../../ContentViewSelectors';
import { selectCVActivationKeys } from '../../../ContentViewDetailSelectors';
import AffectedActivationKeys from '../affectedActivationKeys';
import DeleteContext from '../DeleteContext';
import ContentViewSelect from '../../../../components/ContentViewSelect/ContentViewSelect';
Expand All @@ -17,7 +18,9 @@ const CVReassignActivationKeysForm = () => {
const contentViewsInEnvResponse = useSelector(selectContentViews);
const contentViewsInEnvStatus = useSelector(selectContentViewStatus);
const contentViewsInEnvError = useSelector(selectContentViewError);
const activationKeysResponse = useSelector(selectCVActivationKeys);
const cvInEnvLoading = contentViewsInEnvStatus === STATUS.PENDING;
const [alertDismissed, setAlertDismissed] = useState(false);
const [cvSelectOpen, setCVSelectOpen] = useState(false);
const [cvSelectOptions, setCvSelectionOptions] = useState([]);
const [showActivationKeys, setShowActivationKeys] = useState(false);
Expand Down Expand Up @@ -72,6 +75,9 @@ const CVReassignActivationKeysForm = () => {
contentViewsInEnvError, selectedEnvForAK, setSelectedCVForAK, setSelectedCVNameForAK,
cvInEnvLoading, selectedCVForAK, cvId, versionEnvironments, selectedEnvSet]);

const multiCVWarning = activationKeysResponse?.results?.some?.(key =>
key.multi_content_view_environment);

const fetchSelectedCVName = (id) => {
const { results } = contentViewsInEnvResponse ?? { };
return results.filter(cv => cv.id === id)[0]?.name;
Expand Down Expand Up @@ -102,8 +108,21 @@ const CVReassignActivationKeysForm = () => {
cvSelectOptions,
});

const multiCVRemovalInfo = __('This environment is used in one or more multi-environment activation keys. The environment will simply be removed from the multi-environment keys. The content view and lifecycle environment you select here will only apply to single-environment activation keys. See hammer activation-key --help for more details.');

return (
<>
{!alertDismissed && multiCVWarning && (
<Alert
ouiaId="multi-cv-warning-alert"
variant="warning"
isInline
title={__('Warning')}
actionClose={<AlertActionCloseButton onClose={() => setAlertDismissed(true)} />}
>
<p>{multiCVRemovalInfo}</p>
</Alert>
)}
<EnvironmentPaths
userCheckedItems={selectedEnvForAK}
setUserCheckedItems={setSelectedEnvForAK}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ const CVVersionRemoveReview = () => {
const activationKeysResponse = useSelector(state => selectCVActivationKeys(state, cvId));
const hostsResponse = useSelector(state => selectCVHosts(state, cvId));
const { results: hostResponse } = hostsResponse;
const { results: akResponse } = activationKeysResponse;
const { results: akResponse = [] } = activationKeysResponse || {};
const selectedEnv = versionEnvironments.filter(env => selectedEnvSet.has(env.id));
const versionDeleteInfo = __(`Version ${versionNameToRemove} will be deleted from all environments. It will no longer be available for promotion.`);
const removalNotice = __(`Version ${versionNameToRemove} will be removed from the environments listed below, and will remain available for later promotion. ` +
'Changes listed below will be effective after clicking Remove.');

const multiCVActivationKeys = akResponse.filter(key => key.multi_content_view_environment);
const multiCVActivationKeysCount = multiCVActivationKeys.length;

const singleCVActivationKeysCount = akResponse.length - multiCVActivationKeysCount;

return (
<>
<WizardHeader title={__('Review details')} />
Expand Down Expand Up @@ -62,11 +67,23 @@ const CVVersionRemoveReview = () => {
{affectedActivationKeys &&
<>
<h3>{__('Activation keys')}</h3>
<Flex>
<FlexItem><ExclamationTriangleIcon /></FlexItem>
<FlexItem><p>{__(`${pluralize(akResponse.length, 'activation key')} will be moved to content view ${selectedCVNameForAK} in `)}</p></FlexItem>
<FlexItem><Label isTruncated color="purple" href={`/lifecycle_environments/${selectedEnvForAK[0].id}`}>{selectedEnvForAK[0].name}</Label></FlexItem>
</Flex>
{singleCVActivationKeysCount > 0 && (
<Flex>
<FlexItem><ExclamationTriangleIcon /></FlexItem>
<FlexItem><p>{__(`${pluralize(singleCVActivationKeysCount, 'activation key')} will be moved to content view ${selectedCVNameForAK} in `)}</p></FlexItem>
<FlexItem><Label isTruncated color="purple" href={`/lifecycle_environments/${selectedEnvForAK[0].id}`}>{selectedEnvForAK[0].name}</Label></FlexItem>
</Flex>
)}
{multiCVActivationKeysCount > 0 && (
<Flex>
<FlexItem><ExclamationTriangleIcon /></FlexItem>
<FlexItem>
<p>
{__(`Content view environment will be removed from ${pluralize(multiCVActivationKeysCount, 'multi-environment activation key')}.`)}
</p>
</FlexItem>
</Flex>
)}
</>}
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const AffectedActivationKeys = ({
const columnHeaders = [
__('Name'),
__('Environment'),
__('Multi Content View Environment'),
];
const emptyContentTitle = __('No matching activation keys found.');
const emptyContentBody = __("Given criteria doesn't match any activation keys. Try changing your rule.");
Expand Down Expand Up @@ -65,12 +66,15 @@ const AffectedActivationKeys = ({
</Tr>
</Thead>
<Tbody>
{results?.map(({ name, id, environment }) => (
{results?.map(({
name, id, environment, multi_content_view_environment: multiContentViewEnvironment,
}) => (
<Tr ouiaId={id} key={id}>
<Td>
<a rel="noreferrer" target="_blank" href={urlBuilder(`activation_keys/${id}`, '')}>{name}</a>
</Td>
<Td><EnvironmentLabels environments={environment} /></Td>
<Td>{ multiContentViewEnvironment ? 'Yes' : 'No' }</Td>
</Tr>
))
}
Expand Down
Loading