Skip to content

Commit 08a2bbb

Browse files
authored
Merge pull request #349 from dolthub/liuliu/commit-comparison
Graphql, Web: compare commits, tags, branches and show diffs
2 parents c050456 + f19c1bc commit 08a2bbb

File tree

25 files changed

+267
-46
lines changed

25 files changed

+267
-46
lines changed

web/renderer/components/DatabaseHeaderAndNav/index.module.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
}
2020

2121
.smallHeader {
22-
@apply hidden h-24 pt-4;
22+
@apply hidden h-24;
2323

2424
@screen lg {
25-
@apply h-16 flex items-center;
25+
@apply h-16 flex items-center justify-between;
2626
}
2727
}
2828

web/renderer/components/DatabaseNav/Item.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function NavItem(props: Props) {
2020
<li className={css.disabledTab}>
2121
<span
2222
className={css.innerTab}
23-
data-tooltip-position="top"
23+
data-tooltip-place="left"
2424
data-tooltip-id="disabled-database-nav-item"
2525
data-tooltip-content={`${props.name} tab is only available for Dolt databases`}
2626
>

web/renderer/components/DatabaseTableNav/index.module.css

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828

2929
.topLine {
3030
@apply flex justify-between items-center w-full pb-2 px-4;
31-
@screen lg {
32-
@apply pl-4 pr-3;
33-
}
3431
}
3532

3633
.menuIcon {
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { RefParams } from "@lib/params";
2+
import BranchCommitAndTagSelector from "@components/FormSelectForRefs/BranchCommitAndTagSelector";
3+
import { useState } from "react";
4+
import { BsArrowLeft } from "@react-icons/all-files/bs/BsArrowLeft";
5+
import Link from "@components/links/Link";
6+
import { diff } from "@lib/urls";
7+
import { Button } from "@dolthub/react-components";
8+
import DiffSelector from "./component";
9+
import css from "./index.module.css";
10+
11+
type Props = {
12+
params: RefParams;
13+
};
14+
15+
export default function ForBranchCommitAndTag({ params }: Props) {
16+
const [fromRef, setFromRef] = useState("");
17+
const [toRef, setToRef] = useState("");
18+
19+
return (
20+
<DiffSelector>
21+
<div className={css.container}>
22+
<div className={css.top}>
23+
<div className={css.title}>Pick to revision</div>
24+
<div className={css.title}>Pick from revision</div>
25+
</div>
26+
<div className={css.selectors}>
27+
<div className={css.branchCommitTag}>
28+
<BranchCommitAndTagSelector
29+
params={params}
30+
selectedValue={toRef}
31+
onChangeValue={s => setToRef(s || "")}
32+
/>
33+
</div>
34+
<div className={css.arrow}>
35+
<BsArrowLeft />
36+
</div>
37+
<div className={css.branchCommitTag}>
38+
<BranchCommitAndTagSelector
39+
params={params}
40+
selectedValue={fromRef}
41+
onChangeValue={s => setFromRef(s || "")}
42+
/>
43+
</div>
44+
</div>
45+
</div>
46+
{fromRef && toRef && (
47+
<Link
48+
{...diff({
49+
...params,
50+
fromCommitId: fromRef,
51+
toCommitId: toRef,
52+
})}
53+
className={css.viewDiffButton}
54+
>
55+
<Button disabled={fromRef === toRef} className={css.button}>
56+
View Diff
57+
</Button>
58+
</Link>
59+
)}
60+
</DiffSelector>
61+
);
62+
}

web/renderer/components/DiffSelector/index.module.css

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,34 @@
66
}
77
}
88

9+
.container {
10+
@apply w-[54rem];
11+
}
12+
913
.branch {
1014
@apply mb-6;
1115
}
16+
17+
.branchCommitTag {
18+
@apply w-96;
19+
}
20+
21+
.selectors {
22+
@apply flex mt-4 mb-6 mx-4 items-center;
23+
}
24+
25+
.top {
26+
@apply flex mx-4 mt-8 justify-between;
27+
}
28+
29+
.title {
30+
@apply font-semibold w-96;
31+
}
32+
33+
.arrow {
34+
@apply text-2xl mx-6;
35+
}
36+
37+
.button {
38+
@apply ml-4;
39+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import DiffSelector from "./component";
22
import ForBranch from "./ForBranch";
3+
import ForBranchCommitAndTag from "./ForBranchCommitAndTag";
34
import ForPull from "./ForPull";
45

56
export default Object.assign(DiffSelector, {
67
ForBranch,
78
ForPull,
9+
ForBranchCommitAndTag,
810
});

web/renderer/components/DiffTableNav/CommitInfo/index.module.css

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@
66
@apply mx-3 mb-3;
77
}
88

