Fix #4392 UI: Support deletion of Glossary terms (#4399)

This commit is contained in:
Sachin Chaurasiya 2022-04-24 01:51:14 +05:30 committed by GitHub
parent 7564827bce
commit 8291a09b0d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 109 additions and 39 deletions

View File

@ -57,7 +57,7 @@ const AddGlossary = ({
const [reviewer, setReviewer] = useState<Array<FormattedUsersData>>([]);
const getDescription = () => {
return markdownRef.current?.getEditorContent() || undefined;
return markdownRef.current?.getEditorContent() || '';
};
const onReviewerModalCancel = () => {

View File

@ -84,7 +84,7 @@ const AddGlossaryTerm = ({
}, [glossaryData]);
const getDescription = () => {
return markdownRef.current?.getEditorContent() || undefined;
return markdownRef.current?.getEditorContent() || '';
};
const onRelatedTermsModalCancel = () => {

View File

@ -20,11 +20,13 @@ import {
TITLE_FOR_NON_ADMIN_ACTION,
TITLE_FOR_NON_OWNER_ACTION,
} from '../../constants/constants';
import { EntityType } from '../../enums/entity.enum';
import { Glossary } from '../../generated/entity/data/glossary';
import { Operation } from '../../generated/entity/policies/policy';
import { LabelType, Source, State } from '../../generated/type/tagLabel';
import jsonData from '../../jsons/en';
import UserCard from '../../pages/teams/UserCard';
import { hasEditAccess } from '../../utils/CommonUtils';
import SVGIcons from '../../utils/SvgUtils';
import {
getTagCategories,
@ -37,6 +39,7 @@ import Avatar from '../common/avatar/Avatar';
import Description from '../common/description/Description';
import NonAdminAction from '../common/non-admin-action/NonAdminAction';
import TabsPane from '../common/TabsPane/TabsPane';
import ManageTabComponent from '../ManageTab/ManageTab.component';
import ReviewerModal from '../Modals/ReviewerModal/ReviewerModal.component';
import TagsContainer from '../tags-container/tags-container';
import TagsViewer from '../tags-viewer/tags-viewer';
@ -60,12 +63,12 @@ const GlossaryDetails = ({ isHasAccess, glossary, updateGlossary }: props) => {
const tabs = [
{
name: 'Reviewers',
name: 'Manage',
icon: {
alt: 'schema',
name: 'icon-schema',
title: 'Schema',
selectedName: 'icon-schemacolor',
alt: 'manage',
name: 'icon-manage',
title: 'Manage',
selectedName: 'icon-managecolor',
},
isProtected: false,
position: 1,
@ -177,6 +180,20 @@ const GlossaryDetails = ({ isHasAccess, glossary, updateGlossary }: props) => {
setActiveTab(value);
};
const handleUpdateOwner = (owner: Glossary['owner']) => {
const updatedData = {
...glossary,
owner,
};
return new Promise<void>((_, reject) => {
updateGlossary(updatedData);
setTimeout(() => {
reject();
}, 500);
});
};
useEffect(() => {
if (glossary.reviewers && glossary.reviewers.length) {
setReviewer(
@ -228,7 +245,7 @@ const GlossaryDetails = ({ isHasAccess, glossary, updateGlossary }: props) => {
))}
</div>
) : (
<div className="tw-py-3 tw-text-center tw-bg-white tw-border tw-border-main">
<div className="tw-py-3 tw-text-center tw-bg-white tw-border tw-border-main tw-shadow tw-rounded">
<p className="tw-mb-3">No reviewers assigned</p>
<p>{AddReviewerButton()}</p>
</div>
@ -352,7 +369,29 @@ const GlossaryDetails = ({ isHasAccess, glossary, updateGlossary }: props) => {
/>
<div className="tw-flex-grow tw--mx-6 tw-px-7 tw-py-4">
{activeTab === 1 && getReviewerTabData()}
{activeTab === 1 && (
<div
className="tw-bg-white tw-shadow-md tw-py-6 tw-flex-grow"
data-testid="manage-glossary">
<div className="tw-mx-3">{getReviewerTabData()}</div>
<div className="tw-mt-7">
<ManageTabComponent
allowDelete
hideTier
isRecursiveDelete
currentUser={glossary?.owner?.id}
entityId={glossary.id}
entityName={glossary?.name}
entityType={EntityType.GLOSSARY}
hasEditAccess={hasEditAccess(
glossary?.owner?.type || '',
glossary?.owner?.id || ''
)}
onSave={handleUpdateOwner}
/>
</div>
</div>
)}
</div>
{showRevieweModal && (

View File

@ -23,6 +23,7 @@ import {
} from 'Models';
import React, { Fragment, useEffect, useState } from 'react';
import { TITLE_FOR_NON_ADMIN_ACTION } from '../../constants/constants';
import { EntityType } from '../../enums/entity.enum';
import {
GlossaryTerm,
TermReference,
@ -41,6 +42,7 @@ import { Button } from '../buttons/Button/Button';
import Description from '../common/description/Description';
import NonAdminAction from '../common/non-admin-action/NonAdminAction';
import TabsPane from '../common/TabsPane/TabsPane';
import ManageTabComponent from '../ManageTab/ManageTab.component';
import GlossaryReferenceModal from '../Modals/GlossaryReferenceModal/GlossaryReferenceModal';
import RelatedTermsModal from '../Modals/RelatedTermsModal/RelatedTermsModal';
import ReviewerModal from '../Modals/ReviewerModal/ReviewerModal.component';
@ -98,7 +100,7 @@ const GlossaryTermsV1 = ({
position: 2,
},
{
name: 'Reviewers',
name: 'Manage',
isProtected: false,
position: 3,
},
@ -361,7 +363,7 @@ const GlossaryTermsV1 = ({
))}
</div>
) : (
<div className="tw-py-3 tw-text-center tw-bg-white tw-border tw-border-main">
<div className="tw-py-3 tw-text-center tw-bg-white tw-border tw-border-main tw-shadow tw-rounded">
<p className="tw-mb-3">No reviewers assigned</p>
<p>{AddReviewerButton()}</p>
</div>
@ -611,7 +613,25 @@ const GlossaryTermsV1 = ({
onAssetPaginate={onAssetPaginate}
/>
)}
{activeTab === 3 && getReviewerTabData()}
{activeTab === 3 && (
<div
className="tw-bg-white tw-shadow-md tw-py-6 tw-flex-grow"
data-testid="manage-glossary-term">
<div className="tw-mx-3">{getReviewerTabData()}</div>
<div className="tw--mt-1">
<ManageTabComponent
allowDelete
hideOwner
hideTier
isRecursiveDelete
entityId={glossaryTerm.id}
entityName={glossaryTerm?.name}
entityType={EntityType.GLOSSARY_TERM}
hasEditAccess={false}
/>
</div>
</div>
)}
</div>
{showRelatedTermsModal && (

View File

@ -38,6 +38,7 @@ const ManageTab: FunctionComponent<ManageProps> = ({
currentTier = '',
currentUser = '',
hideTier = false,
hideOwner = false,
onSave,
hasEditAccess,
allowTeamOwner = true,
@ -97,7 +98,7 @@ const ManageTab: FunctionComponent<ManageProps> = ({
const newOwner: TableDetail['owner'] = prepareOwner(updatedOwner);
if (hideTier) {
if (newOwner || !isUndefined(teamJoinable)) {
onSave(newOwner, '', Boolean(teamJoinable)).catch(() => {
onSave?.(newOwner, '', Boolean(teamJoinable)).catch(() => {
setInitialOwnerLoadingState();
});
} else {
@ -105,7 +106,7 @@ const ManageTab: FunctionComponent<ManageProps> = ({
}
} else {
const newTier = prepareTier(updatedTier);
onSave(newOwner, newTier, Boolean(teamJoinable)).catch(() => {
onSave?.(newOwner, newTier, Boolean(teamJoinable)).catch(() => {
setInitialOwnerLoadingState();
});
}
@ -116,7 +117,7 @@ const ManageTab: FunctionComponent<ManageProps> = ({
const newOwner: TableDetail['owner'] = prepareOwner(currentUser);
if (hideTier) {
if (newOwner || !isUndefined(teamJoinable)) {
onSave(newOwner, '', Boolean(teamJoinable)).catch(() => {
onSave?.(newOwner, '', Boolean(teamJoinable)).catch(() => {
setInitialTierLoadingState();
});
} else {
@ -124,7 +125,7 @@ const ManageTab: FunctionComponent<ManageProps> = ({
}
} else {
const newTier = prepareTier(updatedTier);
onSave(newOwner, newTier, Boolean(teamJoinable)).catch(() => {
onSave?.(newOwner, newTier, Boolean(teamJoinable)).catch(() => {
setInitialTierLoadingState();
});
}
@ -305,23 +306,25 @@ const ManageTab: FunctionComponent<ManageProps> = ({
className={classNames('tw-mt-2 tw-pb-4', {
'tw-mb-3': !hideTier,
})}>
<OwnerWidget
allowTeamOwner={allowTeamOwner}
handleIsJoinable={handleIsJoinable}
handleOwnerSelection={handleOwnerSelection}
handleSelectOwnerDropdown={() =>
setListVisible((visible) => !visible)
}
hasEditAccess={hasEditAccess}
isAuthDisabled={isAuthDisabled}
isJoinableActionAllowed={isJoinableActionAllowed()}
listOwners={listOwners}
listVisible={listVisible}
owner={owner}
ownerName={ownerName}
statusOwner={statusOwner}
teamJoinable={teamJoinable}
/>
{!hideOwner && (
<OwnerWidget
allowTeamOwner={allowTeamOwner}
handleIsJoinable={handleIsJoinable}
handleOwnerSelection={handleOwnerSelection}
handleSelectOwnerDropdown={() =>
setListVisible((visible) => !visible)
}
hasEditAccess={hasEditAccess}
isAuthDisabled={isAuthDisabled}
isJoinableActionAllowed={isJoinableActionAllowed()}
listOwners={listOwners}
listVisible={listVisible}
owner={owner}
ownerName={ownerName}
statusOwner={statusOwner}
teamJoinable={teamJoinable}
/>
)}
</div>
{getTierWidget()}
{getDeleteEntityWidget()}

View File

@ -18,9 +18,10 @@ export interface ManageProps {
currentUser?: string;
manageSectionType?: string;
hideTier?: boolean;
hideOwner?: boolean;
isJoinable?: boolean;
allowSoftDelete?: boolean;
onSave: (
onSave?: (
owner: TableDetail['owner'],
tier: TableDetail['tier'],
isJoinable?: boolean

View File

@ -72,6 +72,8 @@ const DeleteWidget = ({
if (services.includes((entityType || '') as EntityType)) {
return `services/${entityType}s`;
} else if (entityType === EntityType.GLOSSARY) {
return `glossaries`;
} else {
return `${entityType}s`;
}

View File

@ -19,7 +19,7 @@ export interface CreateGlossary {
/**
* Description of the glossary instance.
*/
description?: string;
description: string;
/**
* Display Name that identifies this glossary.
*/

View File

@ -19,7 +19,7 @@ export interface CreateGlossaryTerm {
/**
* Description of the glossary term.
*/
description?: string;
description: string;
/**
* Display Name that identifies this glossary.
*/

View File

@ -28,7 +28,7 @@ export interface Glossary {
/**
* Description of the glossary.
*/
description?: string;
description: string;
/**
* Display Name that identifies this glossary.
*/

View File

@ -31,7 +31,7 @@ export interface GlossaryTerm {
/**
* Description of the glossary term.
*/
description?: string;
description: string;
/**
* Display Name that identifies this glossary.
*/
@ -83,7 +83,11 @@ export interface GlossaryTerm {
*/
synonyms?: string[];
/**
* Tags for this glossary term.
* Tags associated with this glossary term. These tags captures relationship of a glossary
* term with a tag automatically. As an example a glossary term 'User.PhoneNumber' might
* have an associated tag 'PII.Sensitive'. When 'User.Address' is used to label a column in
* a table, 'PII.Sensitive' label is also applied automatically due to Associated tag
* relationship.
*/
tags?: TagLabel[];
/**

View File

@ -67,6 +67,7 @@ export const mockedGlossaries = [
children: mockedGlossaryTerms,
deleted: false,
displayName: 'Mocked Glossary',
description: '',
id: 'mocked-glossary-id',
name: 'Mock Glossary',
owner: {