Skip to content

Commit ba61f83

Browse files
committed
Enhancement: Add Checkbox component and integrate it into HistoryPreview and HistoryView
1 parent 3cf35bb commit ba61f83

File tree

7 files changed

+299
-31
lines changed

7 files changed

+299
-31
lines changed

webview-ui/package-lock.json

Lines changed: 213 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webview-ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
},
2020
"dependencies": {
2121
"@radix-ui/react-alert-dialog": "^1.1.6",
22+
"@radix-ui/react-checkbox": "^1.1.5",
2223
"@radix-ui/react-collapsible": "^1.1.3",
2324
"@radix-ui/react-dialog": "^1.1.6",
2425
"@radix-ui/react-dropdown-menu": "^2.1.5",

webview-ui/src/components/history/HistoryPreview.tsx

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ import { memo } from "react"
22

33
import { vscode } from "@/utils/vscode"
44
import { formatLargeNumber, formatDate } from "@/utils/format"
5-
import { Button } from "@/components/ui"
6-
import { VSCodeCheckbox } from "@vscode/webview-ui-toolkit/react"
5+
import { Button, Checkbox } from "@/components/ui"
76

87
import { useAppTranslation } from "../../i18n/TranslationContext"
98
import { CopyButton } from "./CopyButton"
@@ -24,17 +23,27 @@ const HistoryPreview = ({ showHistoryView }: HistoryPreviewProps) => {
2423
<span className="codicon codicon-comment-discussion scale-90 mr-1" />
2524
<span className="font-medium text-xs uppercase">{t("history:recentTasks")}</span>
2625
</div>
27-
<div
28-
className="flex items-center gap-1 text-xs opacity-80 hover:opacity-100 cursor-pointer"
29-
onClick={() => setShowAllWorkspaces(!showAllWorkspaces)}>
30-
<VSCodeCheckbox
31-
checked={showAllWorkspaces}
32-
onChange={(e) => setShowAllWorkspaces((e.target as HTMLInputElement).checked)}
33-
/>
34-
<span className="text-vscode-foreground select-none">{t("history:showAllWorkspaces")}</span>
26+
<div className="flex items-center gap-1 text-xs opacity-80 hover:opacity-100">
27+
<div className="flex items-center space-x-2">
28+
<Checkbox
29+
id="show-all-workspaces"
30+
checked={showAllWorkspaces}
31+
onCheckedChange={(checked) => setShowAllWorkspaces(checked === true)}
32+
variant="description"
33+
/>
34+
<label
35+
htmlFor="show-all-workspaces"
36+
className="text-vscode-descriptionForeground select-none cursor-pointer text-sm">
37+
{t("history:showAllWorkspaces")}
38+
</label>
39+
</div>
3540
</div>
3641
</div>
37-
<Button variant="ghost" size="sm" onClick={() => showHistoryView()} className="uppercase">
42+
<Button
43+
variant="ghost"
44+
size="sm"
45+
onClick={() => showHistoryView()}
46+
className="uppercase text-xs hover:bg-vscode-toolbar-hoverBackground/50 transition-colors">
3847
{t("history:viewAll")}
3948
</Button>
4049
</div>

webview-ui/src/components/history/HistoryView.tsx

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { BatchDeleteTaskDialog } from "./BatchDeleteTaskDialog"
44
import prettyBytes from "pretty-bytes"
55
import { Virtuoso } from "react-virtuoso"
66

7-
import { VSCodeTextField, VSCodeRadioGroup, VSCodeRadio, VSCodeCheckbox } from "@vscode/webview-ui-toolkit/react"
7+
import { VSCodeTextField, VSCodeRadioGroup, VSCodeRadio } from "@vscode/webview-ui-toolkit/react"
88

99
import { vscode } from "@/utils/vscode"
1010
import { formatLargeNumber, formatDate } from "@/utils/format"
1111
import { cn } from "@/lib/utils"
12-
import { Button } from "@/components/ui"
12+
import { Button, Checkbox } from "@/components/ui"
1313
import { useAppTranslation } from "@/i18n/TranslationContext"
1414

1515
import { Tab, TabContent, TabHeader } from "../common/Tab"
@@ -157,9 +157,10 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
157157
</VSCodeRadioGroup>
158158

159159
<div className="flex items-center gap-2" onClick={() => setShowAllWorkspaces(!showAllWorkspaces)}>
160-
<VSCodeCheckbox
160+
<Checkbox
161161
checked={showAllWorkspaces}
162-
onChange={(e) => setShowAllWorkspaces((e.target as HTMLInputElement).checked)}
162+
onCheckedChange={(checked) => setShowAllWorkspaces(checked === true)}
163+
variant="description"
163164
/>
164165
<span className="text-vscode-foreground">{t("history:showAllWorkspaces")}</span>
165166
</div>
@@ -168,9 +169,10 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
168169
{isSelectionMode && tasks.length > 0 && (
169170
<div className="flex items-center py-1 px-2 bg-vscode-editor-background rounded">
170171
<div className="flex items-center gap-2">
171-
<VSCodeCheckbox
172+
<Checkbox
172173
checked={tasks.length > 0 && selectedTaskIds.length === tasks.length}
173-
onChange={(e) => toggleSelectAll((e.target as HTMLInputElement).checked)}
174+
onCheckedChange={(checked) => toggleSelectAll(checked === true)}
175+
variant="description"
174176
/>
175177
<span className="text-vscode-foreground">
176178
{selectedTaskIds.length === tasks.length
@@ -225,11 +227,12 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
225227
onClick={(e) => {
226228
e.stopPropagation()
227229
}}>
228-
<VSCodeCheckbox
230+
<Checkbox
229231
checked={selectedTaskIds.includes(item.id)}
230-
onChange={(e) =>
231-
toggleTaskSelection(item.id, (e.target as HTMLInputElement).checked)
232+
onCheckedChange={(checked) =>
233+
toggleTaskSelection(item.id, checked === true)
232234
}
235+
variant="description"
233236
/>
234237
</div>
235238
)}

webview-ui/src/components/history/useTaskSearch.ts

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,21 @@ export const useTaskSearch = () => {
2424
}, [searchQuery, sortOption, lastNonRelevantSort])
2525

2626
const presentableTasks = useMemo(() => {
27-
return taskHistory.filter((item) => item.ts && item.task)
28-
}, [taskHistory])
27+
let tasks = taskHistory.filter((item) => item.ts && item.task)
28+
if (!showAllWorkspaces) {
29+
tasks = tasks.filter((item) => item.workspace === cwd)
30+
}
31+
return tasks
32+
}, [taskHistory, showAllWorkspaces, cwd])
2933

3034
const fzf = useMemo(() => {
3135
return new Fzf(presentableTasks, {
32-
selector: (item) => `${item.task} ${item.workspace || ""}`,
36+
selector: (item) => `${item.task} ${item.workspace ?? ""}`,
3337
})
3438
}, [presentableTasks])
35-
39+
3640
const tasks = useMemo(() => {
37-
// First filter by workspace if enabled
38-
let results = showAllWorkspaces ? presentableTasks : presentableTasks.filter((item) => item.workspace === cwd)
41+
let results = presentableTasks
3942

4043
if (searchQuery) {
4144
const searchResults = fzf.find(searchQuery)
@@ -58,14 +61,10 @@ export const useTaskSearch = () => {
5861
: undefined,
5962
}
6063
})
61-
.filter((item) => (showAllWorkspaces ? true : item.workspace === cwd))
6264
}
6365

64-
// First apply search if needed
65-
const searchResults = results
66-
6766
// Then sort the results
68-
return [...searchResults].sort((a, b) => {
67+
return [...results].sort((a, b) => {
6968
switch (sortOption) {
7069
case "oldest":
7170
return (a.ts || 0) - (b.ts || 0)

0 commit comments

Comments
 (0)