Skip to content

Commit 53358e7

Browse files
committed
CoPilot review updates
1 parent b93d543 commit 53358e7

File tree

10 files changed

+163
-103
lines changed

10 files changed

+163
-103
lines changed

src/app/api/diff/[owner]/[repository]/[...path]/route.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ export async function GET(req: NextRequest, { params }: { params: Promise<GetDif
4242
})
4343

4444
const result = execSync(`oasdiff changelog --format json "${spec1.downloadURL}" "${spec2.downloadURL}"`, { encoding: 'utf8' })
45-
46-
console.log(result)
4745

4846

4947
const diffData = JSON.parse(result)

src/features/projects/view/toolbar/TrailingToolbarItem.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const TrailingToolbarItem = () => {
6868
<Divider orientation="vertical" flexItem sx={{ marginLeft: 1, marginRight: 1 }} />
6969
}
7070
{specification.editURL &&
71-
<Tooltip title={`Edit ${specification.name}`}>
71+
<Tooltip title={`Edit ${specification.name}`} sx={{ marginLeft: 0.5, marginRight: 0.5 }}>
7272
<IconButton
7373
href={specification.editURL}
7474
target="_blank"
@@ -83,6 +83,7 @@ const TrailingToolbarItem = () => {
8383
</IconButton>
8484
</Tooltip>
8585
}
86+
8687
</Stack>
8788
</>
8889
)
Lines changed: 118 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,138 +1,165 @@
1-
"use client"
1+
"use client";
22

3-
import { useState, useEffect, useContext } from "react"
4-
import { useSessionStorage } from "usehooks-ts"
5-
import { Box, IconButton, Stack, Tooltip, Collapse } from "@mui/material"
6-
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome"
7-
import { faBars, faChevronLeft, faChevronRight, faCodeCompare } from "@fortawesome/free-solid-svg-icons"
8-
import { isMac as checkIsMac, SidebarTogglableContext } from "@/common"
9-
import { useSidebarOpen } from "@/features/sidebar/data"
10-
import useDiffbarOpen from "@/features/sidebar/data/useDiffbarOpen"
11-
import ToggleMobileToolbarButton from "./internal/secondary/ToggleMobileToolbarButton"
3+
import { useState, useEffect, useContext } from "react";
4+
import { useSessionStorage } from "usehooks-ts";
5+
import {
6+
Box,
7+
IconButton,
8+
Stack,
9+
Tooltip,
10+
Collapse,
11+
Divider,
12+
} from "@mui/material";
13+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
14+
import {
15+
faBars,
16+
faChevronLeft,
17+
faChevronRight,
18+
faCodeCompare,
19+
} from "@fortawesome/free-solid-svg-icons";
20+
import { isMac as checkIsMac, SidebarTogglableContext } from "@/common";
21+
import { useSidebarOpen } from "@/features/sidebar/data";
22+
import useDiffbarOpen from "@/features/sidebar/data/useDiffbarOpen";
23+
import ToggleMobileToolbarButton from "./internal/secondary/ToggleMobileToolbarButton";
1224

