From 79648ab6d17db0d9cc519c5f864a55ce49e7fd3a Mon Sep 17 00:00:00 2001 From: Stephen Smith Date: Fri, 18 Oct 2024 16:27:56 -0400 Subject: [PATCH] 21838: Add load favorites saga Arvados-DCO-1.1-Signed-off-by: Stephen Smith --- services/workbench2/src/store/redux-saga.ts | 2 + .../store/tree-picker/tree-picker-actions.ts | 64 +++++++++++++------ .../projects-tree-picker.tsx | 1 - 3 files changed, 47 insertions(+), 20 deletions(-) diff --git a/services/workbench2/src/store/redux-saga.ts b/services/workbench2/src/store/redux-saga.ts index c55b2542fa..1897be5418 100644 --- a/services/workbench2/src/store/redux-saga.ts +++ b/services/workbench2/src/store/redux-saga.ts @@ -9,6 +9,7 @@ import { loadSearchWatcher, refreshTreePickerWatcher, setTreePickerCollectionFilterWatcher, + loadFavoritesProjectWatcher, } from "./tree-picker/tree-picker-actions"; /** @@ -21,6 +22,7 @@ export const rootSaga = function* () { refreshTreePickerWatcher, loadProjectWatcher, loadSearchWatcher, + loadFavoritesProjectWatcher, ]; yield all(sagas.map(saga => diff --git a/services/workbench2/src/store/tree-picker/tree-picker-actions.ts b/services/workbench2/src/store/tree-picker/tree-picker-actions.ts index ae89c04bd0..955d801001 100644 --- a/services/workbench2/src/store/tree-picker/tree-picker-actions.ts +++ b/services/workbench2/src/store/tree-picker/tree-picker-actions.ts @@ -68,6 +68,7 @@ export const treePickerSearchSagas = unionize({ APPLY_COLLECTION_FILTER: ofType<{ pickerId: string }>(), LOAD_PROJECT: ofType(), LOAD_SEARCH: ofType(), + LOAD_FAVORITES_PROJECT: ofType(), REFRESH_TREE_PICKER: ofType<{ pickerId: string }>(), }); @@ -400,14 +401,17 @@ function* loadProjectSaga({type, payload}: { yield put(treePickerActions.LOAD_TREE_PICKER_NODE({ id, pickerId })); - let { items, included } = yield call({context: services.groupsService, fn: services.groupsService.contents}, - globalSearch ? '' : id, - { filters, - excludeHomeProject: loadShared || undefined, - limit: itemLimit+1, - count: "none", - include: includeOwners, - }); + let { items, included } = yield call( + {context: services.groupsService, fn: services.groupsService.contents}, + globalSearch ? '' : id, + { + filters, + excludeHomeProject: loadShared || undefined, + limit: itemLimit+1, + count: "none", + include: includeOwners, + } + ); if (!included) { includeOwners = undefined; @@ -574,10 +578,12 @@ function* refreshTreePickerSaga({type, payload}: { }})); } if (node.id === FAVORITES_PROJECT_ID) { - return acc.concat(put(loadFavoritesProject({ - ...loadParams, - pickerId, - }))); + return acc.concat(call(loadFavoritesProjectSaga, { + type: treePickerSearchSagas.tags.LOAD_FAVORITES_PROJECT, + payload: { + ...loadParams, + pickerId, + }})); } if (node.id === PUBLIC_FAVORITES_PROJECT_ID) { return acc.concat(put(loadPublicFavoritesProject({ @@ -848,16 +854,28 @@ interface LoadFavoritesProjectParams { options?: { showOnlyOwned: boolean, showOnlyWritable: boolean }; } -export const loadFavoritesProject = (params: LoadFavoritesProjectParams) => - async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { +export const loadFavoritesProject = (params: typeof treePickerSearchSagas._Record.LOAD_FAVORITES_PROJECT) => (treePickerSearchSagas.LOAD_FAVORITES_PROJECT(params)); + +export function* loadFavoritesProjectWatcher() { + yield takeEvery(treePickerSearchSagas.tags.LOAD_FAVORITES_PROJECT, loadFavoritesProjectSaga); +} + +function* loadFavoritesProjectSaga({type, payload}: { + type: typeof treePickerSearchSagas.tags.LOAD_FAVORITES_PROJECT, + payload: typeof treePickerSearchSagas._Record.LOAD_FAVORITES_PROJECT, +}) { + try { + const services: ServiceRepository = yield getContext("services"); + const state: RootState = yield select(); + const { pickerId, includeCollections = false, includeDirectories = false, includeFiles = false, options = { showOnlyOwned: true, showOnlyWritable: false }, - } = params; - const uuid = getUserUuid(getState()); + } = payload; + const uuid = getUserUuid(state); if (uuid) { const filters = pipe( (fb: FilterBuilder) => includeCollections @@ -866,9 +884,14 @@ export const loadFavoritesProject = (params: LoadFavoritesProjectParams) => fb => fb.getFilters(), )(new FilterBuilder()); - const { items } = await services.favoriteService.list(uuid, { filters }, options.showOnlyOwned); + const { items } = yield call( + {context: services.favoriteService, fn: services.favoriteService.list}, + uuid, + { filters }, + options.showOnlyOwned, + ); - dispatch(receiveTreePickerData({ + yield put(receiveTreePickerData({ id: 'Favorites', pickerId, data: items.filter((item) => { @@ -885,7 +908,10 @@ export const loadFavoritesProject = (params: LoadFavoritesProjectParams) => extractNodeData: extractGroupContentsNodeData(includeDirectories || includeFiles), })); } - }; + } catch(e) { + yield put(snackbarActions.OPEN_SNACKBAR({ message: `Failed to load favorites`, kind: SnackbarKind.ERROR })); + } +} export const loadPublicFavoritesProject = (params: LoadFavoritesProjectParams) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { diff --git a/services/workbench2/src/views-components/projects-tree-picker/projects-tree-picker.tsx b/services/workbench2/src/views-components/projects-tree-picker/projects-tree-picker.tsx index dc96bb3971..b493aa3afc 100644 --- a/services/workbench2/src/views-components/projects-tree-picker/projects-tree-picker.tsx +++ b/services/workbench2/src/views-components/projects-tree-picker/projects-tree-picker.tsx @@ -189,7 +189,6 @@ export const ProjectsTreePicker = connect(mapStateToProps, mapDispatchToProps)( item: TreeItem, pickerId: string) { this.setState({activeItem: item.data}); - console.log(item.data); } render() { -- 2.30.2