1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from 'react';
6 import { connect } from 'react-redux';
7 import Typography from '@material-ui/core/Typography';
8 import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles';
9 import { ArvadosTheme } from '~/common/custom-theme';
10 import * as classnames from "classnames";
11 import { Link } from 'react-router-dom';
12 import { RootState } from "~/store/store";
13 import { FederationConfig, getNavUrl } from "~/routes/routes";
15 type CssRules = 'attribute' | 'label' | 'value' | 'lowercaseValue' | 'link';
17 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
20 alignItems: 'flex-start',
21 marginBottom: theme.spacing.unit
24 boxSizing: 'border-box',
25 color: theme.palette.grey["500"],
29 boxSizing: 'border-box',
32 alignItems: 'flex-start'
35 textTransform: 'lowercase'
39 color: theme.palette.primary.main,
40 textDecoration: 'none',
41 overflowWrap: 'break-word',
46 interface DetailsAttributeDataProps {
49 value?: React.ReactNode;
51 lowercaseValue?: boolean;
53 children?: React.ReactNode;
54 onValueClick?: () => void;
58 type DetailsAttributeProps = DetailsAttributeDataProps & WithStyles<CssRules> & FederationConfig;
60 const mapStateToProps = ({ auth }: RootState): FederationConfig => ({
61 localCluster: auth.localCluster,
62 remoteHostsConfig: auth.remoteHostsConfig,
63 sessions: auth.sessions
66 export const DetailsAttribute = connect(mapStateToProps)(withStyles(styles)(
67 ({ label, link, value, children, classes, classLabel,
68 classValue, lowercaseValue, onValueClick, linkToUuid,
69 localCluster, remoteHostsConfig, sessions }: DetailsAttributeProps) => {
70 let insertLink: React.ReactNode;
72 const linkUrl = getNavUrl(linkToUuid || "", { localCluster, remoteHostsConfig, sessions });
73 if (linkUrl[0] === '/') {
74 insertLink = <Link to={linkUrl} className={classes.link}>{value}</Link>;
76 insertLink = <a href={linkUrl} className={classes.link} target='_blank'>{value}</a>;
79 insertLink = <a href={link} className={classes.link} target='_blank'>{value}</a>;
81 return <Typography component="div" className={classes.attribute}>
82 <Typography component="span" className={classnames([classes.label, classLabel])}>{label}</Typography>
84 {!insertLink && <Typography
85 onClick={onValueClick}
87 className={classnames([classes.value, classValue, { [classes.lowercaseValue]: lowercaseValue }])}>