-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
List some branches #1126
Merged
Merged
List some branches #1126
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
72450eb
Extract branch list from branch foldout component
niik 4e65870
:fire: obsolete border
niik 358310f
Make the branches list styles stand-alone
niik 3aab6da
Use branch list in merge dialog
niik 2e9b829
Remove obsolete styles
niik 9af6210
Give that merge dialog an id
niik 627c7dd
Style button group, not whole footer
niik 10368ea
Add initial merge dialog styles
niik bbea319
Wider
niik 97b639c
Enable experimental features for ResizeObserver
niik a9a63fc
Use ResizeObserver when available instead of AutoSizer
niik c1f86dc
Fix interactions on scroll bar on Windows
niik 9d2961b
Remove one layer of nesting in lists on Windows
niik 2eef0a3
Add an event for selection changed on filter list
niik 5ef1ab1
Use props to determine selected branch
niik 8a2cc7d
Only check out branch if it's not already checked out
niik 6ac4967
Select current branch initially
niik d367136
Keep track of selection
niik ff5d43c
Branch list keeps track of selection
niik 380adb4
Select the default branch by default
niik e6d2a13
Keep track of selection in merge
niik 47395fb
Dismiss merge dialog on escape
niik e453636
Notify consumers if selection has changed due to filtering
niik 08481e2
Better types
niik 5ca1e14
Only update commit count if we have a selection
niik 4bbea8b
This shouldn't work but it does... why?
niik 6283322
And this is the correct version
niik 67fbac4
Ditch the cancel button :/
niik 3ac6ab3
Clear out old code
niik e2ea315
Some styling of the merge dialog
niik d3b772c
Secondary color and alignment for info text
niik 7c8a0e7
Cleanup list header styles
niik cd8d451
line it all up
niik a334069
Better padding
niik f56f78a
Style the merge info
niik a8f7532
Readonly and :book:
niik 447d2af
:book:
niik 89360a0
:fire: whitespace
niik 5bfbc79
Revert test change
niik 95df1ee
:book: IBranchesState
niik 88ecf8d
:book:
niik 58dd4d4
Don't render previous commit count while calculating
niik f9313d8
:book:
niik 4f9e132
:art: cleanup
niik e33f09d
Merge remote-tracking branch 'origin/master' into list-some-branches
niik c076478
Sentence case on Windows
niik 6d2c7a0
:art: typo
niik 613eb53
Optional onItemClick prop
niik 8b70b50
:art: indentation
niik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import * as React from 'react' | ||
import { Branch } from '../../models/branch' | ||
import { groupBranches, IBranchListItem, BranchGroupIdentifier } from './group-branches' | ||
import { BranchListItem } from './branch' | ||
import { FilterList, IFilterListGroup, SelectionSource } from '../lib/filter-list' | ||
import { assertNever } from '../../lib/fatal-error' | ||
|
||
/** | ||
* TS can't parse generic specialization in JSX, so we have to alias it here | ||
* with the generic type. See https://github.com/Microsoft/TypeScript/issues/6395. | ||
*/ | ||
const BranchesFilterList: new() => FilterList<IBranchListItem> = FilterList as any | ||
|
||
const RowHeight = 30 | ||
|
||
interface IBranchListProps { | ||
|
||
/** | ||
* See IBranchesState.defaultBranch | ||
*/ | ||
readonly defaultBranch: Branch | null | ||
|
||
/** | ||
* The currently checked out branch or null if HEAD is detached | ||
*/ | ||
readonly currentBranch: Branch | null | ||
|
||
/** | ||
* See IBranchesState.allBranches | ||
*/ | ||
readonly allBranches: ReadonlyArray<Branch> | ||
|
||
/** | ||
* See IBranchesState.recentBranches | ||
*/ | ||
readonly recentBranches: ReadonlyArray<Branch> | ||
|
||
/** | ||
* The currently selected branch in the list, see the onSelectionChanged prop. | ||
*/ | ||
readonly selectedBranch: Branch | null | ||
|
||
/** | ||
* Called when a key down happens in the filter field. Users have a chance to | ||
* respond or cancel the default behavior by calling `preventDefault`. | ||
*/ | ||
readonly onFilterKeyDown?: (filter: string, event: React.KeyboardEvent<HTMLInputElement>) => void | ||
|
||
/** Called when an item is clicked. */ | ||
readonly onItemClick?: (item: Branch) => 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). Note that this | ||
* differs from `onRowSelected`. For example, it won't be called if an already | ||
* selected row is clicked on. | ||
* | ||
* @param selectedItem - The Branch that was just selected | ||
* @param source - The kind of user action that provoked the change, | ||
* either a pointer device press, or a keyboard event | ||
* (arrow up/down) | ||
*/ | ||
readonly onSelectionChanged?: (selectedItem: Branch | null, source: SelectionSource) => void | ||
} | ||
|
||
interface IBranchListState { | ||
readonly groups: ReadonlyArray<IFilterListGroup<IBranchListItem>> | ||
readonly selectedItem: IBranchListItem | null | ||
} | ||
|
||
function createState(props: IBranchListProps): IBranchListState { | ||
const groups = groupBranches(props.defaultBranch, props.currentBranch, props.allBranches, props.recentBranches) | ||
|
||
let selectedItem: IBranchListItem | null = null | ||
const selectedBranch = props.selectedBranch | ||
if (selectedBranch) { | ||
for (const group of groups) { | ||
selectedItem = group.items.find(i => { | ||
const branch = i.branch | ||
return branch.name === selectedBranch.name | ||
}) || null | ||
|
||
if (selectedItem) { break } | ||
} | ||
} | ||
|
||
return { groups, selectedItem } | ||
} | ||
|
||
/** The Branches list component. */ | ||
export class BranchList extends React.Component<IBranchListProps, IBranchListState> { | ||
|
||
public constructor(props: IBranchListProps) { | ||
super(props) | ||
this.state = createState(props) | ||
} | ||
|
||
private renderItem = (item: IBranchListItem) => { | ||
const branch = item.branch | ||
const commit = branch.tip | ||
const currentBranchName = this.props.currentBranch ? this.props.currentBranch.name : null | ||
return <BranchListItem | ||
name={branch.name} | ||
isCurrentBranch={branch.name === currentBranchName} | ||
lastCommitDate={commit ? commit.author.date : null}/> | ||
} | ||
|
||
private getGroupLabel(identifier: BranchGroupIdentifier) { | ||
if (identifier === 'default') { | ||
return __DARWIN__ ? 'Default Branch' : 'Default branch' | ||
} else if (identifier === 'recent') { | ||
return __DARWIN__ ? 'Recent Branches' : 'Recent branches' | ||
} else if (identifier === 'other') { | ||
return __DARWIN__ ? 'Other Branches' : 'Other branches' | ||
} else { | ||
return assertNever(identifier, `Unknown identifier: ${identifier}`) | ||
} | ||
} | ||
|
||
private renderGroupHeader = (identifier: BranchGroupIdentifier) => { | ||
return <div className='branches-list-content branches-list-label'>{this.getGroupLabel(identifier)}</div> | ||
} | ||
|
||
private onItemClick = (item: IBranchListItem) => { | ||
if (this.props.onItemClick) { | ||
this.props.onItemClick(item.branch) | ||
} | ||
} | ||
|
||
private onSelectionChanged = (selectedItem: IBranchListItem | null, source: SelectionSource) => { | ||
if (this.props.onSelectionChanged) { | ||
this.props.onSelectionChanged(selectedItem ? selectedItem.branch : null, source) | ||
} | ||
} | ||
|
||
public componentWillReceiveProps(nextProps: IBranchListProps) { | ||
this.setState(createState(nextProps)) | ||
} | ||
|
||
public render() { | ||
return ( | ||
<BranchesFilterList | ||
className='branches-list' | ||
rowHeight={RowHeight} | ||
selectedItem={this.state.selectedItem} | ||
renderItem={this.renderItem} | ||
renderGroupHeader={this.renderGroupHeader} | ||
onItemClick={this.onItemClick} | ||
onFilterKeyDown={this.props.onFilterKeyDown} | ||
onSelectionChanged={this.onSelectionChanged} | ||
groups={this.state.groups} | ||
invalidationProps={this.props.allBranches}/> | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This comment was marked as spam.
Sorry, something went wrong.