2018-02-18 23:07:59 -05:00
|
|
|
/*
|
2021-04-19 13:30:42 -04:00
|
|
|
* Copyright (c) 2015-2021 MinIO, Inc.
|
2018-02-18 23:07:59 -05:00
|
|
|
*
|
2021-04-19 13:30:42 -04:00
|
|
|
* This file is part of MinIO Object Storage stack
|
2018-02-18 23:07:59 -05:00
|
|
|
*
|
2021-04-19 13:30:42 -04:00
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
2018-02-18 23:07:59 -05:00
|
|
|
*
|
2021-04-19 13:30:42 -04:00
|
|
|
* This program is distributed in the hope that it will be useful
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2018-02-18 23:07:59 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
import React from "react"
|
|
|
|
import { connect } from "react-redux"
|
|
|
|
import { Modal, ModalHeader, ModalBody } from "react-bootstrap"
|
|
|
|
import CopyToClipboard from "react-copy-to-clipboard"
|
|
|
|
import web from "../web"
|
|
|
|
import * as objectsActions from "./actions"
|
|
|
|
import * as alertActions from "../alert/actions"
|
|
|
|
import {
|
|
|
|
SHARE_OBJECT_EXPIRY_DAYS,
|
|
|
|
SHARE_OBJECT_EXPIRY_HOURS,
|
2018-03-22 15:25:56 -04:00
|
|
|
SHARE_OBJECT_EXPIRY_MINUTES
|
2018-02-18 23:07:59 -05:00
|
|
|
} from "../constants"
|
2021-03-11 14:21:45 -05:00
|
|
|
import QRCode from "react-qr-code";
|
2018-02-18 23:07:59 -05:00
|
|
|
|
|
|
|
export class ShareObjectModal extends React.Component {
|
|
|
|
constructor(props) {
|
|
|
|
super(props)
|
|
|
|
this.state = {
|
|
|
|
expiry: {
|
|
|
|
days: SHARE_OBJECT_EXPIRY_DAYS,
|
|
|
|
hours: SHARE_OBJECT_EXPIRY_HOURS,
|
2018-03-22 15:25:56 -04:00
|
|
|
minutes: SHARE_OBJECT_EXPIRY_MINUTES
|
|
|
|
}
|
2018-02-18 23:07:59 -05:00
|
|
|
}
|
|
|
|
this.expiryRange = {
|
2018-03-26 15:49:12 -04:00
|
|
|
days: { min: 0, max: 7 },
|
|
|
|
hours: { min: 0, max: 23 },
|
|
|
|
minutes: { min: 0, max: 59 }
|
2018-02-18 23:07:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
updateExpireValue(param, inc) {
|
|
|
|
let expiry = Object.assign({}, this.state.expiry)
|
|
|
|
|
|
|
|
// Not allowing any increments if days is already max
|
|
|
|
if (expiry.days == this.expiryRange["days"].max && inc > 0) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const { min, max } = this.expiryRange[param]
|
|
|
|
expiry[param] = expiry[param] + inc
|
|
|
|
if (expiry[param] < min || expiry[param] > max) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expiry.days == this.expiryRange["days"].max) {
|
|
|
|
expiry.hours = 0
|
|
|
|
expiry.minutes = 0
|
|
|
|
} else if (expiry.days + expiry.hours + expiry.minutes == 0) {
|
|
|
|
expiry.days = this.expiryRange["days"].max
|
|
|
|
}
|
|
|
|
|
|
|
|
this.setState({
|
2018-03-22 15:25:56 -04:00
|
|
|
expiry
|
2018-02-18 23:07:59 -05:00
|
|
|
})
|
|
|
|
|
2018-03-26 15:49:12 -04:00
|
|
|
const { object, shareObject } = this.props
|
|
|
|
shareObject(object.name, expiry.days, expiry.hours, expiry.minutes)
|
2018-02-18 23:07:59 -05:00
|
|
|
}
|
|
|
|
onUrlCopied() {
|
|
|
|
const { showCopyAlert, hideShareObject } = this.props
|
|
|
|
showCopyAlert("Link copied to clipboard!")
|
|
|
|
hideShareObject()
|
|
|
|
}
|
|
|
|
render() {
|
2020-05-02 02:55:53 -04:00
|
|
|
const { shareObjectDetails, hideShareObject } = this.props
|
|
|
|
const url = `${window.location.protocol}//${shareObjectDetails.url}`
|
2018-02-18 23:07:59 -05:00
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
show={true}
|
|
|
|
animation={false}
|
|
|
|
onHide={hideShareObject}
|
|
|
|
bsSize="small"
|
|
|
|
>
|
2018-03-26 15:49:12 -04:00
|
|
|
<ModalHeader>Share Object</ModalHeader>
|
|
|
|
<ModalBody>
|
|
|
|
<div className="input-group copy-text">
|
2021-03-11 14:21:45 -05:00
|
|
|
<QRCode value={url} size={128}/>
|
2018-02-18 23:07:59 -05:00
|
|
|
<label>Shareable Link</label>
|
|
|
|
<input
|
|
|
|
type="text"
|
|
|
|
ref={node => (this.copyTextInput = node)}
|
|
|
|
readOnly="readOnly"
|
2020-05-02 02:55:53 -04:00
|
|
|
value={url}
|
2018-02-18 23:07:59 -05:00
|
|
|
onClick={() => this.copyTextInput.select()}
|
|
|
|
/>
|
|
|
|
</div>
|
2020-05-02 02:55:53 -04:00
|
|
|
{shareObjectDetails.showExpiryDate && (
|
|
|
|
<div
|
2018-03-26 15:49:12 -04:00
|
|
|
className="input-group"
|
2018-02-18 23:07:59 -05:00
|
|
|
style={{ display: web.LoggedIn() ? "block" : "none" }}
|
|
|
|
>
|
|
|
|
<label>Expires in (Max 7 days)</label>
|
|
|
|
<div className="set-expire">
|
2018-03-26 15:49:12 -04:00
|
|
|
<div className="set-expire-item">
|
2018-02-18 23:07:59 -05:00
|
|
|
<i
|
|
|
|
id="increase-days"
|
2018-03-26 15:49:12 -04:00
|
|
|
className="set-expire-increase"
|
2018-02-18 23:07:59 -05:00
|
|
|
onClick={() => this.updateExpireValue("days", 1)}
|
|
|
|
/>
|
2018-03-26 15:49:12 -04:00
|
|
|
<div className="set-expire-title">Days</div>
|
|
|
|
<div className="set-expire-value">
|
2018-02-18 23:07:59 -05:00
|
|
|
<input
|
|
|
|
ref="expireDays"
|
|
|
|
type="number"
|
|
|
|
min={0}
|
|
|
|
max={7}
|
|
|
|
value={this.state.expiry.days}
|
|
|
|
readOnly="readOnly"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<i
|
|
|
|
id="decrease-days"
|
2018-03-26 15:49:12 -04:00
|
|
|
className="set-expire-decrease"
|
2018-02-18 23:07:59 -05:00
|
|
|
onClick={() => this.updateExpireValue("days", -1)}
|
|
|
|
/>
|
|
|
|
</div>
|
2018-03-26 15:49:12 -04:00
|
|
|
<div className="set-expire-item">
|
2018-02-18 23:07:59 -05:00
|
|
|
<i
|
|
|
|
id="increase-hours"
|
2018-03-26 15:49:12 -04:00
|
|
|
className="set-expire-increase"
|
2018-02-18 23:07:59 -05:00
|
|
|
onClick={() => this.updateExpireValue("hours", 1)}
|
|
|
|
/>
|
2018-03-26 15:49:12 -04:00
|
|
|
<div className="set-expire-title">Hours</div>
|
|
|
|
<div className="set-expire-value">
|
2018-02-18 23:07:59 -05:00
|
|
|
<input
|
|
|
|
ref="expireHours"
|
|
|
|
type="number"
|
|
|
|
min={0}
|
|
|
|
max={23}
|
|
|
|
value={this.state.expiry.hours}
|
|
|
|
readOnly="readOnly"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<i
|
2018-03-26 15:49:12 -04:00
|
|
|
className="set-expire-decrease"
|
2018-02-18 23:07:59 -05:00
|
|
|
id="decrease-hours"
|
|
|
|
onClick={() => this.updateExpireValue("hours", -1)}
|
|
|
|
/>
|
|
|
|
</div>
|
2018-03-26 15:49:12 -04:00
|
|
|
<div className="set-expire-item">
|
2018-02-18 23:07:59 -05:00
|
|
|
<i
|
|
|
|
id="increase-minutes"
|
2018-03-26 15:49:12 -04:00
|
|
|
className="set-expire-increase"
|
2018-02-18 23:07:59 -05:00
|
|
|
onClick={() => this.updateExpireValue("minutes", 1)}
|
|
|
|
/>
|
2018-03-26 15:49:12 -04:00
|
|
|
<div className="set-expire-title">Minutes</div>
|
|
|
|
<div className="set-expire-value">
|
2018-02-18 23:07:59 -05:00
|
|
|
<input
|
|
|
|
ref="expireMins"
|
|
|
|
type="number"
|
|
|
|
min={0}
|
|
|
|
max={59}
|
|
|
|
value={this.state.expiry.minutes}
|
|
|
|
readOnly="readOnly"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<i
|
|
|
|
id="decrease-minutes"
|
2018-03-26 15:49:12 -04:00
|
|
|
className="set-expire-decrease"
|
2018-02-18 23:07:59 -05:00
|
|
|
onClick={() => this.updateExpireValue("minutes", -1)}
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-05-02 02:55:53 -04:00
|
|
|
)}
|
2018-03-26 15:49:12 -04:00
|
|
|
</ModalBody>
|
2018-02-18 23:07:59 -05:00
|
|
|
<div className="modal-footer">
|
|
|
|
<CopyToClipboard
|
2020-05-02 02:55:53 -04:00
|
|
|
text={url}
|
2018-02-18 23:07:59 -05:00
|
|
|
onCopy={this.onUrlCopied.bind(this)}
|
|
|
|
>
|
2018-03-26 15:49:12 -04:00
|
|
|
<button className="btn btn-success">Copy Link</button>
|
2018-02-18 23:07:59 -05:00
|
|
|
</CopyToClipboard>
|
2018-03-26 15:49:12 -04:00
|
|
|
<button className="btn btn-link" onClick={hideShareObject}>
|
2018-02-18 23:07:59 -05:00
|
|
|
Cancel
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</Modal>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = (state, ownProps) => {
|
|
|
|
return {
|
2018-03-26 15:49:12 -04:00
|
|
|
object: ownProps.object,
|
2018-03-22 15:25:56 -04:00
|
|
|
shareObjectDetails: state.objects.shareObject
|
2018-02-18 23:07:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapDispatchToProps = dispatch => {
|
|
|
|
return {
|
|
|
|
shareObject: (object, days, hours, minutes) =>
|
|
|
|
dispatch(objectsActions.shareObject(object, days, hours, minutes)),
|
|
|
|
hideShareObject: () => dispatch(objectsActions.hideShareObject()),
|
|
|
|
showCopyAlert: message =>
|
2018-03-26 15:49:12 -04:00
|
|
|
dispatch(alertActions.set({ type: "success", message: message }))
|
2018-02-18 23:07:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(ShareObjectModal)
|