storj.io/minio@v0.0.0-20230509071714-0cbc90f649b1/browser/app/js/objects/ObjectActions.js (about)

     1  /*
     2   * MinIO Cloud Storage (C) 2018 MinIO, Inc.
     3   *
     4   * Licensed under the Apache License, Version 2.0 (the "License");
     5   * you may not use this file except in compliance with the License.
     6   * You may obtain a copy of the License at
     7   *
     8   *     http://www.apache.org/licenses/LICENSE-2.0
     9   *
    10   * Unless required by applicable law or agreed to in writing, software
    11   * distributed under the License is distributed on an "AS IS" BASIS,
    12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13   * See the License for the specific language governing permissions and
    14   * limitations under the License.
    15   */
    16  
    17  import React from "react"
    18  import { connect } from "react-redux"
    19  import { Dropdown } from "react-bootstrap"
    20  import ShareObjectModal from "./ShareObjectModal"
    21  import DeleteObjectConfirmModal from "./DeleteObjectConfirmModal"
    22  import PreviewObjectModal from "./PreviewObjectModal"
    23  
    24  import * as objectsActions from "./actions"
    25  import { getDataType } from "../mime.js"
    26  import {
    27    SHARE_OBJECT_EXPIRY_DAYS,
    28    SHARE_OBJECT_EXPIRY_HOURS,
    29    SHARE_OBJECT_EXPIRY_MINUTES,
    30  } from "../constants"
    31  
    32  export class ObjectActions extends React.Component {
    33    constructor(props) {
    34      super(props)
    35      this.state = {
    36        showDeleteConfirmation: false,
    37        showPreview: false,
    38      }
    39    }
    40    shareObject(e) {
    41      e.preventDefault()
    42      const { object, shareObject } = this.props
    43      shareObject(
    44        object.name,
    45        SHARE_OBJECT_EXPIRY_DAYS,
    46        SHARE_OBJECT_EXPIRY_HOURS,
    47        SHARE_OBJECT_EXPIRY_MINUTES
    48      )
    49    }
    50    handleDownload(e) {
    51      e.preventDefault()
    52      const { object, downloadObject } = this.props
    53      downloadObject(object.name)
    54    }
    55    deleteObject() {
    56      const { object, deleteObject } = this.props
    57      deleteObject(object.name)
    58    }
    59    showDeleteConfirmModal(e) {
    60      e.preventDefault()
    61      this.setState({ showDeleteConfirmation: true })
    62    }
    63    hideDeleteConfirmModal() {
    64      this.setState({
    65        showDeleteConfirmation: false,
    66      })
    67    }
    68    getObjectURL(objectname, callback) {
    69      const { getObjectURL } = this.props
    70      getObjectURL(objectname, callback)
    71    }
    72    showPreviewModal(e) {
    73      e.preventDefault()
    74      this.setState({ showPreview: true })
    75    }
    76    hidePreviewModal() {
    77      this.setState({
    78        showPreview: false,
    79      })
    80    }
    81    render() {
    82      const { object, showShareObjectModal, shareObjectName } = this.props
    83      return (
    84        <Dropdown id={`obj-actions-${object.name}`}>
    85          <Dropdown.Toggle noCaret className="fia-toggle" />
    86          <Dropdown.Menu>
    87            <a
    88              href=""
    89              className="fiad-action"
    90              title="Share"
    91              onClick={this.shareObject.bind(this)}
    92            >
    93              <i className="fas fa-share-alt" />
    94            </a>
    95            {getDataType(object.name, object.contentType) == "image" && (
    96              <a
    97                href=""
    98                className="fiad-action"
    99                title="Preview"
   100                onClick={this.showPreviewModal.bind(this)}
   101              >
   102                <i className="far fa-file-image" />
   103              </a>
   104            )}
   105            <a
   106              href=""
   107              className="fiad-action"
   108              title="Download"
   109              onClick={this.handleDownload.bind(this)}
   110            >
   111              <i className="fas fa-cloud-download-alt" />
   112            </a>
   113            <a
   114              href=""
   115              className="fiad-action"
   116              title="Delete"
   117              onClick={this.showDeleteConfirmModal.bind(this)}
   118            >
   119              <i className="fas fa-trash-alt" />
   120            </a>
   121          </Dropdown.Menu>
   122          {showShareObjectModal && shareObjectName === object.name && (
   123            <ShareObjectModal object={object} />
   124          )}
   125          {this.state.showDeleteConfirmation && (
   126            <DeleteObjectConfirmModal
   127              deleteObject={this.deleteObject.bind(this)}
   128              hideDeleteConfirmModal={this.hideDeleteConfirmModal.bind(this)}
   129            />
   130          )}
   131          {this.state.showPreview && (
   132            <PreviewObjectModal
   133              object={object}
   134              hidePreviewModal={this.hidePreviewModal.bind(this)}
   135              getObjectURL={this.getObjectURL.bind(this)}
   136            />
   137          )}
   138        </Dropdown>
   139      )
   140    }
   141  }
   142  
   143  const mapStateToProps = (state, ownProps) => {
   144    return {
   145      object: ownProps.object,
   146      showShareObjectModal: state.objects.shareObject.show,
   147      shareObjectName: state.objects.shareObject.object,
   148    }
   149  }
   150  
   151  const mapDispatchToProps = (dispatch) => {
   152    return {
   153      downloadObject: object => dispatch(objectsActions.downloadObject(object)),
   154      shareObject: (object, days, hours, minutes) =>
   155        dispatch(objectsActions.shareObject(object, days, hours, minutes)),
   156      deleteObject: (object) => dispatch(objectsActions.deleteObject(object)),
   157      getObjectURL: (object, callback) =>
   158        dispatch(objectsActions.getObjectURL(object, callback)),
   159    }
   160  }
   161  
   162  export default connect(mapStateToProps, mapDispatchToProps)(ObjectActions)