Skip to content

Commit d44f3c8

Browse files
committed
Added General settings with a settings selection option to view all workspaces tasks
1 parent 0504041 commit d44f3c8

File tree

13 files changed

+110
-25
lines changed

13 files changed

+110
-25
lines changed

packages/types/src/global-settings.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ export const globalSettingsSchema = z.object({
107107
historyPreviewCollapsed: z.boolean().optional(),
108108
profileThresholds: z.record(z.string(), z.number()).optional(),
109109
hasOpenedModeSelector: z.boolean().optional(),
110+
showAllWorkspacesTasks: z.boolean().optional(),
110111
lastModeExportPath: z.string().optional(),
111112
lastModeImportPath: z.string().optional(),
112113
})

src/core/webview/ClineProvider.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,7 @@ export class ClineProvider
14131413
profileThresholds,
14141414
alwaysAllowFollowupQuestions,
14151415
followupAutoApproveTimeoutMs,
1416+
showAllWorkspacesTasks,
14161417
} = await this.getState()
14171418

14181419
const telemetryKey = process.env.POSTHOG_API_KEY
@@ -1525,6 +1526,7 @@ export class ClineProvider
15251526
hasOpenedModeSelector: this.getGlobalState("hasOpenedModeSelector") ?? false,
15261527
alwaysAllowFollowupQuestions: alwaysAllowFollowupQuestions ?? false,
15271528
followupAutoApproveTimeoutMs: followupAutoApproveTimeoutMs ?? 60000,
1529+
showAllWorkspacesTasks: showAllWorkspacesTasks ?? false,
15281530
}
15291531
}
15301532

@@ -1677,6 +1679,7 @@ export class ClineProvider
16771679
codebaseIndexEmbedderModelId: "",
16781680
},
16791681
profileThresholds: stateValues.profileThresholds ?? {},
1682+
showAllWorkspacesTasks: stateValues.showAllWorkspacesTasks ?? false,
16801683
}
16811684
}
16821685

src/core/webview/__tests__/ClineProvider.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,7 @@ describe("ClineProvider", () => {
539539
sharingEnabled: false,
540540
profileThresholds: {},
541541
hasOpenedModeSelector: false,
542+
showAllWorkspacesTasks: false,
542543
}
543544

544545
const message: ExtensionMessage = {

src/core/webview/webviewMessageHandler.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1926,5 +1926,10 @@ export const webviewMessageHandler = async (
19261926
}
19271927
break
19281928
}
1929+
1930+
case "showAllWorkspacesTasks":
1931+
await updateGlobalState("showAllWorkspacesTasks", message.bool ?? false)
1932+
await provider.postStateToWebview()
1933+
break
19291934
}
19301935
}

src/shared/ExtensionMessage.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ export interface ExtensionMessage {
102102
| "marketplaceInstallResult"
103103
| "marketplaceData"
104104
| "shareTaskSuccess"
105+
| "showAllWorkspacesTasks"
105106
text?: string
106107
payload?: any // Add a generic payload for now, can refine later
107108
action?:
@@ -270,6 +271,7 @@ export type ExtensionState = Pick<
270271
marketplaceInstalledMetadata?: { project: Record<string, any>; global: Record<string, any> }
271272
profileThresholds: Record<string, number>
272273
hasOpenedModeSelector: boolean
274+
showAllWorkspacesTasks: boolean
273275
}
274276

