From 45dfc9a2a72916bd8fba861fec59e7376f9abcf2 Mon Sep 17 00:00:00 2001 From: sboleyn Date: Thu, 28 Sep 2023 16:36:41 -0700 Subject: [PATCH 01/12] Add configuration for disabling data search --- next.config.js | 1 + src/pages/_app.js | 2 ++ 2 files changed, 3 insertions(+) diff --git a/next.config.js b/next.config.js index 300433bf7..6bddc675a 100644 --- a/next.config.js +++ b/next.config.js @@ -97,5 +97,6 @@ module.exports = withBundleAnalyzer({ SUPPORT_EMAIL: config.get("support_email"), DE_FAQ: config.get("de_faq"), CYVERSE_URL: config.get("cyverse_url"), + ELASTIC_ENABLED: config.get("elastic.enabled"), }, }); diff --git a/src/pages/_app.js b/src/pages/_app.js index d252803e6..ee20a6209 100644 --- a/src/pages/_app.js +++ b/src/pages/_app.js @@ -213,6 +213,7 @@ function MyApp({ Component, pageProps }) { const supportEmail = publicRuntimeConfig.SUPPORT_EMAIL; const deFaq = publicRuntimeConfig.DE_FAQ; const cyverseURL = publicRuntimeConfig.CYVERSE_URL; + const elasticEnabled = publicRuntimeConfig.ELASTIC_ENABLED; setConfig({ intercom, @@ -230,6 +231,7 @@ function MyApp({ Component, pageProps }) { supportEmail, deFaq, cyverseURL, + elasticEnabled, }); const jssStyles = document.querySelector("#jss-server-side"); From 5366642e7b9a6d8e6a0a16b2baa667749d564a04 Mon Sep 17 00:00:00 2001 From: sboleyn Date: Thu, 28 Sep 2023 16:40:59 -0700 Subject: [PATCH 02/12] Use optional chaining to prevent errors when data search is disabled --- src/components/search/detailed/DataSearchResults.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/search/detailed/DataSearchResults.js b/src/components/search/detailed/DataSearchResults.js index ab1d9a4b4..1ac756793 100644 --- a/src/components/search/detailed/DataSearchResults.js +++ b/src/components/search/detailed/DataSearchResults.js @@ -324,7 +324,7 @@ function DataSearchResults(props) { } if ( status !== constants.LOADING && - (!data || data.pages.length === 0 || data.pages[0]?.hits.length === 0) + (!data || data.pages.length === 0 || data.pages[0]?.hits?.length === 0) ) { return ( <> @@ -335,7 +335,7 @@ function DataSearchResults(props) { } let flatData = []; - if (data && data.pages[0].hits.length > 0) { + if (data && data.pages[0].hits?.length > 0) { data.pages.forEach((page) => { flatData = [...flatData, ...page.hits]; }); From d725d75205dc344ef4c80be8c6a9a9d35e85e5ec Mon Sep 17 00:00:00 2001 From: sboleyn Date: Thu, 28 Sep 2023 17:06:33 -0700 Subject: [PATCH 03/12] Remove 'data' from filter and disable data search when elastic is disabled --- src/components/search/GlobalSearchField.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/components/search/GlobalSearchField.js b/src/components/search/GlobalSearchField.js index c189542e3..9352c634d 100644 --- a/src/components/search/GlobalSearchField.js +++ b/src/components/search/GlobalSearchField.js @@ -614,7 +614,7 @@ function GlobalSearchField(props) { const isLoggedIn = !!userProfile?.id; switch (filter) { case searchConstants.DATA: - setDataSearchQueryEnabled(true); + setDataSearchQueryEnabled(config?.elasticEnabled); setAppsSearchQueryEnabled(false); setAnalysesSearchQueryEnabled(false); setTeamSearchQueryEnabled(false); @@ -642,7 +642,7 @@ function GlobalSearchField(props) { break; default: - setDataSearchQueryEnabled(true); + setDataSearchQueryEnabled(config?.elasticEnabled); setAppsSearchQueryEnabled(true); setAnalysesSearchQueryEnabled(isLoggedIn); setTeamSearchQueryEnabled(isLoggedIn); @@ -816,14 +816,17 @@ function GlobalSearchField(props) { ); const searchFilterId = buildID(ids.SEARCH, ids.SEARCH_FILTER_MENU); + const allFilterOptions = [ + searchConstants.ALL, + searchConstants.DATA, + searchConstants.APPS, + searchConstants.ANALYSES, + ]; const filterOptions = singleSearchOption ? [selectedFilter] - : [ - searchConstants.ALL, - searchConstants.DATA, - searchConstants.APPS, - searchConstants.ANALYSES, - ]; + : config?.elasticEnabled + ? allFilterOptions + : allFilterOptions.filter((option) => option !== searchConstants.DATA); return ( <> From 86a43a39adb62e754e7627dabeaf44729569dec0 Mon Sep 17 00:00:00 2001 From: sboleyn Date: Fri, 29 Sep 2023 13:06:46 -0700 Subject: [PATCH 04/12] Remove 'Data' filter from GlobalSearchField on data page when data search is disabled --- src/components/layout/AppBar.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/components/layout/AppBar.js b/src/components/layout/AppBar.js index 4fbd6afd8..9ae79791e 100644 --- a/src/components/layout/AppBar.js +++ b/src/components/layout/AppBar.js @@ -135,7 +135,10 @@ function DEAppBar(props) { filter = searchConstants.APPS; } else if (activeView === NavigationConstants.ANALYSES) { filter = searchConstants.ANALYSES; - } else if (activeView === NavigationConstants.DATA) { + } else if ( + activeView === NavigationConstants.DATA && + config?.elasticEnabled + ) { filter = searchConstants.DATA; } else { filter = searchConstants.ALL; From 54d27a9e6ec7d44813860862a25aae1052060056 Mon Sep 17 00:00:00 2001 From: sboleyn Date: Fri, 29 Sep 2023 15:53:24 -0700 Subject: [PATCH 05/12] Hide view all data option when data search is disabled --- src/components/search/GlobalSearchField.js | 92 +++++++++++++--------- 1 file changed, 54 insertions(+), 38 deletions(-) diff --git a/src/components/search/GlobalSearchField.js b/src/components/search/GlobalSearchField.js index 9352c634d..72c469a54 100644 --- a/src/components/search/GlobalSearchField.js +++ b/src/components/search/GlobalSearchField.js @@ -407,10 +407,14 @@ function GlobalSearchField(props) { }, }; - const viewAllDataOptions = { - id: searchConstants.VIEW_ALL_DATA_ID, - name: searchTerm, - resultType: { type: t("data"), id: searchConstants.DATA }, + const viewAllDataOptions = () => { + return config?.elasticEnabled + ? { + id: searchConstants.VIEW_ALL_DATA_ID, + name: searchTerm, + resultType: { type: t("data"), id: searchConstants.DATA }, + } + : false; }; const viewAllAppOptions = { @@ -447,14 +451,16 @@ function GlobalSearchField(props) { filter === searchConstants.ANALYSES && !singleSearchOption ) { - setOptions([ - ...options, - ...analyses, - viewAllAnalysesOptions, - viewAllAppOptions, - viewAllDataOptions, - viewAllTeamOptions, - ]); + setOptions( + [ + ...options, + ...analyses, + viewAllAnalysesOptions, + viewAllAppOptions, + viewAllDataOptions(), + viewAllTeamOptions, + ].filter(Boolean) + ); } else { setOptions([ ...options, @@ -479,14 +485,16 @@ function GlobalSearchField(props) { }; }); if (filter === searchConstants.APPS && !singleSearchOption) { - setOptions([ - ...options, - ...apps, - viewAllAppOptions, - viewAllAnalysesOptions, - viewAllDataOptions, - viewAllTeamOptions, - ]); + setOptions( + [ + ...options, + ...apps, + viewAllAppOptions, + viewAllAnalysesOptions, + viewAllDataOptions(), + viewAllTeamOptions, + ].filter(Boolean) + ); } else { setOptions([...options, ...apps, viewAllAppOptions]); } @@ -508,19 +516,25 @@ function GlobalSearchField(props) { }; }); if (filter === searchConstants.DATA && !singleSearchOption) { - setOptions([ - ...options, - ...data, - viewAllDataOptions, - viewAllAnalysesOptions, - viewAllAppOptions, - viewAllTeamOptions, - ]); + setOptions( + [ + ...options, + ...data, + viewAllDataOptions(), + viewAllAnalysesOptions, + viewAllAppOptions, + viewAllTeamOptions, + ].filter(Boolean) + ); } else { - setOptions([...options, ...data, viewAllDataOptions]); + setOptions( + [...options, ...data, viewAllDataOptions()].filter( + Boolean + ) + ); } } else { - setOptions([...options, viewAllDataOptions]); + setOptions([...options, viewAllDataOptions()].filter(Boolean)); } } ); @@ -536,14 +550,16 @@ function GlobalSearchField(props) { }; }); if (filter === searchConstants.TEAMS && !singleSearchOption) { - setOptions([ - ...options, - ...teams, - viewAllTeamOptions, - viewAllDataOptions, - viewAllAppOptions, - viewAllAnalysesOptions, - ]); + setOptions( + [ + ...options, + ...teams, + viewAllTeamOptions, + viewAllDataOptions(), + viewAllAppOptions, + viewAllAnalysesOptions, + ].filter(Boolean) + ); } else { setOptions([...options, ...teams, viewAllTeamOptions]); } From ff2c16df61a47ab96a027559c259020b91fbdc81 Mon Sep 17 00:00:00 2001 From: sboleyn Date: Fri, 29 Sep 2023 16:09:38 -0700 Subject: [PATCH 06/12] Add comment to 'viewAllDataOptions' --- src/components/search/GlobalSearchField.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/search/GlobalSearchField.js b/src/components/search/GlobalSearchField.js index 72c469a54..db7b30586 100644 --- a/src/components/search/GlobalSearchField.js +++ b/src/components/search/GlobalSearchField.js @@ -407,6 +407,7 @@ function GlobalSearchField(props) { }, }; + // Return 'view all data' option if data search is enabled; otherwise, return false. False values are filtered out from the options array. const viewAllDataOptions = () => { return config?.elasticEnabled ? { From 26484ce4a0f1573f114447146abc44bc0cab2872 Mon Sep 17 00:00:00 2001 From: sboleyn Date: Fri, 29 Sep 2023 16:48:22 -0700 Subject: [PATCH 07/12] Modified default tab behavior based on data search status --- src/components/search/GlobalSearchField.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/components/search/GlobalSearchField.js b/src/components/search/GlobalSearchField.js index db7b30586..6e0a7bf5f 100644 --- a/src/components/search/GlobalSearchField.js +++ b/src/components/search/GlobalSearchField.js @@ -362,6 +362,8 @@ function GlobalSearchField(props) { const [bootstrapQueryEnabled, setBootstrapQueryEnabled] = useState(false); const [userHomeDir, setUserHomeDir] = useState(null); + const [defaultTab, setDefaultTab] = useState(null); + const theme = useTheme(); const isMobile = useMediaQuery(theme.breakpoints.down("xs")); @@ -434,6 +436,14 @@ function GlobalSearchField(props) { setFilter(selectedFilter); }, [selectedFilter]); + useEffect(() => { + setDefaultTab( + config?.elasticEnabled + ? SEARCH_RESULTS_TABS.data + : SEARCH_RESULTS_TABS.apps + ); + }, [config]); + const { isFetching: searchingAnalyses, error: analysesSearchError } = useAnalysesSearch( analysesSearchKey, @@ -825,7 +835,7 @@ function GlobalSearchField(props) { selectedTab: filter && filter !== searchConstants.ALL ? filter.toUpperCase() - : SEARCH_RESULTS_TABS.data, + : defaultTab, }); } }} From b17f53413b0d6bcf304e97bf359119ed491d8c20 Mon Sep 17 00:00:00 2001 From: sboleyn Date: Fri, 29 Sep 2023 17:26:28 -0700 Subject: [PATCH 08/12] Change default tab on search page based on data search status; conditionally render data research results tabs/tab panel based on data search status --- .../search/detailed/DetailedSearchResults.js | 57 +++++++++++-------- src/pages/search.js | 16 +++++- 2 files changed, 46 insertions(+), 27 deletions(-) diff --git a/src/components/search/detailed/DetailedSearchResults.js b/src/components/search/detailed/DetailedSearchResults.js index b03115f6c..e4ced229d 100644 --- a/src/components/search/detailed/DetailedSearchResults.js +++ b/src/components/search/detailed/DetailedSearchResults.js @@ -39,6 +39,8 @@ import { import AppsIcon from "@material-ui/icons/Apps"; import SearchIcon from "@material-ui/icons/Search"; +import { useConfig } from "contexts/config"; + const useStyles = makeStyles((theme) => ({ root: { flexGrow: 1, @@ -92,6 +94,8 @@ function DetailedSearchResults(props) { const analysesTabId = buildID(baseId, ids.ANALYSES_SEARCH_RESULTS_TAB); const teamTabId = buildID(baseId, ids.TEAM_SEARCH_RESULTS_TAB); + const [config] = useConfig(); + const dataTabIcon = selectedTab === SEARCH_RESULTS_TABS.data ? ( @@ -153,17 +157,21 @@ function DetailedSearchResults(props) { centered={!isMobile} variant={isMobile ? "fullWidth" : "standard"} > - + {config?.elasticEnabled && ( + + )} } /> - - - setDataCount(count)} - baseId={dataTabId} - /> - + {config?.elasticEnabled && ( + + setDataCount(count)} + baseId={dataTabId} + /> + + )}