Skip to content

Commit 1419d1a

Browse files
CompuIvesSaraVieira
authored andcommitted
Improve showing of commit sha (codesandbox#2925)
1 parent f51b052 commit 1419d1a

File tree

5 files changed

+45
-14
lines changed

5 files changed

+45
-14
lines changed

packages/app/src/app/pages/Sandbox/Editor/Workspace/Project/Project.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export const Project: React.FunctionComponent<IProjectProps> = ({
8383
username={sandbox.git.username}
8484
repo={sandbox.git.repo}
8585
branch={sandbox.git.branch}
86+
commitSha={sandbox.git.commitSha}
8687
/>
8788
</Item>
8889
)}

packages/app/src/app/pages/Sandbox/Editor/Workspace/items/GitHub/Git/Git.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export const Git: FunctionComponent = () => {
6868
repo={originalGit.repo}
6969
url={githubRepoUrl(originalGit)}
7070
username={originalGit.username}
71+
commitSha={originalGit.commitSha}
7172
/>
7273
</Margin>
7374

packages/common/src/components/GithubBadge/index.stories.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,22 @@ stories
1010
username="CompuIves"
1111
repo="codesandbox-client"
1212
branch="master"
13+
commitSha="9823ru9238ru8u998ur2398ru"
1314
/>
1415
))
1516
.add('Other Branch', () => (
1617
<GithubBadge
1718
username="CompuIves"
1819
repo="codesandbox-client"
1920
branch="storybook"
21+
commitSha="9823ru9238ru8u998ur2398ru"
22+
/>
23+
))
24+
.add('CommitSha', () => (
25+
<GithubBadge
26+
username="CompuIves"
27+
repo="codesandbox-client"
28+
branch="9823ru9238ru8u998ur2398ru"
29+
commitSha="9823ru9238ru8u998ur2398ru"
2030
/>
2131
));
Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { FunctionComponent } from 'react';
1+
import React, { FunctionComponent, useCallback } from 'react';
22
import GithubIcon from 'react-icons/lib/go/mark-github';
33
import { BorderRadius, Text, Icon, StyledA } from './elements';
44

@@ -7,6 +7,7 @@ type BadgeProps = {
77
repo: string;
88
url?: string;
99
branch: string;
10+
commitSha: string;
1011
};
1112

1213
type DivOrAProps = {
@@ -26,19 +27,36 @@ const GithubBadge: FunctionComponent<BadgeProps> = ({
2627
repo,
2728
url,
2829
branch,
30+
commitSha,
2931
...props
30-
}) => (
31-
<DivOrA {...props} href={url}>
32-
<BorderRadius hasUrl={Boolean(url)}>
33-
<Icon>
34-
<GithubIcon />
35-
</Icon>
36-
<Text>
37-
{username}/{repo}
38-
{branch && branch !== 'master' ? `@${branch}` : ''}
39-
</Text>
40-
</BorderRadius>
41-
</DivOrA>
42-
);
32+
}) => {
33+
const getBadgeName = useCallback(() => {
34+
if (branch === commitSha) {
35+
return branch.substr(0, 7);
36+
}
37+
38+
if (branch === 'master') {
39+
return undefined;
40+
}
41+
42+
return branch;
43+
}, [branch, commitSha]);
44+
45+
const displayBranch = getBadgeName();
46+
47+
return (
48+
<DivOrA {...props} href={url}>
49+
<BorderRadius hasUrl={Boolean(url)}>
50+
<Icon>
51+
<GithubIcon />
52+
</Icon>
53+
<Text>
54+
{username}/{repo}
55+
{displayBranch ? `@${displayBranch}` : ''}
56+
</Text>
57+
</BorderRadius>
58+
</DivOrA>
59+
);
60+
};
4361

4462
export default GithubBadge;

packages/homepage/src/screens/explore/SandboxModal.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ export default class SandboxModal extends React.PureComponent {
249249
username={sandbox.git.username}
250250
repo={sandbox.git.repo}
251251
branch={sandbox.git.branch}
252+
commitSha={sandbox.git.commitSha}
252253
url={githubRepoUrl(sandbox.git)}
253254
/>
254255
)}

0 commit comments

Comments
 (0)