UI: Added recursive param for soft deleting teams. (#7766)

* Changes made to soft delete request for teams with recursive param

* changed soft delete message for team delete

* Worked on comments

* Worked on comments
This commit is contained in:
Aniket Katkar 2022-09-28 17:29:41 +05:30 committed by GitHub
parent 962866a30e
commit ba1a7ca3b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 24 deletions

View File

@ -12,7 +12,6 @@
*/ */
import { AxiosRequestConfig, AxiosResponse } from 'axios'; import { AxiosRequestConfig, AxiosResponse } from 'axios';
import { isUndefined } from 'lodash';
import { Edge } from '../components/EntityLineage/EntityLineage.interface'; import { Edge } from '../components/EntityLineage/EntityLineage.interface';
import { WILD_CARD_CHAR } from '../constants/char.constants'; import { WILD_CARD_CHAR } from '../constants/char.constants';
import { SearchIndex } from '../enums/search.enum'; import { SearchIndex } from '../enums/search.enum';
@ -20,7 +19,6 @@ import { AirflowConfiguration } from '../generated/configuration/airflowConfigur
import { AuthenticationConfiguration } from '../generated/configuration/authenticationConfiguration'; import { AuthenticationConfiguration } from '../generated/configuration/authenticationConfiguration';
import { EntitiesCount } from '../generated/entity/utils/entitiesCount'; import { EntitiesCount } from '../generated/entity/utils/entitiesCount';
import { Paging } from '../generated/type/paging'; import { Paging } from '../generated/type/paging';
import { getURLWithQueryFields } from '../utils/APIUtils';
import { getCurrentUserId } from '../utils/CommonUtils'; import { getCurrentUserId } from '../utils/CommonUtils';
import { getSearchAPIQuery } from '../utils/SearchUtils'; import { getSearchAPIQuery } from '../utils/SearchUtils';
import APIClient from './index'; import APIClient from './index';
@ -222,25 +220,16 @@ export const deleteEntity = async (
entityType: string, entityType: string,
entityId: string, entityId: string,
isRecursive: boolean, isRecursive: boolean,
isSoftDelete = false isHardDelete = true
) => { ) => {
let path = ''; const params = {
hardDelete: isHardDelete,
recursive: isRecursive,
};
if (isSoftDelete) { return APIClient.delete(`/${entityType}/${entityId}`, {
path = getURLWithQueryFields(`/${entityType}/${entityId}`); params,
} else { });
const searchParams = new URLSearchParams({ hardDelete: `true` });
if (!isUndefined(isRecursive)) {
searchParams.set('recursive', `${isRecursive}`);
}
path = getURLWithQueryFields(
`/${entityType}/${entityId}`,
'',
`${searchParams.toString()}`
);
}
return APIClient.delete(path);
}; };
export const getAdvancedFieldOptions = ( export const getAdvancedFieldOptions = (

View File

@ -69,7 +69,10 @@ import {
} from '../../utils/PermissionsUtils'; } from '../../utils/PermissionsUtils';
import { getTeamsWithFqnPath } from '../../utils/RouterUtils'; import { getTeamsWithFqnPath } from '../../utils/RouterUtils';
import SVGIcons, { Icons } from '../../utils/SvgUtils'; import SVGIcons, { Icons } from '../../utils/SvgUtils';
import { filterChildTeams } from '../../utils/TeamUtils'; import {
filterChildTeams,
getDeleteMessagePostFix,
} from '../../utils/TeamUtils';
import { showErrorToast } from '../../utils/ToastUtils'; import { showErrorToast } from '../../utils/ToastUtils';
import { Button } from '../buttons/Button/Button'; import { Button } from '../buttons/Button/Button';
import Description from '../common/description/Description'; import Description from '../common/description/Description';
@ -879,6 +882,7 @@ const TeamDetailsV1 = ({
)} )}
{entityPermissions.EditAll && ( {entityPermissions.EditAll && (
<ManageButton <ManageButton
isRecursiveDelete
afterDeleteAction={afterDeleteAction} afterDeleteAction={afterDeleteAction}
allowSoftDelete={!currentTeam.deleted} allowSoftDelete={!currentTeam.deleted}
buttonClassName="tw-p-4" buttonClassName="tw-p-4"
@ -889,6 +893,14 @@ const TeamDetailsV1 = ({
} }
entityType="team" entityType="team"
extraDropdownContent={extraDropdownContent} extraDropdownContent={extraDropdownContent}
hardDeleteMessagePostFix={getDeleteMessagePostFix(
currentTeam.fullyQualifiedName || currentTeam.name,
'permanently'
)}
softDeleteMessagePostFix={getDeleteMessagePostFix(
currentTeam.fullyQualifiedName || currentTeam.name,
'soft'
)}
/> />
)} )}
</Space> </Space>

View File

