Skip to content

Commit 1d140ad

Browse files
authored
Merge pull request #469 from dolthub/liuliu/fix-routing
App: use Next.js router for commit graph navigation in Electron production build
2 parents dfc8df7 + 0521a5e commit 1d140ad

File tree

10 files changed

+48
-20
lines changed

10 files changed

+48
-20
lines changed

web/build/builder-dmg-config.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ files:
2121
- node_modules/env-paths
2222
- node_modules/fast-deep-equal
2323
- node_modules/fast-uri
24+
- node_modules/find-up
2425
- node_modules/is-obj
2526
- node_modules/json-schema-traverse
2627
- node_modules/json-schema-typed
2728
- node_modules/locate-path
2829
- node_modules/mimic-fn
2930
- node_modules/onetime
31+
- node_modules/path-exists
32+
- node_modules/p-limit
3033
- node_modules/p-locate
3134
- node_modules/p-try
3235
- node_modules/pkg-up
@@ -61,4 +64,4 @@ mac:
6164
provisioningProfile: build/mac/AppleDevelopment.provisionprofile
6265
entitlements: build/mac/entitlements.plist
6366
entitlementsInherit: build/mac/entitlements.inherit.plist
64-
electronVersion: 31.7.1
67+
electronVersion: 36.3.2

web/build/builder-linux-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ files:
2222
- node_modules/env-paths
2323
- node_modules/fast-deep-equal
2424
- node_modules/fast-uri
25+
- node_modules/find-up
2526
- node_modules/is-obj
2627
- node_modules/json-schema-traverse
2728
- node_modules/json-schema-typed
2829
- node_modules/locate-path
2930
- node_modules/mimic-fn
3031
- node_modules/onetime
32+
- node_modules/path-exists
33+
- node_modules/p-limit
3134
- node_modules/p-locate
3235
- node_modules/p-try
3336
- node_modules/pkg-up

web/build/builder-mas-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,15 @@ files:
2121
- node_modules/env-paths
2222
- node_modules/fast-deep-equal
2323
- node_modules/fast-uri
24+
- node_modules/find-up
2425
- node_modules/is-obj
2526
- node_modules/json-schema-traverse
2627
- node_modules/json-schema-typed
2728
- node_modules/locate-path
2829
- node_modules/mimic-fn
2930
- node_modules/onetime
31+
- node_modules/path-exists
32+
- node_modules/p-limit
3033
- node_modules/p-locate
3134
- node_modules/p-try
3235
- node_modules/pkg-up

web/build/builder-win-config.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,15 @@ files:
2222
- node_modules/env-paths
2323
- node_modules/fast-deep-equal
2424
- node_modules/fast-uri
25+
- node_modules/find-up
2526
- node_modules/is-obj
2627
- node_modules/json-schema-traverse
2728
- node_modules/json-schema-typed
2829
- node_modules/locate-path
2930
- node_modules/mimic-fn
3031
- node_modules/onetime
32+
- node_modules/path-exists
33+
- node_modules/p-limit
3134
- node_modules/p-locate
3235
- node_modules/p-try
3336
- node_modules/pkg-up

web/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"apollo-upload-client": "^17.0.0",
4646
"chance": "^1.1.11",
4747
"classnames": "^2.3.2",
48-
"commit-graph": "^2.3.9",
48+
"commit-graph": "^2.3.12",
4949
"diff": "^5.1.0",
5050
"electron-serve": "^1.3.0",
5151
"electron-store": "^8.2.0",

web/renderer/components/CommitGraph/Inner.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { CommitForHistoryFragment } from "@gen/graphql-types";
22
import { BranchHeads } from "@hooks/useCommitListForCommitGraph";
33
import { RefParams } from "@lib/params";
4+
import { useRouter } from "next/router";
45
import { CommitGraph as Graph, Diff } from "commit-graph";
56
import css from "./index.module.css";
67
import { branchPathColors, getCommits } from "./utils";
@@ -15,10 +16,12 @@ type Props = {
1516
};
1617

