Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@uppy/provider-views: Fix range selection not resetting and computing correctly #4415

Merged
merged 3 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function GridListItem (props) {
className={checkBoxClassName}
onChange={toggleCheckbox}
onKeyDown={recordShiftKeyPress}
onMouseDown={recordShiftKeyPress}
name="listitem"
id={id}
checked={isChecked}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ function ListItem (props) {
className={`uppy-u-reset uppy-ProviderBrowserItem-checkbox ${isChecked ? 'uppy-ProviderBrowserItem-checkbox--is-checked' : ''}`}
onChange={toggleCheckbox}
onKeyDown={recordShiftKeyPress}
onMouseDown={recordShiftKeyPress}
// for the <label/>
name="listitem"
id={id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export default class ProviderView extends View {
this.username = res.username || this.username
this.#updateFilesAndFolders(res, files, folders)
this.plugin.setPluginState({ directories: updatedDirectories, filterInput: '' })
this.lastCheckbox = undefined
} catch (err) {
this.handleError(err)
} finally {
Expand Down
15 changes: 8 additions & 7 deletions packages/@uppy/provider-views/src/View.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,31 +123,32 @@ export default class View {
const { folders, files } = this.plugin.getPluginState()
const items = this.filterItems(folders.concat(files))
// Shift-clicking selects a single consecutive list of items
// starting at the previous click and deselects everything else.
// starting at the previous click.
if (this.lastCheckbox && this.isShiftKeyPressed) {
const { currentSelection } = this.plugin.getPluginState()
const prevIndex = items.indexOf(this.lastCheckbox)
const currentIndex = items.indexOf(file)
const currentSelection = (prevIndex < currentIndex)
const newSelection = (prevIndex < currentIndex)
? items.slice(prevIndex, currentIndex + 1)
: items.slice(currentIndex, prevIndex + 1)
const reducedCurrentSelection = []
const reducedNewSelection = []

// Check restrictions on each file in currentSelection,
// reduce it to only contain files that pass restrictions
for (const item of currentSelection) {
for (const item of newSelection) {
const { uppy } = this.plugin
const restrictionError = uppy.validateRestrictions(
remoteFileObjToLocal(item),
[...uppy.getFiles(), ...reducedCurrentSelection],
[...uppy.getFiles(), ...reducedNewSelection],
)

if (!restrictionError) {
reducedCurrentSelection.push(item)
reducedNewSelection.push(item)
} else {
uppy.info({ message: restrictionError.message }, 'error', uppy.opts.infoTimeout)
}
}
this.plugin.setPluginState({ currentSelection: reducedCurrentSelection })
this.plugin.setPluginState({ currentSelection: [...new Set([...currentSelection, ...reducedNewSelection])] })
return
}

Expand Down