Skip to content

Commit

Permalink
Standardize document type text selection
Browse files Browse the repository at this point in the history
  • Loading branch information
john681611 committed Jul 4, 2023
1 parent bd4cec9 commit 7a8df59
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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';
Expand Down Expand Up @@ -145,7 +143,7 @@ export const DocumentNode: FunctionComponent<DocumentNode> = ({
<div className="document-node__link-type-container" key={type}>
{idx > 0 && <hr/>}
<div>
<b>Which {DOCUMENT_TYPE_NAMES[type]}</b>:
<b>Which {getDocumentTypeText(type, links[0].document.doctype)}</b>:
</div>
<div>
<div className="accordion ui fluid styled f0">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -82,7 +81,7 @@ export const CommonRequirementEnumeration = () => {
Object.entries(linksByType).map(([type, links]) => (
<div className="cre-page__links" key={type}>
<div className="cre-page__links-eader">
<b>Which {DOCUMENT_TYPE_NAMES[type]}</b>:
<b>Which {getDocumentTypeText(type, links[0].document.doctype)}</b>:
</div>
{links.sort((a, b) => getDocumentDisplayName(a.document).localeCompare(getDocumentDisplayName(b.document))).map((link, i) => (
<div key={i} className="accordion ui fluid styled cre-page__links-container">
Expand Down
3 changes: 2 additions & 1 deletion application/frontend/src/pages/Standard/StandardSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -75,7 +76,7 @@ export const StandardSection = () => {
Object.entries(linksByType).map(([type, links]) => (
<div className="cre-page__links" key={type}>
<div className="cre-page__links-header">
<b>Which {DOCUMENT_TYPE_NAMES[type]}</b>:
<b>Which {getDocumentTypeText(type, links[0].document.doctype)}</b>:
</div>
{links.sort((a, b) => getDocumentDisplayName(a.document).localeCompare(getDocumentDisplayName(b.document))).map((link, i) => (
<div key={i} className="accordion ui fluid styled cre-page__links-container">
Expand Down
11 changes: 10 additions & 1 deletion application/frontend/src/utils/document.ts
Original file line number Diff line number Diff line change
@@ -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) => {
Expand Down Expand Up @@ -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
}

0 comments on commit 7a8df59

Please sign in to comment.