Skip to content

Commit

Permalink
Allow editing plan hooks and mappings only for specific plan's statuses
Browse files Browse the repository at this point in the history
Reference: https://issues.redhat.com/browse/MTV-1713

Enable editing of plan hooks (under Hooks tab) or plan mappings (under Mappings tab) fields only for the following plan statuses:
'Unknown', 'Canceled', 'Error', 'Failed', 'vmError', 'Warning', 'Ready '

Disable the edit option for those Hooks, Mappings tabs fields for all other plan statuses.

Signed-off-by: Sharon Gratch <[email protected]>
  • Loading branch information
sgratch committed Dec 2, 2024
1 parent 0047638 commit 052d676
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@
"Boot from the second hard drive": "Boot from the second hard drive",
"Boot from the second partition on the first hard drive": "Boot from the second partition on the first hard drive",
"Boot from the second partition on the second hard drive": "Boot from the second partition on the second hard drive",
"Button is disabled since the plan status does not enable editing.": "Button is disabled since the plan status does not enable editing.",
"Button is disabled until a change is detected.": "Button is disabled until a change is detected.",
"CA certificate": "CA certificate",
"CA certificate - disabled when 'Skip certificate validation' is selected": "CA certificate - disabled when 'Skip certificate validation' is selected",
"CA certificate - leave empty to use system CA certificates": "CA certificate - leave empty to use system CA certificates",
Expand All @@ -74,7 +76,7 @@
"Clear all filters": "Clear all filters",
"Click the pencil for setting provider web UI link": "Click the pencil for setting provider web UI link",
"Click the update credentials button to save your changes, button is disabled until a change is detected.": "Click the update credentials button to save your changes, button is disabled until a change is detected.",
"Click the update hooks button to save your changes, button is disabled until a change is detected.": "Click the update hooks button to save your changes, button is disabled until a change is detected.",
"Click the update hooks button to save your changes.": "Click the update hooks button to save your changes.",
"Click the update mappings button to save your changes, button is disabled until a change is detected.": "Click the update mappings button to save your changes, button is disabled until a change is detected.",
"Click to select a different provider from the list.": "Click to select a different provider from the list.",
"Click to unselect.": "Click to unselect.",
Expand Down Expand Up @@ -481,7 +483,7 @@
"The certificate is not a valid PEM-encoded X.509 certificate": "The certificate is not a valid PEM-encoded X.509 certificate",
"The chosen provider is no longer available.": "The chosen provider is no longer available.",
"The current certificate does not match the certificate fetched from URL. Manually validate the fingerprint before proceeding.": "The current certificate does not match the certificate fetched from URL. Manually validate the fingerprint before proceeding.",
"The edit mappings button is disabled if the plan started running and at least one virtual machine was migrated successfully.": "The edit mappings button is disabled if the plan started running and at least one virtual machine was migrated successfully.",
"The edit mappings button is disabled if the plan started running and at least one virtual machine was migrated successfully or when the plan status does not enable editing.": "The edit mappings button is disabled if the plan started running and at least one virtual machine was migrated successfully or when the plan status does not enable editing.",
"The interval in minutes for precopy. Default value is 60.": "The interval in minutes for precopy. Default value is 60.",
"The interval in seconds for snapshot pooling. Default value is 10.": "The interval in seconds for snapshot pooling. Default value is 10.",
"The limit for CPU usage by the controller, specified in milliCPU. Default value is 500m.": "The limit for CPU usage by the controller, specified in milliCPU. Default value is 500m.",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { useEffect, useReducer } from 'react';
import { Base64 } from 'js-base64';
import SectionHeading from 'src/components/headers/SectionHeading';
import { isPlanEditable } from 'src/modules/Plans/utils';
import { AlertMessageForModals } from 'src/modules/Providers/modals';
import { useForkliftTranslation } from 'src/utils/i18n';

Expand Down Expand Up @@ -58,14 +59,27 @@ export const PlanHooks: React.FC<{ name: string; namespace: string }> = ({ name,
});
};

const buttonHelperMsg = () => {
let updateButtonDisabledMsg = '';

if (!isPlanEditable(plan))
updateButtonDisabledMsg = t(
'Button is disabled since the plan status does not enable editing.',
);
else if (!state.hasChanges)
updateButtonDisabledMsg = t('Button is disabled until a change is detected.');

return t('Click the update hooks button to save your changes.') + ' ' + updateButtonDisabledMsg;
};

