Skip to content

investigate refactoring push/pull button internals #6985

Closed

Description

@shiftkey

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:

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:

private getTitle(): string {
if (!this.props.remoteName) {
return 'Publish repository'
}

private getIcon(): OcticonSymbol {
if (this.props.networkActionInProgress) {
return OcticonSymbol.sync
}

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

  1. added
    tech-debt
    on Mar 1, 2019
  2. added this to the 1.7.0 milestone on Mar 1, 2019
  3. shiftkey commented on Mar 6, 2019

    @shiftkey
    MemberAuthor

    Another pain point I've encountered in this area is ToolbarButton (which is rendered by PushPullButton only supports specifying a OcticonSymbol in the icon prop (and iconClassName for 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:

    const addAuthorIcon = new OcticonSymbol(
    12,
    7,
    'M9.875 2.125H12v1.75H9.875V6h-1.75V3.875H6v-1.75h2.125V0h1.75v2.125zM6 ' +
    '6.5a.5.5 0 0 1-.5.5h-5a.5.5 0 0 1-.5-.5V6c0-1.316 2-2 2-2s.114-.204 ' +
    '0-.5c-.42-.31-.472-.795-.5-2C1.587.293 2.434 0 3 0s1.413.293 1.5 1.5c-.028 ' +
    '1.205-.08 1.69-.5 2-.114.295 0 .5 0 .5s2 .684 2 2v.5z'
    )

    EDIT 2: this is not the full workaround, because the icon for force push is made up of multiple path segments which isn't supported by Octicon or OcticonSymbol currently (and has some additional attributes for each path that might also be needed):

    <svg width="10" height="14" viewBox="0 0 10 14" fill="none" xmlns="http://www.w3.org/2000/svg">
      <path fill-rule="evenodd" clip-rule="evenodd" d="M8.33341 6.5L10.0001 6.5L5.00008 0.5L7.96956e-05 6.5L1.66675 6.5L5.00008 2.5L8.33341 6.5Z" fill="white"/>
      <path fill-rule="evenodd" clip-rule="evenodd" d="M3 10L3 14H7L7 10L10 10L5 4.00002L0 10H3Z" fill="white"/>
    </svg>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    tech-debt

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions