Skip to content

Commit

Permalink
Unassign data policy for application
Browse files Browse the repository at this point in the history
Signed-off-by: Gowtham Shanmugasundaram <[email protected]>
  • Loading branch information
GowthamShanmugam committed Jun 28, 2023
1 parent 4241c81 commit b9c3b33
Show file tree
Hide file tree
Showing 15 changed files with 699 additions and 101 deletions.
20 changes: 18 additions & 2 deletions locales/en/plugin__odf-console.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,19 @@
"Assign policy to protect the application and ensure quick recovery. Unassign policy from an application when they no longer require to be managed.": "Assign policy to protect the application and ensure quick recovery. Unassign policy from an application when they no longer require to be managed.",
"Manage list view alert": "Manage list view alert",
"Confirm unassign": "Confirm unassign",
"All placements": "All placements",
"Policy configuration details": "Policy configuration details",
"Replication type": "Replication type",
"Sync interval": "Sync interval",
"Cluster": "Cluster",
"Replication status": "Replication status",
"Last sync {{time}}": "Last sync {{time}}",
"Application resources protected": "Application resources protected",
"placement": "placement",
"placements": "placements",
"PVC label selector": "PVC label selector",
"Policy type": "Policy type",
"Assigned on": "Assigned on",
"View configurations": "View configurations",
"Unassign policy": "Unassign policy",
"No activity": "No activity",
"Relocate in progress": "Relocate in progress",
Expand All @@ -212,6 +222,13 @@
"Unable to unassign all selected policies for the application.": "Unable to unassign all selected policies for the application.",
"My policies": "My policies",
"Assign policy": "Assign policy",
"Unassign policy will no longer DR protect your application, other applications sharing the same placement will also be affected.": "Unassign policy will no longer DR protect your application, other applications sharing the same placement will also be affected.",
"Policy unassigned for the application.": "Policy unassigned for the application.",
"Unable to unassign policy for the application.": "Unable to unassign policy for the application.",
"Confirm": "Confirm",
"Back": "Back",
"Unassign for all": "Unassign for all",
"Unassign": "Unassign",
"List all the connected applications under a policy.": "List all the connected applications under a policy.",
"Application name": "Application name",
"application name search": "application name search",
Expand Down Expand Up @@ -483,7 +500,6 @@
"Create new BucketClass": "Create new BucketClass",
"BucketClass is a CRD representing a class for buckets that defines tiering policies and data placements for an OBC.": "BucketClass is a CRD representing a class for buckets that defines tiering policies and data placements for an OBC.",
"Next": "Next",
"Back": "Back",
"Edit BucketClass Resource": "Edit BucketClass Resource",
"{{storeType}} represents a storage target to be used as the underlying storage for the data in Multicloud Object Gateway buckets.": "{{storeType}} represents a storage target to be used as the underlying storage for the data in Multicloud Object Gateway buckets.",
"What is a BackingStore?": "What is a BackingStore?",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,88 @@ import { StatusBox } from '@odf/shared/generic/status-box';
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook';
import { Modal, ModalVariant } from '@patternfly/react-core';
import { PolicyListView } from './policy-list-view';
import { UnAssignPolicyView } from './unassign-policy-view';
import {
ManagePolicyStateAction,
ManagePolicyStateType,
MessageType,
ModalActionContext,
ModalViewContext,
initialPolicyState,
managePolicyStateReducer,
ManagePolicyState,
} from './utils/reducer';
import { ApplicationType } from './utils/types';

