Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,12 @@
"category": "Coder",
"icon": "$(refresh)"
},
{
"command": "coder.workspaces.search",
"title": "Search Workspaces",
"category": "Coder",
"icon": "$(search)"
},
{
"command": "coder.applyRecommendedSettings",
"title": "Apply Recommended SSH Settings",
Expand Down Expand Up @@ -695,6 +701,10 @@
"command": "coder.workspaces.refresh",
"when": "false"
},
{
"command": "coder.workspaces.search",
"when": "false"
},
{
"command": "coder.applyRecommendedSettings"
}
Expand All @@ -721,7 +731,7 @@
},
{
"command": "coder.createWorkspace",
"when": "coder.authenticated && view == myWorkspaces",
"when": "coder.authenticated && (view == myWorkspaces || view == coder.workspacesPanel)",
"group": "navigation@1"
},
{
Expand Down Expand Up @@ -758,6 +768,11 @@
"command": "coder.workspaces.refresh",
"when": "coder.authenticated && view == coder.workspacesPanel",
"group": "navigation@1"
},
{
"command": "coder.workspaces.search",
"when": "coder.authenticated && view == coder.workspacesPanel",
"group": "navigation@3"
}
],
"view/item/context": [
Expand Down
12 changes: 6 additions & 6 deletions packages/shared/src/workspaces/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ export type WorkspaceAction =
| "update"
| "delete";

/** Builds in flight, or a workspace that is gone, allow no action. */
const INACTIVE_STATUSES: ReadonlySet<WorkspaceStatus> = new Set([
/** Statuses of a build in flight. */
export const ACTIVE_BUILD_STATUSES: ReadonlySet<WorkspaceStatus> = new Set([
"pending",
"starting",
"stopping",
"canceling",
"deleting",
"deleted",
]);

/** Actions allowed now, in display order, as in the dashboard's `abilitiesByWorkspaceStatus`. */
export function workspaceActions(
workspace: Workspace,
): readonly WorkspaceAction[] {
if (INACTIVE_STATUSES.has(workspace.latest_build.status)) {
const { status, transition, has_external_agent } = workspace.latest_build;
// A build in flight, or a workspace that is gone, allows no action.
if (ACTIVE_BUILD_STATUSES.has(status) || status === "deleted") {
return [];
}
// `coder start` reactivates a dormant workspace before starting it.
if (workspace.dormant_at) {
return ["start", "delete"];
}
if (workspace.latest_build.has_external_agent) {
if (has_external_agent) {
return ["delete"];
}
const { status, transition } = workspace.latest_build;
// A policy that forces the active version leaves only an update.
const updateOnly =
workspace.outdated &&
Expand Down
2 changes: 2 additions & 0 deletions packages/shared/src/workspaces/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export const WorkspacesApi = {
// Notifications
/** The whole state, whenever any of it changes */
stateChanged: defineNotification<WorkspacesState>("stateChanged"),
/** Open the search box, or focus it if open */
showSearch: defineNotification<void>("showSearch"),
// Commands
/** Webview signals its subscription is live and asks for the state */
ready: defineCommand<void>("ready"),
Expand Down
14 changes: 14 additions & 0 deletions packages/ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,20 @@ show delay, except within a row's action bar, where crossing between buttons is
instant, the exception native grants a dense cluster of targets. Ctrl+K Ctrl+I opens the focused
row's hover with no delay at all, and moving the focus closes it.

## TreeFindWidget

`TreeFindWidget` is VS Code's tree find widget (`.monaco-tree-type-filter`),
which Modern UI leaves as is. It is controlled through `value` and
`onChange`, and it filters nothing itself: the consumer narrows its own
`nodes`. It is absolutely positioned at the top right of the nearest
positioned ancestor, so keep that ancestor out of the scrolling element, or
make it a sticky row, to float the widget while the list scrolls.

It takes focus when it mounts, and `ref` reaches its input to refocus it.
Escape and the close button call `onClose`; Enter and Arrow Down call
`onFocusList`, where native hands focus back to the tree. `label` is the
accessible name and the placeholder, "Type to search" by default, as native.

## Overlays

`Tooltip`, `ContextMenu`, and `DropdownMenu` wrap the Base UI primitives,
Expand Down
55 changes: 55 additions & 0 deletions packages/ui/src/components/TreeFindWidget/TreeFindWidget.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/* Native .monaco-tree-type-filter (VS Code 1.143); Modern UI leaves it as is.
Content-box like native: 200px plus padding and border. */
.ui-tree-find-widget {
position: absolute;
top: 0;
right: 0;
/* Above the tree's pinned rows (13), below overlays */
z-index: 20;
display: flex;
width: 200px;
max-width: calc(100% - 24px);
margin: 0 10px 0 6px;
padding: 3px;
background: var(--ui-list-filter-widget-background);
border: 1px solid var(--ui-widget-border);
border-bottom-left-radius: 4px;
border-bottom-right-radius: 4px;
box-shadow: 0 0 8px 2px var(--ui-list-filter-widget-shadow);
}

/* Native slides in from above when motion is enabled */
@media (prefers-reduced-motion: no-preference) {
.ui-tree-find-widget {
transition: top 0.3s;
}

@starting-style {
.ui-tree-find-widget {
top: -40px;
}
}
}

.ui-tree-find-widget .ui-tree-find-widget__input {
flex: 1;
min-width: 0;
height: 23px;
}

.ui-tree-find-widget .ui-input__control {
padding: 0 4px;
}

.ui-tree-find-widget .ui-input__control::-webkit-search-cancel-button {
display: none;
}

/* The action bar's 16px codicon with 2px padding */
.ui-tree-find-widget .ui-tree-find-widget__close {
flex: none;
width: 20px;
height: 20px;
margin-left: 4px;
align-self: center;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { useState } from "react";
import { userEvent, within } from "storybook/test";

import { PIXEL_ALL_THEMES } from "#storybook";

import { Tree } from "../Tree/Tree";

import { TreeFindWidget } from "./TreeFindWidget";

import type { Meta, StoryObj } from "@storybook/react-vite";

const NODES = ["alpha", "beta", "gamma", "delta"].map((name) => ({
id: name,
label: name,
icon: "folder" as const,
}));

const FindInTree = (): React.JSX.Element => {
Comment thread
EhabY marked this conversation as resolved.
Resolved
const [value, setValue] = useState("");
return (
<div style={{ position: "relative", width: "300px", height: "160px" }}>
<TreeFindWidget
value={value}
onChange={setValue}
onClose={() => undefined}
/>
<Tree
aria-label="Folders"
nodes={NODES.filter(({ label }) => label.includes(value))}
/>
</div>
);
};

const meta: Meta<typeof FindInTree> = {
title: "UI/TreeFindWidget",
component: FindInTree,
parameters: { pixel: PIXEL_ALL_THEMES },
};
export default meta;
type Story = StoryObj<typeof FindInTree>;

export const Empty: Story = {};

export const Filtering: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.type(
await canvas.findByRole("searchbox", { name: "Type to search" }),
"a",
);
},
};
71 changes: 71 additions & 0 deletions packages/ui/src/components/TreeFindWidget/TreeFindWidget.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { type ComponentProps, type Ref } from "react";

import { cx } from "#cx";

import { IconButton } from "../IconButton/IconButton";
import { Input } from "../Input/Input";

import "./TreeFindWidget.css";

export interface TreeFindWidgetProps extends Omit<
ComponentProps<"div">,
"onChange" | "ref"
> {
value: string;
onChange: (value: string) => void;
/** Escape and the close button. */
onClose: () => void;
/** Enter and Arrow Down, which hand focus back to the list like native. */
onFocusList?: () => void;
/** The input's accessible name and placeholder, as in native. */
label?: string;
/** The input, like `SearchInput`, so a consumer can refocus it. */
ref?: Ref<HTMLInputElement>;
}

/**
* VS Code's tree find widget, floating at the top right of the nearest
* positioned ancestor. Place it outside the scrolling element, or in a
* sticky one, so it stays put while the list scrolls. It takes focus when
* it mounts.
*/
export function TreeFindWidget({
value,
onChange,
onClose,
onFocusList,
label = "Type to search",
ref,
className,
...props
}: TreeFindWidgetProps): React.JSX.Element {
Comment thread
EhabY marked this conversation as resolved.
Resolved
return (
<div {...props} className={cx("ui-tree-find-widget", className)}>
<Input
ref={ref}
type="search"
aria-label={label}
placeholder={label}
value={value}
onChange={onChange}
onKeyDown={(event) => {
if (event.key === "Escape") {
event.preventDefault();
onClose();
} else if (event.key === "Enter" || event.key === "ArrowDown") {
event.preventDefault();
onFocusList?.();
}
}}
className="ui-tree-find-widget__input"
autoFocus
/>
<IconButton
icon="close"
label="Close"
onClick={onClose}
className="ui-tree-find-widget__close"
/>
</div>
);
}
4 changes: 4 additions & 0 deletions packages/ui/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,9 @@ export {
type TooltipProviderProps,
} from "./components/Tooltip/Tooltip";
export { Tree, type TreeProps } from "./components/Tree/Tree";
export {
TreeFindWidget,
type TreeFindWidgetProps,
} from "./components/TreeFindWidget/TreeFindWidget";
export type { TreeNode } from "./components/Tree/treeModel";
export { useVscodeTheme, type VscodeThemeKind } from "./useVscodeTheme";
9 changes: 9 additions & 0 deletions packages/ui/src/tokens.css
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,15 @@
transparent
);

/* Tree find widget (listFilterWidget); high contrast leaves the shadow
unset, dropping it like native */
--ui-list-filter-widget-background: var(--vscode-listFilterWidget-background);
--ui-list-filter-widget-shadow: var(
--vscode-listFilterWidget-shadow,
transparent
);
--ui-widget-border: var(--vscode-widget-border, transparent);

/* Menus */
--ui-menu-background: var(--vscode-menu-background);
--ui-menu-foreground: var(--vscode-menu-foreground);
Expand Down
20 changes: 20 additions & 0 deletions packages/workspaces/src/components/WorkspacesPanel.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ const api = {
refresh: fn(),
setFilter: fn(),
watchAgents: fn(),
onShowSearch: () => () => undefined,
} as const;

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

export const Collapsed: Story = {};

export const Searching: Story = {
args: {
api: {
...api,
onShowSearch: (open) => {
open();
return () => undefined;
},
},
},
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
await userEvent.type(
await canvas.findByRole("searchbox", { name: "Search workspaces" }),
"alice",
);
},
};

export const Expanded: Story = {
play: async ({ canvasElement }) => {
const canvas = within(canvasElement);
Expand Down
Loading
Loading