1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { connect, DispatchProp } from 'react-redux';
7 import Typography from '@mui/material/Typography';
8 import { CustomStyleRulesCallback } from 'common/custom-theme';
9 import { WithStyles } from '@mui/styles';
10 import withStyles from '@mui/styles/withStyles';
11 import { Tooltip } from '@mui/material';
12 import { CopyIcon } from 'components/icon/icon';
13 import CopyToClipboard from 'react-copy-to-clipboard';
14 import { ArvadosTheme } from 'common/custom-theme';
15 import classnames from "classnames";
16 import { Link } from 'react-router-dom';
17 import { RootState } from "store/store";
18 import { FederationConfig, getNavUrl } from "routes/routes";
19 import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions';
21 type CssRules = 'attribute' | 'label' | 'value' | 'lowercaseValue' | 'link' | 'copyIcon';
23 const styles: CustomStyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
25 marginBottom: ".6 rem"
28 boxSizing: 'border-box',
29 color: theme.palette.grey["600"],
34 boxSizing: 'border-box',
35 alignItems: 'flex-start'
38 textTransform: 'lowercase'
41 color: theme.palette.primary.main,
42 textDecoration: 'none',
43 overflowWrap: 'break-word',
47 marginLeft: theme.spacing(1),
48 color: theme.palette.grey["600"],
57 interface DetailsAttributeDataProps {
60 value?: React.ReactNode;
62 lowercaseValue?: boolean;
64 children?: React.ReactNode;
65 onValueClick?: () => void;
68 uuidEnhancer?: Function;
71 type DetailsAttributeProps = DetailsAttributeDataProps & WithStyles<CssRules> & FederationConfig & DispatchProp;
73 const mapStateToProps = ({ auth }: RootState): FederationConfig => ({
74 localCluster: auth.localCluster,
75 remoteHostsConfig: auth.remoteHostsConfig,
76 sessions: auth.sessions
79 export const DetailsAttribute = connect(mapStateToProps)(withStyles(styles)(
80 class extends React.Component<DetailsAttributeProps> {
82 onCopy = (message: string) => {
83 this.props.dispatch(snackbarActions.OPEN_SNACKBAR({
86 kind: SnackbarKind.SUCCESS
91 const { uuidEnhancer, link, value, classes, linkToUuid,
92 localCluster, remoteHostsConfig, sessions } = this.props;
93 let valueNode: React.ReactNode;
96 const uuid = uuidEnhancer ? uuidEnhancer(linkToUuid) : linkToUuid;
97 const linkUrl = getNavUrl(linkToUuid || "", { localCluster, remoteHostsConfig, sessions });
98 if (linkUrl[0] === '/') {
99 valueNode = <Link to={linkUrl} className={classes.link}>{uuid}</Link>;
101 valueNode = <a href={linkUrl} className={classes.link} target='_blank' rel="noopener noreferrer">{uuid}</a>;
104 valueNode = <a href={link} className={classes.link} target='_blank' rel="noopener noreferrer">{value}</a>;
109 return <DetailsAttributeComponent {...this.props} value={valueNode} onCopy={this.onCopy} />;
114 interface DetailsAttributeComponentProps {
115 value: React.ReactNode;
116 onCopy?: (msg: string) => void;
119 export const DetailsAttributeComponent = withStyles(styles)(
120 (props: DetailsAttributeDataProps & WithStyles<CssRules> & DetailsAttributeComponentProps) =>
121 <Typography component="div" className={props.classes.attribute} data-cy={`details-panel-${props.label.toLowerCase()}`}>
122 <Typography component="div" className={classnames([props.classes.label, props.classLabel])}>{props.label}</Typography>
124 onClick={props.onValueClick}
126 data-cy="details-attribute-value"
127 className={classnames([props.classes.value, props.classValue, { [props.classes.lowercaseValue]: props.lowercaseValue }])}>
130 {(props.linkToUuid || props.copyValue) && props.onCopy && <Tooltip title="Copy link to clipboard">
131 <span className={props.classes.copyIcon}>
132 <CopyToClipboard text={props.linkToUuid || props.copyValue || ""} onCopy={() => props.onCopy!("Copied")}>