X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/c57c9f8553e59144b4adeafc90ce2fa2ac946962..5e9c2244747eff9fc02ff3c0d140bdde5e0b6845:/src/components/details-attribute/details-attribute.tsx diff --git a/src/components/details-attribute/details-attribute.tsx b/src/components/details-attribute/details-attribute.tsx index 8f470858..e52c487d 100644 --- a/src/components/details-attribute/details-attribute.tsx +++ b/src/components/details-attribute/details-attribute.tsx @@ -2,43 +2,39 @@ // // SPDX-License-Identifier: AGPL-3.0 -import * as React from 'react'; +import React from 'react'; import { connect, DispatchProp } from 'react-redux'; import Typography from '@material-ui/core/Typography'; import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles'; import { Tooltip } from '@material-ui/core'; -import { CopyIcon } from '~/components/icon/icon'; -import * as CopyToClipboard from 'react-copy-to-clipboard'; -import { ArvadosTheme } from '~/common/custom-theme'; -import * as classnames from "classnames"; +import { CopyIcon } from 'components/icon/icon'; +import CopyToClipboard from 'react-copy-to-clipboard'; +import { ArvadosTheme } from 'common/custom-theme'; +import classnames from "classnames"; import { Link } from 'react-router-dom'; -import { RootState } from "~/store/store"; -import { FederationConfig, getNavUrl } from "~/routes/routes"; -import { snackbarActions, SnackbarKind } from '~/store/snackbar/snackbar-actions'; +import { RootState } from "store/store"; +import { FederationConfig, getNavUrl } from "routes/routes"; +import { snackbarActions, SnackbarKind } from 'store/snackbar/snackbar-actions'; type CssRules = 'attribute' | 'label' | 'value' | 'lowercaseValue' | 'link' | 'copyIcon'; const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ attribute: { - display: 'flex', - alignItems: 'flex-start', - marginBottom: theme.spacing.unit + marginBottom: ".6 rem" }, label: { boxSizing: 'border-box', color: theme.palette.grey["500"], - width: '40%' + width: '100%' }, value: { boxSizing: 'border-box', - width: '60%', alignItems: 'flex-start' }, lowercaseValue: { textTransform: 'lowercase' }, link: { - width: '60%', color: theme.palette.primary.main, textDecoration: 'none', overflowWrap: 'break-word', @@ -46,9 +42,12 @@ const styles: StyleRulesCallback = (theme: ArvadosTheme) => ({ }, copyIcon: { marginLeft: theme.spacing.unit, - fontSize: '1.125rem', color: theme.palette.grey["500"], - cursor: 'pointer' + cursor: 'pointer', + display: 'inline', + '& svg': { + fontSize: '1rem' + } } }); @@ -62,6 +61,8 @@ interface DetailsAttributeDataProps { children?: React.ReactNode; onValueClick?: () => void; linkToUuid?: string; + copyValue?: string; + uuidEnhancer?: Function; } type DetailsAttributeProps = DetailsAttributeDataProps & WithStyles & FederationConfig & DispatchProp; @@ -84,38 +85,51 @@ export const DetailsAttribute = connect(mapStateToProps)(withStyles(styles)( } render() { - const { label, link, value, children, classes, classLabel, - classValue, lowercaseValue, onValueClick, linkToUuid, + const { uuidEnhancer, link, value, classes, linkToUuid, localCluster, remoteHostsConfig, sessions } = this.props; let valueNode: React.ReactNode; if (linkToUuid) { + const uuid = uuidEnhancer ? uuidEnhancer(linkToUuid) : linkToUuid; const linkUrl = getNavUrl(linkToUuid || "", { localCluster, remoteHostsConfig, sessions }); if (linkUrl[0] === '/') { - valueNode = {linkToUuid}; + valueNode = {uuid}; } else { - valueNode = {linkToUuid}; + valueNode = {uuid}; } } else if (link) { - valueNode = {value}; + valueNode = {value}; } else { valueNode = value; } - return - {label} - - {valueNode} - {children} - {linkToUuid && - this.onCopy("Copied")}> - - - } - - ; + + return ; } } )); + +interface DetailsAttributeComponentProps { + value: React.ReactNode; + onCopy?: (msg: string) => void; +} + +export const DetailsAttributeComponent = withStyles(styles)( + (props: DetailsAttributeDataProps & WithStyles & DetailsAttributeComponentProps) => + + {props.label} + + {props.value} + {props.children} + {(props.linkToUuid || props.copyValue) && props.onCopy && + + props.onCopy!("Copied")}> + + + + } + + ); +