Skip to content

Commit ba2c317

Browse files
committed
diff section ui changes
2 parents f9a1cc1 + 019aa99 commit ba2c317

File tree

10 files changed

+86
-60
lines changed

10 files changed

+86
-60
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,3 +188,7 @@ If you are upgrading from a version prior to 2.0.0, please note the changes to p
188188
## [2.3.1]
189189

190190
-- Add support for Dolt diff.
191+
192+
## [2.3.2]
193+
194+
-- Diff section UI fixes.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "commit-graph",
3-
"version": "2.3.1",
3+
"version": "2.3.2",
44
"homepage": "https://liuliu-dev.github.io/CommitGraph/",
55
"author": "Liu Liu <[email protected]>",
66
"description": "A React component to visualize a commit graph.",
@@ -92,4 +92,4 @@
9292
"main": "dist/cjs/index.js",
9393
"module": "dist/esm/index.js",
9494
"types": "dist/index.d.ts"
95-
}
95+
}

src/components/CommitDetails/index.module.css

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
.tooltip {
3535
opacity: 1;
3636
z-index: 10;
37-
max-width: 90%;
37+
max-width: 60%;
3838
visibility: visible;
3939
}
4040

@@ -44,7 +44,7 @@
4444
border: 1px solid #e1e4e8;
4545
background-color: white;
4646
position: absolute;
47-
width: 320px;
47+
width: 360px;
4848
right: 1rem;
4949
top: 1rem;
5050
z-index: 10;
@@ -60,3 +60,11 @@
6060
z-index: 10;
6161
right: 0;
6262
}
63+
64+
.button {
65+
background: transparent;
66+
border: none;
67+
margin-left: 1rem;
68+
color: #3d91f0;
69+
cursor: pointer;
70+
}

src/components/CommitDetails/index.tsx

