Skip to content

Commit

Permalink
Separate documents in search results (#316)
Browse files Browse the repository at this point in the history
* Initial attempt at separating documents in search results

* Make Search Results Separation only on Sources

* Fix: Sorting of nested links missing

---------

Co-authored-by: Spyros <[email protected]>
  • Loading branch information
john681611 and northdpole authored Jul 6, 2023
1 parent bd4cec9 commit 4a55352
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 @@ -149,7 +149,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 4a55352

Please sign in to comment.