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

Fix shift + select multiple files selection in ProviderViews #3768

Merged
merged 1 commit into from
May 23, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions packages/@uppy/provider-views/src/Browser.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function Browser (props) {
showBreadcrumbs,
isChecked,
toggleCheckbox,
recordShiftKeyPress,
handleScroll,
showTitles,
i18n,
Expand Down Expand Up @@ -91,6 +92,7 @@ function Browser (props) {
getItemIcon: () => folder.icon,
isChecked: isChecked(folder),
toggleCheckbox: (event) => toggleCheckbox(event, folder),
recordShiftKeyPress,
type: 'folder',
isDisabled: isChecked(folder)?.loading,
isCheckboxDisabled: folder.id === VIRTUAL_SHARED_DIR,
Expand All @@ -111,6 +113,7 @@ function Browser (props) {
getItemIcon: () => file.icon,
isChecked: isChecked(file),
toggleCheckbox: (event) => toggleCheckbox(event, file),
recordShiftKeyPress,
columns,
showTitles,
viewType,
Expand Down
2 changes: 2 additions & 0 deletions packages/@uppy/provider-views/src/Item/components/GridLi.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ function GridListItem (props) {
itemIconEl,
showTitles,
toggleCheckbox,
recordShiftKeyPress,
id,
children,
} = props
Expand All @@ -25,6 +26,7 @@ function GridListItem (props) {
isChecked ? 'uppy-ProviderBrowserItem-checkbox--is-checked' : ''
} uppy-ProviderBrowserItem-checkbox--grid`}
onChange={toggleCheckbox}
onKeyDown={recordShiftKeyPress}
name="listitem"
id={id}
checked={isChecked}
Expand Down
2 changes: 2 additions & 0 deletions packages/@uppy/provider-views/src/Item/components/ListLi.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function ListItem (props) {
isCheckboxDisabled,
isChecked,
toggleCheckbox,
recordShiftKeyPress,
type,
id,
itemIconEl,
Expand All @@ -34,6 +35,7 @@ function ListItem (props) {
type="checkbox"
className={`uppy-u-reset uppy-ProviderBrowserItem-checkbox ${isChecked ? 'uppy-ProviderBrowserItem-checkbox--is-checked' : ''}`}
onChange={toggleCheckbox}
onKeyDown={recordShiftKeyPress}
// for the <label/>
name="listitem"
id={id}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export default class ProviderView extends View {

const targetViewOptions = { ...this.opts, ...viewOptions }
const { files, folders, filterInput, loading, currentSelection } = this.plugin.getPluginState()
const { isChecked, toggleCheckbox, filterItems } = this.sharedHandler
const { isChecked, toggleCheckbox, recordShiftKeyPress, filterItems } = this.sharedHandler
const hasInput = filterInput !== ''
const headerProps = {
showBreadcrumbs: targetViewOptions.showBreadcrumbs,
Expand All @@ -348,6 +348,7 @@ export default class ProviderView extends View {
const browserProps = {
isChecked,
toggleCheckbox,
recordShiftKeyPress,
currentSelection,
files: hasInput ? filterItems(files) : files,
folders: hasInput ? filterItems(folders) : folders,
Expand Down
8 changes: 6 additions & 2 deletions packages/@uppy/provider-views/src/SharedHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export default class SharedHandler {
this.plugin = plugin
this.filterItems = this.filterItems.bind(this)
this.toggleCheckbox = this.toggleCheckbox.bind(this)
this.recordShiftKeyPress = this.recordShiftKeyPress.bind(this)
this.isChecked = this.isChecked.bind(this)
this.loaderWrapper = this.loaderWrapper.bind(this)
}
Expand All @@ -19,6 +20,10 @@ export default class SharedHandler {
})
}

recordShiftKeyPress (e) {
this.isShiftKeyPressed = e.shiftKey
}

/**
* Toggles file/folder checkbox to on/off state while updating files list.
*
Expand All @@ -32,10 +37,9 @@ export default class SharedHandler {
e.currentTarget.focus()
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.
if (this.lastCheckbox && e.shiftKey) {
if (this.lastCheckbox && this.isShiftKeyPressed) {
const prevIndex = items.indexOf(this.lastCheckbox)
const currentIndex = items.indexOf(file)
const currentSelection = (prevIndex < currentIndex)
Expand Down