export const AppManagePoliciesModal: React.FC<AppManagePoliciesModalProps> = ({
export const ModalBody: React.FC<ModalBodyProps> = ({
applicaitonInfo,
loaded,
loadError,
isOpen,
close,
state,
dispatch,
}) => {
const [state, dispatch] = React.useReducer(
managePolicyStateReducer,
initialPolicyState
);
const { t } = useCustomTranslation();

const setModalContext = (modalViewContext: ModalViewContext) => {
dispatch({
type: ManagePolicyStateType.SET_MODAL_VIEW_CONTEXT,
payload: modalViewContext,
});
};

const setModalActionContext = (modalViewContext: ModalActionContext) =>
const setModalActionContext = (
modalActionViewContext: ModalActionContext,
modalViewContext?: ModalViewContext
) =>
dispatch({
type: ManagePolicyStateType.SET_MODAL_ACTION_CONTEXT,
context: state.modalViewContext,
payload: modalViewContext,
context: modalViewContext || state.modalViewContext,
payload: modalActionViewContext,
});

const setMessage = (message: MessageType) => {
const setMessage = (
message: MessageType,
modalViewContext?: ModalViewContext
) => {
dispatch({
type: ManagePolicyStateType.SET_MESSAGE,
context: state.modalViewContext,
context: modalViewContext || state.modalViewContext,
payload: message,
});
};

return (
(state.modalViewContext === ModalViewContext.POLICY_LIST_VIEW && (
<PolicyListView
dataPolicyInfo={applicaitonInfo?.dataPolicies}
state={state.policyListView}
dispatch={dispatch}
setModalContext={setModalContext}
setModalActionContext={setModalActionContext}
setMessage={setMessage}
/>
)) ||
(state.modalViewContext === ModalViewContext.UNASSIGN_POLICY_VIEW && (
<UnAssignPolicyView
state={state.unAssignPolicyView}
dispatch={dispatch}
setModalContext={setModalContext}
setModalActionContext={setModalActionContext}
setMessage={setMessage}
/>
))
);
};

export const AppManagePoliciesModal: React.FC<AppManagePoliciesModalProps> = ({
applicaitonInfo,
loaded,
loadError,
isOpen,
close,
}) => {
const [state, dispatch] = React.useReducer(
managePolicyStateReducer,
initialPolicyState
);
const { t } = useCustomTranslation();

return (
<Modal
title={t('Manage Policy')}
Expand All @@ -61,27 +98,28 @@ export const AppManagePoliciesModal: React.FC<AppManagePoliciesModalProps> = ({
onClose={close}
>
{loaded && !loadError ? (
state.modalViewContext === ModalViewContext.POLICY_LIST_VIEW && (
<PolicyListView
dataPolicyInfo={applicaitonInfo?.dataPolicies}
state={state.policyListView}
dispatch={dispatch}
setModalContext={setModalContext}
setModalActionContext={setModalActionContext}
setMessage={setMessage}
/>
)
<ModalBody
applicaitonInfo={applicaitonInfo}
state={state}
dispatch={dispatch}
/>
) : (
<StatusBox loadError={loadError} loaded={loaded} />
)}
</Modal>
);
};

export type AppManagePoliciesModalProps = {
type AppManagePoliciesModalProps = {
applicaitonInfo: ApplicationType;
loaded: boolean;
loadError: any;
isOpen: boolean;
close?: () => void;
};

type ModalBodyProps = {
state: ManagePolicyState;
applicaitonInfo: ApplicationType;
dispatch: React.Dispatch<ManagePolicyStateAction>;
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@ import {
Button,
ButtonVariant,
} from '@patternfly/react-core';
import { ModalActionContext, PolicyListViewState } from '../utils/reducer';
import { CommonViewState, ModalActionContext } from '../utils/reducer';
import '../../../../style.scss';

const hasActionFailedOrSuceeded = (modalActionContext: ModalActionContext) =>
const hasActionTriggered = (modalActionContext: ModalActionContext) =>
[
ModalActionContext.UN_ASSIGN_POLICIES_SUCCEEDED,
ModalActionContext.UN_ASSIGN_POLICIES_FAILED,
ModalActionContext.UNASSIGN_POLICY_SUCCEEDED,
ModalActionContext.UN_ASSIGN_POLICIES_SUCCEEDED,
ModalActionContext.UN_ASSIGNING_POLICY,
].includes(modalActionContext);

const AlertMessage: React.FC<AlertMessageType> = ({
const AlertMessage: React.FC<AlertMessageProps> = ({
title,
variant,
children,
Expand All @@ -34,7 +37,7 @@ const AlertMessage: React.FC<AlertMessageType> = ({
);
};

export const ListViewMessages: React.FC<ListViewMessagesProps> = ({
export const Messages: React.FC<MessagesProps> = ({
state,
OnCancel,
OnConfirm,
Expand All @@ -56,7 +59,7 @@ export const ListViewMessages: React.FC<ListViewMessagesProps> = ({
</Button>
</AlertMessage>
)) ||
(hasActionFailedOrSuceeded(modalActionContext) && (
(hasActionTriggered(modalActionContext) && (
<AlertMessage
title={message.title}
variant={message?.variant || AlertVariant.info}
Expand All @@ -68,13 +71,13 @@ export const ListViewMessages: React.FC<ListViewMessagesProps> = ({
);
};

export type ListViewMessagesProps = {
state: PolicyListViewState;
OnCancel: () => void;
OnConfirm: () => void;
export type MessagesProps = {
state: CommonViewState;
OnCancel?: () => void;
OnConfirm?: () => void;
};

type AlertMessageType = {
type AlertMessageProps = {
title: string;
variant: AlertVariant;
children?: React.ReactNode;
Expand Down
Loading

0 comments on commit b9c3b33

Please sign in to comment.