// Copyright (C) The Arvados Authors. All rights reserved. // // SPDX-License-Identifier: AGPL-3.0 import * as React from 'react'; import { StyleRulesCallback, WithStyles, withStyles, Card, CardHeader, IconButton, CardContent, Grid, Tooltip } from '@material-ui/core'; import { connect, DispatchProp } from "react-redux"; import { RouteComponentProps } from 'react-router'; import { ArvadosTheme } from '~/common/custom-theme'; import { RootState } from '~/store/store'; import { MoreOptionsIcon, CollectionIcon, ReadOnlyIcon } from '~/components/icon/icon'; import { DetailsAttribute } from '~/components/details-attribute/details-attribute'; import { CollectionResource } from '~/models/collection'; import { CollectionPanelFiles } from '~/views-components/collection-panel-files/collection-panel-files'; import { CollectionTagForm } from './collection-tag-form'; import { deleteCollectionTag, navigateToProcess } from '~/store/collection-panel/collection-panel-action'; import { getResource } from '~/store/resources/resources'; import { openContextMenu } from '~/store/context-menu/context-menu-actions'; import { ContextMenuKind } from '~/views-components/context-menu/context-menu'; import { formatFileSize } from "~/common/formatters"; import { openDetailsPanel } from '~/store/details-panel/details-panel-action'; import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions'; import { getPropertyChip } from '~/views-components/resource-properties-form/property-chip'; import { IllegalNamingWarning } from '~/components/warning/warning'; import { GroupResource } from '~/models/group'; import { UserResource } from '~/models/user'; import { getUserUuid } from '~/common/getuser'; type CssRules = 'card' | 'iconHeader' | 'tag' | 'label' | 'value' | 'link' | 'centeredLabel' | 'readOnlyIcon'; const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ card: { marginBottom: theme.spacing.unit * 2 }, iconHeader: { fontSize: '1.875rem', color: theme.customs.colors.yellow700 }, tag: { marginRight: theme.spacing.unit, marginBottom: theme.spacing.unit }, label: { fontSize: '0.875rem' }, centeredLabel: { fontSize: '0.875rem', textAlign: 'center' }, value: { textTransform: 'none', fontSize: '0.875rem' }, link: { fontSize: '0.875rem', color: theme.palette.primary.main, '&:hover': { cursor: 'pointer' } }, readOnlyIcon: { marginLeft: theme.spacing.unit, fontSize: 'small', } }); interface CollectionPanelDataProps { item: CollectionResource; isWritable: boolean; } type CollectionPanelProps = CollectionPanelDataProps & DispatchProp & WithStyles & RouteComponentProps<{ id: string }>; export const CollectionPanel = withStyles(styles)( connect((state: RootState, props: RouteComponentProps<{ id: string }>) => { const currentUserUUID = getUserUuid(state); const item = getResource(props.match.params.id)(state.resources); let isWritable = false; if (item && item.ownerUuid === currentUserUUID) { isWritable = true; } else if (item) { const itemOwner = getResource(item.ownerUuid)(state.resources); if (itemOwner) { isWritable = itemOwner.writableBy.indexOf(currentUserUUID || '') >= 0; } } return { item, isWritable }; })( class extends React.Component { render() { const { classes, item, dispatch, isWritable } = this.props; return item ? <> } action={ } title={ {item.name} {isWritable || } } titleTypographyProps={this.titleProps} subheader={item.description} subheaderTypographyProps={this.titleProps} /> {(item.properties.container_request || item.properties.containerRequest) && dispatch(navigateToProcess(item.properties.container_request || item.properties.containerRequest))}> } {isWritable && } { Object.keys(item.properties).length > 0 ? Object.keys(item.properties).map(k => Array.isArray(item.properties[k]) ? item.properties[k].map((v: string) => getPropertyChip( k, v, isWritable ? this.handleDelete(k, item.properties[k]) : undefined, classes.tag)) : getPropertyChip( k, item.properties[k], isWritable ? this.handleDelete(k, item.properties[k]) : undefined, classes.tag) ) :
No properties set on this collection.
}
: null; } handleContextMenu = (event: React.MouseEvent) => { const { uuid, ownerUuid, name, description, kind, isTrashed } = this.props.item; const { isWritable } = this.props; const resource = { uuid, ownerUuid, name, description, kind, menuKind: isWritable ? isTrashed ? ContextMenuKind.TRASHED_COLLECTION : ContextMenuKind.COLLECTION : ContextMenuKind.READONLY_COLLECTION }; this.props.dispatch(openContextMenu(event, resource)); } onCopy = (message: string) => this.props.dispatch(snackbarActions.OPEN_SNACKBAR({ message, hideDuration: 2000, kind: SnackbarKind.SUCCESS })) handleDelete = (key: string, value: string) => () => { this.props.dispatch(deleteCollectionTag(key, value)); } openCollectionDetails = () => { const { item } = this.props; if (item) { this.props.dispatch(openDetailsPanel(item.uuid)); } } titleProps = { onClick: this.openCollectionDetails }; } ) );