Lines changed: 34 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ export default function CommitDetails({
3030
dateFormatFn,
3131
currentBranch,
3232
fullSha,
33-
clicked,
3433
getDiff,
35-
forDolt
34+
forDolt,
3635
}: Props) {
3736
const date = dateFormatFn
3837
? dateFormatFn(commit.commitDate)
@@ -44,6 +43,7 @@ export default function CommitDetails({
4443
const [color, setColor] = useState(commit.commitColor);
4544

4645
const [showDiff, setShowDiff] = useState(false);
46+
const [showDiffButton, setShowDiffButton] = useState(false);
4747
const diffRef = useRef<HTMLDivElement>(null);
4848
useOnClickOutside(diffRef, () => {
4949
setShowDiff(false);
@@ -53,29 +53,39 @@ export default function CommitDetails({
5353
<>
5454
<div
5555
className={css.container}
56-
onMouseOver={mouseOver}
57-
onMouseLeave={mouseLeave}
58-
onClick={() => {
59-
onClick();
60-
if (!showDiff) {
61-
setShowDiff(true);
62-
}
56+
onMouseOver={() => {
57+
mouseOver(), setShowDiffButton(true);
6358
}}
59+
onMouseLeave={() => {
60+
mouseLeave(), setShowDiffButton(false);
61+
}}
62+
onClick={onClick}
6463
>
6564
<div style={{ color: commit.commitColor }} className={css.labelAndLink}>
66-
{commit.commitLink ? (
67-
<a
68-
style={{ color: color }}
69-
href={commit.commitLink}
70-
className={css.bold}
71-
onMouseOver={() => setColor("#1f6dc6")}
72-
onMouseLeave={() => setColor(commit.commitColor)}
73-
>
74-
{commitHashAuthorDate}
75-
</a>
76-
) : (
77-
<span className={css.bold}>{commitHashAuthorDate}</span>
78-
)}
65+
<div>
66+
{commit.commitLink ? (
67+
<a
68+
style={{ color: color }}
69+
href={commit.commitLink}
70+
className={css.bold}
71+
onMouseOver={() => setColor("#1f6dc6")}
72+
onMouseLeave={() => setColor(commit.commitColor)}
73+
>
74+
{commitHashAuthorDate}
75+
</a>
76+
) : (
77+
<span className={css.bold}>{commitHashAuthorDate}</span>
78+
)}
79+
{showDiffButton && !!getDiff && !!commit.parents.length && (
80+
<button
81+
type="button"
82+
className={css.button}
83+
onClick={() => setShowDiff(true)}
84+
>
85+
See commit overview
86+
</button>
87+
)}
88+
</div>
7989
<BranchLabel
8090
branchColor={commit.commitColor}
8191
branches={branch}
@@ -98,9 +108,9 @@ export default function CommitDetails({
98108
/>
99109
)}
100110
</div>
101-
{showDiff && clicked && !!getDiff && (
111+
{showDiff && !!getDiff && (
102112
<div className={css.diffSection} ref={diffRef}>
103-
<DiffSection commit={commit} getDiff={getDiff} forDolt={forDolt}/>
113+
<DiffSection commit={commit} getDiff={getDiff} forDolt={forDolt} />
104114
</div>
105115
)}
106116
</>

src/components/CommitGraph/WithInfiniteScroll.tsx

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import React from "react";
22
import CommitGraph from ".";
3-
import {
4-
Branch,
5-
Commit,
6-
CommitNode,
7-
Diff,
8-
GraphStyle,
9-
} from "../../types";
3+
import { Branch, Commit, CommitNode, Diff, GraphStyle } from "../../types";
104
import InfiniteScroll from "react-infinite-scroller";
115
import css from "./index.module.css";
126

src/components/CommitGraph/index.module.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
}
4343

4444
.clicked {
45-
background-color: #3d91f0;
45+
background-color: #89bcf6;
4646
opacity: 0.3;
4747
}
4848

src/components/CommitGraph/index.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import React, { useRef, useState } from "react";
2-
import {
3-
Branch,
4-
Commit,
5-
CommitNode,
6-
Diff,
7-
GraphStyle,
8-
} from "../../types";
2+
import { Branch, Commit, CommitNode, Diff, GraphStyle } from "../../types";
93
import {
104
defaultStyle,
115
formatCommits,
@@ -42,7 +36,7 @@ export default function CommitGraph({
4236
fullSha,
4337
onCommitClick,
4438
getDiff,
45-
forDolt
39+
forDolt,
4640
}: Props) {
4741
const [hovered, setHovered] = useState(false);
4842
const [clicked, setClicked] = useState(false);

src/components/Curves/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function Inner({ newBranchCurves, mergedCurves, commit }: InnerProps) {
2929
return (
3030
<CurvePath
3131
key={`${commit.hash}-curved-up-path-${c.id}`}
32-
curve={c}
32+
curve={c}
3333
/>
3434
);
3535
})}
@@ -38,7 +38,7 @@ function Inner({ newBranchCurves, mergedCurves, commit }: InnerProps) {
3838
return (
3939
<CurvePath
4040
key={`${commit.hash}-curved-down-path-${curve.id}`}
41-
curve={curve}
41+
curve={curve}
4242
/>
4343
);
4444
})}

src/components/DiffSection/index.module.css

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,25 @@
22
padding: 1rem 1.5rem;
33
}
44

5-
.hashes {
5+
.commitAndParents {
66
display: flex;
77
justify-content: space-between;
8-
align-items: center;
8+
flex-direction: column;
9+
align-items: start;
910
margin-bottom: 1rem;
1011
}
1112

13+
.hashes {
14+
display: flex;
15+
}
16+
1217
.bold {
1318
font-weight: 600;
14-
margin-left: 0.5rem;
19+
margin-right: 0.25rem;
1520
}
1621

1722
.summary {
1823
padding: 0 0 1rem 1.5rem;
19-
display: flex;
2024
border-bottom: 1px solid #e1e4e8;
2125
div {
2226
display: flex;
@@ -44,20 +48,23 @@
4448
color: #c5a15a;
4549
margin-right: 0.25rem;
4650
font-weight: 600;
51+
width: 0.75rem;
4752
}
4853

4954
.deleted {
5055
color: #fa7978;
5156
margin-right: 0.25rem;
5257
font-weight: 600;
5358
stroke-width: 3px;
59+
width: 0.75rem;
5460
}
5561

5662
.added {
5763
color: #29e3c1;
5864
margin-right: 0.25rem;
5965
font-weight: 600;
6066
stroke-width: 3px;
67+
width: 0.75rem;
6168
}
6269

6370
.file {

src/components/DiffSection/index.tsx

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,24 +31,33 @@ export default function DiffSection({ commit, getDiff, forDolt }: Props) {
3131
}, [commit, getDiff]);
3232

3333
const { added, modified, deleted } = getChanged(diff?.files || []);
34-
const parents = commit.parents.map(parent => parent.slice(0, 7)).join(", ");
35-
const file=forDolt ? "table" : "file";
34+
const file = forDolt ? "table" : "file";
35+
3636
return (
3737
<div>
3838
<div className={css.top}>
39-
<div className={css.hashes}>
40-
<div>
41-
commit:
42-
<span className={css.bold}>{commit.hash.slice(0, 7)}</span>
39+
<div className={css.commitAndParents}>
40+
<div className={css.hashes}>
41+
<div className={css.bold}>commit:</div>
42+
<div>{commit.hash}</div>
4343
</div>
44-
<div>
45-
parent:
46-
<span className={css.bold}>{parents}</span>
44+
<div className={css.hashes}>
45+
<div className={css.bold}>
46+
{pluralize(commit.parents.length, "parent")}:
47+
</div>
48+
<div>
49+
{commit.parents.map((p, i) => (
50+
<div>
51+
{p}
52+
{i === commit.parents.length - 1 ? "" : ","}
53+
</div>
54+
))}
55+
</div>
4756
</div>
4857
</div>
4958
<div className={css.message}>{commit.message}</div>
5059
</div>
51-
{diff && (
60+
{!!diff?.files.length && (
5261
<>
5362
<div className={css.summary}>
5463
{!!modified && (

0 commit comments

Comments
 (0)