Skip to content

Commit

Permalink
Merge pull request desktop#19700 from desktop/add-missing-list-callba…
Browse files Browse the repository at this point in the history
…cks-to-augmented-filtered-section-list

Filtered Changes: Add missing list callbacks to augmented filtered section list
  • Loading branch information
tidy-dev authored Dec 19, 2024
2 parents 2d5e47a + 4ba30c6 commit 1c8c160
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 28 deletions.
47 changes: 19 additions & 28 deletions app/src/ui/changes/filter-changes-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ interface IFilterChangesListProps {
readonly onChangesListScrolled: (scrollTop: number) => void

/* The scrollTop of the compareList. It is stored to allow for scroll position persistence */
// TBD: readonly changesListScrollTop?: number
readonly changesListScrollTop?: number

/**
* Called to open a file in its default application
Expand Down Expand Up @@ -769,12 +769,10 @@ export class FilterChangesList extends React.Component<
}

private onItemContextMenu = (
item: any,
item: IChangesListItem,
event: React.MouseEvent<HTMLDivElement>
) => {
const row = 0 /// TBD;
const { workingDirectory } = this.props
const file = workingDirectory.files[row]
const file = item.change

if (this.props.isCommitting) {
return
Expand Down Expand Up @@ -816,8 +814,7 @@ export class FilterChangesList extends React.Component<
}
}

// TBD: make private
public onScroll = (scrollTop: number, clientHeight: number) => {
private onScroll = (scrollTop: number, clientHeight: number) => {
this.props.onChangesListScrolled(scrollTop)
}

Expand Down Expand Up @@ -1009,16 +1006,12 @@ export class FilterChangesList extends React.Component<
)
}

// TBD: make private
public onRowDoubleClick = (row: number) => {
const file = this.props.workingDirectory.files[row]

this.props.onOpenItemInExternalEditor(file.path)
private onChangedFileDoubleClick = (item: IChangesListItem) => {
this.props.onOpenItemInExternalEditor(item.change.path)
}

// TBD: make private
public onRowKeyDown = (
_row: number,
private onItemKeyDown = (
_item: IChangesListItem,
event: React.KeyboardEvent<HTMLDivElement>
) => {
// The commit is already in-flight but this check prevents the
Expand Down Expand Up @@ -1112,24 +1105,24 @@ export class FilterChangesList extends React.Component<
filterText={this.state.filterText}
onFilterTextChanged={this.onFilterTextChanged}
selectedItem={this.state.selectedItem}
// selectionMode="multi"...
renderItem={this.renderChangedFile}
onItemClick={this.onChangedFileClick}
// selectionMode="multi"...
// onRowDoubleClick={this.onRowDoubleClick}
// onRowKeyboardFocus={this.onRowFocus}
// onRowBlur={this.onRowBlur}
// onScroll={this.onScroll}
// setScrollTop={this.props.changesListScrollTop}
// onRowKeyDown={this.onRowKeyDown}
onItemDoubleClick={this.onChangedFileDoubleClick}
onItemKeyboardFocus={this.onChangedFileFocus}
onItemBlur={this.onChangedFileBlur}
onScroll={this.onScroll}
setScrollTop={this.props.changesListScrollTop}
onItemKeyDown={this.onItemKeyDown}
onSelectionChanged={this.onFileSelectionChanged}
groups={this.state.groups} //
groups={this.state.groups}
invalidationProps={{
workingDirectory: workingDirectory,
isCommitting: isCommitting,
focusedRow: this.state.focusedRow,
}}
onItemContextMenu={this.onItemContextMenu}
// ariaLabel={filesDescription}
ariaLabel={filesDescription}
/>
</div>
{this.renderStashedChanges()}
Expand All @@ -1138,13 +1131,11 @@ export class FilterChangesList extends React.Component<
)
}

// TBD: Needs private once hooked into list
public onRowFocus = (changeListItem: IChangesListItem) => {
private onChangedFileFocus = (changeListItem: IChangesListItem) => {
this.setState({ focusedRow: changeListItem.id })
}

// TBD: Needs private once hooked into list
public onRowBlur = (changeListItem: IChangesListItem) => {
private onChangedFileBlur = (changeListItem: IChangesListItem) => {
if (this.state.focusedRow === changeListItem.id) {
this.setState({ focusedRow: null })
}
Expand Down
87 changes: 87 additions & 0 deletions app/src/ui/lib/augmented-filter-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ interface IAugmentedSectionFilterListProps<T extends IFilterListItem> {
*/
readonly onItemClick?: (item: T, source: ClickSource) => void

readonly onItemDoubleClick?: (item: T, source: ClickSource) => void

/**
* This function will be called when the selection changes as a result of a
* user keyboard or mouse action (i.e. not when props change). This function
Expand Down Expand Up @@ -168,6 +170,31 @@ interface IAugmentedSectionFilterListProps<T extends IFilterListItem> {
item: T,
event: React.MouseEvent<HTMLDivElement>
) => void

/** This function will be called only when an item obtains focus via keyboard */
readonly onItemKeyboardFocus?: (
item: T,
event: React.KeyboardEvent<any>
) => void

/** This function will be called when a row loses focus */
readonly onItemBlur?: (
item: T,
event: React.FocusEvent<HTMLDivElement>
) => void

readonly onItemKeyDown?: (item: T, event: React.KeyboardEvent<any>) => void

readonly onScroll?: (scrollTop: number, clientHeight: number) => void

/**
* The number of pixels from the top of the list indicating
* where to scroll do on rendering of the list.
*/
readonly setScrollTop?: number

/** The aria-label attribute for the list component. */
readonly ariaLabel?: string
}

