Skip to content

Commit 35da9c6

Browse files
committed
Disable diff button if diff cannot be determined
1 parent e3f37ea commit 35da9c6

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

src/features/sidebar/view/SecondarySplitHeader.tsx

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import { isMac as checkIsMac, SidebarTogglableContext } from "@/common";
2121
import { useSidebarOpen } from "@/features/sidebar/data";
2222
import useDiffbarOpen from "@/features/sidebar/data/useDiffbarOpen";
2323
import ToggleMobileToolbarButton from "./internal/secondary/ToggleMobileToolbarButton";
24+
import { useProjectSelection } from "@/features/projects/data";
2425

2526
const SecondarySplitHeader = ({
2627
mobileToolbar,
@@ -35,6 +36,7 @@ const SecondarySplitHeader = ({
3536
"isMobileToolbarVisible",
3637
true
3738
);
39+
const { specification } = useProjectSelection();
3840
return (
3941
<Box>
4042
<Box
@@ -72,6 +74,7 @@ const SecondarySplitHeader = ({
7274
<ToggleDiffButton
7375
isDiffbarOpen={isDiffbarOpen}
7476
onClick={setDiffbarOpen}
77+
isDiffAvailable={!!specification?.diffURL}
7578
/>
7679
</Box>
7780
{mobileToolbar && (
@@ -134,9 +137,11 @@ const ToggleSidebarButton = ({
134137
const ToggleDiffButton = ({
135138
isDiffbarOpen,
136139
onClick,
140+
isDiffAvailable,
137141
}: {
138142
isDiffbarOpen: boolean;
139143
onClick: (isDiffbarOpen: boolean) => void;
144+
isDiffAvailable: boolean;
140145
}) => {
141146
const [isMac, setIsMac] = useState(false);
142147
useEffect(() => {
@@ -148,23 +153,31 @@ const ToggleDiffButton = ({
148153
}, []);
149154
const isSidebarTogglable = useContext(SidebarTogglableContext);
150155
const openCloseKeyboardShortcut = `(${isMac ? "⌘" : "^"} + K)`;
151-
const tooltip = isDiffbarOpen ? "Hide changes" : "Show changes";
156+
const isDisabled = !isDiffAvailable && !isDiffbarOpen;
157+
const tooltip = isDisabled
158+
? "Changes cannot be displayed"
159+
: isDiffbarOpen
160+
? "Hide changes"
161+
: "Show changes";
152162
return (
153163
<Box sx={{ display: isSidebarTogglable ? "block" : "none" }}>
154-
155-
<Tooltip title={`${tooltip} ${openCloseKeyboardShortcut}`}>
156-
<IconButton
157-
size="medium"
158-
color="primary"
159-
onClick={() => onClick(!isDiffbarOpen)}
160-
edge="end"
161-
>
162-
<FontAwesomeIcon
163-
icon={isDiffbarOpen ? faChevronRight : faArrowRightArrowLeft}
164-
size="xs"
165-
style={{ aspectRatio: 1, padding: 2 }}
166-
/>
167-
</IconButton>
164+
165+
<Tooltip title={isDisabled ? tooltip : `${tooltip} ${openCloseKeyboardShortcut}`}>
166+
<span>
167+
<IconButton
168+
size="medium"
169+
color="primary"
170+
onClick={() => onClick(!isDiffbarOpen)}
171+
edge="end"
172+
disabled={isDisabled}
173+
>
174+
<FontAwesomeIcon
175+
icon={isDiffbarOpen ? faChevronRight : faArrowRightArrowLeft}
176+
size="xs"
177+
style={{ aspectRatio: 1, padding: 2 }}
178+
/>
179+
</IconButton>
180+
</span>
168181
</Tooltip>
169182
</Box>
170183
);

0 commit comments

Comments
 (0)