@ -16,6 +16,8 @@ export interface DeleteWidgetModalProps {
onCancel: () => void; onCancel: () => void;
allowSoftDelete?: boolean; allowSoftDelete?: boolean;
deleteMessage?: string; deleteMessage?: string;
softDeleteMessagePostFix?: string;
hardDeleteMessagePostFix?: string;
entityName: string; entityName: string;
entityType: string; entityType: string;
isAdminUser?: boolean; isAdminUser?: boolean;

View File

@ -31,6 +31,8 @@ const DeleteWidgetModal = ({
allowSoftDelete = true, allowSoftDelete = true,
visible, visible,
deleteMessage, deleteMessage,
softDeleteMessagePostFix = '',
hardDeleteMessagePostFix = '',
entityName, entityName,
entityType, entityType,
onCancel, onCancel,
@ -48,7 +50,7 @@ const DeleteWidgetModal = ({
); );
const prepareDeleteMessage = (softDelete = false) => { const prepareDeleteMessage = (softDelete = false) => {
const softDeleteText = `Soft deleting will deactivate the ${entityName}. This will disable any discovery, read or write operations on ${entityName}`; const softDeleteText = `Soft deleting will deactivate the ${entityName}. This will disable any discovery, read or write operations on ${entityName}.`;
const hardDeleteText = getEntityDeleteMessage(getTitleCase(entityType), ''); const hardDeleteText = getEntityDeleteMessage(getTitleCase(entityType), '');
return softDelete ? softDeleteText : hardDeleteText; return softDelete ? softDeleteText : hardDeleteText;
@ -57,13 +59,15 @@ const DeleteWidgetModal = ({
const DELETE_OPTION = [ const DELETE_OPTION = [
{ {
title: `Delete ${entityType}${entityName}`, title: `Delete ${entityType}${entityName}`,
description: prepareDeleteMessage(true), description: `${prepareDeleteMessage(true)} ${softDeleteMessagePostFix}`,
type: DeleteType.SOFT_DELETE, type: DeleteType.SOFT_DELETE,
isAllowd: allowSoftDelete, isAllowd: allowSoftDelete,
}, },
{ {
title: `Permanently Delete ${entityType}${entityName}`, title: `Permanently Delete ${entityType}${entityName}`,
description: deleteMessage || prepareDeleteMessage(), description: `${
deleteMessage || prepareDeleteMessage()
} ${hardDeleteMessagePostFix}`,
type: DeleteType.HARD_DELETE, type: DeleteType.HARD_DELETE,
isAllowd: true, isAllowd: true,
}, },
@ -115,7 +119,7 @@ const DeleteWidgetModal = ({
prepareType ? prepareEntityType() : entityType, prepareType ? prepareEntityType() : entityType,
entityId ?? '', entityId ?? '',
Boolean(isRecursiveDelete), Boolean(isRecursiveDelete),
entityDeleteState.softDelete !entityDeleteState.softDelete
) )
.then((res) => { .then((res) => {
if (res.status === 200) { if (res.status === 200) {

View File

@ -33,6 +33,8 @@ interface Props {
entityFQN?: string; entityFQN?: string;
isRecursiveDelete?: boolean; isRecursiveDelete?: boolean;
deleteMessage?: string; deleteMessage?: string;
softDeleteMessagePostFix?: string;
hardDeleteMessagePostFix?: string;
canDelete?: boolean; canDelete?: boolean;
extraDropdownContent?: ItemType[]; extraDropdownContent?: ItemType[];
onAnnouncementClick?: () => void; onAnnouncementClick?: () => void;
@ -43,6 +45,8 @@ const ManageButton: FC<Props> = ({
afterDeleteAction, afterDeleteAction,
buttonClassName, buttonClassName,
deleteMessage, deleteMessage,
softDeleteMessagePostFix,
hardDeleteMessagePostFix,
entityName, entityName,
entityType, entityType,
canDelete, canDelete,
@ -157,7 +161,9 @@ const ManageButton: FC<Props> = ({
entityId={entityId || ''} entityId={entityId || ''}
entityName={entityName || ''} entityName={entityName || ''}
entityType={entityType || ''} entityType={entityType || ''}
hardDeleteMessagePostFix={hardDeleteMessagePostFix}
isRecursiveDelete={isRecursiveDelete} isRecursiveDelete={isRecursiveDelete}
softDeleteMessagePostFix={softDeleteMessagePostFix}
visible={isDelete} visible={isDelete}
onCancel={() => setIsDelete(false)} onCancel={() => setIsDelete(false)}
/> />

View File

@ -27,3 +27,10 @@ export const filterChildTeams = (
teamsList: Team[], teamsList: Team[],
showDeletedTeams: boolean showDeletedTeams: boolean
) => teamsList.filter((d) => d.deleted === showDeletedTeams); ) => teamsList.filter((d) => d.deleted === showDeletedTeams);
export const getDeleteMessagePostFix = (
teamName: string,
deleteType: string
) => {
return `Any teams under "${teamName}" will be ${deleteType} deleted as well.`;
};