Skip to content

Commit

Permalink
Merge branch 'main' into doc_type_text_standardisation
Browse files Browse the repository at this point in the history
  • Loading branch information
northdpole committed Jul 6, 2023
2 parents 40d857c + 4a55352 commit 6635027
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export const DocumentNode: FunctionComponent<DocumentNode> = ({
</div>
<div>
<div className="accordion ui fluid styled f0">
{links.map((link, i) => (
{links.sort((a, b) => getDocumentDisplayName(a.document).localeCompare(getDocumentDisplayName(b.document))).map((link, i) => (
<div key={Math.random()}>
<DocumentNode
node={link.document}
Expand Down
2 changes: 1 addition & 1 deletion application/frontend/src/pages/Search/SearchName.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const SearchName = () => {
</div>
<div className="eight wide column">
<h1 className="standard-page__heading">Matching sources</h1>
{nodes && <SearchResults results={nodes} />}
{nodes && <SearchResults results={nodes} grouped />}
</div>
</div>
)}
Expand Down
21 changes: 15 additions & 6 deletions application/frontend/src/pages/Search/components/SearchResults.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,24 @@ import React from 'react';
import { DocumentNode } from '../../../components/DocumentNode';
import { getDocumentDisplayName } from 'application/frontend/src/utils/document';

export const SearchResults = ({ results }) => {
export const SearchResults = ({ results, grouped=false }) => {
if (results && results.length != 0) {
const sortedResults = results.sort((a, b) => getDocumentDisplayName(a).localeCompare(getDocumentDisplayName(b)))
let lastDocumentName = sortedResults[0].id ?? sortedResults[0].name
return (
<>
{results.sort((a, b) => getDocumentDisplayName(a).localeCompare(getDocumentDisplayName(b))).map((document, i) => (
<div key={i} className="accordion ui fluid styled standard-page__links-container">
<DocumentNode node={document} linkType={'Standard'} />
</div>
))}
{sortedResults.map((document, i) => {let temp = (
<>
{grouped && lastDocumentName !== (document.id ?? document.name) &&<hr style={{marginBottom: "40px"}} />}
<div key={i} className="accordion ui fluid styled standard-page__links-container">
<DocumentNode node={document} linkType={'Standard'} />
</div>
</>

)
lastDocumentName = (document.id ?? document.name);
return temp
})}
</>
);
}
Expand Down

0 comments on commit 6635027

Please sign in to comment.