Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(web): Add SelectInput empty state (#17591)

Ben Bachem1ce385d9067f
diff --git a/web/src/components/design-system/SelectInput/SelectInput.stories.tsx b/web/src/components/design-system/SelectInput/SelectInput.stories.tsx
index baad84608d..c646df67a6 100644
--- a/web/src/components/design-system/SelectInput/SelectInput.stories.tsx
+++ b/web/src/components/design-system/SelectInput/SelectInput.stories.tsx
@@ -1,5 +1,5 @@
import { useState } from "react";
-import { expect, fn, userEvent, within } from "storybook/test";
+import { expect, fn, userEvent, waitFor, within } from "storybook/test";
import preview from "../../../../.storybook/preview";
import { SelectInput } from "./SelectInput";
@@ -91,6 +91,26 @@ export const WithLongText = meta.story({
),
});
+export const Empty = meta.story({
+ name: "(Test) Empty",
+ args: {
+ value: "",
+ placeholder: "Select a model",
+ options: [],
+ emptyMessage: "No models available.",
+ onValueChange: fn(),
+ },
+ play: async ({ canvasElement }) => {
+ const canvas = within(canvasElement);
+ const body = within(canvasElement.ownerDocument.body);
+
+ await userEvent.click(canvas.getByRole("combobox"));
+ await waitFor(() =>
+ expect(body.getByText("No models available.")).toBeVisible(),
+ );
+ },
+});
+
export const TestKeyboardSelection = meta.story({
name: "(Test) Keyboard Selection",
args: {
diff --git a/web/src/components/design-system/SelectInput/SelectInput.tsx b/web/src/components/design-system/SelectInput/SelectInput.tsx
index 0b78bb422f..c0dcf49e2b 100644
--- a/web/src/components/design-system/SelectInput/SelectInput.tsx
+++ b/web/src/components/design-system/SelectInput/SelectInput.tsx
@@ -39,6 +39,7 @@ type SelectInputProps<V> = {
options: SelectInputNode<V>[];
onValueChange: (newValue: V) => void;
placeholder: string;
+ emptyMessage?: string;
error?: boolean;
} & Pick<
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>,
@@ -55,6 +56,7 @@ function SelectInputInner<V extends string>(
options,
onValueChange,
placeholder,
+ emptyMessage = "No options available.",
error,
...triggerProps
}: SelectInputProps<V>,
@@ -69,6 +71,9 @@ function SelectInputInner<V extends string>(
const selectedOption = options
.flatMap((node) => (isSelectGroup(node) ? node.options : [node]))
.find((option) => option.value === value);
+ const hasOptions = options.some((node) =>
+ isSelectGroup(node) ? node.options.length > 0 : true,
+ );
const renderNode = useCallback(
(
node: SelectInputNode<V>,
@@ -164,8 +169,17 @@ function SelectInputInner<V extends string>(
bottom ? "after:opacity-100" : "after:opacity-0",
)}
>
- {options.map((node, index) =>
- renderNode(node, index > 0 && isSelectGroup(options[index - 1])),
+ {!hasOptions ? (
+ <div className="text-muted-foreground py-6 text-center text-sm">
+ {emptyMessage}
+ </div>
+ ) : (
+ options.map((node, index) =>
+ renderNode(
+ node,
+ index > 0 && isSelectGroup(options[index - 1]),
+ ),
+ )
)}
</SelectPrimitive.Viewport>
<SelectPrimitive.ScrollDownButton
diff --git a/web/src/features/projects/components/TransferProjectDialog.stories.tsx b/web/src/features/projects/components/TransferProjectDialog.stories.tsx
index ad01282ee0..ee655ab10f 100644
--- a/web/src/features/projects/components/TransferProjectDialog.stories.tsx
+++ b/web/src/features/projects/components/TransferProjectDialog.stories.tsx
@@ -1,5 +1,5 @@
import { type ComponentProps } from "react";
-import { expect, fn, userEvent, within } from "storybook/test";
+import { expect, fn, userEvent, waitFor, within } from "storybook/test";
import preview from "../../../../.storybook/preview";
import { DialogController } from "@/src/components/design-system/DialogController/DialogController";
@@ -44,6 +44,27 @@ export const Loading = meta.story({
},
});
+export const Empty = meta.story({
+ name: "(Test) Empty",
+ args: {
+ ...defaultArgs,
+ organizations: [],
+ },
+ play: async ({ canvasElement }) => {
+ const body = within(canvasElement.ownerDocument.body);
+
+ await expect(
+ body.getByRole("button", { name: "Transfer project" }),
+ ).toBeDisabled();
+ await userEvent.click(body.getByRole("combobox"));
+ await waitFor(() =>
+ expect(
+ body.getByText(/No eligible organizations available/),
+ ).toBeVisible(),
+ );
+ },
+});
+
export const ConfirmsTransfer = meta.story({
name: "(Test) Confirms transfer",
args: defaultArgs,
diff --git a/web/src/features/projects/components/TransferProjectDialog.tsx b/web/src/features/projects/components/TransferProjectDialog.tsx
index 04df75a7f2..16215f9cca 100644
--- a/web/src/features/projects/components/TransferProjectDialog.tsx
+++ b/web/src/features/projects/components/TransferProjectDialog.tsx
@@ -45,7 +45,9 @@ export function TransferProjectDialog({
name: z.string().includes(confirmMessage, {
message: `Please confirm with "${confirmMessage}"`,
}),
- organizationId: z.string(),
+ organizationId: z.string().min(1, {
+ message: "Please select an organization",
+ }),
});
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
@@ -65,6 +67,7 @@ export function TransferProjectDialog({
form: formId,
variant: "destructive",
loading: isPending,
+ disabled: organizations.length === 0,
},
]}
>
@@ -107,6 +110,7 @@ export function TransferProjectDialog({
value={field.value}
disabled={isPending}
placeholder="Select organization"
+ emptyMessage="No eligible organizations available. You need owner or admin access to another organization to transfer this project."
options={organizations.map((organization) => ({
value: organization.id,
label: organization.name,