1718
export default function Inner(props: Props) {
19+
const router = useRouter();
20+
1821
return (
1922
<div className={css.graphContainer}>
2023
<Graph.WithInfiniteScroll
21-
commits={getCommits(props.commits, props.params)}
24+
commits={getCommits(props.commits, props.params, router)}
2225
branchHeads={props.branchHeads}
2326
currentBranch={props.params.refName}
2427
graphStyle={{

web/renderer/components/CommitGraph/utils.tsx renamed to web/renderer/components/CommitGraph/utils.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,14 @@ import { CommitForHistoryFragment } from "@gen/graphql-types";
22
import { RefParams } from "@lib/params";
33
import { colors as customColors } from "@lib/tailwind";
44
import { commit } from "@lib/urls";
5+
import { Commit } from "commit-graph";
6+
import { NextRouter } from "next/router";
57

6-
export function getCommit(c: CommitForHistoryFragment, params: RefParams) {
8+
export function getCommit(
9+
c: CommitForHistoryFragment,
10+
params: RefParams,
11+
router: NextRouter,
12+
): Commit {
713
return {
814
sha: c.commitId,
915
commit: {
@@ -17,15 +23,19 @@ export function getCommit(c: CommitForHistoryFragment, params: RefParams) {
1723
parents: c.parents.map(p => {
1824
return { sha: p };
1925
}),
20-
html_url: commit({ ...params, commitId: c.commitId }).asPathname(),
26+
onCommitNavigate: () => {
27+
const { href, as } = commit({ ...params, commitId: c.commitId });
28+
router.push(href, as).catch(console.error);
29+
},
2130
};
2231
}
2332

2433
export function getCommits(
2534
commits: CommitForHistoryFragment[],
2635
params: RefParams,
27-
) {
28-
return commits.map(c => getCommit(c, params));
36+
router: NextRouter,
37+
): Commit[] {
38+
return commits.map(c => getCommit(c, params, router));
2939
}
3040

3141
// colors to choose from for branch paths

web/renderer/components/pageComponents/DatabasePage/ForCommits/CommitLog/CommitLogItem.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { getLongDateTimeString } from "@dolthub/web-utils";
55
import { CommitForHistoryFragment } from "@gen/graphql-types";
66
import { useCommitOverview } from "@hooks/useCommitListForCommitGraph/useCommitOverview";
77
import { RefParams } from "@lib/params";
8+
import { useRouter } from "next/router";
89
import cx from "classnames";
910
import { DiffSection } from "commit-graph";
1011
import css from "./index.module.css";
@@ -24,6 +25,7 @@ export default function CommitLogItem(props: Props) {
2425
const { commit, activeHash, params } = props;
2526
const { state, setState, err, getDiff, loading, diffRef } =
2627
useCommitOverview(params);
28+
const router = useRouter();
2729

2830
return (
2931
<li
@@ -96,7 +98,7 @@ export default function CommitLogItem(props: Props) {
9698
{state.showOverview && (
9799
<div ref={diffRef}>
98100
<DiffSection
99-
commit={getCommit(commit, params)}
101+
commit={getCommit(commit, params, router)}
100102
diff={state.diffOverview}
101103
loading={loading}
102104
forDolt

web/renderer/components/pageComponents/DatabasePage/ForCommits/CommitLog/Uncommitted.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { RefParams, RequiredCommitsParams } from "@lib/params";
1212
import { diff } from "@lib/urls";
1313
import { FaCaretDown } from "@react-icons/all-files/fa/FaCaretDown";
1414
import cx from "classnames";
15+
import { useRouter } from "next/router";
1516
import { DiffSection } from "commit-graph";
1617
import { useState } from "react";
1718
import css from "./index.module.css";
@@ -47,7 +48,7 @@ function Item(props: ItemProps) {
4748
emailAddress: "",
4849
},
4950
};
50-
51+
const router = useRouter();
5152
return (
5253
<li
5354
className={cx(css.item, {
@@ -105,7 +106,7 @@ function Item(props: ItemProps) {
105106
{state.showOverview && (
106107
<div ref={diffRef}>
107108
<DiffSection
108-
commit={getCommit(commit, props.params)}
109+
commit={getCommit(commit, props.params, router)}
109110
diff={state.diffOverview}
110111
loading={loading}
111112
forDolt

web/yarn.lock

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4914,9 +4914,9 @@ __metadata:
49144914
languageName: node
49154915
linkType: hard
49164916

4917-
"@rollup/plugin-typescript@npm:11.1.6":
4918-
version: 11.1.6
4919-
resolution: "@rollup/plugin-typescript@npm:11.1.6"
4917+
"@rollup/plugin-typescript@npm:12.1.2":
4918+
version: 12.1.2
4919+
resolution: "@rollup/plugin-typescript@npm:12.1.2"
49204920
dependencies:
49214921
"@rollup/pluginutils": "npm:^5.1.0"
49224922
resolve: "npm:^1.22.1"
@@ -4929,7 +4929,7 @@ __metadata:
49294929
optional: true
49304930
tslib:
49314931
optional: true
4932-
checksum: 10c0/5347cd73ac28d4cf2401a3e689864a1a0df8f3ae029abd9c38525cbc84bcfa16c3a32a0ac5698dac65ec531ba7cf8332e14f5fc7f8fa501193da23320a134c5c
4932+
checksum: 10c0/f447e23371bb1815030446ada3f57608bc6665f8aa2cd7343c4aa18021790fa3ba4783146ea576fb650d6ec68876182d0bc789a05b1a9163c09b16c17efdf868
49334933
languageName: node
49344934
linkType: hard
49354935

@@ -8174,14 +8174,14 @@ __metadata:
81748174
languageName: node
81758175
linkType: hard
81768176

8177-
"commit-graph@npm:^2.3.9":
8178-
version: 2.3.9
8179-
resolution: "commit-graph@npm:2.3.9"
8177+
"commit-graph@npm:^2.3.12":
8178+
version: 2.3.12
8179+
resolution: "commit-graph@npm:2.3.12"
81808180
dependencies:
81818181
"@dolthub/react-components": "npm:^0.2.7"
81828182
"@dolthub/react-hooks": "npm:^0.1.7"
81838183
"@dolthub/web-utils": "npm:^0.1.5"
8184-
"@rollup/plugin-typescript": "npm:11.1.6"
8184+
"@rollup/plugin-typescript": "npm:12.1.2"
81858185
classnames: "npm:^2.3.2"
81868186
react: "npm:>=18.0.0"
81878187
react-copy-to-clipboard: "npm:^5.1.0"
@@ -8193,7 +8193,7 @@ __metadata:
81938193
peerDependencies:
81948194
react: ">=18.0.0"
81958195
react-dom: ">=18.0.0"
8196-
checksum: 10c0/1e737b204ca88e5290f0d2f8b86cbd4145b03a27ce02f4acd52cfa77b09983fafeac32d058cec4901292c135adceabbfc0e324da781c085f50e85764a51dca1e
8196+
checksum: 10c0/15e713c062131948d8b5d17137f6d1ab60d2bc92afef8c1a9b82865305c0b389d4184cb4a7d38d9cb458474a59c79c238ed3501707570db50c110e36f0f12af9
81978197
languageName: node
81988198
linkType: hard
81998199

@@ -9226,7 +9226,7 @@ __metadata:
92269226
babel-jest: "npm:^29.7.0"
92279227
chance: "npm:^1.1.11"
92289228
classnames: "npm:^2.3.2"
9229-
commit-graph: "npm:^2.3.9"
9229+
commit-graph: "npm:^2.3.12"
92309230
cssnano: "npm:^7.0.7"
92319231
diff: "npm:^5.1.0"
92329232
electron: "npm:^36.3.2"

0 commit comments

Comments
 (0)