merge master
[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 { ServiceRepository } from "~/services/services";
8 import { TreePickerId, receiveTreePickerData } from "~/views-components/project-tree-picker/project-tree-picker";
9 import { mockProjectResource } from "~/models/test-utils";
10 import { treePickerActions } from "~/store/tree-picker/tree-picker-actions";
11
12 export const resetPickerProjectTree = () => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
13     dispatch<any>(treePickerActions.RESET_TREE_PICKER({pickerId: TreePickerId.PROJECTS}));
14     dispatch<any>(treePickerActions.RESET_TREE_PICKER({pickerId: TreePickerId.SHARED_WITH_ME}));
15     dispatch<any>(treePickerActions.RESET_TREE_PICKER({pickerId: TreePickerId.FAVORITES}));
16
17     dispatch<any>(initPickerProjectTree());
18 };
19
20 export const initPickerProjectTree = () => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
21     const uuid = services.authService.getUuid();
22
23     dispatch<any>(getPickerTreeProjects(uuid));
24     dispatch<any>(getSharedWithMeProjectsPickerTree(uuid));
25     dispatch<any>(getFavoritesProjectsPickerTree(uuid));
26 };
27
28 const getPickerTreeProjects = (uuid: string = '') => {
29     return getProjectsPickerTree(uuid, TreePickerId.PROJECTS);
30 };
31
32 const getSharedWithMeProjectsPickerTree = (uuid: string = '') => {
33     return getProjectsPickerTree(uuid, TreePickerId.SHARED_WITH_ME);
34 };
35
36 const getFavoritesProjectsPickerTree = (uuid: string = '') => {
37     return getProjectsPickerTree(uuid, TreePickerId.FAVORITES);
38 };
39
40 const getProjectsPickerTree = (uuid: string, kind: string) => {
41     return receiveTreePickerData(
42         '',
43         [mockProjectResource({ uuid, name: kind })],
44         kind
45     );
46 };