275277
export interface ClineSayTool {

src/shared/WebviewMessage.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ export interface WebviewMessage {
176176
| "fetchMarketplaceData"
177177
| "switchTab"
178178
| "profileThresholds"
179+
| "showAllWorkspacesTasks"
179180
| "shareTaskSuccess"
180181
| "exportMode"
181182
| "exportModeResult"

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

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import React, { memo, useState } from "react"
2+
3+
import { vscode } from "@/utils/vscode"
24
import { DeleteTaskDialog } from "./DeleteTaskDialog"
35
import { BatchDeleteTaskDialog } from "./BatchDeleteTaskDialog"
46
import { Virtuoso } from "react-virtuoso"
@@ -35,8 +37,8 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
3537
sortOption,
3638
setSortOption,
3739
setLastNonRelevantSort,
38-
showAllWorkspaces,
39-
setShowAllWorkspaces,
40+
showAllWorkspacesTasks,
41+
setShowAllWorkspacesTasks,
4042
} = useTaskSearch()
4143
const { t } = useAppTranslation()
4244

@@ -129,12 +131,19 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
129131
</VSCodeTextField>
130132
<div className="flex gap-2">
131133
<Select
132-
value={showAllWorkspaces ? "all" : "current"}
133-
onValueChange={(value) => setShowAllWorkspaces(value === "all")}>
134+
value={showAllWorkspacesTasks ? "all" : "current"}
135+
onValueChange={(value) => {
136+
const showAll = value === "all"
137+
setShowAllWorkspacesTasks(showAll)
138+
vscode.postMessage({
139+
type: "showAllWorkspacesTasks",
140+
bool: showAll,
141+
})
142+
}}>
134143
<SelectTrigger className="flex-1">
135144
<SelectValue>
136145
{t("history:workspace.prefix")}{" "}
137-
{t(`history:workspace.${showAllWorkspaces ? "all" : "current"}`)}
146+
{t(`history:workspace.${showAllWorkspacesTasks ? "all" : "current"}`)}
138147
</SelectValue>
139148
</SelectTrigger>
140149
<SelectContent>
@@ -238,7 +247,7 @@ const HistoryView = ({ onDone }: HistoryViewProps) => {
238247
key={item.id}
239248
item={item}
240249
variant="full"
241-
showWorkspace={showAllWorkspaces}
250+
showWorkspace={showAllWorkspacesTasks}
242251
isSelectionMode={isSelectionMode}
243252
isSelected={selectedTaskIds.includes(item.id)}
244253
onToggleSelection={toggleTaskSelection}

webview-ui/src/components/history/__tests__/useTaskSearch.spec.tsx

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ describe("useTaskSearch", () => {
5757
mockUseExtensionState.mockReturnValue({
5858
taskHistory: mockTaskHistory,
5959
cwd: "/workspace/project1",
60+
showAllWorkspacesTasks: false,
61+
setShowAllWorkspacesTasks: vi.fn(),
6062
} as any)
6163
})
6264

@@ -75,22 +77,22 @@ describe("useTaskSearch", () => {
7577
expect(result.current.tasks.every((task) => task.workspace === "/workspace/project1")).toBe(true)
7678
})
7779

78-
it("shows all workspaces when showAllWorkspaces is true", () => {
80+
it("shows all workspaces when showAllWorkspacesTasks is true", () => {
7981
const { result } = renderHook(() => useTaskSearch())
8082

8183
act(() => {
82-
result.current.setShowAllWorkspaces(true)
84+
result.current.setShowAllWorkspacesTasks(true)
8385
})
8486

8587
expect(result.current.tasks).toHaveLength(3)
86-
expect(result.current.showAllWorkspaces).toBe(true)
88+
expect(result.current.showAllWorkspacesTasks).toBe(true)
8789
})
8890

8991
it("sorts by newest by default", () => {
9092
const { result } = renderHook(() => useTaskSearch())
9193

9294
act(() => {
93-
result.current.setShowAllWorkspaces(true)
95+
result.current.setShowAllWorkspacesTasks(true)
9496
})
9597

9698
expect(result.current.sortOption).toBe("newest")
@@ -103,7 +105,7 @@ describe("useTaskSearch", () => {
103105
const { result } = renderHook(() => useTaskSearch())
104106

105107
act(() => {
106-
result.current.setShowAllWorkspaces(true)
108+
result.current.setShowAllWorkspacesTasks(true)
107109
result.current.setSortOption("oldest")
108110
})
109111

@@ -116,7 +118,7 @@ describe("useTaskSearch", () => {
116118
const { result } = renderHook(() => useTaskSearch())
117119

118120
act(() => {
119-
result.current.setShowAllWorkspaces(true)
121+
result.current.setShowAllWorkspacesTasks(true)
120122
result.current.setSortOption("mostExpensive")
121123
})
122124

@@ -129,7 +131,7 @@ describe("useTaskSearch", () => {
129131
const { result } = renderHook(() => useTaskSearch())
130132

131133
act(() => {
132-
result.current.setShowAllWorkspaces(true)
134+
result.current.setShowAllWorkspacesTasks(true)
133135
result.current.setSortOption("mostTokens")
134136
})
135137

@@ -145,7 +147,7 @@ describe("useTaskSearch", () => {
145147
const { result } = renderHook(() => useTaskSearch())
146148

147149
act(() => {
148-
result.current.setShowAllWorkspaces(true)
150+
result.current.setShowAllWorkspacesTasks(true)
149151
result.current.setSearchQuery("React")
150152
})
151153

@@ -252,7 +254,7 @@ describe("useTaskSearch", () => {
252254
const { result } = renderHook(() => useTaskSearch())
253255

254256
act(() => {
255-
result.current.setShowAllWorkspaces(true)
257+
result.current.setShowAllWorkspacesTasks(true)
256258
})
257259

258260
// Should only include tasks with both ts and task content
@@ -264,7 +266,7 @@ describe("useTaskSearch", () => {
264266
const { result } = renderHook(() => useTaskSearch())
265267

266268
act(() => {
267-
result.current.setShowAllWorkspaces(true)
269+
result.current.setShowAllWorkspacesTasks(true)
268270
result.current.setSearchQuery("nonexistent")
269271
})
270272

@@ -275,7 +277,7 @@ describe("useTaskSearch", () => {
275277
const { result } = renderHook(() => useTaskSearch())
276278

277279
act(() => {
278-
result.current.setShowAllWorkspaces(true)
280+
result.current.setShowAllWorkspacesTasks(true)
279281
result.current.setSearchQuery("test")
280282
result.current.setSortOption("mostRelevant")
281283
})

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

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@ import { useExtensionState } from "@/context/ExtensionStateContext"
77
type SortOption = "newest" | "oldest" | "mostExpensive" | "mostTokens" | "mostRelevant"
88

99
export const useTaskSearch = () => {
10-
const { taskHistory, cwd } = useExtensionState()
10+
const { taskHistory, cwd, showAllWorkspacesTasks, setShowAllWorkspacesTasks } = useExtensionState()
1111
const [searchQuery, setSearchQuery] = useState("")
1212
const [sortOption, setSortOption] = useState<SortOption>("newest")
1313
const [lastNonRelevantSort, setLastNonRelevantSort] = useState<SortOption | null>("newest")
14-
const [showAllWorkspaces, setShowAllWorkspaces] = useState(false)
1514

1615
useEffect(() => {
1716
if (searchQuery && sortOption !== "mostRelevant" && !lastNonRelevantSort) {
@@ -25,11 +24,11 @@ export const useTaskSearch = () => {
2524

2625
const presentableTasks = useMemo(() => {
2726
let tasks = taskHistory.filter((item) => item.ts && item.task)
28-
if (!showAllWorkspaces) {
27+
if (!showAllWorkspacesTasks) {
2928
tasks = tasks.filter((item) => item.workspace === cwd)
3029
}
3130
return tasks
32-
}, [taskHistory, showAllWorkspaces, cwd])
31+
}, [taskHistory, showAllWorkspacesTasks, cwd])
3332

3433
const fzf = useMemo(() => {
3534
return new Fzf(presentableTasks, {
@@ -86,7 +85,7 @@ export const useTaskSearch = () => {
8685
setSortOption,
8786
lastNonRelevantSort,
8887
setLastNonRelevantSort,
89-
showAllWorkspaces,
90-
setShowAllWorkspaces,
88+
showAllWorkspacesTasks,
89+
setShowAllWorkspacesTasks,
9190
}
9291
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { VSCodeCheckbox } from "@vscode/webview-ui-toolkit/react"
2+
3+
import { ExtensionStateContextType } from "@/context/ExtensionStateContext"
4+
import { SetCachedStateField } from "./types"
5+
6+
type GeneralProps = {
7+
showAllWorkspacesTasks: boolean
8+
setCachedStateField: SetCachedStateField<keyof ExtensionStateContextType>
9+
}
10+
11+
export const GeneralSettings = ({ showAllWorkspacesTasks, setCachedStateField }: GeneralProps) => {
12+
const handleShowAllTasks = (e: any) => {
13+
const checked = e.target.checked
14+
setCachedStateField("showAllWorkspacesTasks", checked)
15+
}
16+
17+
return (
18+
<div className="flex flex-col gap-y-2">
19+
<div className="flex items-center justify-between p-2">
20+
<div className="flex flex-col">
21+
<span className="text-vscode-settings-headerForeground text-lg">Show All Tasks</span>
22+
<span className="text-vscode-descriptionForeground text-sm">
23+
Show tasks from all projects instead of only the current one
24+
</span>
25+
</div>
26+
<VSCodeCheckbox checked={showAllWorkspacesTasks} onChange={handleShowAllTasks} />
27+
</div>
28+
</div>
29+
)
30+
}

0 commit comments

Comments
 (0)