2023-09-18 16:14:33 -04:00
|
|
|
import { PageRoutes } from '../../conf/Global';
|
2022-06-29 22:41:41 -04:00
|
|
|
import { useDeleteAssertionMutation } from '../../graphql/assertion.generated';
|
2023-05-17 00:17:25 -07:00
|
|
|
import { useDeleteDataProductMutation } from '../../graphql/dataProduct.generated';
|
2022-06-29 22:41:41 -04:00
|
|
|
import { useDeleteDomainMutation } from '../../graphql/domain.generated';
|
|
|
|
import { useDeleteGlossaryEntityMutation } from '../../graphql/glossary.generated';
|
|
|
|
import { useRemoveGroupMutation } from '../../graphql/group.generated';
|
|
|
|
import { useDeleteTagMutation } from '../../graphql/tag.generated';
|
|
|
|
import { useRemoveUserMutation } from '../../graphql/user.generated';
|
|
|
|
import { EntityType } from '../../types.generated';
|
2023-05-17 00:17:25 -07:00
|
|
|
import { GenericEntityProperties } from '../entity/shared/types';
|
2022-06-29 22:41:41 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a relative redirect path which is used after an Entity has been deleted from it's profile page.
|
|
|
|
*
|
|
|
|
* @param type the entity type being deleted
|
|
|
|
*/
|
2023-05-17 00:17:25 -07:00
|
|
|
export const getEntityProfileDeleteRedirectPath = (type: EntityType, entityData: GenericEntityProperties | null) => {
|
|
|
|
const domain = entityData?.domain?.domain;
|
2022-06-29 22:41:41 -04:00
|
|
|
switch (type) {
|
|
|
|
case EntityType.CorpGroup:
|
|
|
|
case EntityType.CorpUser:
|
|
|
|
case EntityType.Tag:
|
|
|
|
// Return Home.
|
|
|
|
return '/';
|
2023-09-18 16:14:33 -04:00
|
|
|
case EntityType.Domain:
|
|
|
|
return `${PageRoutes.DOMAINS}`;
|
2022-06-29 22:41:41 -04:00
|
|
|
case EntityType.GlossaryNode:
|
|
|
|
case EntityType.GlossaryTerm:
|
|
|
|
// Return to glossary page.
|
|
|
|
return '/glossary';
|
2023-05-17 00:17:25 -07:00
|
|
|
case EntityType.DataProduct:
|
|
|
|
// Return to Data Products tab of the domain it was part of
|
|
|
|
if (domain) {
|
|
|
|
return `/domain/${domain.urn}/Data Products`;
|
|
|
|
}
|
|
|
|
return '/';
|
2022-06-29 22:41:41 -04:00
|
|
|
default:
|
|
|
|
return () => undefined;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a mutation hook for deleting an entity of a particular type.
|
|
|
|
*
|
|
|
|
* TODO: Push this back into the entity registry.
|
|
|
|
*
|
|
|
|
* @param type the entity type being deleted
|
|
|
|
*/
|
|
|
|
export const getDeleteEntityMutation = (type: EntityType) => {
|
|
|
|
switch (type) {
|
|
|
|
case EntityType.CorpGroup:
|
|
|
|
return useRemoveGroupMutation;
|
|
|
|
case EntityType.CorpUser:
|
|
|
|
return useRemoveUserMutation;
|
|
|
|
case EntityType.Assertion:
|
|
|
|
return useDeleteAssertionMutation;
|
|
|
|
case EntityType.Domain:
|
|
|
|
return useDeleteDomainMutation;
|
|
|
|
case EntityType.Tag:
|
|
|
|
return useDeleteTagMutation;
|
|
|
|
case EntityType.GlossaryNode:
|
|
|
|
case EntityType.GlossaryTerm:
|
|
|
|
return useDeleteGlossaryEntityMutation;
|
2023-05-17 00:17:25 -07:00
|
|
|
case EntityType.DataProduct:
|
|
|
|
return useDeleteDataProductMutation;
|
2022-06-29 22:41:41 -04:00
|
|
|
default:
|
|
|
|
return () => undefined;
|
|
|
|
}
|
|
|
|
};
|