Skip to content

Commit 66377d2

Browse files
authored
Add search filter button to Coder Workspaces tree views (#603)
Fixes #330
1 parent 67e85e6 commit 66377d2

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

package.json

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
{
205205
"command": "coder.createWorkspace",
206206
"title": "Create Workspace",
207+
"category": "Coder",
207208
"when": "coder.authenticated",
208209
"icon": "$(add)"
209210
},
@@ -226,7 +227,8 @@
226227
},
227228
{
228229
"command": "coder.refreshWorkspaces",
229-
"title": "Coder: Refresh Workspace",
230+
"title": "Refresh Workspace",
231+
"category": "Coder",
230232
"icon": "$(refresh)",
231233
"when": "coder.authenticated"
232234
},
@@ -241,13 +243,33 @@
241243
"title": "Coder: Open App Status",
242244
"icon": "$(robot)",
243245
"when": "coder.authenticated"
246+
},
247+
{
248+
"command": "coder.searchMyWorkspaces",
249+
"title": "Search",
250+
"category": "Coder",
251+
"icon": "$(search)"
252+
},
253+
{
254+
"command": "coder.searchAllWorkspaces",
255+
"title": "Search",
256+
"category": "Coder",
257+
"icon": "$(search)"
244258
}
245259
],
246260
"menus": {
247261
"commandPalette": [
248262
{
249263
"command": "coder.openFromSidebar",
250264
"when": "false"
265+
},
266+
{
267+
"command": "coder.searchMyWorkspaces",
268+
"when": "false"
269+
},
270+
{
271+
"command": "coder.searchAllWorkspaces",
272+
"when": "false"
251273
}
252274
],
253275
"view/title": [
@@ -262,12 +284,22 @@
262284
{
263285
"command": "coder.createWorkspace",
264286
"when": "coder.authenticated && view == myWorkspaces",
265-
"group": "navigation"
287+
"group": "navigation@1"
266288
},
267289
{
268290
"command": "coder.refreshWorkspaces",
269291
"when": "coder.authenticated && view == myWorkspaces",
270-
"group": "navigation"
292+
"group": "navigation@2"
293+
},
294+
{
295+
"command": "coder.searchMyWorkspaces",
296+
"when": "coder.authenticated && view == myWorkspaces",
297+
"group": "navigation@3"
298+
},
299+
{
300+
"command": "coder.searchAllWorkspaces",
301+
"when": "coder.authenticated && view == allWorkspaces",
302+
"group": "navigation@3"
271303
}
272304
],
273305
"view/item/context": [

src/extension.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ import {
1818
WorkspaceQuery,
1919
} from "./workspace/workspacesProvider";
2020

21+
const MY_WORKSPACES_TREE_ID = "myWorkspaces";
22+
const ALL_WORKSPACES_TREE_ID = "allWorkspaces";
23+
2124
export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
2225
// The Remote SSH extension's proposed APIs are used to override the SSH host
2326
// name in VS Code itself. It's visually unappealing having a lengthy name!
@@ -86,15 +89,15 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
8689

8790
// createTreeView, unlike registerTreeDataProvider, gives us the tree view API
8891
// (so we can see when it is visible) but otherwise they have the same effect.
89-
const myWsTree = vscode.window.createTreeView("myWorkspaces", {
92+
const myWsTree = vscode.window.createTreeView(MY_WORKSPACES_TREE_ID, {
9093
treeDataProvider: myWorkspacesProvider,
9194
});
9295
myWorkspacesProvider.setVisibility(myWsTree.visible);
9396
myWsTree.onDidChangeVisibility((event) => {
9497
myWorkspacesProvider.setVisibility(event.visible);
9598
});
9699

97-
const allWsTree = vscode.window.createTreeView("allWorkspaces", {
100+
const allWsTree = vscode.window.createTreeView(ALL_WORKSPACES_TREE_ID, {
98101
treeDataProvider: allWorkspacesProvider,
99102
});
100103
allWorkspacesProvider.setVisibility(allWsTree.visible);
@@ -298,6 +301,12 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
298301
"coder.viewLogs",
299302
commands.viewLogs.bind(commands),
300303
);
304+
vscode.commands.registerCommand("coder.searchMyWorkspaces", async () =>
305+
showTreeViewSearch(MY_WORKSPACES_TREE_ID),
306+
);
307+
vscode.commands.registerCommand("coder.searchAllWorkspaces", async () =>
308+
showTreeViewSearch(ALL_WORKSPACES_TREE_ID),
309+
);
301310

302311
// Since the "onResolveRemoteAuthority:ssh-remote" activation event exists
303312
// in package.json we're able to perform actions before the authority is
@@ -421,3 +430,8 @@ export async function activate(ctx: vscode.ExtensionContext): Promise<void> {
421430
}
422431
}
423432
}
433+
434+
async function showTreeViewSearch(id: string): Promise<void> {
435+
await vscode.commands.executeCommand(`${id}.focus`);
436+
await vscode.commands.executeCommand("list.find");
437+
}

src/workspace/workspacesProvider.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ export class WorkspaceProvider
262262
// yet.
263263
appStatuses.push(
264264
new AppStatusTreeItem({
265+
id: status.id,
265266
name: status.message,
266267
command: app.command,
267268
workspace_name: element.workspace.name,
@@ -335,6 +336,7 @@ class AgentMetadataTreeItem extends vscode.TreeItem {
335336
metadataEvent.result.collected_at,
336337
).toLocaleString();
337338

339+
this.id = metadataEvent.description.key;
338340
this.tooltip = "Collected at " + collected_at;
339341
this.contextValue = "coderAgentMetadata";
340342
}
@@ -343,13 +345,15 @@ class AgentMetadataTreeItem extends vscode.TreeItem {
343345
class AppStatusTreeItem extends vscode.TreeItem {
344346
constructor(
345347
public readonly app: {
348+
id: string;
346349
name: string;
347350
url?: string;
348351
command?: string;
349352
workspace_name?: string;
350353
},
351354
) {
352355
super("", vscode.TreeItemCollapsibleState.None);
356+
this.id = app.id;
353357
this.description = app.name;
354358
this.contextValue = "coderAppStatus";
355359

@@ -369,6 +373,7 @@ type CoderOpenableTreeItemType =
369373

370374
export class OpenableTreeItem extends vscode.TreeItem {
371375
constructor(
376+
id: string,
372377
label: string,
373378
tooltip: string,
374379
description: string,
@@ -379,6 +384,7 @@ export class OpenableTreeItem extends vscode.TreeItem {
379384
contextValue: CoderOpenableTreeItemType,
380385
) {
381386
super(label, collapsibleState);
387+
this.id = id;
382388
this.contextValue = contextValue;
383389
this.tooltip = tooltip;
384390
this.description = description;
@@ -397,6 +403,7 @@ export class AgentTreeItem extends OpenableTreeItem {
397403
watchMetadata = false,
398404
) {
399405
super(
406+
agent.id, // id
400407
agent.name, // label
401408
`Status: ${agent.status}`, // tooltip
402409
agent.status, // description
@@ -434,6 +441,7 @@ export class WorkspaceTreeItem extends OpenableTreeItem {
434441
const detail = `Template: ${workspace.template_display_name || workspace.template_name} • Status: ${status}`;
435442
const agents = extractAgents(workspace.latest_build.resources);
436443
super(
444+
workspace.id,
437445
label,
438446
detail,
439447
workspace.latest_build.status, // description

0 commit comments

Comments
 (0)