From 4a55352e2fc6a95b1b58fd5c9d6027a34c535faa Mon Sep 17 00:00:00 2001 From: John Harvey <10814889+john681611@users.noreply.github.com> Date: Thu, 6 Jul 2023 11:54:49 +0100 Subject: [PATCH] Separate documents in search results (#316) * 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 --- .../components/DocumentNode/DocumentNode.tsx | 2 +- .../frontend/src/pages/Search/SearchName.tsx | 2 +- .../pages/Search/components/SearchResults.tsx | 21 +++++++++++++------ 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/application/frontend/src/components/DocumentNode/DocumentNode.tsx b/application/frontend/src/components/DocumentNode/DocumentNode.tsx index 97ccb3306..ac2be82e6 100644 --- a/application/frontend/src/components/DocumentNode/DocumentNode.tsx +++ b/application/frontend/src/components/DocumentNode/DocumentNode.tsx @@ -149,7 +149,7 @@ export const DocumentNode: FunctionComponent = ({
- {links.map((link, i) => ( + {links.sort((a, b) => getDocumentDisplayName(a.document).localeCompare(getDocumentDisplayName(b.document))).map((link, i) => (
{

Matching sources

- {nodes && } + {nodes && }
)} diff --git a/application/frontend/src/pages/Search/components/SearchResults.tsx b/application/frontend/src/pages/Search/components/SearchResults.tsx index a618da28c..a17de00c5 100644 --- a/application/frontend/src/pages/Search/components/SearchResults.tsx +++ b/application/frontend/src/pages/Search/components/SearchResults.tsx @@ -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) => ( -
- -
- ))} + {sortedResults.map((document, i) => {let temp = ( + <> + {grouped && lastDocumentName !== (document.id ?? document.name) &&
} +
+ +
+ + + ) + lastDocumentName = (document.id ?? document.name); + return temp + })} ); }