-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bulk unassign data policy for application
Signed-off-by: Gowtham Shanmugasundaram <[email protected]>
- Loading branch information
1 parent
d0202d1
commit 15ced70
Showing
6 changed files
with
229 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
packages/mco/components/modals/app-manage-policies/helper/messages.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import * as React from 'react'; | ||
import { useCustomTranslation } from '@odf/shared/useCustomTranslationHook'; | ||
import { TFunction } from 'i18next'; | ||
import { | ||
Alert, | ||
AlertVariant, | ||
Button, | ||
ButtonVariant, | ||
} from '@patternfly/react-core'; | ||
import { ModalActionContext, PolicyListViewState } from '../utils/reducer'; | ||
|
||
const AlertMessage: React.FC<AlertMessageType> = (props) => { | ||
const { title, variant, children, t } = props; | ||
return ( | ||
<Alert | ||
area-label={t('Manage list view alert')} | ||
title={title} | ||
variant={variant} | ||
isInline | ||
className="odf-alert" | ||
> | ||
{children} | ||
</Alert> | ||
); | ||
}; | ||
|
||
export const ListViewMessages: React.FC<ListViewMessagesType> = (props) => { | ||
const { t } = useCustomTranslation(); | ||
const modalActionContext = props?.state?.modalActionContext; | ||
|
||
return ( | ||
<React.Fragment> | ||
{(!!props?.state?.error && ( | ||
<AlertMessage | ||
title={t('Unable to unassign selected policies for the application.')} | ||
variant={AlertVariant.danger} | ||
t={t} | ||
> | ||
{props?.state?.error} | ||
</AlertMessage> | ||
)) || | ||
(modalActionContext === ModalActionContext.UN_ASSIGNING_POLICIES && ( | ||
<AlertMessage | ||
title={t( | ||
'Selected policies ({{ count }}) will be removed for your application. This may have some affect on other applications sharing the placement.', | ||
{ count: props?.state?.policies?.length } | ||
)} | ||
variant={AlertVariant.warning} | ||
t={t} | ||
> | ||
<Button variant={ButtonVariant.link} onClick={props?.OnConfirm}> | ||
{t('Confirm unassign')}{' '} | ||
</Button> | ||
<Button variant={ButtonVariant.link} onClick={props?.OnCancel}> | ||
{t('Cancel')} | ||
</Button> | ||
</AlertMessage> | ||
)) || | ||
(modalActionContext === | ||
ModalActionContext.UN_ASSIGN_POLICIES_SUCCEEDED && ( | ||
<AlertMessage | ||
title={t('Selected policies unassigned for the application.')} | ||
variant={AlertVariant.success} | ||
t={t} | ||
/> | ||
))} | ||
</React.Fragment> | ||
); | ||
}; | ||
|
||
export type ListViewMessagesType = { | ||
state: PolicyListViewState; | ||
OnCancel: () => void; | ||
OnConfirm: () => void; | ||
}; | ||
|
||
type AlertMessageType = { | ||
title: string; | ||
variant: AlertVariant; | ||
children?: React.ReactNode; | ||
t: TFunction; | ||
}; |
33 changes: 33 additions & 0 deletions
33
packages/mco/components/modals/app-manage-policies/helper/view-panel.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import * as React from 'react'; | ||
import { Text } from '@patternfly/react-core'; | ||
|
||
export const ViewPanelHeader: React.FC<ViewPanelHeaderProps> = ({ | ||
title, | ||
children, | ||
}) => { | ||
return ( | ||
<div className="mco-manage-policies__panelHeader"> | ||
<Text component="h3"> {title} </Text> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
export const ViewPanelContent: React.FC<ViewPanelContentProps> = ({ | ||
children, | ||
}) => { | ||
return ( | ||
<div className="mco-manage-policies__panelContent--col-padding"> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
type ViewPanelHeaderProps = { | ||
title: React.ReactNode; | ||
children?: React.ReactNode; | ||
}; | ||
|
||
type ViewPanelContentProps = { | ||
children?: React.ReactNode; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
packages/mco/components/modals/app-manage-policies/utils/k8s-utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { ACMPlacementModel, DRPlacementControlModel } from '@odf/mco//models'; | ||
import { | ||
HUB_CLUSTER_NAME, | ||
PROTECTED_APP_ANNOTATION_WO_SLASH, | ||
} from '@odf/mco/constants'; | ||
import { getName, getNamespace } from '@odf/shared/selectors'; | ||
import { K8sResourceKind } from '@odf/shared/types'; | ||
import { k8sDelete, k8sPatch } from '@openshift-console/dynamic-plugin-sdk'; | ||
import { DRPlacementControlType } from './types'; | ||
|
||
export const unAssignPromises = (drpcs: DRPlacementControlType[]) => { | ||
const promises: Promise<K8sResourceKind>[] = []; | ||
const patch = [ | ||
{ | ||
op: 'remove', | ||
path: `/metadata/annotations/${PROTECTED_APP_ANNOTATION_WO_SLASH}`, | ||
}, | ||
]; | ||
|
||
drpcs?.forEach((drpc) => { | ||
promises.push( | ||
k8sPatch({ | ||
model: ACMPlacementModel, | ||
resource: { | ||
metadata: { | ||
name: getName(drpc?.placementInfo), | ||
namespace: getNamespace(drpc?.placementInfo), | ||
}, | ||
}, | ||
data: patch, | ||
cluster: HUB_CLUSTER_NAME, | ||
}) | ||
); | ||
|
||
promises.push( | ||
k8sDelete({ | ||
model: DRPlacementControlModel, | ||
resource: { | ||
metadata: { | ||
name: getName(drpc), | ||
namespace: getNamespace(drpc), | ||
}, | ||
}, | ||
requestInit: null, | ||
json: null, | ||
cluster: HUB_CLUSTER_NAME, | ||
}) | ||
); | ||
}); | ||
|
||
return promises; | ||
}; |