Move onContextMenu from file row to file list

This commit is contained in:
Sergio Padrino 2023-07-30 23:13:03 +02:00
parent f3ff8b1b9e
commit cb1207d6c8
2 changed files with 9 additions and 12 deletions

View file

@ -8,19 +8,9 @@ import { Octicon, iconForStatus } from '../octicons'
interface ICommittedFileItemProps {
readonly availableWidth: number
readonly file: CommittedFileChange
readonly onContextMenu?: (
file: CommittedFileChange,
event: React.MouseEvent<HTMLDivElement>
) => void
}
export class CommittedFileItem extends React.Component<ICommittedFileItemProps> {
private onContextMenu = (event: React.MouseEvent<HTMLDivElement>) => {
if (this.props.onContextMenu !== undefined) {
this.props.onContextMenu(this.props.file, event)
}
}
public render() {
const { file } = this.props
const status = file.status
@ -36,7 +26,7 @@ export class CommittedFileItem extends React.Component<ICommittedFileItemProps>
statusWidth
return (
<div className="file" onContextMenu={this.onContextMenu}>
<div className="file">
<PathLabel
path={file.path}
status={file.status}

View file

@ -30,7 +30,6 @@ export class FileList extends React.Component<IFileListProps> {
<CommittedFileItem
file={this.props.files[row]}
availableWidth={this.props.availableWidth}
onContextMenu={this.props.onContextMenu}
/>
)
}
@ -39,6 +38,13 @@ export class FileList extends React.Component<IFileListProps> {
return file ? this.props.files.findIndex(f => f.path === file.path) : -1
}
private onRowContextMenu = (
row: number,
event: React.MouseEvent<HTMLDivElement>
) => {
this.props.onContextMenu?.(this.props.files[row], event)
}
public render() {
return (
<div className="file-list">
@ -49,6 +55,7 @@ export class FileList extends React.Component<IFileListProps> {
selectedRows={[this.rowForFile(this.props.selectedFile)]}
onSelectedRowChanged={this.onSelectedRowChanged}
onRowDoubleClick={this.props.onRowDoubleClick}
onRowContextMenu={this.onRowContextMenu}
/>
</div>
)