-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathDiffSettingsMenu.tsx
More file actions
96 lines (93 loc) · 3.23 KB
/
Copy pathDiffSettingsMenu.tsx
File metadata and controls
96 lines (93 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
import { DotsThree } from "@phosphor-icons/react";
import {
Button,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from "@posthog/quill";
import { useDiffViewerStore } from "@posthog/ui/features/code-editor/diffViewerStore";
import type { CommentFileFilter } from "../commentFileFilter";
import { CommentFilterSubmenu } from "./CommentFilterSubmenu";
interface DiffSettingsMenuProps {
commentedFileCount: number;
unresolvedCommentedFileCount: number;
commentFilter: CommentFileFilter;
onCommentFilterChange?: (filter: CommentFileFilter) => void;
}
export function DiffSettingsMenu({
commentedFileCount,
unresolvedCommentedFileCount,
commentFilter,
onCommentFilterChange,
}: DiffSettingsMenuProps) {
const wordWrap = useDiffViewerStore((s) => s.wordWrap);
const toggleWordWrap = useDiffViewerStore((s) => s.toggleWordWrap);
const wordDiffs = useDiffViewerStore((s) => s.wordDiffs);
const toggleWordDiffs = useDiffViewerStore((s) => s.toggleWordDiffs);
const hideWhitespaceChanges = useDiffViewerStore(
(s) => s.hideWhitespaceChanges,
);
const toggleHideWhitespaceChanges = useDiffViewerStore(
(s) => s.toggleHideWhitespaceChanges,
);
const showReviewComments = useDiffViewerStore((s) => s.showReviewComments);
const toggleShowReviewComments = useDiffViewerStore(
(s) => s.toggleShowReviewComments,
);
const handleToggleReviewComments = () => {
if (showReviewComments && commentFilter !== "none") {
onCommentFilterChange?.("none");
}
toggleShowReviewComments();
};
return (
<DropdownMenu>
<DropdownMenuTrigger
render={
<Button
size="icon-sm"
variant={commentFilter === "none" ? "default" : "primary"}
aria-label={
commentFilter === "none"
? "Diff settings"
: `Diff settings, ${commentFilter} comment filter active`
}
className="rounded-xs"
>
<DotsThree size={16} weight="bold" />
</Button>
}
/>
<DropdownMenuContent
align="end"
side="bottom"
sideOffset={6}
className="min-w-[180px]"
>
<DropdownMenuItem onClick={toggleWordWrap}>
{wordWrap ? "Disable word wrap" : "Enable word wrap"}
</DropdownMenuItem>
<DropdownMenuItem onClick={toggleWordDiffs}>
{wordDiffs ? "Disable word diffs" : "Enable word diffs"}
</DropdownMenuItem>
<DropdownMenuItem onClick={toggleHideWhitespaceChanges}>
{hideWhitespaceChanges ? "Show whitespace" : "Hide whitespace"}
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem onClick={handleToggleReviewComments}>
{showReviewComments ? "Hide review comments" : "Show review comments"}
</DropdownMenuItem>
{showReviewComments && onCommentFilterChange && (
<CommentFilterSubmenu
commentedFileCount={commentedFileCount}
unresolvedCommentedFileCount={unresolvedCommentedFileCount}
commentFilter={commentFilter}
onCommentFilterChange={onCommentFilterChange}
/>
)}
</DropdownMenuContent>
</DropdownMenu>
);
}