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

Support multi-selection in file lists #1136

Merged
merged 61 commits into from
Jul 28, 2022
Merged
Show file tree
Hide file tree
Changes from 59 commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
e74a50b
enable multiple selection with control-click without functionality
BoscoCHW Jun 20, 2022
b6e5a58
Implemented multiple file selection with control-click
BoscoCHW Jun 21, 2022
24e8b40
Remove handling this.state.selectedFiles is null in FileList selectFi…
BoscoCHW Jun 22, 2022
3873908
Enable toggle select/deselect files with control-click
BoscoCHW Jun 22, 2022
1564fbe
Implement Shift-Click file selection
BoscoCHW Jun 22, 2022
0c39912
extract file comparison logic and remove duplicate selected files due…
BoscoCHW Jun 22, 2022
8ca54d6
limit multiple file selection by control-click to within the same cat…
BoscoCHW Jun 23, 2022
771b54c
rename replaceSelectedFile to selectOnlyOneFile for better comprehension
BoscoCHW Jun 23, 2022
8d9ebbc
shift-click on a file with a different category (git status) becomes …
BoscoCHW Jun 23, 2022
02255ba
Make FileItem action commands (open, diff and stage file) apply to se…
BoscoCHW Jun 23, 2022
daf70ca
Make FileItem action commands (open, diff and unstage file) apply to …
BoscoCHW Jun 23, 2022
0b8df08
Make FileItem action commands (discarding changes and staging file) a…
BoscoCHW Jun 24, 2022
b113c11
fix bug - open correct files on clicking action button
BoscoCHW Jun 24, 2022
3bba8ff
fix bug - diff correct files on clicking action button
BoscoCHW Jun 24, 2022
312ef19
fix bug - unstage correct files on clicking action button
BoscoCHW Jun 24, 2022
d747f65
fix bug - stage correct files on clicking action button
BoscoCHW Jun 24, 2022
36612e1
fix bug - discard changes on correct files on clicking action button
BoscoCHW Jun 24, 2022
f085627
Merge branch 'jupyterlab:master' into issue-379
BoscoCHW Jun 24, 2022
3a24be0
Merge branch 'issue-379' of https://github.com/BoscoCHW/jupyterlab-gi…
BoscoCHW Jun 24, 2022
f6fc277
fix FileItem test
BoscoCHW Jun 24, 2022
6067f3b
Rename function filesAreEqual to areFilesEqual
BoscoCHW Jun 27, 2022
794a8ac
Remove selectedFileStatus from state
BoscoCHW Jun 27, 2022
925006e
change _openDiffViews function to async and await the execute command
BoscoCHW Jun 27, 2022
16f8d2b
Remove unnecessary code in openContextMenu
BoscoCHW Jun 27, 2022
155a765
Ensure selectFiles arrives at correct state
BoscoCHW Jun 27, 2022
8060a1b
implement single selection callback 'setSelection'
BoscoCHW Jun 27, 2022
171d2cc
rework _selectUntilFile to index in sub array
BoscoCHW Jun 27, 2022
78a5c64
fix FileItem test
BoscoCHW Jun 27, 2022
923074a
implement advanced shift-click behaviours
BoscoCHW Jun 28, 2022
fca292c
Added label to wrap around div object to allow click on whole div ele…
iflinda Jun 28, 2022
058771e
Fixed label placement issue
iflinda Jun 28, 2022
ea0b4b9
Styled filename div
iflinda Jun 29, 2022
4289b1a
Fixed styling issue by importing and applying fileLabelStyle to the a…
iflinda Jun 29, 2022
50c00dc
tried implementing shiftclick but unsuccessful:
BoscoCHW Jun 29, 2022
60eb81d
Fixed issue with shift click when clicking in reverse order
iflinda Jun 30, 2022
8af21b0
Implement markedFile getter in gitModel
BoscoCHW Jun 30, 2022
5fe8a22
Merge branch 'issue-379-simple-staging-test' of https://github.com/Bo…
BoscoCHW Jun 30, 2022
28213d0
implement shift click
BoscoCHW Jun 30, 2022
d02f950
Fix bug for shift-click for simple staging
BoscoCHW Jul 6, 2022
0fe22e9
Clean up
BoscoCHW Jul 6, 2022
12d345b
remove console logs
BoscoCHW Jul 6, 2022
c155dbe
insert in FileItemStyle.ts
BoscoCHW Jul 6, 2022
48b38ca
added simple ui tests for ctlr and shift click on file selection for …
BoscoCHW Jul 7, 2022
a90ee9f
Add skeleton code for implementing de/select all button for simple st…
BoscoCHW Jul 11, 2022
1db6fa4
Fix original ui tests
BoscoCHW Jul 11, 2022
2182835
Changed file name in ui-tests README and have the select all in simpl…
iflinda Jul 13, 2022
71858cf
Changed name of variables and function from markAllFile to toggleAllF…
iflinda Jul 13, 2022
e9113fd
Added the ability to deselect items using select all
iflinda Jul 14, 2022
efa5859
Simplified code in toggleAllFiles to use state and removed redundant …
iflinda Jul 14, 2022
8d4c6b6
Improve mark-all button behaviour - sync checked state of the box to …
BoscoCHW Jul 19, 2022
b55a072
Fix ui tests
BoscoCHW Jul 19, 2022
ad69888
Add ui tests for simple staging
BoscoCHW Jul 19, 2022
c1b9791
Clear all signal connections when unmounting FileList
BoscoCHW Jul 21, 2022
0688f2a
Delete commented code in GitPanel
BoscoCHW Jul 21, 2022
2f3acfa
Delete unused prop from interface (GitStage)
BoscoCHW Jul 21, 2022
fae294f
Improve consistency and fix bug
BoscoCHW Jul 21, 2022
b401781
fix ui test readme
BoscoCHW Jul 21, 2022
041c933
Change control-click ui test to expect exactly 2 selected items
BoscoCHW Jul 21, 2022
0184526
Stop propagation when users click on action buttons on FileItem
BoscoCHW Jul 21, 2022
a5c100b
Add doc strings for functions
BoscoCHW Jul 25, 2022
95f6910
Document helper functions
BoscoCHW Jul 25, 2022
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
114 changes: 75 additions & 39 deletions src/components/FileItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import * as React from 'react';
import { classes } from 'typestyle';
import { GitExtension } from '../model';
import {
checkboxLabelContainerStyle,
checkboxLabelLastContainerStyle,
checkboxLabelStyle,
fileChangedLabelBrandStyle,
fileChangedLabelInfoStyle,
fileChangedLabelStyle,
Expand All @@ -12,6 +15,7 @@ import {
selectedFileChangedLabelStyle,
selectedFileStyle
} from '../style/FileItemStyle';
import { fileLabelStyle } from '../style/FilePathStyle';
import { Git } from '../tokens';
import { FilePath } from './FilePath';

Expand Down Expand Up @@ -44,20 +48,16 @@ interface IGitMarkBoxProps {
* File status
*/
stage: Git.Status;
/**
* Whether the checkbox is checked
*/
checked: boolean;
}

/**
* Render the selection box in simple mode
*/
class GitMarkBox extends React.PureComponent<IGitMarkBoxProps> {
protected _onClick = (): void => {
// toggle will emit a markChanged signal
this.props.model.toggleMark(this.props.fname);

// needed if markChanged doesn't force an update of a parent
this.forceUpdate();
};

protected _onDoubleClick = (
event: React.MouseEvent<HTMLInputElement>
): void => {
Expand All @@ -76,8 +76,7 @@ class GitMarkBox extends React.PureComponent<IGitMarkBoxProps> {
name="gitMark"
className={gitMarkBoxStyle}
type="checkbox"
checked={this.props.model.getMark(this.props.fname)}
onChange={this._onClick}
checked={this.props.checked}
onDoubleClick={this._onDoubleClick}
/>
);
Expand Down Expand Up @@ -117,9 +116,12 @@ export interface IFileItemProps {
*/
selected?: boolean;
/**
* Callback to select the file
* Callback to select file(s)
*/
selectFile?: (file: Git.IStatusFile | null) => void;
setSelection?: (
file: Git.IStatusFile,
options?: { singleton?: boolean; group?: boolean }
) => void;
/**
* Optional style class
*/
Expand All @@ -132,12 +134,40 @@ export interface IFileItemProps {
* The application language translator.
*/
trans: TranslationBundle;
/**
* Callback to implement shift-click for simple staging
*/
markUntilFile?: (file: Git.IStatusFile) => void;
/**
* whether the GitMarkBox is checked
*/
checked?: boolean;
}

export class FileItem extends React.PureComponent<IFileItemProps> {
constructor(props: IFileItemProps) {
super(props);
}

protected _onClick = (event: React.MouseEvent<HTMLInputElement>): void => {
if (this.props.markBox) {
if (event.shiftKey) {
this.props.markUntilFile(this.props.file);
} else {
this.props.model.toggleMark(this.props.file.to);
this.props.setSelection(this.props.file, { singleton: true });
}
} else {
if (event.ctrlKey || event.metaKey) {
this.props.setSelection(this.props.file);
} else if (event.shiftKey) {
this.props.setSelection(this.props.file, { group: true });
} else {
this.props.setSelection(this.props.file, { singleton: true });
}
}
};

protected _getFileChangedLabel(change: keyof typeof STATUS_CODES): string {
return STATUS_CODES[change] || 'Unmodified';
}
Expand Down Expand Up @@ -190,11 +220,10 @@ export class FileItem extends React.PureComponent<IFileItemProps> {

return (
<div
data-test-selected={this.props.selected}
data-test-checked={this.props.checked}
className={this._getFileClass()}
onClick={
this.props.selectFile &&
(() => this.props.selectFile(this.props.file))
}
onClick={this._onClick}
onContextMenu={
this.props.contextMenu &&
(event => {
Expand All @@ -205,29 +234,36 @@ export class FileItem extends React.PureComponent<IFileItemProps> {
style={this.props.style}
title={this.props.trans.__(`%1 • ${status}`, this.props.file.to)}
>
{this.props.markBox && (
<GitMarkBox
fname={this.props.file.to}
stage={this.props.file.status}
model={this.props.model}
/>
)}
<FilePath
filepath={this.props.file.to}
filetype={this.props.file.type}
/>
{this.props.actions}
<span
className={this._getFileChangedLabelClass(
this.props.file.status === 'unmerged' ? '!' : this.props.file.y
)}
>
{this.props.file.status === 'unmerged'
? '!'
: this.props.file.y === '?'
? 'U'
: status_code}
</span>
<div className={checkboxLabelContainerStyle}>
<div className={checkboxLabelStyle + ' ' + fileLabelStyle}>
{this.props.markBox && (
<GitMarkBox
fname={this.props.file.to}
stage={this.props.file.status}
model={this.props.model}
checked={this.props.checked}
/>
)}
<FilePath
filepath={this.props.file.to}
filetype={this.props.file.type}
/>
</div>
<div className={checkboxLabelLastContainerStyle}>
{this.props.actions}
<span
className={this._getFileChangedLabelClass(
this.props.file.status === 'unmerged' ? '!' : this.props.file.y
)}
>
{this.props.file.status === 'unmerged'
? '!'
: this.props.file.y === '?'
? 'U'
: status_code}
</span>
</div>
</div>
</div>
);
}
Expand Down
Loading