interface IAugmentedSectionFilterListState<T extends IFilterListItem> {
Expand Down Expand Up @@ -376,13 +403,19 @@ export class AugmentedSectionFilterList<
}
onSelectedRowChanged={this.onSelectedRowChanged}
onRowClick={this.onRowClick}
onRowDoubleClick={this.onRowDoubleClick}
onRowKeyDown={this.onRowKeyDown}
onRowContextMenu={this.onRowContextMenu}
onRowKeyboardFocus={this.onRowKeyboardFocus}
onRowBlur={this.onRowBlur}
canSelectRow={this.canSelectRow}
invalidationProps={{
...this.props,
...this.props.invalidationProps,
}}
onScroll={this.props.onScroll}
setScrollTop={this.props.setScrollTop}
ariaLabel={this.props.ariaLabel}
/>
)
}
Expand Down Expand Up @@ -483,6 +516,16 @@ export class AugmentedSectionFilterList<
}
}

private onRowDoubleClick = (index: RowIndexPath, source: ClickSource) => {
if (this.props.onItemDoubleClick) {
const row = this.state.rows[index.section][index.row]

if (row.kind === 'item') {
this.props.onItemDoubleClick(row.item, source)
}
}
}

private onRowContextMenu = (
index: RowIndexPath,
source: React.MouseEvent<HTMLDivElement>
Expand All @@ -500,10 +543,54 @@ export class AugmentedSectionFilterList<
this.props.onItemContextMenu(row.item, source)
}

private onRowKeyboardFocus = (
index: RowIndexPath,
source: React.KeyboardEvent<any>
) => {
if (!this.props.onItemKeyboardFocus) {
return
}

const row = this.state.rows[index.section][index.row]

if (row.kind !== 'item') {
return
}

this.props.onItemKeyboardFocus(row.item, source)
}

private onRowBlur = (
index: RowIndexPath,
source: React.FocusEvent<HTMLDivElement>
) => {
if (!this.props.onItemBlur) {
return
}

const row = this.state.rows[index.section][index.row]

if (row.kind !== 'item') {
return
}

this.props.onItemBlur(row.item, source)
}

private onRowKeyDown = (
indexPath: RowIndexPath,
event: React.KeyboardEvent<any>
) => {
const row = this.state.rows[indexPath.section][indexPath.row]

if (row.kind === 'item' && this.props.onItemKeyDown) {
this.props.onItemKeyDown(row.item, event)
}

if (event.defaultPrevented) {
return
}

const list = this.list
if (!list) {
return
Expand Down

0 comments on commit 1c8c160

Please sign in to comment.