diff --git a/locales/en/plugin__odf-console.json b/locales/en/plugin__odf-console.json index 6ffb51beb..6d428dd92 100644 --- a/locales/en/plugin__odf-console.json +++ b/locales/en/plugin__odf-console.json @@ -204,16 +204,13 @@ "Secure your application by assigning a policy from the available policy templates.": "Secure your application by assigning a policy from the available policy templates.", "Manage data policy": "Manage data policy", "Assign a policy to protect the application and to ensure a quick recovery.": "Assign a policy to protect the application and to ensure a quick recovery.", - "Policy": "Policy", - "PersistentVolumeClaim": "PersistentVolumeClaim", - "Review and assign": "Review and assign", - "Assign": "Assign", "New policy assigned to application.": "New policy assigned to application.", "Unable to assign policy to application.": "Unable to assign policy to application.", - "Next": "Next", - "Back": "Back", "Assign policy nav": "Assign policy nav", "Assign policy content": "Assign policy content", + "Assign": "Assign", + "Next": "Next", + "Back": "Back", "Manage list view alert": "Manage list view alert", "Confirm unassign": "Confirm unassign", "All placements": "All placements", @@ -233,12 +230,12 @@ "No activity": "No activity", "No assigned data policy found": "No assigned data policy found", "Delete": "Delete", + "Required": "Required", "Select a placement": "Select a placement", "{{count}} selected_one": "{{count}} selected", "{{count}} selected_other": "{{count}} selected", "Select labels": "Select labels", "Use PVC label selectors to effortlessly specify the application resources that need protection.": "Use PVC label selectors to effortlessly specify the application resources that need protection.", - "If no label is provided, all PVCs will be protected. Define your preferences to protect specific resources.": "If no label is provided, all PVCs will be protected. Define your preferences to protect specific resources.", "Application resource": "Application resource", "Add application resource": "Add application resource", "Select a policy": "Select a policy", @@ -288,6 +285,9 @@ "minutes": "minutes", "hours": "hours", "days": "days", + "Policy": "Policy", + "PersistentVolumeClaim": "PersistentVolumeClaim", + "Review and assign": "Review and assign", "{{async}}, interval: {{interval}}": "{{async}}, interval: {{interval}}", "In use: {{targetClusters}}": "In use: {{targetClusters}}", "Used: {{targetClusters}}": "Used: {{targetClusters}}", @@ -1155,6 +1155,5 @@ "Cannot change resource name (original: \"{{name}}\", updated: \"{{newName}}\").": "Cannot change resource name (original: \"{{name}}\", updated: \"{{newName}}\").", "Cannot change resource namespace (original: \"{{namespace}}\", updated: \"{{newNamespace}}\").": "Cannot change resource namespace (original: \"{{namespace}}\", updated: \"{{newNamespace}}\").", "Cannot change resource kind (original: \"{{original}}\", updated: \"{{updated}}\").": "Cannot change resource kind (original: \"{{original}}\", updated: \"{{updated}}\").", - "Cannot change API group (original: \"{{apiGroup}}\", updated: \"{{newAPIGroup}}\").": "Cannot change API group (original: \"{{apiGroup}}\", updated: \"{{newAPIGroup}}\").", - "Required": "Required" + "Cannot change API group (original: \"{{apiGroup}}\", updated: \"{{newAPIGroup}}\").": "Cannot change API group (original: \"{{apiGroup}}\", updated: \"{{newAPIGroup}}\")." } diff --git a/packages/mco/components/modals/app-manage-policies/assign-policy-view.tsx b/packages/mco/components/modals/app-manage-policies/assign-policy-view.tsx index 93b022fa5..77429cee4 100644 --- a/packages/mco/components/modals/app-manage-policies/assign-policy-view.tsx +++ b/packages/mco/components/modals/app-manage-policies/assign-policy-view.tsx @@ -1,7 +1,6 @@ import * as React from 'react'; import { createRefFromK8Resource } from '@odf/mco/utils'; import { ModalBody } from '@odf/shared/modals/Modal'; -import { getName } from '@odf/shared/selectors'; import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook'; import { getErrorMessage } from '@odf/shared/utils'; import { TFunction } from 'i18next'; @@ -25,6 +24,8 @@ import { DataPolicyType, PlacementType, } from './utils/types'; +import { AssignPolicySteps, AssignPolicyStepsNames } from '@odf/mco/constants'; +import { AssignPolicyViewFooter } from './helper/assign-policy-view-footer'; export const createSteps = ( workloadNamespace: string, @@ -32,7 +33,7 @@ export const createSteps = ( matchingPolicies: DRPolicyType[], state: AssignPolicyViewState, stepIdReached: number, - isAssignDisabled: boolean, + isValidationEnabled: boolean, t: TFunction, setPolicy: (policy?: DataPolicyType) => void, setDRPlacementControls: ( @@ -41,40 +42,36 @@ export const createSteps = ( ): WizardStep[] => [ { id: 1, - name: t('Policy'), + name: AssignPolicyStepsNames(t)[AssignPolicySteps.Policy], component: ( ), - enableNext: !!getName(state.policy), }, { id: 2, - name: t('PersistentVolumeClaim'), + name: AssignPolicyStepsNames(t)[AssignPolicySteps.PersistentVolumeClaim], component: ( ), canJumpTo: stepIdReached >= 2, - enableNext: !!state.policy?.placementControlInfo?.length, }, { id: 3, - name: t('Review and assign'), + name: AssignPolicyStepsNames(t)[AssignPolicySteps.ReviewAndAssign], component: , - nextButtonText: t('Assign'), canJumpTo: stepIdReached >= 3, - enableNext: !isAssignDisabled, - hideBackButton: isAssignDisabled, - hideCancelButton: isAssignDisabled, }, ]; @@ -89,16 +86,7 @@ export const AssignPolicyView: React.FC = ({ }) => { const { t } = useCustomTranslation(); const [stepIdReached, setStepIdReached] = React.useState(1); - const [isAssignDisabled, setAssignDisabled] = React.useState(false); - - const onNext = ({ id }: WizardStep) => { - if (id) { - if (typeof id === 'string') { - id = parseInt(id, 10); - } - setStepIdReached(stepIdReached < id ? id : stepIdReached); - } - }; + const [isValidationEnabled, setEnableValidation] = React.useState(false); const setPolicy = (policy: DataPolicyType = null) => dispatch({ @@ -116,8 +104,7 @@ export const AssignPolicyView: React.FC = ({ payload: drPlacementControls, }); - const assignPolicy = () => { - setAssignDisabled(true); + const onSubmit = () => { const updateContext = ( title: string, description: string, @@ -160,32 +147,38 @@ export const AssignPolicyView: React.FC = ({ }); }; + const onClose = () => { + setModalContext(ModalViewContext.POLICY_LIST_VIEW); + // reset policy info + setPolicy(); + }; + return ( { - setModalContext(ModalViewContext.POLICY_LIST_VIEW); - // reset policy info - setPolicy(); - }} steps={createSteps( applicaitonInfo.workloadNamespace, applicaitonInfo.placements, matchingPolicies, state, stepIdReached, - isAssignDisabled, + isValidationEnabled, t, setPolicy, setDRPlacementControls )} - onNext={onNext} + footer={ + + } height={450} /> diff --git a/packages/mco/components/modals/app-manage-policies/helper/assign-policy-view-footer.tsx b/packages/mco/components/modals/app-manage-policies/helper/assign-policy-view-footer.tsx new file mode 100644 index 000000000..6610a049f --- /dev/null +++ b/packages/mco/components/modals/app-manage-policies/helper/assign-policy-view-footer.tsx @@ -0,0 +1,111 @@ +import * as React from 'react'; +import { TFunction } from 'i18next'; +import { + Button, + WizardContextType, + WizardContext, + WizardFooter, +} from '@patternfly/react-core'; +import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook'; +import { AssignPolicySteps, AssignPolicyStepsNames } from '@odf/mco/constants'; +import { DRPlacementControlType, DataPolicyType } from '../utils/types'; +import { getName } from '@odf/shared/selectors'; + +const isPVCSelectorFound = (placementControlInfo?: DRPlacementControlType[]) => + !!placementControlInfo?.every((drpc) => !!drpc?.pvcSelector?.length); + +const canJumpToNextStep = ( + stepName: string, + dataPolicy: DataPolicyType, + t: TFunction +) => { + switch (stepName) { + case AssignPolicyStepsNames(t)[AssignPolicySteps.Policy]: + return !!getName(dataPolicy); + case AssignPolicyStepsNames(t)[AssignPolicySteps.PersistentVolumeClaim]: + return ( + !!dataPolicy?.placementControlInfo?.length && + isPVCSelectorFound(dataPolicy?.placementControlInfo) + ); + default: + return false; + } +}; + +export const AssignPolicyViewFooter: React.FC = ({ + dataPolicy, + stepIdReached, + setStepIdReached, + onSubmit, + onCancel, + setEnableValidation, +}) => { + const { t } = useCustomTranslation(); + const [requestInProgress, setRequestInProgress] = React.useState(false); + const { activeStep, onNext, onBack } = + React.useContext(WizardContext); + + const stepId = activeStep.id as number; + const stepName = activeStep.name as string; + + const moveToNextStep = () => { + setEnableValidation(true); + if (canJumpToNextStep(stepName, dataPolicy, t)) { + setStepIdReached(stepIdReached <= stepId ? stepId + 1 : stepIdReached); + onNext(); + setEnableValidation(false); + } + }; + + const handleNext = async () => { + switch (stepName) { + case AssignPolicyStepsNames(t)[AssignPolicySteps.ReviewAndAssign]: + setRequestInProgress(true); + await onSubmit(); + setRequestInProgress(false); + break; + default: + moveToNextStep(); + } + }; + + return ( + + + {/* Disabling the back button for the first step (Policy) in wizard */} + + + + ); +}; + +type AssignPolicyViewFooterProps = { + dataPolicy: DataPolicyType; + stepIdReached: number; + setStepIdReached: React.Dispatch>; + onSubmit: () => void; + onCancel: () => void; + setEnableValidation: React.Dispatch>; +}; diff --git a/packages/mco/components/modals/app-manage-policies/helper/pvc-details-wizard-content.tsx b/packages/mco/components/modals/app-manage-policies/helper/pvc-details-wizard-content.tsx index 41e510c8c..4a88aebc3 100644 --- a/packages/mco/components/modals/app-manage-policies/helper/pvc-details-wizard-content.tsx +++ b/packages/mco/components/modals/app-manage-policies/helper/pvc-details-wizard-content.tsx @@ -14,8 +14,6 @@ import { import { ObjectReference } from '@openshift-console/dynamic-plugin-sdk'; import * as _ from 'lodash-es'; import { - Alert, - AlertVariant, Button, Form, FormGroup, @@ -124,6 +122,7 @@ const PairElement: React.FC = ({ placementNames, labels, tags, + isValidationEnabled, createPlacementControlInfo, updatePlacementControlInfo, }: extraProps = extraProps; @@ -163,7 +162,15 @@ const PairElement: React.FC = ({ return (
-
+ = ({ )} placeholderText={t('Select a placement')} onChange={onChangePlacement} + required + validated={ + isValidationEnabled && !selectedPlacement ? 'error' : 'default' + } /> -
-
+ + = ({ : t('Select labels') } variant={SelectVariant.checkbox} + required + validated={ + isValidationEnabled && !selectedLabels?.length ? 'error' : 'default' + } /> -
-
+ + -
+
); }; @@ -216,6 +239,7 @@ export const PVCDetailsWizardContent: React.FC = unProtectedPlacements, policyRef, workloadNamespace, + isValidationEnabled, setDRPlacementControls, }) => { const { t } = useCustomTranslation(); @@ -295,34 +319,23 @@ export const PVCDetailsWizardContent: React.FC = )} - - - - - setTags(nameValuePairs)} - PairElementComponent={PairElement} - nameString={t('Application resource')} - valueString={t('PVC label selector')} - addString={t('Add application resource')} - isAddDisabled={tags.length !== selectedPlacementControls.length} - extraProps={{ - placementNames, - labels, - tags, - createPlacementControlInfo, - updatePlacementControlInfo, - }} - /> - + setTags(nameValuePairs)} + PairElementComponent={PairElement} + nameString={t('Application resource')} + valueString={t('PVC label selector')} + addString={t('Add application resource')} + isAddDisabled={tags.length !== selectedPlacementControls.length} + extraProps={{ + placementNames, + labels, + tags, + isValidationEnabled, + createPlacementControlInfo, + updatePlacementControlInfo, + }} + /> ); }; @@ -333,6 +346,7 @@ type extraProps = { placementNames: string[]; labels: string[]; tags: TagsType; + isValidationEnabled: boolean; createPlacementControlInfo: (placementName: string, index: number) => void; updatePlacementControlInfo: (labels: string[], index: number) => void; }; @@ -342,6 +356,7 @@ type PVCDetailsWizardContentProps = { unProtectedPlacements: PlacementType[]; policyRef: ObjectReference; workloadNamespace: string; + isValidationEnabled: boolean; setDRPlacementControls: ( drPlacementControls: DRPlacementControlType[] ) => void; diff --git a/packages/mco/components/modals/app-manage-policies/helper/select-policy-wizard-content.tsx b/packages/mco/components/modals/app-manage-policies/helper/select-policy-wizard-content.tsx index 16d3f7268..7de06248b 100644 --- a/packages/mco/components/modals/app-manage-policies/helper/select-policy-wizard-content.tsx +++ b/packages/mco/components/modals/app-manage-policies/helper/select-policy-wizard-content.tsx @@ -14,23 +14,27 @@ const findPolicy = (name: string, dataPolicies: DRPolicyType[]) => dataPolicies.find((policy) => getName(policy) === name); export const SelectPolicyWizardContent: React.FC = - ({ policy, matchingPolicies, setPolicy }) => { + ({ policy, matchingPolicies, isValidationEnabled, setPolicy }) => { const { t } = useCustomTranslation(); + const name = getName(policy); return (
{ - if (getName(policy) !== value) { + if (name !== value) { setPolicy(findPolicy(value, matchingPolicies)); } }} @@ -43,5 +47,6 @@ export const SelectPolicyWizardContent: React.FC type SelectPolicyWizardContentProps = { policy: DataPolicyType; matchingPolicies: DRPolicyType[]; + isValidationEnabled: boolean; setPolicy: (policy: DataPolicyType) => void; }; diff --git a/packages/mco/constants/disaster-recovery.ts b/packages/mco/constants/disaster-recovery.ts index cfbca1c84..c03249fbd 100644 --- a/packages/mco/constants/disaster-recovery.ts +++ b/packages/mco/constants/disaster-recovery.ts @@ -67,3 +67,15 @@ export const SYNC_SCHEDULE_DISPLAY_TEXT = ( [TIME_UNITS.Hours]: t('hours'), [TIME_UNITS.Days]: t('days'), }); + +// Asisgn policy wizard steps +export enum AssignPolicySteps { + Policy = 'policy', + PersistentVolumeClaim = 'persistent-volume-claim', + ReviewAndAssign = 'review-and-assign', +} +export const AssignPolicyStepsNames = (t: TFunction) => ({ + [AssignPolicySteps.Policy]: t('Policy'), + [AssignPolicySteps.PersistentVolumeClaim]: t('PersistentVolumeClaim'), + [AssignPolicySteps.ReviewAndAssign]: t('Review and assign'), +}); diff --git a/packages/shared/src/dropdown/singleselectdropdown.tsx b/packages/shared/src/dropdown/singleselectdropdown.tsx index b22444c2d..99ae8dcdc 100644 --- a/packages/shared/src/dropdown/singleselectdropdown.tsx +++ b/packages/shared/src/dropdown/singleselectdropdown.tsx @@ -63,4 +63,6 @@ export type SingleSelectDropdownProps = { onFilter?: SelectProps['onFilter']; hasInlineFilter?: SelectProps['hasInlineFilter']; isDisabled?: boolean; + validated?: 'success' | 'warning' | 'error' | 'default'; + required?: boolean; };