Merge branch 'main' into 19069-workflow-launching
[arvados-workbench2.git] / src / store / side-panel-tree / side-panel-tree-actions.ts
index 4aa5e26e3468b7bed559421a848611875bde34b8..58f7d82d956546644532767679547e39023d87c5 100644 (file)
@@ -3,27 +3,31 @@
 // 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 { 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 { 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 { GroupContentsResourcePrefix } from 'services/groups-service/groups-service';
+import { GroupClass } from 'models/group';
+import { CategoriesListReducer } from 'common/plugintypes';
+import { pluginConfig } from 'plugins';
 
 export enum SidePanelTreeCategory {
     PROJECTS = 'Projects',
     SHARED_WITH_ME = 'Shared with me',
     PUBLIC_FAVORITES = 'Public Favorites',
     WORKFLOWS = 'Workflows',
-    FAVORITES = 'Favorites',
-    TRASH = 'Trash'
+    FAVORITES = 'My Favorites',
+    TRASH = 'Trash',
+    ALL_PROCESSES = 'All Processes',
+    GROUPS = 'Groups',
 }
 
 export const SIDE_PANEL_TREE = 'sidePanelTree';
@@ -43,35 +47,49 @@ export const getSidePanelTreeBranch = (uuid: string) => (treePicker: TreePicker)
     return [];
 };
 
-const SIDE_PANEL_CATEGORIES = [
+let SIDE_PANEL_CATEGORIES: string[] = [
+    SidePanelTreeCategory.PROJECTS,
+    SidePanelTreeCategory.SHARED_WITH_ME,
     SidePanelTreeCategory.PUBLIC_FAVORITES,
-    SidePanelTreeCategory.WORKFLOWS,
     SidePanelTreeCategory.FAVORITES,
-    SidePanelTreeCategory.TRASH,
+    //    SidePanelTreeCategory.WORKFLOWS,
+    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, getState: () => RootState, { authService }: ServiceRepository) => {
         const rootProjectUuid = getUserUuid(getState());
-        if (!rootProjectUuid) {
-            return;
-        }
-        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 });
+        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.SHARED_WITH_ME) {
+                dispatch(treePickerActions.LOAD_TREE_PICKER_NODE_SUCCESS({
+                    id: category,
+                    pickerId: SIDE_PANEL_TREE,
+                    nodes: []
+                }));
+            }
         });
     };
 
@@ -81,7 +99,7 @@ export const loadSidePanelTreeProjects = (projectUuid: string) =>
         const node = treePicker ? getNode(projectUuid)(treePicker) : undefined;
         if (projectUuid === SidePanelTreeCategory.SHARED_WITH_ME) {
             await dispatch<any>(loadSharedRoot);
-        } else if (node || projectUuid === '') {
+        } else if (node || projectUuid !== '') {
             await dispatch<any>(loadProject(projectUuid));
         }
     };
@@ -91,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<ProjectResource>()
                 .addAsc('name')
@@ -106,13 +124,14 @@ const loadProject = (projectUuid: string) =>
         dispatch(resourcesActions.SET_RESOURCES(items));
     };
 
-const loadSharedRoot = async (dispatch: Dispatch, _: () => RootState, services: ServiceRepository) => {
+const loadSharedRoot = async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
     dispatch(treePickerActions.LOAD_TREE_PICKER_NODE({ id: SidePanelTreeCategory.SHARED_WITH_ME, pickerId: SIDE_PANEL_TREE }));
 
     const params = {
         filters: `[${new FilterBuilder()
             .addIsA('uuid', ResourceKind.PROJECT)
-            .addEqual('groupClass', GroupClass.PROJECT)
+            .addIn('group_class', [GroupClass.PROJECT, GroupClass.FILTER])
+            .addDistinct('uuid', getState().auth.config.uuidPrefix + '-j7d0g-publicfavorites')
             .getFilters()}]`,
         order: new OrderBuilder<ProjectResource>()
             .addAsc('name', GroupContentsResourcePrefix.PROJECT)
@@ -161,9 +180,7 @@ export const activateSidePanelTreeProject = (id: string) =>
 export const activateSidePanelTreeBranch = (id: string) =>
     async (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
         const userUuid = getUserUuid(getState());
-        if (!userUuid) {
-            return;
-        }
+        if (!userUuid) { return; }
         const ancestors = await services.ancestorsService.ancestors(id, userUuid);
         const isShared = ancestors.every(({ uuid }) => uuid !== userUuid);
         if (isShared) {