1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
15 } from '@material-ui/core';
16 import { ApiClientAuthorization } from 'models/api-client-authorization';
17 import { CopyIcon, RemoveIcon } from 'components/icon/icon';
18 import CopyToClipboard from 'react-copy-to-clipboard';
19 import { ArvadosTheme } from 'common/custom-theme';
20 import moment from 'moment';
22 type CssRules = 'sharingUrlText'
27 const styles: StyleRulesCallback<CssRules> = (theme: ArvadosTheme) => ({
32 color: theme.palette.grey["500"],
37 verticalAlign: 'middle',
43 borderBottom: `1px solid ${theme.palette.grey["300"]}`,
47 export interface SharingURLsComponentDataProps {
48 collectionUuid: string;
49 sharingTokens: ApiClientAuthorization[];
50 sharingURLsPrefix: string;
53 export interface SharingURLsComponentActionProps {
54 onDeleteSharingToken: (uuid: string) => void;
55 onCopy: (message: string) => void;
58 type SharingURLsComponentProps = SharingURLsComponentDataProps & SharingURLsComponentActionProps;
60 export const SharingURLsComponent = withStyles(styles)((props: SharingURLsComponentProps & WithStyles<CssRules>) => <Grid container direction='column' spacing={24} className={props.classes.sharingUrlList}>
61 { props.sharingTokens.length > 0
63 .sort((a, b) => (new Date(a.expiresAt).getTime() - new Date(b.expiresAt).getTime()))
65 const url = props.sharingURLsPrefix.includes('*')
66 ? `${props.sharingURLsPrefix.replace('*', props.collectionUuid)}/t=${token.apiToken}/_/`
67 : `${props.sharingURLsPrefix}/c=${props.collectionUuid}/t=${token.apiToken}/_/`;
68 const expDate = new Date(token.expiresAt);
69 const urlLabel = `Token ${token.apiToken.slice(0, 8)}... expiring at: ${expDate.toLocaleString()} (${moment(expDate).fromNow()})`;
71 return <Grid container alignItems='center' key={token.uuid} className={props.classes.sharingUrlRow}>
73 <Link className={props.classes.sharingUrlText} href={url} target='_blank'>
79 <span className={props.classes.sharingUrlButton}><Tooltip title='Copy to clipboard'>
80 <CopyToClipboard text={url} onCopy={() => props.onCopy('Sharing URL copied')}>
84 <span className={props.classes.sharingUrlButton}><Tooltip title='Remove'>
85 <IconButton onClick={() => props.onDeleteSharingToken(token.uuid)}>
92 : <Grid item><Typography>No sharing URLs</Typography></Grid> }