feat(frontend): add additional tabs to glossary terms view (#7392)

Adds tabs for "Contained by" and "Inherited by" on the Glossary Related Terms tab.
This commit is contained in:
Alexey Kravtsov 2023-02-23 00:30:47 +03:00 committed by GitHub
parent d436ab9f9b
commit 79aa66ab0a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 57 additions and 21 deletions

View File

@ -12,6 +12,8 @@ import RelatedTerm from './RelatedTerm';
export enum RelatedTermTypes { export enum RelatedTermTypes {
hasRelatedTerms = 'Contains', hasRelatedTerms = 'Contains',
isRelatedTerms = 'Inherits', isRelatedTerms = 'Inherits',
containedBy = 'Contained by',
isAChildren = 'Inherited by',
} }
export type Props = { export type Props = {
@ -42,9 +44,13 @@ export default function GlossaryRelatedTermsResult({ glossaryRelatedTermType, gl
}); });
const contentLoading = false; const contentLoading = false;
const relationshipType = const relationshipType =
glossaryRelatedTermType === RelatedTermTypes.hasRelatedTerms glossaryRelatedTermType === RelatedTermTypes.hasRelatedTerms ||
glossaryRelatedTermType === RelatedTermTypes.containedBy
? TermRelationshipType.HasA ? TermRelationshipType.HasA
: TermRelationshipType.IsA; : TermRelationshipType.IsA;
const canEditRelatedTerms =
glossaryRelatedTermType === RelatedTermTypes.isRelatedTerms ||
glossaryRelatedTermType === RelatedTermTypes.hasRelatedTerms;
return ( return (
<> <>
@ -56,12 +62,19 @@ export default function GlossaryRelatedTermsResult({ glossaryRelatedTermType, gl
<Typography.Title style={{ margin: '0' }} level={3}> <Typography.Title style={{ margin: '0' }} level={3}>
{glossaryRelatedTermType} {glossaryRelatedTermType}
</Typography.Title> </Typography.Title>
<Button type="text" onClick={() => setIsShowingAddModal(true)}> {canEditRelatedTerms && (
<PlusOutlined /> Add Terms <Button type="text" onClick={() => setIsShowingAddModal(true)}>
</Button> <PlusOutlined /> Add Terms
</Button>
)}
</TitleContainer> </TitleContainer>
{glossaryRelatedTermUrns.map((urn) => ( {glossaryRelatedTermUrns.map((urn) => (
<RelatedTerm key={urn} urn={urn} relationshipType={relationshipType} /> <RelatedTerm
key={urn}
urn={urn}
relationshipType={relationshipType}
isEditable={canEditRelatedTerms}
/>
))} ))}
{glossaryRelatedTermUrns.length === 0 && ( {glossaryRelatedTermUrns.length === 0 && (
<EmptyTab tab={glossaryRelatedTermType.toLocaleLowerCase()} /> <EmptyTab tab={glossaryRelatedTermType.toLocaleLowerCase()} />

View File

@ -35,10 +35,11 @@ const MenuItem = styled.div`
interface Props { interface Props {
urn: string; urn: string;
relationshipType: TermRelationshipType; relationshipType: TermRelationshipType;
isEditable: boolean;
} }
function RelatedTerm(props: Props) { function RelatedTerm(props: Props) {
const { urn, relationshipType } = props; const { urn, relationshipType, isEditable } = props;
const entityRegistry = useEntityRegistry(); const entityRegistry = useEntityRegistry();
const { data, loading } = useGetGlossaryTermQuery({ variables: { urn } }); const { data, loading } = useGetGlossaryTermQuery({ variables: { urn } });
@ -54,20 +55,22 @@ function RelatedTerm(props: Props) {
<ListItem> <ListItem>
<Profile> <Profile>
{entityRegistry.renderPreview(EntityType.GlossaryTerm, PreviewType.PREVIEW, data?.glossaryTerm)} {entityRegistry.renderPreview(EntityType.GlossaryTerm, PreviewType.PREVIEW, data?.glossaryTerm)}
<Dropdown {isEditable && (
overlay={ <Dropdown
<Menu> overlay={
<Menu.Item key="0"> <Menu>
<MenuItem onClick={onRemove}> <Menu.Item key="0">
<DeleteOutlined /> &nbsp; Remove Term <MenuItem onClick={onRemove}>
</MenuItem> <DeleteOutlined /> &nbsp; Remove Term
</Menu.Item> </MenuItem>
</Menu> </Menu.Item>
} </Menu>
trigger={['click']} }
> trigger={['click']}
<MenuIcon /> >
</Dropdown> <MenuIcon />
</Dropdown>
)}
</Profile> </Profile>
<Divider style={{ margin: '20px 0' }} /> <Divider style={{ margin: '20px 0' }} />
</ListItem> </ListItem>

View File

@ -51,12 +51,20 @@ export const EMPTY_MESSAGES = {
}, },
contains: { contains: {
title: 'Contains no Terms', title: 'Contains no Terms',
description: 'Terms can contain other terms to represent an "Has A" style relationship.', description: 'Terms can contain other terms to represent a "Has A" style relationship.',
}, },
inherits: { inherits: {
title: 'Does not inherit from any terms', title: 'Does not inherit from any terms',
description: 'Terms can inherit from other terms to represent an "Is A" style relationship.', description: 'Terms can inherit from other terms to represent an "Is A" style relationship.',
}, },
'contained by': {
title: 'Is not contained by any terms',
description: 'Terms can be contained by other terms to represent a "Has A" style relationship.',
},
'inherited by': {
title: 'Is not inherited by any terms',
description: 'Terms can be inherited by other terms to represent an "Is A" style relationship.',
},
}; };
export const ELASTIC_MAX_COUNT = 10000; export const ELASTIC_MAX_COUNT = 10000;

View File

@ -42,6 +42,18 @@ query getGlossaryTerm($urn: String!, $start: Int, $count: Int) {
} }
} }
} }
containedBy: relationships(input: { types: ["HasA"], direction: INCOMING, start: $start, count: $count }) {
start
count
total
relationships {
entity {
... on GlossaryTerm {
urn
}
}
}
}
parentNodes { parentNodes {
...parentNodesFields ...parentNodesFields
} }