1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import * as React from "react";
6 import { Dialog, DialogActions, Button, StyleRulesCallback, WithStyles, withStyles, CardHeader, Tab, Tabs } from '@material-ui/core';
7 import { withDialog } from "~/store/dialog/with-dialog";
8 import { COLLECTION_WEBDAV_S3_DIALOG_NAME, WebDavS3InfoDialogData } from '~/store/collections/collection-info-actions';
9 import { WithDialogProps } from '~/store/dialog/with-dialog';
10 import { compose } from 'redux';
11 import { DetailsAttribute } from "~/components/details-attribute/details-attribute";
13 type CssRules = 'details';
15 const styles: StyleRulesCallback<CssRules> = theme => ({
17 marginLeft: theme.spacing.unit * 3,
18 marginRight: theme.spacing.unit * 3,
22 interface TabPanelData {
23 children: React.ReactElement<any>[];
28 function TabPanel(props: TabPanelData) {
29 const { children, value, index } = props;
34 hidden={value !== index}
35 id={`simple-tabpanel-${index}`}
36 aria-labelledby={`simple-tab-${index}`}
38 {value === index && children}
43 export const WebDavS3InfoDialog = compose(
44 withDialog(COLLECTION_WEBDAV_S3_DIALOG_NAME),
47 (props: WithDialogProps<WebDavS3InfoDialogData> & WithStyles<CssRules>) => {
48 if (!props.data.downloadUrl) { return null; }
53 if (props.data.collectionsUrl.indexOf("*") > -1) {
54 const withuuid = props.data.collectionsUrl.replace("*", props.data.uuid);
55 winDav = new URL(withuuid);
56 cyberDav = new URL(withuuid);
58 winDav = new URL(props.data.downloadUrl);
59 cyberDav = new URL(props.data.downloadUrl);
60 winDav.pathname = `/by_id/${props.data.uuid}/`;
61 cyberDav.pathname = `/by_id/${props.data.uuid}/`;
64 cyberDav.protocol = { "http:": "dav:", "https:": "davs:" }[cyberDav.protocol];
66 const s3endpoint = new URL(props.data.collectionsUrl.replace(/\/\*(--[^.]+)?\./, "/"));
68 const sp = props.data.token.split("/");
71 if (sp.length === 3 && sp[0] === "v2" && props.data.homeCluster === props.data.localCluster) {
75 tokenUuid = props.data.token.replace(/\//g, "_");
76 tokenSecret = tokenUuid;
82 onClose={props.closeDialog}
83 style={{ alignSelf: 'stretch' }}>
85 title={`WebDAV and S3`} />
86 <div className={props.classes.details} >
87 <Tabs value={props.data.activeTab} onChange={props.data.setActiveTab}>
88 <Tab key="cyberduck" label="Cyberduck/Mountain Duck or Gnome Files" />
89 <Tab key="windows" label="Windows or MacOS" />
90 <Tab key="s3" label="Using an S3 client" />
93 <TabPanel index={1} value={props.data.activeTab}>
97 label='Internet address'
98 value={winDav.toString()}
99 copyValue={winDav.toString()} />
103 value={props.data.username}
104 copyValue={props.data.username} />
108 value={props.data.token}
109 copyValue={props.data.token} />
113 <li>Open File Explorer</li>
114 <li>Click on "This PC", then go to Computer → Add a Network Location</li>
115 <li>Click Next, then choose "Add a custom network location", then click Next</li>
121 <li>Click Go → Connect to server</li>
125 <TabPanel index={0} value={props.data.activeTab}>
128 value={<a href={cyberDav.toString()}>{cyberDav.toString()}</a>}
129 copyValue={cyberDav.toString()} />
133 value={props.data.username}
134 copyValue={props.data.username} />
138 value={props.data.token}
139 copyValue={props.data.token} />
144 <li>Select +Other Locations</li>
145 <li>Connect to Server → Enter server address</li>
150 <TabPanel index={2} value={props.data.activeTab}>
153 value={s3endpoint.host}
154 copyValue={s3endpoint.host} />
158 value={props.data.uuid}
159 copyValue={props.data.uuid} />
164 copyValue={tokenUuid} />
169 copyValue={tokenSecret} />
178 onClick={props.closeDialog}>