9-
.hash {
9+
.fixedWidth {
10+
@apply inline-block w-12;
11+
}
12+
13+
.bold {
1014
@apply font-mono font-semibold text-sm;
1115
}
1216

web/renderer/components/DiffTableNav/CommitInfo/index.test.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { MockedProvider } from "@apollo/client/testing";
22
import useMockRouter from "@hooks/useMockRouter";
33
import { render, screen } from "@testing-library/react";
44
import { commit as commitLink, diff } from "@lib/urls";
5-
import CommitInfo, { getDiffRange } from ".";
5+
import CommitInfo from ".";
66
import * as mocks from "./mocks";
77

88
const jestRouter = jest.spyOn(require("next/router"), "useRouter");
@@ -73,9 +73,8 @@ describe("test CommitInfo", () => {
7373
<CommitInfo params={{ ...mocks.params, toCommitId, fromCommitId }} />,
7474
);
7575

76-
expect(
77-
screen.getByText(getDiffRange(fromCommitId, toCommitId)),
78-
).toBeVisible();
76+
expect(screen.getByText(fromCommitId)).toBeVisible();
77+
expect(screen.getByText(toCommitId)).toBeVisible();
7978
expect(screen.queryByText("1 parent")).not.toBeInTheDocument();
8079
});
8180
});

web/renderer/components/DiffTableNav/CommitInfo/index.tsx

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { QueryHandler } from "@dolthub/react-components";
22
import { useHistoryForCommitQuery } from "@gen/graphql-types";
33
import { RefParams } from "@lib/params";
44
import { useRouter } from "next/router";
5-
import Inner, { shortCommit } from "./Inner";
5+
import Inner from "./Inner";
66
import css from "./index.module.css";
77

