X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/2b3f667039ba2e7efe0852d58ae2c62899b773f0..0602c276f01e91b1bb6dafcc3adfc0dd43a922fc:/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 09009930d0..8fac7dc22b 100644 --- a/src/store/side-panel-tree/side-panel-tree-actions.ts +++ b/src/store/side-panel-tree/side-panel-tree-actions.ts @@ -3,28 +3,33 @@ // SPDX-License-Identifier: AGPL-3.0 import { Dispatch } from 'redux'; -import { treePickerActions } from "~/store/tree-picker/tree-picker-actions"; -import { RootState } from '~/store/store'; -import { ServiceRepository } from '~/services/services'; -import { FilterBuilder } from '~/services/api/filter-builder'; -import { resourcesActions } from '~/store/resources/resources-actions'; -import { getTreePicker, TreePicker } from '~/store/tree-picker/tree-picker'; -import { getNodeAncestors, getNodeAncestorsIds, getNode, TreeNode, initTreeNode, TreeNodeStatus } from '~/models/tree'; -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 { treePickerActions } from "store/tree-picker/tree-picker-actions"; +import { RootState } from 'store/store'; +import { getUserUuid } from "common/getuser"; +import { ServiceRepository } from 'services/services'; +import { FilterBuilder } from 'services/api/filter-builder'; +import { resourcesActions } from 'store/resources/resources-actions'; +import { getTreePicker, TreePicker } from 'store/tree-picker/tree-picker'; +import { getNodeAncestors, getNodeAncestorsIds, getNode, TreeNode, initTreeNode, TreeNodeStatus } from 'models/tree'; +import { ProjectResource } from 'models/project'; +import { OrderBuilder } from 'services/api/order-builder'; +import { ResourceKind } from 'models/resource'; +import { CategoriesListReducer } from 'common/plugintypes'; +import { pluginConfig } from 'plugins'; +import { LinkClass } from 'models/link'; export enum SidePanelTreeCategory { - PROJECTS = 'Projects', + PROJECTS = 'Home Projects', SHARED_WITH_ME = 'Shared with me', - WORKFLOWS = 'Workflows', - FAVORITES = 'Favorites', - TRASH = 'Trash' + PUBLIC_FAVORITES = 'Public Favorites', + FAVORITES = 'My Favorites', + TRASH = 'Trash', + ALL_PROCESSES = 'All Processes', + GROUPS = 'Groups', } export const SIDE_PANEL_TREE = 'sidePanelTree'; +const TREE_NODE_LIMIT = 50 export const getSidePanelTree = (treePicker: TreePicker) => getTreePicker(SIDE_PANEL_TREE)(treePicker); @@ -41,31 +46,48 @@ export const getSidePanelTreeBranch = (uuid: string) => (treePicker: TreePicker) return []; }; -const SIDE_PANEL_CATEGORIES = [ - SidePanelTreeCategory.WORKFLOWS, +let SIDE_PANEL_CATEGORIES: string[] = [ + SidePanelTreeCategory.PROJECTS, + SidePanelTreeCategory.SHARED_WITH_ME, + SidePanelTreeCategory.PUBLIC_FAVORITES, SidePanelTreeCategory.FAVORITES, - SidePanelTreeCategory.TRASH, + SidePanelTreeCategory.GROUPS, + SidePanelTreeCategory.ALL_PROCESSES, + SidePanelTreeCategory.TRASH ]; +const reduceCatsFn: (a: string[], + b: CategoriesListReducer) => string[] = (a, b) => b(a); + +SIDE_PANEL_CATEGORIES = pluginConfig.sidePanelCategories.reduce(reduceCatsFn, SIDE_PANEL_CATEGORIES); + export const isSidePanelTreeCategory = (id: string) => SIDE_PANEL_CATEGORIES.some(category => category === id); + export const initSidePanelTree = () => - (dispatch: Dispatch, _: () => RootState, { authService }: ServiceRepository) => { - const rootProjectUuid = authService.getUuid() || ''; - const nodes = SIDE_PANEL_CATEGORIES.map(id => initTreeNode({ id, value: id })); - const projectsNode = initTreeNode({ id: rootProjectUuid, value: SidePanelTreeCategory.PROJECTS }); - const sharedNode = initTreeNode({ id: SidePanelTreeCategory.SHARED_WITH_ME, value: SidePanelTreeCategory.SHARED_WITH_ME }); + (dispatch: Dispatch, getState: () => RootState, { authService }: ServiceRepository) => { + const rootProjectUuid = getUserUuid(getState()); + if (!rootProjectUuid) { return; } + const nodes = SIDE_PANEL_CATEGORIES.map(id => { + if (id === SidePanelTreeCategory.PROJECTS) { + return initTreeNode({ id: rootProjectUuid, value: SidePanelTreeCategory.PROJECTS }); + } else { + return initTreeNode({ id, value: id }); + } + }); dispatch(treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ id: '', pickerId: SIDE_PANEL_TREE, - nodes: [projectsNode, sharedNode, ...nodes] + nodes })); SIDE_PANEL_CATEGORIES.forEach(category => { - dispatch(treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ - id: category, - pickerId: SIDE_PANEL_TREE, - nodes: [] - })); + if (category !== SidePanelTreeCategory.PROJECTS && category !== SidePanelTreeCategory.FAVORITES && category !== SidePanelTreeCategory.PUBLIC_FAVORITES ) { + dispatch(treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ + id: category, + pickerId: SIDE_PANEL_TREE, + nodes: [] + })); + } }); }; @@ -73,9 +95,11 @@ 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); - } else if (node || projectUuid === '') { + if (projectUuid === SidePanelTreeCategory.PUBLIC_FAVORITES) { + await dispatch(loadPublicFavorites); + } else if (projectUuid === SidePanelTreeCategory.FAVORITES) { + await dispatch(loadFavorites); + } else if (node || projectUuid !== '') { await dispatch(loadProject(projectUuid)); } }; @@ -85,7 +109,7 @@ const loadProject = (projectUuid: string) => dispatch(treePickerActions.LOAD_TREE_PICKER_NODE({ id: projectUuid, pickerId: SIDE_PANEL_TREE })); const params = { filters: new FilterBuilder() - .addEqual('ownerUuid', projectUuid) + .addEqual('owner_uuid', projectUuid) .getFilters(), order: new OrderBuilder() .addAsc('name') @@ -100,25 +124,58 @@ const loadProject = (projectUuid: string) => dispatch(resourcesActions.SET_RESOURCES(items)); }; -const loadSharedRoot = async (dispatch: Dispatch, _: () => RootState, services: ServiceRepository) => { - dispatch(treePickerActions.LOAD_TREE_PICKER_NODE({ id: SidePanelTreeCategory.SHARED_WITH_ME, pickerId: SIDE_PANEL_TREE })); +const loadFavorites = 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() - .addIsA('uuid', ResourceKind.PROJECT) - .addEqual('groupClass', GroupClass.PROJECT) - .getFilters()}]`, + filters: new FilterBuilder() + .addEqual("link_class", LinkClass.STAR) + .addEqual('tail_uuid', getUserUuid(getState())) + .addEqual('tail_kind', ResourceKind.USER) + .getFilters(), order: new OrderBuilder() - .addAsc('name', GroupContentsResourcePrefix.PROJECT) + .addDesc('createdAt') .getOrder(), + limit: 50 + } + + 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)); +}; + +const loadPublicFavorites = 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() + .addEqual('link_class', LinkClass.STAR) + .addEqual('owner_uuid', publicProjectUuid) + .addIsA('head_uuid', typeFilters) + .getFilters(), + order: new OrderBuilder() + .addDesc('createdAt') + .getOrder(), + limit: TREE_NODE_LIMIT }; - const { items } = await services.groupsService.shared(params); + const { items } = await services.linkService.list(params); + console.log(items) dispatch(treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({ - id: SidePanelTreeCategory.SHARED_WITH_ME, + id: SidePanelTreeCategory.PUBLIC_FAVORITES, pickerId: SIDE_PANEL_TREE, - nodes: items.map(item => initTreeNode({ id: item.uuid, value: item })), + nodes: items.map(item => initTreeNode({ id: item.headUuid, value: item })), })); dispatch(resourcesActions.SET_RESOURCES(items)); @@ -127,6 +184,7 @@ const loadSharedRoot = async (dispatch: Dispatch, _: () => RootState, services: export const activateSidePanelTreeItem = (id: string) => async (dispatch: Dispatch, getState: () => RootState) => { const node = getSidePanelTreeNode(id)(getState().treePicker); + console.log(id) if (node && !node.active) { dispatch(treePickerActions.ACTIVATE_TREE_PICKER_NODE({ id, pickerId: SIDE_PANEL_TREE })); } @@ -152,20 +210,15 @@ export const activateSidePanelTreeProject = (id: string) => }; export const activateSidePanelTreeBranch = (id: string) => - async (dispatch: Dispatch, _: void, services: ServiceRepository) => { - const ancestors = await services.ancestorsService.ancestors(id, services.authService.getUuid() || ''); - const isShared = ancestors.every(({ uuid }) => uuid !== services.authService.getUuid()); - if (isShared) { - await dispatch(loadSidePanelTreeProjects(SidePanelTreeCategory.SHARED_WITH_ME)); - } + async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { + const userUuid = getUserUuid(getState()); + if (!userUuid) { return; } + const ancestors = await services.ancestorsService.ancestors(id, userUuid); 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 }));