// Copyright (C) The Arvados Authors. All rights reserved. // // SPDX-License-Identifier: AGPL-3.0 import * as React from "react"; import { Dispatch } from "redux"; import { connect } from "react-redux"; import { Typography } from "@material-ui/core"; import { TreePicker, TreePickerProps } from "../tree-picker/tree-picker"; import { TreeItem, TreeItemStatus } from "~/components/tree/tree"; import { ProjectResource } from "~/models/project"; import { treePickerActions, loadProjectTreePickerProjects, loadFavoriteTreePickerProjects, loadPublicFavoriteTreePickerProjects } from "~/store/tree-picker/tree-picker-actions"; import { ListItemTextIcon } from "~/components/list-item-text-icon/list-item-text-icon"; import { ProjectIcon, FavoriteIcon, ProjectsIcon, ShareMeIcon, PublicFavoriteIcon } from '~/components/icon/icon'; import { RootState } from "~/store/store"; import { ServiceRepository } from "~/services/services"; import { WrappedFieldProps } from 'redux-form'; import { TreePickerId } from '~/models/tree'; import { ProjectsTreePicker } from '~/views-components/projects-tree-picker/projects-tree-picker'; import { ProjectsTreePickerItem } from '~/views-components/projects-tree-picker/generic-projects-tree-picker'; import { PickerIdProp } from '~/store/tree-picker/picker-id'; type ProjectTreePickerProps = Pick, 'onContextMenu' | 'toggleItemActive' | 'toggleItemOpen' | 'toggleItemSelection'>; const mapDispatchToProps = (dispatch: Dispatch, props: { onChange: (projectUuid: string) => void }): ProjectTreePickerProps => ({ onContextMenu: () => { return; }, toggleItemActive: (_, { id }, pickerId) => { getNotSelectedTreePickerKind(pickerId) .forEach(pickerId => dispatch(treePickerActions.ACTIVATE_TREE_PICKER_NODE({ id: '', pickerId }))); dispatch(treePickerActions.ACTIVATE_TREE_PICKER_NODE({ id, pickerId })); props.onChange(id); }, toggleItemOpen: (_, { id, status }, pickerId) => { dispatch(toggleItemOpen(id, status, pickerId)); }, toggleItemSelection: (_, { id }, pickerId) => { dispatch(treePickerActions.TOGGLE_TREE_PICKER_NODE_SELECTION({ id, pickerId })); }, }); const toggleItemOpen = (id: string, status: TreeItemStatus, pickerId: string) => (dispatch: Dispatch, getState: () => RootState, services: ServiceRepository) => { if (status === TreeItemStatus.INITIAL) { if (pickerId === TreePickerId.PROJECTS) { dispatch(loadProjectTreePickerProjects(id)); } else if (pickerId === TreePickerId.FAVORITES) { dispatch(loadFavoriteTreePickerProjects(id === services.authService.getUuid() ? '' : id)); } else if (pickerId === TreePickerId.PUBLIC_FAVORITES) { dispatch(loadPublicFavoriteTreePickerProjects(id === services.authService.getUuid() ? '' : id)); // TODO: load sharedWithMe } } else { dispatch(treePickerActions.TOGGLE_TREE_PICKER_NODE_COLLAPSE({ id, pickerId })); } }; const getNotSelectedTreePickerKind = (pickerId: string) => { return [TreePickerId.PROJECTS, TreePickerId.FAVORITES, TreePickerId.SHARED_WITH_ME].filter(nodeId => nodeId !== pickerId); }; export const ProjectTreePicker = connect(undefined, mapDispatchToProps)((props: ProjectTreePickerProps) =>
Select a project
); const getProjectPickerIcon = (item: TreeItem) => { switch (item.data.name) { case TreePickerId.FAVORITES: return FavoriteIcon; case TreePickerId.PROJECTS: return ProjectsIcon; case TreePickerId.SHARED_WITH_ME: return ShareMeIcon; case TreePickerId.PUBLIC_FAVORITES: return PublicFavoriteIcon; default: return ProjectIcon; } }; const renderTreeItem = (item: TreeItem) => ; export const ProjectTreePickerField = (props: WrappedFieldProps & PickerIdProp) =>
{props.meta.dirty && props.meta.error && {props.meta.error} }
; const handleChange = (props: WrappedFieldProps) => (_: any, { id }: TreeItem) => props.input.onChange(id); export const CollectionTreePickerField = (props: WrappedFieldProps & PickerIdProp) =>
{props.meta.dirty && props.meta.error && {props.meta.error} }
;