Skip to content

Commit

Permalink
Remove searchTree from redux store (#1191)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmfalke authored Aug 26, 2024
1 parent 1d86e56 commit a5d60cd
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 71 deletions.
2 changes: 1 addition & 1 deletion packages/libs/web-common/src/util/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]));
Expand Down
10 changes: 0 additions & 10 deletions packages/libs/web-common/src/wrapStoreModules.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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('');

Expand Down Expand Up @@ -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,
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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) }
),
};
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -16,29 +14,13 @@ const composeReducerWith = curryN(2, composeReducers);

export default compose(
useUserDatasetsWorkspace ? addUserDatasetStoreModules : identity,
update('globalData.reduce', composeReducerWith(mbioGlobalData)),
update(
'studies.reduce',
composeReducerWith(applyCustomDisplayNameToStudySearches)
),
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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
}

Expand Down

0 comments on commit a5d60cd

Please sign in to comment.