1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { default as unionize, ofType, UnionOf } from "unionize";
7 import { TreePickerNode } from "./tree-picker";
8 import { receiveTreePickerData, TreePickerKind } from "../../views-components/project-tree-picker/project-tree-picker";
9 import { mockProjectResource } from "../../models/test-utils";
10 import { Dispatch } from "redux";
11 import { RootState } from "../store";
12 import { ServiceRepository } from "../../services/services";
14 export const treePickerActions = unionize({
15 LOAD_TREE_PICKER_NODE: ofType<{ id: string, pickerId: string }>(),
16 LOAD_TREE_PICKER_NODE_SUCCESS: ofType<{ id: string, nodes: Array<TreePickerNode>, pickerId: string }>(),
17 TOGGLE_TREE_PICKER_NODE_COLLAPSE: ofType<{ id: string, pickerId: string }>(),
18 TOGGLE_TREE_PICKER_NODE_SELECT: ofType<{ id: string, pickerId: string }>()
24 export const initPickerProjectTree = () => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => {
25 const uuid = services.authService.getUuid();
27 dispatch<any>(getPickerTreeProjects(uuid));
28 dispatch<any>(getSharedWithMeProjectsPickerTree(uuid));
29 dispatch<any>(getFavoritesProjectsPickerTree(uuid));
32 const getPickerTreeProjects = (uuid: string = '') => {
33 return getProjectsPickerTree(uuid, TreePickerKind.PROJECTS);
36 const getSharedWithMeProjectsPickerTree = (uuid: string = '') => {
37 return getProjectsPickerTree(uuid, TreePickerKind.SHARED_WITH_ME);
40 const getFavoritesProjectsPickerTree = (uuid: string = '') => {
41 return getProjectsPickerTree(uuid, TreePickerKind.FAVORITES);
44 const getProjectsPickerTree = (uuid: string, kind: string) => {
45 return receiveTreePickerData(
47 [mockProjectResource({ uuid, name: kind })],
52 export type TreePickerAction = UnionOf<typeof treePickerActions>;