From e62157f13be877f5fe391c79b3daf7e8157049c7 Mon Sep 17 00:00:00 2001 From: Marcel Gerber Date: Mon, 18 Mar 2024 16:42:49 +0100 Subject: [PATCH] feat(search): surface explorer views in autocomplete --- site/search/Autocomplete.tsx | 36 +++++++++++++++++++++++++++++------- 1 file changed, 29 insertions(+), 7 deletions(-) diff --git a/site/search/Autocomplete.tsx b/site/search/Autocomplete.tsx index 6a5ae89cd91..8185f1a26b4 100644 --- a/site/search/Autocomplete.tsx +++ b/site/search/Autocomplete.tsx @@ -73,7 +73,12 @@ const getItemUrl: AutocompleteSource["getItemUrl"] = ({ item }) => const prependSubdirectoryToAlgoliaItemUrl = (item: BaseItem): string => { const indexName = parseIndexName(item.__autocomplete_indexName as string) const subdirectory = indexNameToSubdirectoryMap[indexName] - return `${subdirectory}/${item.slug}` + switch (indexName) { + case SearchIndexName.ExplorerViews: + return `${subdirectory}/${item.explorerSlug}${item.viewQueryParams}` + default: + return `${subdirectory}/${item.slug}` + } } const FeaturedSearchesSource: AutocompleteSource = { @@ -133,6 +138,14 @@ const AlgoliaSource: AutocompleteSource = { distinct: true, }, }, + { + indexName: getIndexName(SearchIndexName.ExplorerViews), + query, + params: { + hitsPerPage: 1, + distinct: true, + }, + }, { indexName: getIndexName(SearchIndexName.Explorers), query, @@ -152,11 +165,20 @@ const AlgoliaSource: AutocompleteSource = { item.__autocomplete_indexName as string ) const indexLabel = - index === SearchIndexName.Charts - ? "Chart" - : index === SearchIndexName.Explorers - ? "Explorer" - : pageTypeDisplayNames[item.type as PageType] + index === SearchIndexName.Charts ? ( + "Chart" + ) : index === SearchIndexName.Explorers ? ( + "Explorer" + ) : index === SearchIndexName.ExplorerViews ? ( + <> + in {item.explorerTitle} Data Explorer + + ) : ( + pageTypeDisplayNames[item.type as PageType] + ) + + const mainAttribute = + index === SearchIndexName.ExplorerViews ? "viewTitle" : "title" return (
= {