Skip to content

Commit

Permalink
Merge pull request desktop#18124 from desktop/submodule-sha-copy
Browse files Browse the repository at this point in the history
Replace SHA tooltips with copy buttons in submodule diffs
  • Loading branch information
sergiou87 authored Feb 2, 2024
2 parents ecb68b6 + 0f5bce4 commit 6858fce
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
26 changes: 19 additions & 7 deletions app/src/ui/diff/submodule-diff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import React from 'react'
import { parseRepositoryIdentifier } from '../../lib/remote-parsing'
import { ISubmoduleDiff } from '../../models/diff'
import { LinkButton } from '../lib/link-button'
import { TooltippedCommitSHA } from '../lib/tooltipped-commit-sha'
import { Octicon } from '../octicons'
import * as OcticonSymbol from '../octicons/octicons.generated'
import { SuggestedAction } from '../suggested-actions'
import { Ref } from '../lib/ref'
import { CopyButton } from '../copy-button'
import { shortenSHA } from '../../models/commit'

type SubmoduleItemIcon =
| {
Expand Down Expand Up @@ -108,33 +110,43 @@ export class SubmoduleDiff extends React.Component<ISubmoduleDiffProps> {
{ octicon: OcticonSymbol.diffModified, className: 'modified-icon' },
<>
This submodule changed its commit from{' '}
{this.renderTooltippedCommitSHA(oldSHA)} to{' '}
{this.renderTooltippedCommitSHA(newSHA)}.{suffix}
{this.renderCommitSHA(oldSHA, 'previous')} to{' '}
{this.renderCommitSHA(newSHA, 'new')}.{suffix}
</>
)
} else if (oldSHA === null && newSHA !== null) {
return this.renderSubmoduleDiffItem(
{ octicon: OcticonSymbol.diffAdded, className: 'added-icon' },
<>
This submodule {verb} added pointing at commit{' '}
{this.renderTooltippedCommitSHA(newSHA)}.{suffix}
{this.renderCommitSHA(newSHA)}.{suffix}
</>
)
} else if (oldSHA !== null && newSHA === null) {
return this.renderSubmoduleDiffItem(
{ octicon: OcticonSymbol.diffRemoved, className: 'removed-icon' },
<>
This submodule {verb} removed while it was pointing at commit{' '}
{this.renderTooltippedCommitSHA(oldSHA)}.{suffix}
{this.renderCommitSHA(oldSHA)}.{suffix}
</>
)
}

return null
}

private renderTooltippedCommitSHA(sha: string) {
return <TooltippedCommitSHA commit={sha} asRef={true} />
private renderCommitSHA(sha: string, which?: 'previous' | 'new') {
const whichInfix = which === undefined ? '' : ` ${which}`

return (
<>
<Ref>{shortenSHA(sha)}</Ref>
<CopyButton
ariaLabel={`Copy the full${whichInfix} SHA`}
copyContent={sha}
/>
</>
)
}

private renderSubmodulesChangesInfo() {
Expand Down
18 changes: 18 additions & 0 deletions app/styles/ui/changes/_submodule-diff.scss
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,22 @@
}
}
}

.copy-button {
// Removing default button styles
background: transparent;
border: none;
padding: 0;
height: auto;
min-width: 16px;

.octicon {
// Reverting margin-top change from .item .octicon
margin-top: revert;
}

:hover {
color: var(--text-secondary-color);
}
}
}

0 comments on commit 6858fce

Please sign in to comment.