X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/3c7e3cdc547ad5468421e1c049daa94b0d4b8bc0..e1e17729d024637f9f3392611c9a59dc31e5db23:/src/views-components/sharing-dialog/sharing-dialog-component.tsx diff --git a/src/views-components/sharing-dialog/sharing-dialog-component.tsx b/src/views-components/sharing-dialog/sharing-dialog-component.tsx index be15cce6..b2f31397 100644 --- a/src/views-components/sharing-dialog/sharing-dialog-component.tsx +++ b/src/views-components/sharing-dialog/sharing-dialog-component.tsx @@ -3,63 +3,195 @@ // SPDX-License-Identifier: AGPL-3.0 import React from 'react'; -import { Dialog, DialogTitle, Button, Grid, DialogContent, CircularProgress, Paper } from '@material-ui/core'; +import { + Dialog, + DialogTitle, + Button, + Grid, + DialogContent, + CircularProgress, + Paper, + Tabs, + Tab, + Checkbox, + FormControlLabel, + Typography, +} from '@material-ui/core'; +import { + StyleRulesCallback, + WithStyles, + withStyles +} from '@material-ui/core/styles'; import { DialogActions } from 'components/dialog-actions/dialog-actions'; -import { StyleRulesCallback, WithStyles, withStyles } from '@material-ui/core/styles'; - +import { SharingURLsContent } from './sharing-urls'; +import { + extractUuidObjectType, + ResourceObjectType +} from 'models/resource'; +import { SharingInvitationForm } from './sharing-invitation-form'; +import { SharingManagementForm } from './sharing-management-form'; +import { + BasePicker, + Calendar, + MuiPickersUtilsProvider, + TimePickerView +} from 'material-ui-pickers'; +import DateFnsUtils from "@date-io/date-fns"; +import moment from 'moment'; +import { SharingPublicAccessForm } from './sharing-public-access-form'; export interface SharingDialogDataProps { open: boolean; loading: boolean; saveEnabled: boolean; - advancedEnabled: boolean; - children: React.ReactNode; + sharedResourceUuid: string; + sharingURLsNr: number; + privateAccess: boolean; + sharingURLsDisabled: boolean; } export interface SharingDialogActionProps { onClose: () => void; - onExited: () => void; onSave: () => void; - onAdvanced: () => void; + onCreateSharingToken: (d: Date | undefined) => () => void; + refreshPermissions: () => void; +} +enum SharingDialogTab { + PERMISSIONS = 0, + URLS = 1, } -export default (props: SharingDialogDataProps & SharingDialogActionProps) => { - const { children, open, loading, advancedEnabled, saveEnabled, onAdvanced, onClose, onExited, onSave } = props; +export type SharingDialogComponentProps = SharingDialogDataProps & SharingDialogActionProps; + +export default (props: SharingDialogComponentProps) => { + const { open, loading, saveEnabled, sharedResourceUuid, + sharingURLsNr, privateAccess, sharingURLsDisabled, + onClose, onSave, onCreateSharingToken, refreshPermissions } = props; + const showTabs = !sharingURLsDisabled && extractUuidObjectType(sharedResourceUuid) === ResourceObjectType.COLLECTION; + const [tabNr, setTabNr] = React.useState(SharingDialogTab.PERMISSIONS); + const [expDate, setExpDate] = React.useState(); + const [withExpiration, setWithExpiration] = React.useState(false); + + // Sets up the dialog depending on the resource type + if (!showTabs && tabNr !== SharingDialogTab.PERMISSIONS) { + setTabNr(SharingDialogTab.PERMISSIONS); + } + + React.useEffect(() => { + if (!withExpiration) { + setExpDate(undefined); + } else { + setExpDate(moment().add(2, 'hour').minutes(0).seconds(0).toDate()); + } + }, [withExpiration]); + return + disableBackdropClick={saveEnabled} + disableEscapeKeyDown={saveEnabled}> Sharing settings - + + { showTabs && + { + if (tb === SharingDialogTab.PERMISSIONS) { + refreshPermissions(); + } + setTabNr(tb)} + }> + + 0 ? '('+sharingURLsNr+')' : ''}`} disabled={saveEnabled} /> + + } - {children} + { tabNr === SharingDialogTab.PERMISSIONS && + + + + + + + + + } + { tabNr === SharingDialogTab.URLS && + + } - {advancedEnabled && - - - + { tabNr === SharingDialogTab.PERMISSIONS && + + + + } + { tabNr === SharingDialogTab.URLS && withExpiration && <> + + + + {({ date, handleChange }) => (<> + + + + + {}} + onSecondsChange={() => {}} + onHourChange={handleChange} + /> + + )} + + + + + + Maximum expiration date may be limited by the cluster configuration. + + + + } + { tabNr === SharingDialogTab.PERMISSIONS && !sharingURLsDisabled && + privateAccess && sharingURLsNr > 0 && + + + Although there aren't specific permissions set, this is publicly accessible via Sharing URL(s). + + } + { tabNr === SharingDialogTab.URLS && <> + setWithExpiration(e.target.checked)} />} + label="With expiration" /> + - + + } + { tabNr === SharingDialogTab.PERMISSIONS && - + + } + +