Skip to content

Commit abdbfd0

Browse files
committed
on commit click for routing
1 parent d333286 commit abdbfd0

File tree

8 files changed

+45
-38
lines changed

8 files changed

+45
-38
lines changed

CHANGELOG.md

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

194194
-- Diff section UI fixes.
195+
196+
## [2.3.11]
197+
198+
-- Add optional `onCommitClick` in `commit` object, to handle routing in commit item.

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.9",
3+
"version": "2.3.11",
44
"homepage": "https://liuliu-dev.github.io/CommitGraph/",
55
"author": "Liu Liu <[email protected]>",
66
"description": "A React component to visualize a commit graph.",
@@ -97,4 +97,4 @@
9797
"cross-spawn": "^7.0.5",
9898
"wrap-ansi/string-width": "^4.2.0"
9999
}
100-
}
100+
}

rollup.config.js

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,19 @@ export default [
1212
{
1313
input: "src/index.ts",
1414
output: [
15-
{
16-
file: packageJson.main,
17-
format: "cjs",
18-
sourcemap: false,
19-
},
20-
{
21-
file: packageJson.module,
22-
format: "esm",
23-
sourcemap: false,
24-
},
15+
{ file: packageJson.main, format: "cjs", sourcemap: false },
16+
{ file: packageJson.module, format: "esm", sourcemap: false },
2517
],
2618
plugins: [
2719
peerDepsExternal(),
2820
resolve(),
2921
commonjs(),
30-
typescript({ tsconfig: "./tsconfig.json" }),
22+
typescript({
23+
tsconfig: "./tsconfig.json",
24+
noEmit: false,
25+
declaration: false,
26+
exclude: ["**/__tests__", "**/*.test.ts"],
27+
}),
3128
terser(),
3229
postcss(),
3330
],

src/components/CommitDetails/index.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,7 @@
5454
color: #3d91f0;
5555
cursor: pointer;
5656
}
57+
58+
.clickable{
59+
cursor: pointer;
60+
}

src/components/CommitDetails/index.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,22 @@ export default function CommitDetails({
6868
>
6969
<div style={{ color: commit.commitColor }} className={css.labelAndLink}>
7070
<div>
71-
{commit.commitLink ? (
71+
{commit.onCommitClick ? (
72+
<span
73+
style={{ color: color }}
74+
className={`${css.bold} ${css.clickable}`}
75+
onClick={() => {
76+
commit.onCommitClick!();
77+
}}
78+
onMouseOver={() => setColor("#1f6dc6")}
79+
onMouseLeave={() => setColor(commit.commitColor)}
80+
>
81+
{commitHashAuthorDate}
82+
</span>
83+
) : commit.commitLink ? (
7284
<a
7385
style={{ color: color }}
74-
href={commit.commitLink}
86+
href={commit.commitLink as string}
7587
className={css.bold}
7688
onMouseOver={() => setColor("#1f6dc6")}
7789
onMouseLeave={() => setColor(commit.commitColor)}
@@ -81,6 +93,7 @@ export default function CommitDetails({
8193
) : (
8294
<span className={css.bold}>{commitHashAuthorDate}</span>
8395
)}
96+
8497
{showDiffButton && !!getDiff && !!commit.parents.length && (
8598
<button
8699
type="button"

src/helpers/utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export function formatCommits(commits: Commit[]): CommitNode[] {
3838
message: commit.commit.message,
3939
commitDate: new Date(commit.commit.author.date),
4040
commitLink: commit.html_url,
41+
onCommitClick: commit.onCommitClick,
4142
commitColor: "",
4243
x: -1,
4344
y: -1,
@@ -115,5 +116,6 @@ export function fromCommitNodeToCommit(commit: CommitNode): Commit {
115116
},
116117
parents: commit.parents.map(p => ({ sha: p })),
117118
html_url: commit.commitLink,
119+
onCommitClick: commit.onCommitClick,
118120
};
119121
}

src/types.ts

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,14 @@
1-
type ParentCommit = {
2-
sha: string;
3-
};
1+
type ParentCommit = { sha: string };
42

53
export type Commit = {
64
sha: string;
75
commit: {
8-
author: {
9-
name: string;
10-
date: string | number | Date;
11-
email?: string;
12-
};
6+
author: { name: string; date: string | number | Date; email?: string };
137
message: string;
148
};
159
parents: ParentCommit[];
1610
html_url?: string;
11+
onCommitClick?: () => void;
1712
};
1813

1914
export type CommitNode = {
@@ -29,6 +24,7 @@ export type CommitNode = {
2924
y: number;
3025
commitColor: string;
3126
commitLink?: string;
27+
onCommitClick?: () => void;
3228
};
3329

3430
export type BranchPathType = {
@@ -40,13 +36,7 @@ export type BranchPathType = {
4036
branchOrder: number;
4137
};
4238

43-
export type Branch = {
44-
name: string;
45-
commit: {
46-
sha: string;
47-
};
48-
link?: string;
49-
};
39+
export type Branch = { name: string; commit: { sha: string }; link?: string };
5040

5141
export type GraphStyle = {
5242
commitSpacing: number;
@@ -64,7 +54,4 @@ export type ChangedItem = {
6454
blob_url?: string;
6555
};
6656

67-
export type Diff = {
68-
files?: ChangedItem[];
69-
tables?: ChangedItem[];
70-
};
57+
export type Diff = { files?: ChangedItem[]; tables?: ChangedItem[] };

tsconfig.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,24 @@
33
"rootDir": "src",
44
"baseUrl": ".",
55
"declaration": true,
6-
"declarationDir": "types",
76
"outDir": "dist",
87
"target": "ES2015",
98
"lib": ["DOM", "ESNext"],
109
"module": "ESNext",
1110
"moduleResolution": "node",
1211
"jsx": "react",
13-
"emitDeclarationOnly": true,
12+
"emitDeclarationOnly": false,
1413
"resolveJsonModule": true,
1514
"esModuleInterop": true,
1615
"skipLibCheck": true,
1716
"strict": true,
1817
"noImplicitAny": true,
19-
"types": ["node"]
18+
"types": ["node"],
19+
"noEmit": false
2020
},
2121
"exclude": [
2222
"node_modules",
23-
"../dist",
23+
"dist",
2424
"src/**/**/*.test.ts",
2525
"src/stories",
2626
"src/**/sampleCommits.ts"

0 commit comments

Comments
 (0)