From 8196dfc1ff2f51267ea767ebecdb6b506fb998ba Mon Sep 17 00:00:00 2001 From: Gaurav Vaidya Date: Wed, 1 May 2024 01:46:57 -0400 Subject: [PATCH 1/3] Update the maximum number of search results from /search_var. This commit collects the constants into a single location and documents them, and increases MAX_SEARCH_VAR_SIZE from 1000 to 3000 because the lower limit is causing DUG-468. --- src/components/search/context.js | 37 ++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/src/components/search/context.js b/src/components/search/context.js index 8d1292ab..311f35e0 100644 --- a/src/components/search/context.js +++ b/src/components/search/context.js @@ -11,6 +11,15 @@ export const useHelxSearch = () => useContext(HelxSearchContext) const PER_PAGE = 20 +// The maximum number of search results to retrieve when calling /search_var. +// "Pain" has 2095 elements, so limiting this to 3000 is probably fine for now. +const MAX_SEARCH_VAR_SIZE = 3000 + +// The maximum number of search results to retrieve when calling /search_var +// from the fetchAllVariables() function. I assume this is used in variable +// search, and so needs to be able to grab _all_ possible variables. +const MAX_SEARCH_VAR_ALL_VARIABLES_SIZE = 10000 + export const SearchLayout = Object.freeze({ GRID: 'GRID', // LIST: 'LIST', @@ -51,17 +60,17 @@ export const HelxSearch = ({ children }) => { const inputRef = useRef() const navigate = useNavigate() const [searchHistory, setSearchHistory] = useLocalStorage('search_history', []) - + /** Abort controllers */ const fetchConceptsController = useRef() const searchSelectedResultController = useRef() // const selectedResultLoading = useMemo(() => selectedResult && selectedResult.loading === true, [selectedResult]) // const selectedResultFailed = useMemo(() => selectedResult && selectedResult.failed === true, [selectedResult]) - + /** Decorate `selectedResult` with fields: * - previousResult: the last value of `selectedResult` - * + * */ const setSelectedResult = useCallback((result) => { // Make sure to cancel searchSelectedResult requests so that calls to it don't override state with stale data. @@ -118,8 +127,8 @@ export const HelxSearch = ({ children }) => { let foundConceptResult, synonymousConcepts, results - - + + if (searchSelectedResultController.current) searchSelectedResultController.current.abort() searchSelectedResultController.current = new AbortController() @@ -155,7 +164,7 @@ export const HelxSearch = ({ children }) => { if (!conceptPages[currentPage]) return [] else return conceptPages[currentPage] }, [conceptPages, currentPage]) - + const setLayout = (newLayout) => { // Only track when layout changes if (layout !== newLayout) { @@ -318,7 +327,7 @@ export const HelxSearch = ({ children }) => { concept: _id, index: 'variables_index', query: _query, - size: 1000 + size: MAX_SEARCH_VAR_SIZE, }, axiosOptions) if (!result) { return [] @@ -327,7 +336,7 @@ export const HelxSearch = ({ children }) => { .reduce((studies, key) => { if (key !== "cde") { const newStudies = [...result[key].map(item => ({ type: key, ...item }))] - return [...newStudies, ...studies] + return [...newStudies, ...studies] } return [...studies] }, []) @@ -345,7 +354,7 @@ export const HelxSearch = ({ children }) => { concept: _id, index: 'variables_index', query: _query, - size: 1000 + size: MAX_SEARCH_VAR_SIZE, }, axiosOptions) if (!result) { return null @@ -354,7 +363,7 @@ export const HelxSearch = ({ children }) => { .reduce((studies, key) => { if (key === 'cde') { const newStudies = [...result[key].map(item => ({ type: key, ...item }))] - return [...newStudies, ...studies] + return [...newStudies, ...studies] } return [...studies] }, []) @@ -412,7 +421,7 @@ export const HelxSearch = ({ children }) => { variableToUpdate["study_name"] = study.c_name variableToUpdate["withinFilter"] = "none" variables.push(variableToUpdate) - + studyToUpdate["elements"].push(variableToUpdate) }) @@ -441,12 +450,12 @@ export const HelxSearch = ({ children }) => { const params = { index: 'variables_index', query: query, - size: 10000 + size: MAX_SEARCH_VAR_ALL_VARIABLES_SIZE, } const response = await axios.post(`${helxSearchUrl}/search_var`, params) if (response.status === 200 && response.data.status === 'success' && response?.data?.result && Object.keys(response?.data?.result).length > 0) { - - // Data structure of studies matches API response + + // Data structure of studies matches API response const studies = Object.entries(response.data.result).reduce((acc, [studySource, studies]) => { studies.forEach((study) => { study.data_source = studySource From 01205a40e7c8c13caf8f93f2b18fb9c6e579db26 Mon Sep 17 00:00:00 2001 From: frostyfan109 Date: Fri, 17 May 2024 12:10:07 -0400 Subject: [PATCH 2/3] Add configurable asset url --- bin/populate_env | 5 ++++- src/contexts/environment-context.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bin/populate_env b/bin/populate_env index ee7c0055..f508fb47 100755 --- a/bin/populate_env +++ b/bin/populate_env @@ -14,7 +14,8 @@ brand_name="${REACT_APP_UI_BRAND_NAME}" tranql_url="${REACT_APP_TRANQL_URL:-\/tranql}" hidden_result_tabs="${REACT_APP_HIDDEN_RESULT_TABS}" deployment_namespace="${REACT_APP_DEPLOYMENT_NAMESPACE}" -appstore_asset_branch="${REACT_APP_APPSTORE_ASSET_BRANCH}" +appstore_asset_base_url="${REACT_APP_APPSTORE_ASSET_BASE_URL:-https:\/\/raw.githubusercontent.com\/helxplatform\/appstore}" +appstore_asset_branch="${REACT_APP_APPSTORE_ASSET_BRANCH:-master}" analytics_enabled="${REACT_APP_ANALYTICS_ENABLED:-false}" analytics_platform="${REACT_APP_ANALYTICS_PLATFORM}" analytics_token="${REACT_APP_ANALYTICS_TOKEN}" @@ -40,6 +41,7 @@ template='{ }, "hidden_result_tabs": "%HIDDEN_RESULT_TABS%", "deployment_namespace": "%DEPLOYMENT_NAMESPACE%", + "appstore_asset_base_url": "%APPSTORE_ASSET_BASE_URL%", "appstore_asset_branch": "%APPSTORE_ASSET_BRANCH%", "meta": { "title": "%META_TITLE%", @@ -62,6 +64,7 @@ echo "$template" | sed \ -e "s/%HIDDEN_RESULT_TABS%/$hidden_result_tabs/" \ -e "s/%TRANQL_URL%/$tranql_url/" \ -e "s/%DEPLOYMENT_NAMESPACE%/$deployment_namespace/" \ + -e "s/%APPSTORE_ASSET_BASE_URL%/$appstore_asset_base_url/" \ -e "s/%APPSTORE_ASSET_BRANCH%/$appstore_asset_branch/" \ -e "s/%ANALYTICS_ENABLED%/$analytics_enabled/" \ -e "s/%ANALYTICS_PLATFORM%/$analytics_platform/" \ diff --git a/src/contexts/environment-context.js b/src/contexts/environment-context.js index 1449a9e4..cf7c7d0b 100644 --- a/src/contexts/environment-context.js +++ b/src/contexts/environment-context.js @@ -131,7 +131,7 @@ export const EnvironmentProvider = ({ children }) => { let brandAssetFolder = context.brand // `catalyst` is the supported name, but support `cat` and `bdc` as well. if (brandAssetFolder === "cat" || brandAssetFolder === "bdc") brandAssetFolder = "bdc" - context.logo_url = `https://raw.githubusercontent.com/helxplatform/appstore/${ context.appstore_asset_branch }/appstore/core/static/images/${ brandAssetFolder }/logo.png` + context.logo_url = `${ context.appstore_asset_base_url }/${ context.appstore_asset_branch }/appstore/core/static/images/${ brandAssetFolder }/logo.png` setContext(context); setIsLoadingContext(false); } From 8327d36b485d76a371203d879478cfdd576d309e Mon Sep 17 00:00:00 2001 From: waTeim Date: Wed, 29 May 2024 16:21:39 -0400 Subject: [PATCH 3/3] feature: configurable asset