Skip to content

Commit b44f4a9

Browse files
authored
feat(workspaces): add search, faster polling, and startup fixes to the panel (#1205)
Fills the gaps in the experimental Workspaces panel before it becomes the default sidebar view, and cuts the requests it makes while idle. - Poll every 5s while a build runs or agents are starting, and every 30s otherwise, like the dashboard - Look up Agent chats only when the listed workspace IDs change, or on refresh, filter switch or session change - Keep a dropped agent metadata socket instead of replacing it, since ReconnectingWebSocket already reconnects it - Log socket errors as warnings and successful reconnects at info - Wait for the stored session check before listing, so the login page no longer flashes on startup - Add TreeFindWidget to @repo/ui, matching VS Code's tree find widget in stable and Modern UI - Search the panel by name, owner or template from the title bar or Ctrl+F (Cmd+F on macOS); Escape closes it - Add the Create Workspace button to the panel's title bar Related to #1113
1 parent efd3485 commit b44f4a9

29 files changed

Lines changed: 725 additions & 80 deletions

‎package.json‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,12 @@
555555
"category": "Coder",
556556
"icon": "$(refresh)"
557557
},
558+
{
559+
"command": "coder.workspaces.search",
560+
"title": "Search Workspaces",
561+
"category": "Coder",
562+
"icon": "$(search)"
563+
},
558564
{
559565
"command": "coder.applyRecommendedSettings",
560566
"title": "Apply Recommended SSH Settings",
@@ -695,6 +701,10 @@
695701
"command": "coder.workspaces.refresh",
696702
"when": "false"
697703
},
704+
{
705+
"command": "coder.workspaces.search",
706+
"when": "false"
707+
},
698708
{
699709
"command": "coder.applyRecommendedSettings"
700710
}
@@ -721,7 +731,7 @@
721731
},
722732
{
723733
"command": "coder.createWorkspace",
724-
"when": "coder.authenticated && view == myWorkspaces",
734+
"when": "coder.authenticated && (view == myWorkspaces || view == coder.workspacesPanel)",
725735
"group": "navigation@1"
726736
},
727737
{
@@ -758,6 +768,11 @@
758768
"command": "coder.workspaces.refresh",
759769
"when": "coder.authenticated && view == coder.workspacesPanel",
760770
"group": "navigation@1"
771+
},
772+
{
773+
"command": "coder.workspaces.search",
774+
"when": "coder.authenticated && view == coder.workspacesPanel",
775+
"group": "navigation@3"
761776
}
762777
],
763778
"view/item/context": [

‎packages/shared/src/workspaces/actions.ts‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,31 +10,31 @@ export type WorkspaceAction =
1010
| "update"
1111
| "delete";
1212

13-
/** Builds in flight, or a workspace that is gone, allow no action. */
14-
const INACTIVE_STATUSES: ReadonlySet<WorkspaceStatus> = new Set([
13+
/** Statuses of a build in flight. */
14+
export const ACTIVE_BUILD_STATUSES: ReadonlySet<WorkspaceStatus> = new Set([
1515
"pending",
1616
"starting",
1717
"stopping",
1818
"canceling",
1919
"deleting",
20-
"deleted",
2120
]);
2221

2322
/** Actions allowed now, in display order, as in the dashboard's `abilitiesByWorkspaceStatus`. */
2423
export function workspaceActions(
2524
workspace: Workspace,
2625
): readonly WorkspaceAction[] {
27-
if (INACTIVE_STATUSES.has(workspace.latest_build.status)) {
26+
const { status, transition, has_external_agent } = workspace.latest_build;
27+
// A build in flight, or a workspace that is gone, allows no action.
28+
if (ACTIVE_BUILD_STATUSES.has(status) || status === "deleted") {
2829
return [];
2930
}
3031
// `coder start` reactivates a dormant workspace before starting it.
3132
if (workspace.dormant_at) {
3233
return ["start", "delete"];
3334
}
34-
if (workspace.latest_build.has_external_agent) {
35+
if (has_external_agent) {
3536
return ["delete"];
3637
}
37-
const { status, transition } = workspace.latest_build;
3838
// A policy that forces the active version leaves only an update.
3939
const updateOnly =
4040
workspace.outdated &&

‎packages/shared/src/workspaces/api.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export const WorkspacesApi = {
2121
// Notifications
2222
/** The whole state, whenever any of it changes */
2323
stateChanged: defineNotification<WorkspacesState>("stateChanged"),
24+
/** Open the search box, or focus it if open */
25+
showSearch: defineNotification<void>("showSearch"),
2426
// Commands
2527
/** Webview signals its subscription is live and asks for the state */
2628
ready: defineCommand<void>("ready"),

‎packages/ui/README.md‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,20 @@ show delay, except within a row's action bar, where crossing between buttons is
166166
instant, the exception native grants a dense cluster of targets. Ctrl+K Ctrl+I opens the focused
167167
row's hover with no delay at all, and moving the focus closes it.
168168

169+
## TreeFindWidget
170+
171+
`TreeFindWidget` is VS Code's tree find widget (`.monaco-tree-type-filter`),
172+
which Modern UI leaves as is. It is controlled through `value` and
173+
`onChange`, and it filters nothing itself: the consumer narrows its own
174+
`nodes`. It is absolutely positioned at the top right of the nearest
175+
positioned ancestor, so keep that ancestor out of the scrolling element, or
176+
make it a sticky row, to float the widget while the list scrolls.
177+
178+
It takes focus when it mounts, and `ref` reaches its input to refocus it.
179+
Escape and the close button call `onClose`; Enter and Arrow Down call
180+
`onFocusList`, where native hands focus back to the tree. `label` is the
181+
accessible name and the placeholder, "Type to search" by default, as native.
182+
169183
## Overlays
170184

171185
`Tooltip`, `ContextMenu`, and `DropdownMenu` wrap the Base UI primitives,
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* Native .monaco-tree-type-filter (VS Code 1.143); Modern UI leaves it as is.
2+
Content-box like native: 200px plus padding and border. */
3+
.ui-tree-find-widget {
4+
position: absolute;
5+
top: 0;
6+
right: 0;
7+
/* Above the tree's pinned rows (13), below overlays */
8+
z-index: 20;
9+
display: flex;
10+
width: 200px;
11+
max-width: calc(100% - 24px);
12+
margin: 0 10px 0 6px;
13+
padding: 3px;
14+
background: var(--ui-list-filter-widget-background);
15+
border: 1px solid var(--ui-widget-border);
16+
border-bottom-left-radius: 4px;
17+
border-bottom-right-radius: 4px;
18+
box-shadow: 0 0 8px 2px var(--ui-list-filter-widget-shadow);
19+
}
20+
21+
/* Native slides in from above when motion is enabled */
22+
@media (prefers-reduced-motion: no-preference) {
23+
.ui-tree-find-widget {
24+
transition: top 0.3s;
25+
}
26+
27+
@starting-style {
28+
.ui-tree-find-widget {
29+
top: -40px;
30+
}
31+
}
32+
}
33+
34+
.ui-tree-find-widget .ui-tree-find-widget__input {
35+
flex: 1;
36+
min-width: 0;
37+
height: 23px;
38+
}
39+
40+
.ui-tree-find-widget .ui-input__control {
41+
padding: 0 4px;
42+
}
43+
44+
.ui-tree-find-widget .ui-input__control::-webkit-search-cancel-button {
45+
display: none;
46+
}
47+
48+
/* The action bar's 16px codicon with 2px padding */
49+
.ui-tree-find-widget .ui-tree-find-widget__close {
50+
flex: none;
51+
width: 20px;
52+
height: 20px;
53+
margin-left: 4px;
54+
align-self: center;
55+
}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import { useState } from "react";
2+
import { userEvent, within } from "storybook/test";
3+
4+
import { PIXEL_ALL_THEMES } from "#storybook";
5+
6+
import { Tree } from "../Tree/Tree";
7+
8+
import { TreeFindWidget } from "./TreeFindWidget";
9+
10+
import type { Meta, StoryObj } from "@storybook/react-vite";
11+
12+
const NODES = ["alpha", "beta", "gamma", "delta"].map((name) => ({
13+
id: name,
14+
label: name,
15+
icon: "folder" as const,
16+
}));
17+
18+
const FindInTree = (): React.JSX.Element => {
19+
const [value, setValue] = useState("");
20+
return (
21+
<div style={{ position: "relative", width: "300px", height: "160px" }}>
22+
<TreeFindWidget
23+
value={value}
24+
onChange={setValue}
25+
onClose={() => undefined}
26+
/>
27+
<Tree
28+
aria-label="Folders"
29+
nodes={NODES.filter(({ label }) => label.includes(value))}
30+
/>
31+
</div>
32+
);
33+
};
34+
35+
const meta: Meta<typeof FindInTree> = {
36+
title: "UI/TreeFindWidget",
37+
component: FindInTree,
38+
parameters: { pixel: PIXEL_ALL_THEMES },
39+
};
40+
export default meta;
41+
type Story = StoryObj<typeof FindInTree>;
42+
43+
export const Empty: Story = {};
44+
45+
export const Filtering: Story = {
46+
play: async ({ canvasElement }) => {
47+
const canvas = within(canvasElement);
48+
await userEvent.type(
49+
await canvas.findByRole("searchbox", { name: "Type to search" }),
50+
"a",
51+
);
52+
},
53+
};
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
import { type ComponentProps, type Ref } from "react";
2+
3+
import { cx } from "#cx";
4+
5+
import { IconButton } from "../IconButton/IconButton";
6+
import { Input } from "../Input/Input";
7+
8+
import "./TreeFindWidget.css";
9+
10+
export interface TreeFindWidgetProps extends Omit<
11+
ComponentProps<"div">,
12+
"onChange" | "ref"
13+
> {
14+
value: string;
15+
onChange: (value: string) => void;
16+
/** Escape and the close button. */
17+
onClose: () => void;
18+
/** Enter and Arrow Down, which hand focus back to the list like native. */
19+
onFocusList?: () => void;
20+
/** The input's accessible name and placeholder, as in native. */
21+
label?: string;
22+
/** The input, like `SearchInput`, so a consumer can refocus it. */
23+
ref?: Ref<HTMLInputElement>;
24+
}
25+
26+
/**
27+
* VS Code's tree find widget, floating at the top right of the nearest
28+
* positioned ancestor. Place it outside the scrolling element, or in a
29+
* sticky one, so it stays put while the list scrolls. It takes focus when
30+
* it mounts.
31+
*/
32+
export function TreeFindWidget({
33+
value,
34+
onChange,
35+
onClose,
36+
onFocusList,
37+
label = "Type to search",
38+
ref,
39+
className,
40+
...props
41+
}: TreeFindWidgetProps): React.JSX.Element {
42+
return (
43+
<div {...props} className={cx("ui-tree-find-widget", className)}>
44+
<Input
45+
ref={ref}
46+
type="search"
47+
aria-label={label}
48+
placeholder={label}
49+
value={value}
50+
onChange={onChange}
51+
onKeyDown={(event) => {
52+
if (event.key === "Escape") {
53+
event.preventDefault();
54+
onClose();
55+
} else if (event.key === "Enter" || event.key === "ArrowDown") {
56+
event.preventDefault();
57+
onFocusList?.();
58+
}
59+
}}
60+
className="ui-tree-find-widget__input"
61+
autoFocus
62+
/>
63+
<IconButton
64+
icon="close"
65+
label="Close"
66+
onClick={onClose}
67+
className="ui-tree-find-widget__close"
68+
/>
69+
</div>
70+
);
71+
}

‎packages/ui/src/index.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,9 @@ export {
9090
type TooltipProviderProps,
9191
} from "./components/Tooltip/Tooltip";
9292
export { Tree, type TreeProps } from "./components/Tree/Tree";
93+
export {
94+
TreeFindWidget,
95+
type TreeFindWidgetProps,
96+
} from "./components/TreeFindWidget/TreeFindWidget";
9397
export type { TreeNode } from "./components/Tree/treeModel";
9498
export { useVscodeTheme, type VscodeThemeKind } from "./useVscodeTheme";

‎packages/ui/src/tokens.css‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,15 @@
257257
transparent
258258
);
259259

260+
/* Tree find widget (listFilterWidget); high contrast leaves the shadow
261+
unset, dropping it like native */
262+
--ui-list-filter-widget-background: var(--vscode-listFilterWidget-background);
263+
--ui-list-filter-widget-shadow: var(
264+
--vscode-listFilterWidget-shadow,
265+
transparent
266+
);
267+
--ui-widget-border: var(--vscode-widget-border, transparent);
268+
260269
/* Menus */
261270
--ui-menu-background: var(--vscode-menu-background);
262271
--ui-menu-foreground: var(--vscode-menu-foreground);

‎packages/workspaces/src/components/WorkspacesPanel.stories.tsx‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ const api = {
167167
refresh: fn(),
168168
setFilter: fn(),
169169
watchAgents: fn(),
170+
onShowSearch: () => () => undefined,
170171
} as const;
171172

172173
const meta: Meta<typeof WorkspacesPanel> = {
@@ -194,6 +195,25 @@ type Story = StoryObj<typeof WorkspacesPanel>;
194195

195196
export const Collapsed: Story = {};
196197

198+
export const Searching: Story = {
199+
args: {
200+
api: {
201+
...api,
202+
onShowSearch: (open) => {
203+
open();
204+
return () => undefined;
205+
},
206+
},
207+
},
208+
play: async ({ canvasElement }) => {
209+
const canvas = within(canvasElement);
210+
await userEvent.type(
211+
await canvas.findByRole("searchbox", { name: "Search workspaces" }),
212+
"alice",
213+
);
214+
},
215+
};
216+
197217
export const Expanded: Story = {
198218
play: async ({ canvasElement }) => {
199219
const canvas = within(canvasElement);

0 commit comments

Comments
 (0)