1325
const SecondarySplitHeader = ({
1426
mobileToolbar,
15-
children
27+
children,
1628
}: {
17-
mobileToolbar?: React.ReactNode
18-
children?: React.ReactNode
29+
mobileToolbar?: React.ReactNode;
30+
children?: React.ReactNode;
1931
}) => {
20-
const [isSidebarOpen, setSidebarOpen] = useSidebarOpen()
21-
const [isDiffbarOpen, setDiffbarOpen] = useDiffbarOpen()
22-
const [isMobileToolbarVisible, setMobileToolbarVisible] = useSessionStorage("isMobileToolbarVisible", true)
32+
const [isSidebarOpen, setSidebarOpen] = useSidebarOpen();
33+
const [isDiffbarOpen, setDiffbarOpen] = useDiffbarOpen();
34+
const [isMobileToolbarVisible, setMobileToolbarVisible] = useSessionStorage(
35+
"isMobileToolbarVisible",
36+
true
37+
);
2338
return (
2439
<Box>
25-
<Box sx={{
26-
display: "flex",
27-
alignItems: "center",
28-
paddingLeft: 2,
29-
paddingRight: 2,
30-
height: 64,
31-
margin: "auto"
32-
}}>
40+
<Box
41+
sx={{
42+
display: "flex",
43+
alignItems: "center",
44+
paddingLeft: 2,
45+
paddingRight: 2,
46+
height: 64,
47+
margin: "auto",
48+
}}
49+
>
3350
<ToggleSidebarButton
3451
isSidebarOpen={isSidebarOpen}
3552
onClick={setSidebarOpen}
3653
/>
37-
<Box sx={{ display: "flex", flexGrow: 1, justifyContent: "end" }}>
54+
<Box sx={{ display: "flex", flexGrow: 1, justifyContent: "end" }}>
3855
<Stack direction="row" alignItems="center">
3956
{children}
40-
<ToggleDiffButton
41-
isDiffbarOpen={isDiffbarOpen}
42-
onClick={setDiffbarOpen}
57+
<Divider
58+
orientation="vertical"
59+
flexItem
60+
sx={{ marginLeft: 0.5, marginRight: 0.5 }}
4361
/>
44-
{mobileToolbar &&
62+
{mobileToolbar && (
4563
<ToggleMobileToolbarButton
4664
direction={isMobileToolbarVisible ? "up" : "down"}
47-
onToggle={() => setMobileToolbarVisible(!isMobileToolbarVisible) }
65+
onToggle={() =>
66+
setMobileToolbarVisible(!isMobileToolbarVisible)
67+
}
4868
/>
49-
}
69+
)}
5070
</Stack>
5171
</Box>
72+
<ToggleDiffButton
73+
isDiffbarOpen={isDiffbarOpen}
74+
onClick={setDiffbarOpen}
75+
/>
5276
</Box>
53-
{mobileToolbar &&
77+
{mobileToolbar && (
5478
<Collapse in={isMobileToolbarVisible}>
55-
<Box sx={{
56-
padding: 2,
57-
paddingTop: 0,
58-
display: { sm: "block", md: "none" }
59-
}}>
79+
<Box
80+
sx={{
81+
padding: 2,
82+
paddingTop: 0,
83+
display: { sm: "block", md: "none" },
84+
}}
85+
>
6086
{mobileToolbar}
6187
</Box>
6288
</Collapse>
63-
}
89+
)}
6490
</Box>
65-
)
66-
}
91+
);
92+
};
6793

68-
export default SecondarySplitHeader
94+
export default SecondarySplitHeader;
6995

