Repository navigation
Description
I've had to touch this a few times recently to add new inputs and render different details as part of working on rebase workflows:
- provide a better description when rebase in progress #6984
- display "pull with rebase" if user has set this in config #6893
- [rebase] enable
--force-with-leaseafter rebasing #6981
I'd like to look at reorganzing the internals so that the logic is a bit easier to follow for future changes.
My gut feeling is that we're duplicating the same checks around the place, and future changes have the potential to put the button into an unclear state.
For example, we check whether this.props.remoteName is undefined in three places:
desktop/app/src/ui/toolbar/push-pull-button.tsx
Lines 146 to 149 in 40a7aba
| private getTitle(): string { | |
| if (!this.props.remoteName) { | |
| return 'Publish repository' | |
| } |
desktop/app/src/ui/toolbar/push-pull-button.tsx
Lines 161 to 164 in 40a7aba
| private getIcon(): OcticonSymbol { | |
| if (this.props.networkActionInProgress) { | |
| return OcticonSymbol.sync | |
| } |
desktop/app/src/ui/toolbar/push-pull-button.tsx
Lines 186 to 189 in 40a7aba
| private getDescription(tipState: TipState): JSX.Element | string { | |
| if (!this.props.remoteName) { | |
| return 'Publish this repository to GitHub' | |
| } |
My preferred approach at the moment would be to introduce render functions for each expected state that the button can be in:
export class PushPullButton extends React.Component<IPushPullButtonProps, {}> {
public render() {
const { progress, remoteName } = this.props
if (progress) {
return renderProgressButton(progress)
}
if (!remoteName) {
return renderPublishRepositoryButton()
}
// other states
}
}I've also been looking for an opportunity to evaluate automated component testing in anger, and ensuring I render the same elements for the same props feels like a compelling reason to wrap this component in some tests before making changes to render().
Activity
shiftkey commentedon Mar 6, 2019
Another pain point I've encountered in this area is
ToolbarButton(which is rendered byPushPullButtononly supports specifying aOcticonSymbolin theiconprop (andiconClassNamefor setting CSS), but in #6981 I would like to use a custom SVG icon to represent the force push behaviour.EDIT: I knew there was a workaround in here for it:
desktop/app/src/ui/changes/commit-message.tsx
Lines 27 to 34 in 02e1a74
EDIT 2: this is not the full workaround, because the icon for force push is made up of multiple
pathsegments which isn't supported byOcticonorOcticonSymbolcurrently (and has some additional attributes for each path that might also be needed):