Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORE 1961 #547

Merged
merged 12 commits into from
Oct 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions config/default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,6 @@ username:
subscriptions:
checkout_url: https://cyverse-subscription-sandbox.phoenixbioinformatics.org
enforce: true

elastic:
enabled: true
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
},
});
5 changes: 4 additions & 1 deletion src/components/layout/AppBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
117 changes: 70 additions & 47 deletions src/components/search/GlobalSearchField.js
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@ function GlobalSearchField(props) {
const { t: analysesI18n } = useTranslation("analyses");
const { t: i18NSearch } = useTranslation("search");
const appRecordFields = appFields(appsI18n);
const defaultTab = config?.elasticEnabled
? SEARCH_RESULTS_TABS.data
: SEARCH_RESULTS_TABS.apps;

const [searchTerm, setSearchTerm] = useState(search);
const [filter, setFilter] = useState(selectedFilter || searchConstants.ALL);
Expand Down Expand Up @@ -407,10 +410,15 @@ function GlobalSearchField(props) {
},
};

const viewAllDataOptions = {
id: searchConstants.VIEW_ALL_DATA_ID,
name: searchTerm,
resultType: { type: t("data"), id: searchConstants.DATA },
// 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
? {
id: searchConstants.VIEW_ALL_DATA_ID,
name: searchTerm,
resultType: { type: t("data"), id: searchConstants.DATA },
}
: false;
};

const viewAllAppOptions = {
Expand Down Expand Up @@ -447,14 +455,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,
Expand All @@ -479,14 +489,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]);
}
Expand All @@ -508,19 +520,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));
}
}
);
Expand All @@ -536,14 +554,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]);
}
Expand Down Expand Up @@ -614,7 +634,7 @@ function GlobalSearchField(props) {
const isLoggedIn = !!userProfile?.id;
switch (filter) {
case searchConstants.DATA:
setDataSearchQueryEnabled(true);
setDataSearchQueryEnabled(config?.elasticEnabled);
setAppsSearchQueryEnabled(false);
setAnalysesSearchQueryEnabled(false);
setTeamSearchQueryEnabled(false);
Expand Down Expand Up @@ -642,7 +662,7 @@ function GlobalSearchField(props) {
break;

default:
setDataSearchQueryEnabled(true);
setDataSearchQueryEnabled(config?.elasticEnabled);
setAppsSearchQueryEnabled(true);
setAnalysesSearchQueryEnabled(isLoggedIn);
setTeamSearchQueryEnabled(isLoggedIn);
Expand Down Expand Up @@ -808,22 +828,25 @@ function GlobalSearchField(props) {
selectedTab:
filter && filter !== searchConstants.ALL
? filter.toUpperCase()
: SEARCH_RESULTS_TABS.data,
: defaultTab,
});
}
}}
/>
);

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 (
<>
Expand Down
4 changes: 2 additions & 2 deletions src/components/search/detailed/DataSearchResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
Expand All @@ -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];
});
Expand Down
57 changes: 33 additions & 24 deletions src/components/search/detailed/DetailedSearchResults.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 ? (
<DataIcon className={classes.selectedTabIcon} />
Expand Down Expand Up @@ -153,17 +157,21 @@ function DetailedSearchResults(props) {
centered={!isMobile}
variant={isMobile ? "fullWidth" : "standard"}
>
<DETab
value={SEARCH_RESULTS_TABS.data}
key={dataTabId}
id={dataTabId}
label={
isMobile
? `(${dataCount})`
: t("search:dataSearchTab", { count: dataCount })
}
icon={dataTabIcon}
/>
{config?.elasticEnabled && (
<DETab
value={SEARCH_RESULTS_TABS.data}
key={dataTabId}
id={dataTabId}
label={
isMobile
? `(${dataCount})`
: t("search:dataSearchTab", {
count: dataCount,
})
}
icon={dataTabIcon}
/>
)}
<DETab
value={SEARCH_RESULTS_TABS.apps}
key={appsTabId}
Expand Down Expand Up @@ -202,19 +210,20 @@ function DetailedSearchResults(props) {
icon={<TeamIcon />}
/>
</Tabs>

<DETabPanel
tabId={dataTabId}
value={SEARCH_RESULTS_TABS.data}
selectedTab={selectedTab}
>
<DataSearchResults
searchTerm={searchTerm}
advancedDataQuery={advancedDataQuery}
updateResultCount={(count) => setDataCount(count)}
baseId={dataTabId}
/>
</DETabPanel>
{config?.elasticEnabled && (
<DETabPanel
tabId={dataTabId}
value={SEARCH_RESULTS_TABS.data}
selectedTab={selectedTab}
>
<DataSearchResults
searchTerm={searchTerm}
advancedDataQuery={advancedDataQuery}
updateResultCount={(count) => setDataCount(count)}
baseId={dataTabId}
/>
</DETabPanel>
)}
<DETabPanel
tabId={appsTabId}
value={SEARCH_RESULTS_TABS.apps}
Expand Down
2 changes: 2 additions & 0 deletions src/pages/_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -230,6 +231,7 @@ function MyApp({ Component, pageProps }) {
supportEmail,
deFaq,
cyverseURL,
elasticEnabled,
});

const jssStyles = document.querySelector("#jss-server-side");
Expand Down
8 changes: 7 additions & 1 deletion src/pages/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ import GlobalSearchField from "components/search/GlobalSearchField";
import DetailedSearchResults from "components/search/detailed/DetailedSearchResults";
import SEARCH_RESULTS_TABS from "components/search/detailed/tabs";
import NavigationConstants from "common/NavigationConstants";
import { useConfig } from "contexts/config";

export default function Search() {
const [config] = useConfig();
const router = useRouter();
const defaultTab = config?.elasticEnabled
? SEARCH_RESULTS_TABS.data
: SEARCH_RESULTS_TABS.apps;
const { searchTerm, filter, selectedTab, advancedDataQuery } =
router?.query;
let tab = selectedTab || SEARCH_RESULTS_TABS.data;

let tab = selectedTab || defaultTab;
const onShowDetailedSearch = (query) => {
router.push({
pathname: `/${NavigationConstants.SEARCH}`,
Expand Down
1 change: 1 addition & 0 deletions stories/configMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,5 @@ export default {
"https://cyverse-subscription-sandbox.phoenixbioinformatics.org",
enforce: true,
},
elasticEnabled: true,
};
Loading