7096
const ToggleSidebarButton = ({
7197
isSidebarOpen,
72-
onClick
98+
onClick,
7399
}: {
74-
isSidebarOpen: boolean,
75-
onClick: (isSidebarOpen: boolean) => void
100+
isSidebarOpen: boolean;
101+
onClick: (isSidebarOpen: boolean) => void;
76102
}) => {
77-
const [isMac, setIsMac] = useState(false)
103+
const [isMac, setIsMac] = useState(false);
78104
useEffect(() => {
79105
// checkIsMac uses window so we delay the check.
80-
setIsMac(checkIsMac())
81-
}, [isMac, setIsMac])
82-
const isSidebarTogglable = useContext(SidebarTogglableContext)
83-
const openCloseKeyboardShortcut = `(${isMac ? "⌘" : "^"} + .)`
84-
const tooltip = isSidebarOpen ? "Show Projects" : "Hide Projects"
106+
setIsMac(checkIsMac());
107+
}, [isMac, setIsMac]);
108+
const isSidebarTogglable = useContext(SidebarTogglableContext);
109+
const openCloseKeyboardShortcut = `(${isMac ? "⌘" : "^"} + .)`;
110+
const tooltip = isSidebarOpen ? "Show Projects" : "Hide Projects";
85111
return (
86112
<Box sx={{ display: isSidebarTogglable ? "block" : "none" }}>
87-
<Tooltip title={`${tooltip} ${openCloseKeyboardShortcut}`}>
88-
<IconButton
89-
size="medium"
90-
color="primary"
91-
onClick={() => onClick(!isSidebarOpen)}
92-
edge="start"
93-
>
94-
<FontAwesomeIcon
95-
icon={isSidebarOpen ? faChevronLeft : faBars}
96-
size="sm"
97-
style={{ aspectRatio: 1, padding: 2 }}
98-
/>
99-
</IconButton>
100-
</Tooltip>
113+
<Tooltip title={`${tooltip} ${openCloseKeyboardShortcut}`}>
114+
<IconButton
115+
size="medium"
116+
color="primary"
117+
onClick={() => onClick(!isSidebarOpen)}
118+
edge="start"
119+
>
120+
<FontAwesomeIcon
121+
icon={isSidebarOpen ? faChevronLeft : faBars}
122+
size="sm"
123+
style={{ aspectRatio: 1, padding: 2 }}
124+
/>
125+
</IconButton>
126+
</Tooltip>
101127
</Box>
102-
)
103-
}
128+
);
129+
};
104130

105131
const ToggleDiffButton = ({
106132
isDiffbarOpen,
107-
onClick
133+
onClick,
108134
}: {
109-
isDiffbarOpen: boolean,
110-
onClick: (isDiffbarOpen: boolean) => void
135+
isDiffbarOpen: boolean;
136+
onClick: (isDiffbarOpen: boolean) => void;
111137
}) => {
112-
const [isMac, setIsMac] = useState(false)
138+
const [isMac, setIsMac] = useState(false);
113139
useEffect(() => {
114140
// checkIsMac uses window so we delay the check.
115-
setIsMac(checkIsMac())
116-
}, [isMac, setIsMac])
117-
const isSidebarTogglable = useContext(SidebarTogglableContext)
118-
const openCloseKeyboardShortcut = `(${isMac ? "⌘" : "^"} + K)`
119-
const tooltip = isDiffbarOpen ? "Hide Diff" : "Show Diff"
141+
setIsMac(checkIsMac());
142+
}, [isMac, setIsMac]);
143+
const isSidebarTogglable = useContext(SidebarTogglableContext);
144+
const openCloseKeyboardShortcut = `(${isMac ? "⌘" : "^"} + K)`;
145+
const tooltip = isDiffbarOpen ? "Hide Diff" : "Show Diff";
120146
return (
121147
<Box sx={{ display: isSidebarTogglable ? "block" : "none" }}>
122-
<Tooltip title={`${tooltip} ${openCloseKeyboardShortcut}`}>
123-
<IconButton
124-
size="medium"
125-
color="primary"
126-
onClick={() => onClick(!isDiffbarOpen)}
127-
edge="end"
128-
>
129-
<FontAwesomeIcon
130-
icon={isDiffbarOpen ? faChevronRight : faCodeCompare}
131-
size="sm"
132-
style={{ aspectRatio: 1, padding: 2 }}
133-
/>
134-
</IconButton>
135-
</Tooltip>
148+
149+
<Tooltip title={`${tooltip} ${openCloseKeyboardShortcut}`}>
150+
<IconButton
151+
size="medium"
152+
color="primary"
153+
onClick={() => onClick(!isDiffbarOpen)}
154+
edge="end"
155+
>
156+
<FontAwesomeIcon
157+
icon={isDiffbarOpen ? faChevronRight : faCodeCompare}
158+
size="sm"
159+
style={{ aspectRatio: 1, padding: 2 }}
160+
/>
161+
</IconButton>
162+
</Tooltip>
136163
</Box>
137-
)
138-
}
164+
);
165+
};

