Skip to content

Commit

Permalink
Dashboard: add options to show remove button after complete (#2284)
Browse files Browse the repository at this point in the history
  • Loading branch information
arturi authored May 25, 2020
1 parent 52f8506 commit 99db9f2
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 5 deletions.
14 changes: 11 additions & 3 deletions packages/@uppy/dashboard/src/components/FileItem/Buttons/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ function RemoveButton ({ i18n, onClick }) {
)
}

const copyLinkToClipboard = (event, props) =>
const copyLinkToClipboard = (event, props) => {
copyToClipboard(props.file.uploadURL, props.i18n('copyLinkToClipboardFallback'))
.then(() => {
props.log('Link copied to clipboard.')
Expand All @@ -51,6 +51,7 @@ const copyLinkToClipboard = (event, props) =>
.catch(props.log)
// avoid losing focus
.then(() => event.target.focus({ preventScroll: true }))
}

function CopyLinkButton (props) {
return (
Expand Down Expand Up @@ -93,7 +94,9 @@ module.exports = function Buttons (props) {
showRemoveButton,
i18n,
removeFile,
toggleFileCard
toggleFileCard,
log,
info
} = props

return (
Expand All @@ -112,7 +115,12 @@ module.exports = function Buttons (props) {
onClick={() => toggleFileCard(file.id)}
/>
{showLinkToFileUploadResult && file.uploadURL ? (
<CopyLinkButton i18n={i18n} />
<CopyLinkButton
file={file}
i18n={i18n}
info={info}
log={log}
/>
) : null}
{showRemoveButton ? (
<RemoveButton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ function progressIndicatorTitle (props) {
}

module.exports = function FileProgress (props) {
if (props.hideRetryButton && props.error) {
if ((props.hideRetryButton && props.error) ||
(props.isUploaded && props.showRemoveButtonAfterComplete)) {
return <div class="uppy-DashboardItem-progress" />
} else if (
props.isUploaded ||
Expand Down
7 changes: 6 additions & 1 deletion packages/@uppy/dashboard/src/components/FileItem/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,14 @@ module.exports = class FileItem extends Component {
const isPaused = file.isPaused || false
const error = file.error || false

const showRemoveButton = this.props.individualCancellation
let showRemoveButton = this.props.individualCancellation
? !isUploaded
: !uploadInProgress && !isUploaded

if (isUploaded && this.props.showRemoveButtonAfterComplete) {
showRemoveButton = true
}

const dashboardItemClass = classNames({
'uppy-u-reset': true,
'uppy-DashboardItem': true,
Expand Down Expand Up @@ -69,6 +73,7 @@ module.exports = class FileItem extends Component {

hideRetryButton={this.props.hideRetryButton}
hidePauseResumeCancelButtons={this.props.hidePauseResumeCancelButtons}
showRemoveButtonAfterComplete={this.props.showRemoveButtonAfterComplete}

resumableUploads={this.props.resumableUploads}
individualCancellation={this.props.individualCancellation}
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/dashboard/src/components/FileList.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module.exports = (props) => {
hideRetryButton: props.hideRetryButton,
hidePauseResumeCancelButtons: props.hidePauseResumeCancelButtons,
showLinkToFileUploadResult: props.showLinkToFileUploadResult,
showRemoveButtonAfterComplete: props.showRemoveButtonAfterComplete,
isWide: props.isWide,
metaFields: props.metaFields,
// callbacks
Expand Down
2 changes: 2 additions & 0 deletions packages/@uppy/dashboard/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ module.exports = class Dashboard extends Plugin {
proudlyDisplayPoweredByUppy: true,
onRequestCloseModal: () => this.closeModal(),
showSelectedFiles: true,
showRemoveButtonAfterComplete: false,
browserBackButtonClose: false,
theme: 'light'
}
Expand Down Expand Up @@ -852,6 +853,7 @@ module.exports = class Dashboard extends Plugin {
showLinkToFileUploadResult: this.opts.showLinkToFileUploadResult,
proudlyDisplayPoweredByUppy: this.opts.proudlyDisplayPoweredByUppy,
hideCancelButton: this.opts.hideCancelButton,
showRemoveButtonAfterComplete: this.opts.showRemoveButtonAfterComplete,
containerWidth: pluginState.containerWidth,
containerHeight: pluginState.containerHeight,
areInsidesReadyToBeVisible: pluginState.areInsidesReadyToBeVisible,
Expand Down
1 change: 1 addition & 0 deletions packages/@uppy/dashboard/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ declare module Dashboard {
showLinkToFileUploadResult?: boolean
showProgressDetails?: boolean
showSelectedFiles?: boolean
showRemoveButtonAfterComplete?: boolean
replaceTargetContent?: boolean
target?: Uppy.PluginTarget
theme?: 'auto' | 'dark' | 'light'
Expand Down
5 changes: 5 additions & 0 deletions website/src/docs/dashboard.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ uppy.use(Dashboard, {
proudlyDisplayPoweredByUppy: true,
onRequestCloseModal: () => this.closeModal(),
showSelectedFiles: true,
showRemoveButtonAfterComplete: false,
locale: defaultLocale,
browserBackButtonClose: false,
theme: 'light'
Expand Down Expand Up @@ -188,6 +189,10 @@ Show the list (grid) of selected files with preview and file name. In case you a

See also `disableStatusBar` option, which can hide the progress and upload button.

### `showRemoveButtonAfterComplete: false`

Sometimes you might want to let users remove an uploaded file. Enabling this option only shows the remove `X` button in the Dashboard UI, but to actually send a request you should listen to [`file-removed`](https://uppy.io/docs/uppy/#file-removed) event and add your logic there.

### `note: null`

Optionally, specify a string of text that explains something about the upload for the user. This is a place to explain any `restrictions` that are put in place. For example: `'Images and video only, 2–3 files, up to 1 MB'`.
Expand Down

0 comments on commit 99db9f2

Please sign in to comment.