const HooksTabAction = (
<>
<Flex>
<FlexItem>
<Button
variant="primary"
onClick={onUpdate}
isDisabled={!state.hasChanges}
isDisabled={!state.hasChanges || !isPlanEditable(plan)}
isLoading={state.isLoading}
>
{t('Update hooks')}
Expand All @@ -78,13 +92,8 @@ export const PlanHooks: React.FC<{ name: string; namespace: string }> = ({ name,
</Button>
</FlexItem>
</Flex>

<HelperText className="forklift-section-plan-helper-text">
<HelperTextItem variant="indeterminate">
{t(
'Click the update hooks button to save your changes, button is disabled until a change is detected.',
)}
</HelperTextItem>
<HelperTextItem variant="indeterminate">{buttonHelperMsg()}</HelperTextItem>
</HelperText>

<Divider />
Expand Down Expand Up @@ -231,7 +240,7 @@ export const PlanHooks: React.FC<{ name: string; namespace: string }> = ({ name,
value={state.postHook?.spec?.image}
type="url"
onChange={(e, v) => onChangePostHookImage(v, e)}
aria-label="pre hook image"
aria-label="post hook image"
/>
<HelperText>
<HelperTextItem>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { ReactNode, useReducer, useState } from 'react';
import { isPlanEditable } from 'src/modules/Plans/utils';
import { InventoryNetwork } from 'src/modules/Providers/hooks/useNetworks';
import { InventoryStorage } from 'src/modules/Providers/hooks/useStorages';
import { useForkliftTranslation } from 'src/utils/i18n';
Expand Down Expand Up @@ -35,8 +36,8 @@ import Pencil from '@patternfly/react-icons/dist/esm/icons/pencil-alt-icon';
import { Mapping, MappingList } from '../../components';
import {
canDeleteAndPatchPlanHooks,
hasPlanEditable,
hasPlanMappingsChanged,
hasSomeCompleteRunningVMs,
mapSourceNetworksIdsToLabels,
mapSourceStoragesIdsToLabels,
mapTargetNetworksIdsToLabels,
Expand Down Expand Up @@ -564,7 +565,7 @@ export const PlanMappingsSection: React.FC<PlanMappingsSectionProps> = ({

const PlanMappingsSectionViewMode: React.FC = () => {
const { t } = useForkliftTranslation();
const DisableEditMappings = !hasPlanEditable(plan);
const DisableEditMappings = hasSomeCompleteRunningVMs(plan) || !isPlanEditable(plan);

return (
<>
Expand All @@ -583,7 +584,7 @@ export const PlanMappingsSection: React.FC<PlanMappingsSectionProps> = ({
<HelperText className="forklift-section-plan-helper-text">
<HelperTextItem variant="indeterminate">
{t(
'The edit mappings button is disabled if the plan started running and at least one virtual machine was migrated successfully.',
'The edit mappings button is disabled if the plan started running and at least one virtual machine was migrated successfully or when the plan status does not enable editing.',
)}
</HelperTextItem>
</HelperText>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { V1beta1Plan } from '@kubev2v/types';

export const hasPlanEditable = (plan: V1beta1Plan) => {
export const hasSomeCompleteRunningVMs = (plan: V1beta1Plan) => {
const planHasNeverStarted = !plan.status?.migration?.started ? true : false;

const migrationHasSomeCompleteRunningVMs =
Expand All @@ -10,5 +10,5 @@ export const hasPlanEditable = (plan: V1beta1Plan) => {
vm.phase !== 'Completed',
).length > 0 || false;

return planHasNeverStarted || !migrationHasSomeCompleteRunningVMs;
return !planHasNeverStarted && migrationHasSomeCompleteRunningVMs;
};
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ export * from './constants';
export * from './getInventoryApiUrl';
export * from './getValueByJsonPath';
export * from './hasPipelineCompleted';
export * from './hasPlanEditable';
export * from './hasPlanMappingsChanged';
export * from './hasSomeCompleteRunningVMs';
export * from './hasTaskCompleted';
export * from './mapMappingsIdsToLabels';
export * from './patchPlanMappingsData';
Expand Down

0 comments on commit 052d676

Please sign in to comment.