From 8829e8228e9e8a0d693e349aad125d142f8cc657 Mon Sep 17 00:00:00 2001 From: Emma Indal Date: Fri, 21 May 2021 09:45:54 +0200 Subject: [PATCH] wip composable result list Signed-off-by: Emma Indal Signed-off-by: Eric Peterson --- packages/search-common/src/types.ts | 1 + .../src/engines/LunrSearchEngine.ts | 2 +- .../SearchResultNext/SearchResultNext.tsx | 47 ++++++++++++++++--- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/packages/search-common/src/types.ts b/packages/search-common/src/types.ts index daa5823424..c26ecdcb4c 100644 --- a/packages/search-common/src/types.ts +++ b/packages/search-common/src/types.ts @@ -23,6 +23,7 @@ export interface SearchQuery { } export interface SearchResult { + type: string; document: IndexableDocument; } diff --git a/plugins/search-backend-node/src/engines/LunrSearchEngine.ts b/plugins/search-backend-node/src/engines/LunrSearchEngine.ts index 77bba3ff6c..3829693d4e 100644 --- a/plugins/search-backend-node/src/engines/LunrSearchEngine.ts +++ b/plugins/search-backend-node/src/engines/LunrSearchEngine.ts @@ -146,7 +146,7 @@ export class LunrSearchEngine implements SearchEngine { // Translate results into SearchResultSet const resultSet: SearchResultSet = { results: results.map(d => { - return { document: this.docStore[d.ref] }; + return { type: 'techdocs', document: this.docStore[d.ref] }; }), }; diff --git a/plugins/search/src/components/SearchResultNext/SearchResultNext.tsx b/plugins/search/src/components/SearchResultNext/SearchResultNext.tsx index af772c4967..53fc4ff17b 100644 --- a/plugins/search/src/components/SearchResultNext/SearchResultNext.tsx +++ b/plugins/search/src/components/SearchResultNext/SearchResultNext.tsx @@ -35,6 +35,21 @@ const DefaultResultListItem = ({ result }: any) => { ); }; +const TechDocsResultListItem = ({ result }: any) => { + return ( + + + + + + + ); +}; + export const SearchResultNext = () => { const { result: { loading, error, value }, @@ -57,12 +72,32 @@ export const SearchResultNext = () => { return ( - {value.results.map(result => ( - - ))} + {value.results.map(result => { + // Render different result items based on document type + switch (result.type) { + case 'software-catalog': + return ( + + ); + case 'techdocs': + return ( + + ); + default: + return ( + + ); + } + })} ); };