Skip to content

Commit

Permalink
deleting-pvc-inside-pvc-page-the-status
Browse files Browse the repository at this point in the history
  • Loading branch information
cyril-ui-developer committed Jul 21, 2021
1 parent 7cf66c2 commit ae7c789
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
17 changes: 13 additions & 4 deletions frontend/public/components/modals/delete-pvc-modal.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as React from 'react';
import { useHistory } from 'react-router-dom';
import { Stack, StackItem } from '@patternfly/react-core';
import { Trans, useTranslation } from 'react-i18next';
import { HandlePromiseProps, withHandlePromise } from '../utils';
import { HandlePromiseProps, withHandlePromise, resourceListPathFromModel } from '../utils';
import { getName, YellowExclamationTriangleIcon } from '@console/shared';
import { useResolvedExtensions } from '@console/dynamic-plugin-sdk/src/api/useResolvedExtensions';
import { isPVCDelete, PVCDelete } from '@console/dynamic-plugin-sdk/src/extensions/pvc';
Expand All @@ -12,15 +13,16 @@ import {
ModalSubmitFooter,
ModalComponentProps,
} from '../factory';
import { k8sKill, PersistentVolumeClaimKind } from '@console/internal/module/k8s';
import { k8sKill, PersistentVolumeClaimKind, K8sKind } from '@console/internal/module/k8s';
import { PersistentVolumeClaimModel } from '../../models';

const DeletePVCModal = withHandlePromise<DeletePVCModalProps>((props) => {
const { pvc, inProgress, errorMessage, handlePromise, close, cancel } = props;
const { pvc, inProgress, errorMessage, handlePromise, close, cancel, kind } = props;
const [pvcDeleteExtensions] = useResolvedExtensions<PVCDelete>(isPVCDelete);
const pvcName = getName(pvc);
const { t } = useTranslation();
const pvcMetadata = { metadata: { ...pvc?.metadata } };
const history = useHistory();

const submit = (e) => {
e.preventDefault();
Expand All @@ -30,7 +32,12 @@ const DeletePVCModal = withHandlePromise<DeletePVCModalProps>((props) => {
({ properties: { predicate, onPVCKill } }) =>
predicate(pvcMetadata) && onPVCKill(pvcMetadata),
);
return handlePromise(Promise.all([promise, ...extensionPromises]), close);

handlePromise(Promise.all([promise, ...extensionPromises]), () => {
close();
// Redirect to resourcce list page if the resouce is deleted.
history.push(resourceListPathFromModel(kind, pvc?.metadata?.namespace));
});
};

const alertComponents = pvcDeleteExtensions.map(
Expand Down Expand Up @@ -72,6 +79,8 @@ const DeletePVCModal = withHandlePromise<DeletePVCModalProps>((props) => {

export type DeletePVCModalProps = {
pvc: PersistentVolumeClaimKind;
redirectTo?: string;
kind: K8sKind;
} & ModalComponentProps &
HandlePromiseProps;

Expand Down
9 changes: 6 additions & 3 deletions frontend/public/components/persistent-volume-claim.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,14 @@ const menuActions = [
ModifyLabels,
ModifyAnnotations,
Edit,
(kind, obj) => ({
(kind, pvc) => ({
label: i18next.t('public~Delete PersistentVolumeClaim'),
callback: () =>
deletePVCModal({
pvc: obj,
kind,
pvc,
}),
accessReview: asAccessReview(kind, obj, 'delete'),
accessReview: asAccessReview(kind, pvc, 'delete'),
}),
];

Expand Down Expand Up @@ -431,9 +432,11 @@ export const PersistentVolumeClaimsPage = (props) => {
/>
);
};

export const PersistentVolumeClaimsDetailsPage = (props) => (
<DetailsPage
{...props}
getResourceStatus={(pvc) => (pvc.metadata.deletionTimestamp ? 'Terminating' : pvc.status.phase)}
menuActions={menuActions}
pages={[
navFactory.details(Details),
Expand Down

0 comments on commit ae7c789

Please sign in to comment.