1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
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';
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 }));
18 dispatch<any>(initPickerProjectTree());
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));
29 const getPickerTreeProjects = (uuid: string = '') => {
30 return getProjectsPickerTree(uuid, TreePickerId.PROJECTS);
33 const getSharedWithMeProjectsPickerTree = (uuid: string = '') => {
34 return getProjectsPickerTree(uuid, TreePickerId.SHARED_WITH_ME);
37 const getFavoritesProjectsPickerTree = (uuid: string = '') => {
38 return getProjectsPickerTree(uuid, TreePickerId.FAVORITES);
41 const getProjectsPickerTree = (uuid: string, kind: string) => {
42 return receiveTreePickerProjectsData(
44 [mockProjectResource({ uuid, name: kind })],