diff --git a/packages/libs/web-common/src/util/category.js b/packages/libs/web-common/src/util/category.js index 884826390a..b6cc346be7 100644 --- a/packages/libs/web-common/src/util/category.js +++ b/packages/libs/web-common/src/util/category.js @@ -18,7 +18,7 @@ let isSearchMenuScope = isQualifying({ targetType: 'search', scope: 'menu' }); * * @param {Ontology} ontology * @param {RecordClass[]} recordClasses - * @returns RecordClassTree + * @returns {import('@veupathdb/wdk-client/lib/Utils/CategoryUtils').CategoryTreeNode} */ export function getSearchMenuCategoryTree(ontology, recordClasses) { let recordClassMap = new Map(recordClasses.map((rc) => [rc.fullName, rc])); diff --git a/packages/libs/web-common/src/wrapStoreModules.js b/packages/libs/web-common/src/wrapStoreModules.js index e3b376836e..52c6b3a900 100644 --- a/packages/libs/web-common/src/wrapStoreModules.js +++ b/packages/libs/web-common/src/wrapStoreModules.js @@ -5,7 +5,6 @@ import { QUICK_SEARCH_LOADED, } from './actioncreators/GlobalActionCreators'; import * as contactUs from './store-modules/ContactUsStoreModule'; -import { getSearchMenuCategoryTree } from './util/category'; import { selectReporterComponent } from './util/reporter'; import * as galaxyTerms from './store-modules/GalaxyTerms'; @@ -83,15 +82,6 @@ function ebrcGlobalData(state, { type, payload }) { quickSearchesLoading: false, }); - case 'static/all-data-loaded': - return { - ...state, - searchTree: getSearchMenuCategoryTree( - state.ontology, - state.recordClasses - ), - }; - default: return state; } diff --git a/packages/sites/genomics-site/webapp/wdkCustomization/js/client/components/homepage/VEuPathDBHomePage.tsx b/packages/sites/genomics-site/webapp/wdkCustomization/js/client/components/homepage/VEuPathDBHomePage.tsx index 99da4d289b..884dd1756a 100644 --- a/packages/sites/genomics-site/webapp/wdkCustomization/js/client/components/homepage/VEuPathDBHomePage.tsx +++ b/packages/sites/genomics-site/webapp/wdkCustomization/js/client/components/homepage/VEuPathDBHomePage.tsx @@ -72,6 +72,7 @@ import { Question } from '@veupathdb/wdk-client/lib/Utils/WdkModel'; import { Tooltip, Warning } from '@veupathdb/coreui'; import './VEuPathDBHomePage.scss'; +import { searchTree } from '../../selectors/QueryGridSelectors'; const vpdbCx = makeVpdbClassNameHelper(''); @@ -1135,8 +1136,7 @@ const filterMenuItemEntry = ( // FIXME: Use a hook instead of "connect" to provide the global data const mapStateToProps = (state: RootState) => ({ - // FIXME: This is not typesafe. - searchTree: get(state.globalData, 'searchTree') as CategoryTreeNode, + searchTree: searchTree(state), buildNumber: state.globalData.config?.buildNumber, releaseDate: state.globalData.config?.releaseDate, displayName: state.globalData.config?.displayName, diff --git a/packages/sites/genomics-site/webapp/wdkCustomization/js/client/selectors/QueryGridSelectors.js b/packages/sites/genomics-site/webapp/wdkCustomization/js/client/selectors/QueryGridSelectors.js deleted file mode 100644 index dc6614b8a8..0000000000 --- a/packages/sites/genomics-site/webapp/wdkCustomization/js/client/selectors/QueryGridSelectors.js +++ /dev/null @@ -1,3 +0,0 @@ -import { get } from 'lodash/fp'; - -export const searchTree = get('globalData.searchTree'); diff --git a/packages/sites/genomics-site/webapp/wdkCustomization/js/client/selectors/QueryGridSelectors.ts b/packages/sites/genomics-site/webapp/wdkCustomization/js/client/selectors/QueryGridSelectors.ts new file mode 100644 index 0000000000..b7ffa834b9 --- /dev/null +++ b/packages/sites/genomics-site/webapp/wdkCustomization/js/client/selectors/QueryGridSelectors.ts @@ -0,0 +1,18 @@ +import { getSearchMenuCategoryTree } from '@veupathdb/web-common/lib/util/category'; +import { getLeaves } from '@veupathdb/wdk-client/lib/Utils/TreeUtils'; +import { RootState } from '@veupathdb/wdk-client/lib/Core/State/Types'; + +export function searchTree(state: RootState) { + const { ontology, recordClasses } = state.globalData; + if (ontology == null || recordClasses == null) return undefined; + const tree = getSearchMenuCategoryTree(ontology, recordClasses); + return { + ...tree, + children: tree.children.map((node) => + node.properties.label?.[0] === + 'TranscriptRecordClasses.TranscriptRecordClass' + ? node + : { ...node, children: getLeaves(node, (node) => node.children) } + ), + }; +} diff --git a/packages/sites/genomics-site/webapp/wdkCustomization/js/client/storeModules/GlobalData.js b/packages/sites/genomics-site/webapp/wdkCustomization/js/client/storeModules/GlobalData.js deleted file mode 100644 index 9cbc77745e..0000000000 --- a/packages/sites/genomics-site/webapp/wdkCustomization/js/client/storeModules/GlobalData.js +++ /dev/null @@ -1,27 +0,0 @@ -import { allDataLoaded } from '@veupathdb/wdk-client/lib/Actions/StaticDataActions'; -import { getLeaves } from '@veupathdb/wdk-client/lib/Utils/TreeUtils'; - -export function reduce(state, action) { - switch (action.type) { - // flatten search tree - case allDataLoaded.type: - return { - ...state, - searchTree: { - ...state.searchTree, - children: state.searchTree.children.map((node) => - node.properties.label[0] === - 'TranscriptRecordClasses.TranscriptRecordClass' - ? node - : { ...node, children: getLeaves(node, (node) => node.children) } - ), - }, - }; - default: - return state; - } -} - -// FIXME Update basket count in header when wdk basket actions are moved to epic middleware -// export function observe(action$, state$, services) { -// } diff --git a/packages/sites/genomics-site/webapp/wdkCustomization/js/client/wrapStoreModules.js b/packages/sites/genomics-site/webapp/wdkCustomization/js/client/wrapStoreModules.js index 8c79eb7870..e923f5da30 100644 --- a/packages/sites/genomics-site/webapp/wdkCustomization/js/client/wrapStoreModules.js +++ b/packages/sites/genomics-site/webapp/wdkCustomization/js/client/wrapStoreModules.js @@ -6,7 +6,6 @@ import * as blastSummaryView from '@veupathdb/blast-summary-view/lib/StoreModule import { wrapStoreModules as addUserDatasetStoreModules } from '@veupathdb/user-datasets/lib/StoreModules'; -import * as globalData from './storeModules/GlobalData'; import * as record from './storeModules/Record'; import * as userCommentForm from './storeModules/UserCommentFormStoreModule'; import * as userCommentShow from './storeModules/UserCommentShowStoreModule'; @@ -17,13 +16,6 @@ export default flowRight( (storeModules) => ({ ...storeModules, record, - globalData: { - ...storeModules.globalData, - reduce: (state, action) => { - state = storeModules.globalData.reduce(state, action); - return globalData.reduce(state, action); - }, - }, userCommentForm, userCommentShow, blastSummaryView, diff --git a/packages/sites/mbio-site/webapp/wdkCustomization/js/client/wrapStoreModules.js b/packages/sites/mbio-site/webapp/wdkCustomization/js/client/wrapStoreModules.js index a545466ab4..1f435c818b 100644 --- a/packages/sites/mbio-site/webapp/wdkCustomization/js/client/wrapStoreModules.js +++ b/packages/sites/mbio-site/webapp/wdkCustomization/js/client/wrapStoreModules.js @@ -1,7 +1,5 @@ import { compose, curryN, identity, partition, update } from 'lodash/fp'; -import { getLeaves } from '@veupathdb/wdk-client/lib/Utils/TreeUtils'; - import { useUserDatasetsWorkspace } from '@veupathdb/web-common/lib/config'; import { wrapStoreModules as addUserDatasetStoreModules } from '@veupathdb/user-datasets/lib/StoreModules'; @@ -16,7 +14,6 @@ const composeReducerWith = curryN(2, composeReducers); export default compose( useUserDatasetsWorkspace ? addUserDatasetStoreModules : identity, - update('globalData.reduce', composeReducerWith(mbioGlobalData)), update( 'studies.reduce', composeReducerWith(applyCustomDisplayNameToStudySearches) @@ -24,21 +21,6 @@ export default compose( update('searchCards.reduce', composeReducerWith(applyCustomIconToSearchCards)) ); -function mbioGlobalData(state, action) { - switch (action.type) { - // flatten search tree - case 'static/all-data-loaded': - return { - ...state, - searchTree: { - children: getLeaves(state.searchTree, (node) => node.children), - }, - }; - default: - return state; - } -} - function applyCustomDisplayNameToStudySearches(studies) { return { ...studies, diff --git a/packages/sites/ortho-site/webapp/wdkCustomization/js/client/hooks/searchCheckboxTree.ts b/packages/sites/ortho-site/webapp/wdkCustomization/js/client/hooks/searchCheckboxTree.ts index 7548bef19a..adcee20492 100644 --- a/packages/sites/ortho-site/webapp/wdkCustomization/js/client/hooks/searchCheckboxTree.ts +++ b/packages/sites/ortho-site/webapp/wdkCustomization/js/client/hooks/searchCheckboxTree.ts @@ -6,11 +6,16 @@ import { RootState } from '@veupathdb/wdk-client/lib/Core/State/Types'; import { useSessionBackedState } from '@veupathdb/wdk-client/lib/Hooks/SessionBackedState'; import { CategoryTreeNode } from '@veupathdb/wdk-client/lib/Utils/CategoryUtils'; import { decode, arrayOf, string } from '@veupathdb/wdk-client/lib/Utils/Json'; +import { getSearchMenuCategoryTree } from '@veupathdb/web-common/lib/util/category'; export function useSearchTree() { return useSelector( - (state: RootState) => - get(state.globalData, 'searchTree') as CategoryTreeNode | undefined + ({ globalData: { ontology, recordClasses } }: RootState) => + (ontology && + recordClasses && + getSearchMenuCategoryTree(ontology, recordClasses)) as + | CategoryTreeNode + | undefined ); }