src/features/sidebar/view/internal/ClientSplitView.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ const ClientSplitView = ({
5151
setDiffbarOpen(!isDiffbarOpen);
5252
}
5353
},
54-
[isDiffbarOpen ,setDiffbarOpen]
54+
[isDiffbarOpen, setDiffbarOpen]
5555
);
5656

5757
const sidebarWidth = 320;

src/features/sidebar/view/internal/diffbar/DiffContent.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,22 @@ import DiffHeader from "./components/DiffHeader";
77
import DiffList from "./components/DiffList";
88
import DiffDialog from "./components/DiffDialog";
99

10+
interface DiffChange {
11+
path?: string;
12+
text?: string;
13+
}
14+
15+
interface DiffData {
16+
from: string;
17+
to: string;
18+
changes: DiffChange[];
19+
}
20+
1021
const DiffContent = () => {
1122
const { project, specification, version } = useProjectSelection();
1223
const [fromBranch, setFromBranch] = useState("");
1324
const [toBranch, setToBranch] = useState("");
14-
const [data, setData] = useState<any>(null);
25+
const [data, setData] = useState<DiffData | null>(null);
1526
const [selectedChange, setSelectedChange] = useState<number | null>(null);
1627
const [loading, setLoading] = useState(false);
1728

@@ -61,7 +72,7 @@ const DiffContent = () => {
6172
<DiffList
6273
changes={data ? changes : []}
6374
loading={loading}
64-
data={data}
75+
data={!!data}
6576
selectedChange={selectedChange}
6677
onClick={(i) => setSelectedChange(i)}
6778
/>

src/features/sidebar/view/internal/diffbar/components/DiffDialog.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,18 @@ import {
1313
import { softPaperSx } from "@/common/theme/theme";
1414
import MonoQuotedText from "./MonoQuotedText";
1515

16+
interface ChangeDetails {
17+
path?: string;
18+
text?: string | React.ReactNode;
19+
}
20+
1621
const DiffDialog = ({
1722
open,
1823
change,
1924
onClose,
2025
}: {
2126
open: boolean;
22-
change: any | null;
27+
change: ChangeDetails | null;
2328
onClose: () => void;
2429
}) => {
2530
return (
@@ -57,7 +62,9 @@ const DiffDialog = ({
5762
)}
5863
{change?.text && (
5964
<Box>
60-
<Typography sx={{ mb: 1, fontWeight: 600 }}>Description:</Typography>
65+
<Typography sx={{ mb: 1, fontWeight: 600 }}>
66+
Description:
67+
</Typography>
6168
<Typography variant="body0" sx={{ wordBreak: "break-word" }}>
6269
{typeof change.text === "string" ? (
6370
<MonoQuotedText text={change.text} />

src/features/sidebar/view/internal/diffbar/components/DiffHeader.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,18 @@
33
import React from "react";
44
import { Box, Typography, FormControl, Select, MenuItem } from "@mui/material";
55

6+
interface Version {
7+
id: string;
8+
name: string;
9+
}
10+
11+
612
const DiffHeader = ({
713
versions,
814
fromBranch,
915
onChange,
1016
}: {
11-
versions: any[];
17+
versions: Version[];
1218
fromBranch: string;
1319
onChange: (ref: string) => void;
1420
}) => {

src/features/sidebar/view/internal/diffbar/components/DiffList.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,19 @@ import React from "react";
44
import { Box, Typography } from "@mui/material";
55
import PopulatedDiffList from "./PopulatedDiffList";
66

7+
interface Change {
8+
path?: string;
9+
text?: string;
10+
}
11+
712
const DiffList = ({
813
changes,
914
loading,
1015
data,
1116
selectedChange,
1217
onClick,
1318
}: {
14-
changes: any[];
19+
changes: Change[];
1520
loading: boolean;
1621
data: boolean;
1722
selectedChange: number | null;

0 commit comments

Comments
 (0)