From 7a8df59d13024b8e9170ba2e63d5d5574819d4de Mon Sep 17 00:00:00 2001 From: john681611 Date: Tue, 4 Jul 2023 18:16:59 +0100 Subject: [PATCH] Standardize document type text selection --- .../src/components/DocumentNode/DocumentNode.tsx | 6 ++---- .../src/components/FilterButton/FilterButton.tsx | 7 ------- .../src/pages/BrowseRootCres/browseRootCres.tsx | 1 - .../CommonRequirementEnumeration.tsx | 5 ++--- .../frontend/src/pages/Standard/StandardSection.tsx | 3 ++- application/frontend/src/utils/document.ts | 11 ++++++++++- 6 files changed, 16 insertions(+), 17 deletions(-) diff --git a/application/frontend/src/components/DocumentNode/DocumentNode.tsx b/application/frontend/src/components/DocumentNode/DocumentNode.tsx index 97ccb3306..0a9bd253d 100644 --- a/application/frontend/src/components/DocumentNode/DocumentNode.tsx +++ b/application/frontend/src/components/DocumentNode/DocumentNode.tsx @@ -5,8 +5,6 @@ import React, { FunctionComponent, useContext, useEffect, useMemo, useState } fr import { Link, useHistory } from 'react-router-dom'; import { - DOCUMENT_TYPES, - DOCUMENT_TYPE_NAMES, TYPE_CONTAINS, TYPE_IS_PART_OF, TYPE_RELATED, @@ -15,7 +13,7 @@ import { useEnvironment } from '../../hooks'; import { applyFilters } from '../../hooks/applyFilters'; import { Document } from '../../types'; import { getDocumentDisplayName, groupLinksByType } from '../../utils'; -import { getApiEndpoint, getInternalUrl } from '../../utils/document'; +import { getApiEndpoint, getDocumentTypeText, getInternalUrl } from '../../utils/document'; import { FilterButton } from '../FilterButton/FilterButton'; import { LoadingAndErrorIndicator } from '../LoadingAndErrorIndicator'; import { Icon } from 'semantic-ui-react'; @@ -145,7 +143,7 @@ export const DocumentNode: FunctionComponent = ({
{idx > 0 &&
}
- Which {DOCUMENT_TYPE_NAMES[type]}: + Which {getDocumentTypeText(type, links[0].document.doctype)}:
diff --git a/application/frontend/src/components/FilterButton/FilterButton.tsx b/application/frontend/src/components/FilterButton/FilterButton.tsx index 96a1e12f6..7bc0f3461 100644 --- a/application/frontend/src/components/FilterButton/FilterButton.tsx +++ b/application/frontend/src/components/FilterButton/FilterButton.tsx @@ -3,13 +3,6 @@ import React, { FunctionComponent, useEffect, useMemo, useState } from 'react'; import { Link, useHistory } from 'react-router-dom'; import { Button } from 'semantic-ui-react'; -import { - DOCUMENT_TYPE_NAMES, - TYPE_CONTAINS, - TYPE_IS_PART_OF, - TYPE_LINKED_TO, - TYPE_RELATED, -} from '../../const'; import { useEnvironment } from '../../hooks'; import { Document, LinkedDocument } from '../../types'; import { getDocumentDisplayName, groupLinksByType } from '../../utils'; diff --git a/application/frontend/src/pages/BrowseRootCres/browseRootCres.tsx b/application/frontend/src/pages/BrowseRootCres/browseRootCres.tsx index bfae68549..5d5f6744b 100644 --- a/application/frontend/src/pages/BrowseRootCres/browseRootCres.tsx +++ b/application/frontend/src/pages/BrowseRootCres/browseRootCres.tsx @@ -7,7 +7,6 @@ import { useParams } from 'react-router-dom'; import { DocumentNode } from '../../components/DocumentNode'; import { ClearFilterButton, FilterButton } from '../../components/FilterButton/FilterButton'; import { LoadingAndErrorIndicator } from '../../components/LoadingAndErrorIndicator'; -import { DOCUMENT_TYPE_NAMES } from '../../const'; import { useEnvironment } from '../../hooks'; import { applyFilters, filterContext } from '../../hooks/applyFilters'; import { Document } from '../../types'; diff --git a/application/frontend/src/pages/CommonRequirementEnumeration/CommonRequirementEnumeration.tsx b/application/frontend/src/pages/CommonRequirementEnumeration/CommonRequirementEnumeration.tsx index 5f9a6b893..f3e939687 100644 --- a/application/frontend/src/pages/CommonRequirementEnumeration/CommonRequirementEnumeration.tsx +++ b/application/frontend/src/pages/CommonRequirementEnumeration/CommonRequirementEnumeration.tsx @@ -7,12 +7,11 @@ import { useParams } from 'react-router-dom'; import { DocumentNode } from '../../components/DocumentNode'; import { ClearFilterButton, FilterButton } from '../../components/FilterButton/FilterButton'; import { LoadingAndErrorIndicator } from '../../components/LoadingAndErrorIndicator'; -import { DOCUMENT_TYPE_NAMES } from '../../const'; import { useEnvironment } from '../../hooks'; import { applyFilters, filterContext } from '../../hooks/applyFilters'; import { Document } from '../../types'; import { groupLinksByType } from '../../utils'; -import { getDocumentDisplayName, orderLinksByType } from '../../utils/document'; +import { getDocumentDisplayName, getDocumentTypeText, orderLinksByType } from '../../utils/document'; export const CommonRequirementEnumeration = () => { const { id } = useParams(); @@ -82,7 +81,7 @@ export const CommonRequirementEnumeration = () => { Object.entries(linksByType).map(([type, links]) => (
- Which {DOCUMENT_TYPE_NAMES[type]}: + Which {getDocumentTypeText(type, links[0].document.doctype)}:
{links.sort((a, b) => getDocumentDisplayName(a.document).localeCompare(getDocumentDisplayName(b.document))).map((link, i) => (
diff --git a/application/frontend/src/pages/Standard/StandardSection.tsx b/application/frontend/src/pages/Standard/StandardSection.tsx index d27b46261..782023217 100644 --- a/application/frontend/src/pages/Standard/StandardSection.tsx +++ b/application/frontend/src/pages/Standard/StandardSection.tsx @@ -11,6 +11,7 @@ import { DOCUMENT_TYPES, DOCUMENT_TYPE_NAMES, TOOL } from '../../const'; import { useEnvironment } from '../../hooks'; import { Document } from '../../types'; import { getDocumentDisplayName, groupLinksByType } from '../../utils'; +import { getDocumentTypeText } from '../../utils/document'; export const StandardSection = () => { const { id, section, sectionID } = useParams(); @@ -75,7 +76,7 @@ export const StandardSection = () => { Object.entries(linksByType).map(([type, links]) => (
- Which {DOCUMENT_TYPE_NAMES[type]}: + Which {getDocumentTypeText(type, links[0].document.doctype)}:
{links.sort((a, b) => getDocumentDisplayName(a.document).localeCompare(getDocumentDisplayName(b.document))).map((link, i) => (
diff --git a/application/frontend/src/utils/document.ts b/application/frontend/src/utils/document.ts index 14103be32..3ce0d948b 100644 --- a/application/frontend/src/utils/document.ts +++ b/application/frontend/src/utils/document.ts @@ -1,4 +1,4 @@ -import { TYPE_CONTAINS, TYPE_IS_PART_OF, TYPE_LINKED_TO, TYPE_RELATED, TYPE_SAM, TYPE_SAME } from '../const'; +import { DOCUMENT_TYPES, DOCUMENT_TYPE_NAMES, TYPE_IS_PART_OF, TYPE_LINKED_TO } from '../const'; import { Document, LinkedDocument } from '../types'; export const getDocumentDisplayName = (document: Document) => { @@ -72,3 +72,12 @@ export const getApiEndpoint = (doc: Document, apiUrl: string): string => { return `${apiUrl}/id/${doc.id}`; }; + +export const getDocumentTypeText = (linkType, docType): string => { + let docText = DOCUMENT_TYPE_NAMES[linkType]; + if(linkType === TYPE_LINKED_TO && docType === DOCUMENT_TYPES.TYPE_CRE) + { + docText = DOCUMENT_TYPE_NAMES[TYPE_IS_PART_OF]; + } + return docText +}