19482: Fix context menu, breadcrumbs
[arvados.git] / src / store / project-tree-picker / project-tree-picker-actions.ts
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 import { Dispatch } from "redux";
6 import { RootState } from "store/store";
7 import { getUserUuid } from "common/getuser";
8 import { ServiceRepository } from "services/services";
9 import { mockProjectResource } from "models/test-utils";
10 import { treePickerActions, receiveTreePickerProjectsData } from "store/tree-picker/tree-picker-actions";
11 import { TreePickerId } from 'models/tree';
12
13 export const resetPickerProjectTree = () => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
14     dispatch<any>(treePickerActions.RESET_TREE_PICKER({ pickerId: TreePickerId.PROJECTS }));
15     dispatch<any>(treePickerActions.RESET_TREE_PICKER({ pickerId: TreePickerId.SHARED_WITH_ME }));
16     dispatch<any>(treePickerActions.RESET_TREE_PICKER({ pickerId: TreePickerId.FAVORITES }));
17
18     dispatch<any>(initPickerProjectTree());
19 };
20
21 export const initPickerProjectTree = () => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
22     const uuid = getUserUuid(getState());
23     if (!uuid) { return; }
24     dispatch<any>(getPickerTreeProjects(uuid));
25     dispatch<any>(getSharedWithMeProjectsPickerTree(uuid));
26     dispatch<any>(getFavoritesProjectsPickerTree(uuid));
27 };
28
29 const getPickerTreeProjects = (uuid: string = '') => {
30     return getProjectsPickerTree(uuid, TreePickerId.PROJECTS);
31 };
32
33 const getSharedWithMeProjectsPickerTree = (uuid: string = '') => {
34     return getProjectsPickerTree(uuid, TreePickerId.SHARED_WITH_ME);
35 };
36
37 const getFavoritesProjectsPickerTree = (uuid: string = '') => {
38     return getProjectsPickerTree(uuid, TreePickerId.FAVORITES);
39 };
40
41 const getProjectsPickerTree = (uuid: string, kind: string) => {
42     return receiveTreePickerProjectsData(
43         '',
44         [mockProjectResource({ uuid, name: kind })],
45         kind
46     );
47 };