88
type Props = {
@@ -39,10 +39,17 @@ export default function CommitInfo({ params }: Props) {
3939
<div className={css.container} data-cy="commit-info">
4040
<div className={css.top}>
4141
<div data-cy="viewing-message">
42-
Viewing changes from{" "}
43-
<span className={css.hash}>
44-
{getDiffRange(fromCommitForInfo, params.toCommitId)}
45-
</span>
42+
Viewing changes
43+
<div className={css.hashes}>
44+
<div>
45+
<span className={css.fixedWidth}>from</span>
46+
<span className={css.bold}>{fromCommitForInfo}</span>
47+
</div>
48+
<div>
49+
<span className={css.fixedWidth}>to</span>{" "}
50+
<span className={css.bold}>{params.toCommitId}</span>
51+
</div>
52+
</div>
4653
</div>
4754
</div>
4855
</div>
@@ -52,7 +59,7 @@ export default function CommitInfo({ params }: Props) {
5259
}
5360

5461
export function getDiffRange(fromCommit: string, toCommit: string): string {
55-
return `${shortCommit(fromCommit)}..${shortCommit(toCommit)}`;
62+
return `${fromCommit}..${toCommit}`;
5663
}
5764

5865
function isDiffRange(asPath: string) {

web/renderer/components/DiffTableNav/ForRef.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import DiffSelector from "@components/DiffSelector";
21
import { RefParams } from "@lib/params";
32
import DiffTableNav from "./component";
43
import css from "./index.module.css";
@@ -13,10 +12,9 @@ export default function ForRef(props: Props) {
1312
{...props}
1413
diffStat={
1514
<p className={css.noDiff} data-cy="diff-layout-no-diff">
16-
Select commit to view diff
15+
Select revision to view diff
1716
</p>
1817
}
19-
diffSelector={<DiffSelector.ForBranch params={props.params} />}
2018
diffTables={null}
2119
/>
2220
);
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { FormSelect } from "@dolthub/react-components";
2+
import { Maybe } from "@dolthub/web-utils";
3+
import { OptionalRefParams } from "@lib/params";
4+
import useGetBranchOptionsForSelect from "@components/FormSelectForRefs/useGetBranchOptionsForSelect";
5+
import useGetCommitOptionsForSelect from "@components/FormSelectForRefs/useGetCommitOptionsForSelect";
6+
import getGroupOption from "./getGroupOption";
7+
import useGetTagOptionsForSelect from "./useGetTagOptionsForSelect";
8+
import css from "./index.module.css";
9+
10+
type Props = {
11+
params: OptionalRefParams;
12+
selectedValue: Maybe<string>;
13+
onChangeValue: (s: Maybe<string>) => void;
14+
};
15+
16+
export default function BranchCommitAndTagSelector(props: Props) {
17+
const {
18+
branchOptions,
19+
error: branchErr,
20+
loading: branchLoading,
21+
} = useGetBranchOptionsForSelect(props.params);
22+
const {
23+
commitOptions,
24+
error: commitErr,
25+
loading: commitLoading,
26+
} = useGetCommitOptionsForSelect(props.params);
27+
const {
28+
tagOptions,
29+
error: tagErr,
30+
loading: tagLoading,
31+
} = useGetTagOptionsForSelect(props.params);
32+
33+
const handleChangeRef = async (refName: Maybe<string>) => {
34+
if (!refName) return;
35+
props.onChangeValue(refName);
36+
};
37+
38+
const options = [
39+
getGroupOption(branchOptions, "Branches", undefined, branchErr),
40+
getGroupOption(commitOptions, "Commits", undefined, commitErr),
41+
getGroupOption(tagOptions, "Tags", undefined, tagErr),
42+
];
43+
44+
return (
45+
<FormSelect.Grouped
46+
isLoading={branchLoading || commitLoading || tagLoading}
47+
value={[...branchOptions, ...commitOptions, ...tagOptions].find(
48+
t => t.value === props.selectedValue,
49+
)}
50+
onChange={async e => handleChangeRef(e?.value)}
51+
options={options}
52+
placeholder="select a branch, commit or tag..."
53+
className={css.branchAndCommitSelect}
54+
selectedOptionFirst
55+
light
56+
/>
57+
);
58+
}

web/renderer/components/FormSelectForRefs/getGroupOption.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ApolloErrorType } from "@lib/errors/types";
66
export default function getGroupOption(
77
options: Array<FormSelectTypes.Option<string>>,
88
label: string,
9-
footerRoute: Route,
9+
footerRoute?: Route,
1010
error?: ApolloErrorType,
1111
): FormSelectTypes.CustomGroupBase<FormSelectTypes.Option<string>> {
1212
const lowerLabel = label.toLowerCase();
@@ -16,6 +16,6 @@ export default function getGroupOption(
1616
noOptionsMsg: error
1717
? `Error getting ${lowerLabel}: ${error.message}`
1818
: `No ${lowerLabel} found`,
19-
footer: <Link {...footerRoute}>View all {lowerLabel}</Link>,
19+
footer: footerRoute && <Link {...footerRoute}>View all {lowerLabel}</Link>,
2020
};
2121
}

web/renderer/components/pageComponents/DatabasePage/ForBranches/BranchesPage/index.module.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,7 @@
6969
.iconGray {
7070
@apply fill-storm-200;
7171
}
72+
73+
.button {
74+
@apply mr-4;
75+
}

web/renderer/components/pageComponents/DatabasePage/ForBranches/BranchesPage/index.tsx

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import { gqlDepNotFound } from "@lib/errors/graphql";
1818
import { errorMatches } from "@lib/errors/helpers";
1919
import { OptionalRefParams } from "@lib/params";
2020
import { refetchBranchQueries } from "@lib/refetchQueries";
21-
import { newBranch } from "@lib/urls";
21+
import { compare, newBranch } from "@lib/urls";
2222
import { useState } from "react";
2323
import BranchList from "./BranchList";
24-
import css from "./index.module.css";
2524
import { useBranchList } from "./useBranchList";
25+
import css from "./index.module.css";
2626

2727
type Props = {
2828
params: OptionalRefParams;
@@ -39,6 +39,7 @@ type InnerProps = {
3939
function Inner(props: InnerProps): JSX.Element {
4040
const [isDeleteModalOpen, setDeleteModalOpen] = useState(false);
4141
const [branchNameToDelete, setBranchNameToDelete] = useState("");
42+
4243
const createUrl = newBranch({
4344
...props.params,
4445
refName:
@@ -71,6 +72,11 @@ function Inner(props: InnerProps): JSX.Element {
7172
isClearable
7273
horizontal
7374
/>
75+
{props.branches.length && (
76+
<Link {...compare(props.params)}>
77+
<Button className={css.button}>Diff Branches</Button>
78+
</Link>
79+
)}
7480
<HideForNoWritesWrapper params={props.params}>
7581
<Link {...createUrl} className={css.white}>
7682
<Button>Create Branch</Button>

web/renderer/components/pageComponents/DatabasePage/ForCommits/CommitLog/index.module.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@
66
@apply flex justify-between;
77
}
88

9+
.buttons {
10+
@apply flex;
11+
}
12+
13+
.button {
14+
@apply mr-4;
15+
}
16+
917
.title {
1018
@apply mx-6;
1119
}

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import Page404 from "@components/Page404";
2-
import { Loader } from "@dolthub/react-components";
2+
import { Button, Loader } from "@dolthub/react-components";
33
import { useAnchorTag, useReactiveWidth } from "@dolthub/react-hooks";
44
import { CommitForHistoryFragment } from "@gen/graphql-types";
5+
import Link from "@components/links/Link";
56
import { useCommitListForBranch } from "@hooks/useCommitListForBranch";
67
import { RefParams } from "@lib/params";
8+
import { compare } from "@lib/urls";
79
import { useRouter } from "next/router";
810
import { useEffect, useState } from "react";
911
import InfiniteScroll from "react-infinite-scroller";
@@ -50,7 +52,12 @@ function Inner({ commits, ...props }: InnerProps) {
5052
<div className={css.container}>
5153
<div className={css.top}>
5254
<h1 className={css.title}>Commit Log</h1>
53-
<CommitGraphButton params={props.params} />
55+
<Button.Group className={css.buttons}>
56+
<Link {...compare(props.params)}>
57+
<Button className={css.button}>Diff Commits</Button>
58+
</Link>
59+
<CommitGraphButton params={props.params} />
60+
</Button.Group>
5461
</div>
5562
<InfiniteScroll
5663
loadMore={props.loadMore}

0 commit comments

Comments
 (0)