X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/be5e418e1bb0ff54401b71c2cf6865222d182c18..ba244d0282e8dc6c21ebf6a509750717bae35783:/src/store/side-panel-tree/side-panel-tree-actions.ts diff --git a/src/store/side-panel-tree/side-panel-tree-actions.ts b/src/store/side-panel-tree/side-panel-tree-actions.ts index f6015fbf..44dfe869 100644 --- a/src/store/side-panel-tree/side-panel-tree-actions.ts +++ b/src/store/side-panel-tree/side-panel-tree-actions.ts @@ -14,22 +14,23 @@ import { getNodeAncestors, getNodeAncestorsIds, getNode, TreeNode, initTreeNode, import { ProjectResource } from 'models/project'; import { OrderBuilder } from 'services/api/order-builder'; import { ResourceKind } from 'models/resource'; -import { GroupContentsResourcePrefix } from 'services/groups-service/groups-service'; -import { GroupClass } from 'models/group'; import { CategoriesListReducer } from 'common/plugintypes'; import { pluginConfig } from 'plugins'; +import { LinkClass } from 'models/link'; export enum SidePanelTreeCategory { PROJECTS = 'Home Projects', - SHARED_WITH_ME = 'Shared with me', - PUBLIC_FAVORITES = 'Public Favorites', FAVORITES = 'My Favorites', - TRASH = 'Trash', + PUBLIC_FAVORITES = 'Public Favorites', + SHARED_WITH_ME = 'Shared with me', ALL_PROCESSES = 'All Processes', + SHELL_ACCESS = 'Shell Access', GROUPS = 'Groups', + TRASH = 'Trash', } export const SIDE_PANEL_TREE = 'sidePanelTree'; +const SIDEPANEL_TREE_NODE_LIMIT = 50 export const getSidePanelTree = (treePicker: TreePicker) => getTreePicker(SIDE_PANEL_TREE)(treePicker); @@ -48,11 +49,12 @@ export const getSidePanelTreeBranch = (uuid: string) => (treePicker: TreePicker) let SIDE_PANEL_CATEGORIES: string[] = [ SidePanelTreeCategory.PROJECTS, - SidePanelTreeCategory.SHARED_WITH_ME, - SidePanelTreeCategory.PUBLIC_FAVORITES, SidePanelTreeCategory.FAVORITES, - SidePanelTreeCategory.GROUPS, + SidePanelTreeCategory.PUBLIC_FAVORITES, + SidePanelTreeCategory.SHARED_WITH_ME, SidePanelTreeCategory.ALL_PROCESSES, + SidePanelTreeCategory.SHELL_ACCESS, + SidePanelTreeCategory.GROUPS, SidePanelTreeCategory.TRASH ]; @@ -81,7 +83,7 @@ export const initSidePanelTree = () => nodes })); SIDE_PANEL_CATEGORIES.forEach(category => { - if (category !== SidePanelTreeCategory.PROJECTS && category !== SidePanelTreeCategory.SHARED_WITH_ME) { + if (category !== SidePanelTreeCategory.PROJECTS && category !== SidePanelTreeCategory.FAVORITES && category !== SidePanelTreeCategory.PUBLIC_FAVORITES ) { dispatch(treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ id: category, pickerId: SIDE_PANEL_TREE, @@ -95,8 +97,10 @@ export const loadSidePanelTreeProjects = (projectUuid: string) => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { const treePicker = getTreePicker(SIDE_PANEL_TREE)(getState().treePicker); const node = treePicker ? getNode(projectUuid)(treePicker) : undefined; - if (projectUuid === SidePanelTreeCategory.SHARED_WITH_ME) { - await dispatch(loadSharedRoot); + if (projectUuid === SidePanelTreeCategory.PUBLIC_FAVORITES) { + await dispatch(loadPublicFavoritesTree()); + } else if (projectUuid === SidePanelTreeCategory.FAVORITES) { + await dispatch(loadFavoritesTree()); } else if (node || projectUuid !== '') { await dispatch(loadProject(projectUuid)); } @@ -110,10 +114,13 @@ const loadProject = (projectUuid: string) => .addEqual('owner_uuid', projectUuid) .getFilters(), order: new OrderBuilder() - .addAsc('name') - .getOrder() + .addDesc('createdAt') + .getOrder(), + limit: SIDEPANEL_TREE_NODE_LIMIT, }; + const { items } = await services.projectService.list(params); + dispatch(treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ id: projectUuid, pickerId: SIDE_PANEL_TREE, @@ -122,28 +129,58 @@ const loadProject = (projectUuid: string) => dispatch(resourcesActions.SET_RESOURCES(items)); }; -const loadSharedRoot = async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { - dispatch(treePickerActions.LOAD_TREE_PICKER_NODE({ id: SidePanelTreeCategory.SHARED_WITH_ME, pickerId: SIDE_PANEL_TREE })); +export const loadFavoritesTree = () => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + dispatch(treePickerActions.LOAD_TREE_PICKER_NODE({ id: SidePanelTreeCategory.FAVORITES, pickerId: SIDE_PANEL_TREE })); + + const params = { + filters: new FilterBuilder() + .addEqual('link_class', LinkClass.STAR) + .addEqual('tail_uuid', getUserUuid(getState())) + .addEqual('tail_kind', ResourceKind.USER) + .getFilters(), + order: new OrderBuilder().addDesc('createdAt').getOrder(), + limit: SIDEPANEL_TREE_NODE_LIMIT, + }; + + const { items } = await services.linkService.list(params); + + dispatch( + treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ + id: SidePanelTreeCategory.FAVORITES, + pickerId: SIDE_PANEL_TREE, + nodes: items.map(item => initTreeNode({ id: item.headUuid, value: item })), + }) + ); + + dispatch(resourcesActions.SET_RESOURCES(items)); +}; + +export const loadPublicFavoritesTree = () => async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + dispatch(treePickerActions.LOAD_TREE_PICKER_NODE({ id: SidePanelTreeCategory.PUBLIC_FAVORITES, pickerId: SIDE_PANEL_TREE })); + + const uuidPrefix = getState().auth.config.uuidPrefix; + const publicProjectUuid = `${uuidPrefix}-j7d0g-publicfavorites`; + const typeFilters = [ResourceKind.COLLECTION, ResourceKind.CONTAINER_REQUEST, ResourceKind.GROUP, ResourceKind.WORKFLOW]; const params = { - filters: `[${new FilterBuilder() - .addIsA('uuid', ResourceKind.PROJECT) - .addIn('group_class', [GroupClass.PROJECT, GroupClass.FILTER]) - .addDistinct('uuid', getState().auth.config.uuidPrefix + '-j7d0g-publicfavorites') - .getFilters()}]`, - order: new OrderBuilder() - .addAsc('name', GroupContentsResourcePrefix.PROJECT) - .getOrder(), - limit: 1000 + filters: new FilterBuilder() + .addEqual('link_class', LinkClass.STAR) + .addEqual('owner_uuid', publicProjectUuid) + .addIsA('head_uuid', typeFilters) + .getFilters(), + order: new OrderBuilder().addDesc('createdAt').getOrder(), + limit: SIDEPANEL_TREE_NODE_LIMIT, }; - const { items } = await services.groupsService.shared(params); + const { items } = await services.linkService.list(params); - dispatch(treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ - id: SidePanelTreeCategory.SHARED_WITH_ME, - pickerId: SIDE_PANEL_TREE, - nodes: items.map(item => initTreeNode({ id: item.uuid, value: item })), - })); + dispatch( + treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ + id: SidePanelTreeCategory.PUBLIC_FAVORITES, + pickerId: SIDE_PANEL_TREE, + nodes: items.map(item => initTreeNode({ id: item.headUuid, value: item })), + }) + ); dispatch(resourcesActions.SET_RESOURCES(items)); }; @@ -152,9 +189,9 @@ export const activateSidePanelTreeItem = (id: string) => async (dispatch: Dispatch, getState: () => RootState) => { const node = getSidePanelTreeNode(id)(getState().treePicker); if (node && !node.active) { - dispatch(treePickerActions.ACTIVATE_TREE_PICKER_NODE({ id, pickerId: SIDE_PANEL_TREE })); - } - if (!isSidePanelTreeCategory(id)) { + dispatch(treePickerActions.ACTIVATE_TREE_PICKER_NODE({ id, pickerId: SIDE_PANEL_TREE })); + } + if (!isSidePanelTreeCategory(id)) { await dispatch(activateSidePanelTreeProject(id)); } }; @@ -180,18 +217,11 @@ export const activateSidePanelTreeBranch = (id: string) => const userUuid = getUserUuid(getState()); if (!userUuid) { return; } const ancestors = await services.ancestorsService.ancestors(id, userUuid); - const isShared = ancestors.every(({ uuid }) => uuid !== userUuid); - if (isShared) { - await dispatch(loadSidePanelTreeProjects(SidePanelTreeCategory.SHARED_WITH_ME)); - } for (const ancestor of ancestors) { await dispatch(loadSidePanelTreeProjects(ancestor.uuid)); } dispatch(treePickerActions.EXPAND_TREE_PICKER_NODES({ - ids: [ - ...(isShared ? [SidePanelTreeCategory.SHARED_WITH_ME] : []), - ...ancestors.map(ancestor => ancestor.uuid) - ], + ids: ancestors.map(ancestor => ancestor.uuid), pickerId: SIDE_PANEL_TREE })); dispatch(treePickerActions.ACTIVATE_TREE_PICKER_NODE({ id, pickerId: SIDE_PANEL_TREE })); @@ -203,7 +233,7 @@ export const toggleSidePanelTreeItemCollapse = (id: string) => if (node && node.status === TreeNodeStatus.INITIAL) { await dispatch(loadSidePanelTreeProjects(node.id)); } - dispatch(treePickerActions.TOGGLE_TREE_PICKER_NODE_COLLAPSE({ id, pickerId: SIDE_PANEL_TREE })); + dispatch(treePickerActions.TOGGLE_TREE_PICKER_NODE_COLLAPSE({ id, pickerId: SIDE_PANEL_TREE })); }; export const expandSidePanelTreeItem = (id: string) =>