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: select multiple files via click checkbox with shift key #6895

Merged
merged 1 commit into from
Oct 14, 2024
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
8 changes: 5 additions & 3 deletions frontend/src/components/dirent-list-view/dirent-list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,9 @@ class DirentListItem extends React.Component {
};

// buiness handler
onItemSelected = () => {
this.props.onItemSelected(this.state.dirent);
onItemSelected = (event) => {
event.stopPropagation();
this.props.onItemSelected(this.state.dirent, event);
};

onItemStarred = (e) => {
Expand Down Expand Up @@ -822,7 +823,8 @@ class DirentListItem extends React.Component {
<input
type="checkbox"
className="vam"
onChange={this.onItemSelected}
onClick={this.onItemSelected}
onChange={() => {}}
checked={isSelected}
aria-label={isSelected ? gettext('Unselect this item') : gettext('Select this item')}
/>
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/dirent-list-view/dirent-list-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ class DirentListView extends React.Component {
this.freezeItem();
};

onItemSelected = (dirent) => {
onItemSelected = (dirent, event) => {
this.setState({ activeDirent: null });
this.props.onItemSelected(dirent);
this.props.onItemSelected(dirent, event);
};

onDirentClick = (dirent, event) => {
Expand Down
67 changes: 50 additions & 17 deletions frontend/src/pages/lib-content-view/lib-content-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -1520,40 +1520,73 @@ class LibContentView extends React.Component {
}
};

onDirentSelected = (dirent) => {
onDirentSelected = (dirent, event) => {
this.setState({
currentDirent: dirent && dirent.isActive ? null : dirent
});
let direntList = this.state.direntList.map(item => {
if (dirent && item.name === dirent.name) {
item.isSelected = !item.isSelected;

const { direntList, lastSelectedIndex, selectedDirentList } = this.state;
const clickedDirentIndex = dirent ? direntList.findIndex((currDirent) => currDirent.name === dirent.name) : -1;
const clickedDirent = clickedDirentIndex > -1 ? direntList[clickedDirentIndex] : null;
let nextSelectedIndex = null;
if (clickedDirent && !clickedDirent.isSelected) {
nextSelectedIndex = clickedDirentIndex;
}

let nextDirentList = direntList;
if (event && event.shiftKey && lastSelectedIndex !== null && nextSelectedIndex !== null) {
// select multiple files with shift key
const start = Math.min(lastSelectedIndex, nextSelectedIndex);
const end = Math.max(lastSelectedIndex, nextSelectedIndex);
const direntListInRange = direntList.slice(start, end + 1);
if (direntListInRange.length > 0) {
const nameDirentSelectedMap = selectedDirentList.reduce((currNameDirentSelectedMap, currDirent) => {
return { ...currNameDirentSelectedMap, [currDirent.name]: true };
}, {});
const nameDirentSelectingMap = direntListInRange.reduce((currNameDirentSelectingMap, currDirent) => {
return { ...currNameDirentSelectingMap, [currDirent.name]: true };
}, {});
nextDirentList = direntList.map((currDirent) => {
if (nameDirentSelectedMap[currDirent.name] || nameDirentSelectingMap[currDirent.name]) {
currDirent.isSelected = true;
}
return currDirent;
});
}
return item;
});
let selectedDirentList = direntList.filter(item => {
return item.isSelected;
});
if (selectedDirentList.length) {
} else {
nextDirentList = direntList.map(item => {
if (dirent && item.name === dirent.name) {
item.isSelected = !item.isSelected;
}
return item;
});
}

const nextSelectedDirentList = nextDirentList.filter(item => item.isSelected);
if (nextSelectedDirentList.length) {
this.setState({ isDirentSelected: true });
if (selectedDirentList.length === direntList.length) {
if (nextSelectedDirentList.length === nextDirentList.length) {
this.setState({
isAllDirentSelected: true,
direntList: direntList,
selectedDirentList: selectedDirentList,
direntList: nextDirentList,
selectedDirentList: nextSelectedDirentList,
lastSelectedIndex: nextSelectedIndex,
});
} else {
this.setState({
isAllDirentSelected: false,
direntList: direntList,
selectedDirentList: selectedDirentList
direntList: nextDirentList,
selectedDirentList: nextSelectedDirentList,
lastSelectedIndex: nextSelectedIndex,
});
}
} else {
this.setState({
isDirentSelected: false,
isAllDirentSelected: false,
direntList: direntList,
selectedDirentList: []
direntList: nextDirentList,
selectedDirentList: [],
lastSelectedIndex: nextSelectedIndex,
});
}
};
Expand Down
Loading