mirror of
https://github.com/datahub-project/datahub.git
synced 2025-10-07 23:16:38 +00:00
fix(glossary) Fix Glossary success messages and sort Glossary (#5533)
* show error and success messages in glossary properly * sort glossary nodes and terms alphabetically Co-authored-by: Chris Collins <chriscollins@Chriss-MBP-2.lan>
This commit is contained in:
parent
d1f0c7a6aa
commit
d9d77646af
@ -1,16 +1,22 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { EntityType, GlossaryNode, GlossaryTerm } from '../../../types.generated';
|
import { EntityType, GlossaryNode, GlossaryTerm } from '../../../types.generated';
|
||||||
import GlossaryEntitiesList from '../../glossary/GlossaryEntitiesList';
|
import GlossaryEntitiesList from '../../glossary/GlossaryEntitiesList';
|
||||||
|
import { useEntityRegistry } from '../../useEntityRegistry';
|
||||||
|
import { sortGlossaryTerms } from '../glossaryTerm/utils';
|
||||||
import { useEntityData } from '../shared/EntityContext';
|
import { useEntityData } from '../shared/EntityContext';
|
||||||
|
import { sortGlossaryNodes } from './utils';
|
||||||
|
|
||||||
function ChildrenTab() {
|
function ChildrenTab() {
|
||||||
const { entityData } = useEntityData();
|
const { entityData } = useEntityData();
|
||||||
|
const entityRegistry = useEntityRegistry();
|
||||||
|
|
||||||
const childNodes = entityData?.children?.relationships
|
const childNodes = entityData?.children?.relationships
|
||||||
.filter((child) => child.entity?.type === EntityType.GlossaryNode)
|
.filter((child) => child.entity?.type === EntityType.GlossaryNode)
|
||||||
|
.sort((nodeA, nodeB) => sortGlossaryNodes(entityRegistry, nodeA.entity, nodeB.entity))
|
||||||
.map((child) => child.entity);
|
.map((child) => child.entity);
|
||||||
const childTerms = entityData?.children?.relationships
|
const childTerms = entityData?.children?.relationships
|
||||||
.filter((child) => child.entity?.type === EntityType.GlossaryTerm)
|
.filter((child) => child.entity?.type === EntityType.GlossaryTerm)
|
||||||
|
.sort((termA, termB) => sortGlossaryTerms(entityRegistry, termA.entity, termB.entity))
|
||||||
.map((child) => child.entity);
|
.map((child) => child.entity);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
8
datahub-web-react/src/app/entity/glossaryNode/utils.ts
Normal file
8
datahub-web-react/src/app/entity/glossaryNode/utils.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { Entity, EntityType } from '../../../types.generated';
|
||||||
|
import EntityRegistry from '../EntityRegistry';
|
||||||
|
|
||||||
|
export function sortGlossaryNodes(entityRegistry: EntityRegistry, nodeA?: Entity | null, nodeB?: Entity | null) {
|
||||||
|
const nodeAName = entityRegistry.getDisplayName(EntityType.GlossaryNode, nodeA);
|
||||||
|
const nodeBName = entityRegistry.getDisplayName(EntityType.GlossaryNode, nodeB);
|
||||||
|
return nodeAName.localeCompare(nodeBName);
|
||||||
|
}
|
8
datahub-web-react/src/app/entity/glossaryTerm/utils.ts
Normal file
8
datahub-web-react/src/app/entity/glossaryTerm/utils.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
import { Entity, EntityType } from '../../../types.generated';
|
||||||
|
import EntityRegistry from '../EntityRegistry';
|
||||||
|
|
||||||
|
export function sortGlossaryTerms(entityRegistry: EntityRegistry, nodeA?: Entity | null, nodeB?: Entity | null) {
|
||||||
|
const nodeAName = entityRegistry.getDisplayName(EntityType.GlossaryTerm, nodeA) || '';
|
||||||
|
const nodeBName = entityRegistry.getDisplayName(EntityType.GlossaryTerm, nodeB) || '';
|
||||||
|
return nodeAName.localeCompare(nodeBName);
|
||||||
|
}
|
@ -49,11 +49,7 @@ function CreateGlossaryEntityModal(props: Props) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.then(() => {
|
||||||
message.destroy();
|
|
||||||
message.error({ content: `Failed to create: \n ${e.message || ''}`, duration: 3 });
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
message.loading({ content: 'Updating...', duration: 2 });
|
message.loading({ content: 'Updating...', duration: 2 });
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
message.success({
|
message.success({
|
||||||
@ -65,6 +61,10 @@ function CreateGlossaryEntityModal(props: Props) {
|
|||||||
refetchData();
|
refetchData();
|
||||||
}
|
}
|
||||||
}, 2000);
|
}, 2000);
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
message.destroy();
|
||||||
|
message.error({ content: `Failed to create: \n ${e.message || ''}`, duration: 3 });
|
||||||
});
|
});
|
||||||
onClose();
|
onClose();
|
||||||
}
|
}
|
||||||
|
@ -43,11 +43,7 @@ function MoveGlossaryEntityModal(props: Props) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.catch((e) => {
|
.then(() => {
|
||||||
message.destroy();
|
|
||||||
message.error({ content: `Failed to move: \n ${e.message || ''}`, duration: 3 });
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
message.loading({ content: 'Updating...', duration: 2 });
|
message.loading({ content: 'Updating...', duration: 2 });
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
message.success({
|
message.success({
|
||||||
@ -59,6 +55,10 @@ function MoveGlossaryEntityModal(props: Props) {
|
|||||||
refetchData();
|
refetchData();
|
||||||
}
|
}
|
||||||
}, 2000);
|
}, 2000);
|
||||||
|
})
|
||||||
|
.catch((e) => {
|
||||||
|
message.destroy();
|
||||||
|
message.error({ content: `Failed to move: \n ${e.message || ''}`, duration: 3 });
|
||||||
});
|
});
|
||||||
onClose();
|
onClose();
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,9 @@ import EmptyGlossarySection from './EmptyGlossarySection';
|
|||||||
import CreateGlossaryEntityModal from '../entity/shared/EntityDropdown/CreateGlossaryEntityModal';
|
import CreateGlossaryEntityModal from '../entity/shared/EntityDropdown/CreateGlossaryEntityModal';
|
||||||
import { EntityType } from '../../types.generated';
|
import { EntityType } from '../../types.generated';
|
||||||
import { Message } from '../shared/Message';
|
import { Message } from '../shared/Message';
|
||||||
|
import { sortGlossaryTerms } from '../entity/glossaryTerm/utils';
|
||||||
|
import { useEntityRegistry } from '../useEntityRegistry';
|
||||||
|
import { sortGlossaryNodes } from '../entity/glossaryNode/utils';
|
||||||
|
|
||||||
export const HeaderWrapper = styled(TabToolbar)`
|
export const HeaderWrapper = styled(TabToolbar)`
|
||||||
padding: 15px 45px 10px 24px;
|
padding: 15px 45px 10px 24px;
|
||||||
@ -44,9 +47,14 @@ function BusinessGlossaryPage() {
|
|||||||
const [browserWidth, setBrowserWidth] = useState(window.innerWidth * 0.2);
|
const [browserWidth, setBrowserWidth] = useState(window.innerWidth * 0.2);
|
||||||
const { data: termsData, refetch: refetchForTerms, loading: termsLoading } = useGetRootGlossaryTermsQuery();
|
const { data: termsData, refetch: refetchForTerms, loading: termsLoading } = useGetRootGlossaryTermsQuery();
|
||||||
const { data: nodesData, refetch: refetchForNodes, loading: nodesLoading } = useGetRootGlossaryNodesQuery();
|
const { data: nodesData, refetch: refetchForNodes, loading: nodesLoading } = useGetRootGlossaryNodesQuery();
|
||||||
|
const entityRegistry = useEntityRegistry();
|
||||||
|
|
||||||
const terms = termsData?.getRootGlossaryTerms?.terms;
|
const terms = termsData?.getRootGlossaryTerms?.terms.sort((termA, termB) =>
|
||||||
const nodes = nodesData?.getRootGlossaryNodes?.nodes;
|
sortGlossaryTerms(entityRegistry, termA, termB),
|
||||||
|
);
|
||||||
|
const nodes = nodesData?.getRootGlossaryNodes?.nodes.sort((nodeA, nodeB) =>
|
||||||
|
sortGlossaryNodes(entityRegistry, nodeA, nodeB),
|
||||||
|
);
|
||||||
|
|
||||||
const hasTermsOrNodes = !!nodes?.length || !!terms?.length;
|
const hasTermsOrNodes = !!nodes?.length || !!terms?.length;
|
||||||
|
|
||||||
|
@ -2,6 +2,9 @@ import React, { useEffect } from 'react';
|
|||||||
import styled from 'styled-components/macro';
|
import styled from 'styled-components/macro';
|
||||||
import { useGetRootGlossaryNodesQuery, useGetRootGlossaryTermsQuery } from '../../../graphql/glossary.generated';
|
import { useGetRootGlossaryNodesQuery, useGetRootGlossaryTermsQuery } from '../../../graphql/glossary.generated';
|
||||||
import { GlossaryNode, GlossaryTerm } from '../../../types.generated';
|
import { GlossaryNode, GlossaryTerm } from '../../../types.generated';
|
||||||
|
import { sortGlossaryNodes } from '../../entity/glossaryNode/utils';
|
||||||
|
import { sortGlossaryTerms } from '../../entity/glossaryTerm/utils';
|
||||||
|
import { useEntityRegistry } from '../../useEntityRegistry';
|
||||||
import NodeItem from './NodeItem';
|
import NodeItem from './NodeItem';
|
||||||
import TermItem from './TermItem';
|
import TermItem from './TermItem';
|
||||||
|
|
||||||
@ -44,6 +47,10 @@ function GlossaryBrowser(props: Props) {
|
|||||||
const displayedNodes = rootNodes || nodesData?.getRootGlossaryNodes?.nodes || [];
|
const displayedNodes = rootNodes || nodesData?.getRootGlossaryNodes?.nodes || [];
|
||||||
const displayedTerms = rootTerms || termsData?.getRootGlossaryTerms?.terms || [];
|
const displayedTerms = rootTerms || termsData?.getRootGlossaryTerms?.terms || [];
|
||||||
|
|
||||||
|
const entityRegistry = useEntityRegistry();
|
||||||
|
const sortedNodes = displayedNodes.sort((nodeA, nodeB) => sortGlossaryNodes(entityRegistry, nodeA, nodeB));
|
||||||
|
const sortedTerms = displayedTerms.sort((termA, termB) => sortGlossaryTerms(entityRegistry, termA, termB));
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (refreshBrowser) {
|
if (refreshBrowser) {
|
||||||
refetchNodes();
|
refetchNodes();
|
||||||
@ -53,7 +60,7 @@ function GlossaryBrowser(props: Props) {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<BrowserWrapper>
|
<BrowserWrapper>
|
||||||
{displayedNodes.map((node) => (
|
{sortedNodes.map((node) => (
|
||||||
<NodeItem
|
<NodeItem
|
||||||
key={node.urn}
|
key={node.urn}
|
||||||
node={node}
|
node={node}
|
||||||
@ -67,7 +74,7 @@ function GlossaryBrowser(props: Props) {
|
|||||||
/>
|
/>
|
||||||
))}
|
))}
|
||||||
{!hideTerms &&
|
{!hideTerms &&
|
||||||
displayedTerms.map((term) => (
|
sortedTerms.map((term) => (
|
||||||
<TermItem key={term.urn} term={term} isSelecting={isSelecting} selectTerm={selectTerm} />
|
<TermItem key={term.urn} term={term} isSelecting={isSelecting} selectTerm={selectTerm} />
|
||||||
))}
|
))}
|
||||||
</BrowserWrapper>
|
</BrowserWrapper>
|
||||||
|
@ -7,6 +7,8 @@ import { useEntityRegistry } from '../../useEntityRegistry';
|
|||||||
import { useGetGlossaryNodeQuery } from '../../../graphql/glossaryNode.generated';
|
import { useGetGlossaryNodeQuery } from '../../../graphql/glossaryNode.generated';
|
||||||
import TermItem, { TermLink as NodeLink, NameWrapper } from './TermItem';
|
import TermItem, { TermLink as NodeLink, NameWrapper } from './TermItem';
|
||||||
import { useEntityData } from '../../entity/shared/EntityContext';
|
import { useEntityData } from '../../entity/shared/EntityContext';
|
||||||
|
import { sortGlossaryNodes } from '../../entity/glossaryNode/utils';
|
||||||
|
import { sortGlossaryTerms } from '../../entity/glossaryTerm/utils';
|
||||||
|
|
||||||
const ItemWrapper = styled.div`
|
const ItemWrapper = styled.div`
|
||||||
display: flex;
|
display: flex;
|
||||||
@ -93,10 +95,12 @@ function NodeItem(props: Props) {
|
|||||||
const childNodes =
|
const childNodes =
|
||||||
(children as any)
|
(children as any)
|
||||||
?.filter((child) => child.entity?.type === EntityType.GlossaryNode)
|
?.filter((child) => child.entity?.type === EntityType.GlossaryNode)
|
||||||
|
.sort((nodeA, nodeB) => sortGlossaryNodes(entityRegistry, nodeA.entity, nodeB.entity))
|
||||||
.map((child) => child.entity) || [];
|
.map((child) => child.entity) || [];
|
||||||
const childTerms =
|
const childTerms =
|
||||||
(children as any)
|
(children as any)
|
||||||
?.filter((child) => child.entity?.type === EntityType.GlossaryTerm)
|
?.filter((child) => child.entity?.type === EntityType.GlossaryTerm)
|
||||||
|
.sort((termA, termB) => sortGlossaryTerms(entityRegistry, termA.entity, termB.entity))
|
||||||
.map((child) => child.entity) || [];
|
.map((child) => child.entity) || [];
|
||||||
|
|
||||||
if (shouldHideNode) return null;
|
if (shouldHideNode) return null;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user