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
20 changes: 20 additions & 0 deletions __tests__/components/automations/automation-view-toggle.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,24 @@ describe("AutomationViewToggle", () => {

expect(onChange).toHaveBeenCalledWith("list");
});

it("does not open the menu or fire onChange when disabled", async () => {
// Arrange
const user = userEvent.setup();
const onChange = vi.fn();
render(
<AutomationViewToggle view="grid" onChange={onChange} disabled />,
);
const trigger = screen.getByTestId("automations-view-toggle");

// Act — try to open the menu
await user.click(trigger);

// Assert — menu items never render and onChange stays untouched
expect(trigger).toBeDisabled();
expect(
screen.queryByTestId("automations-view-toggle-list"),
).not.toBeInTheDocument();
expect(onChange).not.toHaveBeenCalled();
});
});
23 changes: 23 additions & 0 deletions __tests__/routes/automations-list.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,27 @@ describe("AutomationsList — view mode toggle", () => {
"list",
);
});

it("disables the view-mode toggle when the user has no automations", async () => {
// Arrange — service returns an empty list, so the page lands on EmptyState.
vi.mocked(AutomationService.getAutomations).mockResolvedValue({
automations: [],
total: 0,
});
const user = userEvent.setup();
renderList();
await waitFor(() => {
expect(AutomationService.getAutomations).toHaveBeenCalledTimes(1);
});

// Act — try to open the toggle's grid/list menu.
const trigger = await screen.findByTestId("automations-view-toggle");
await user.click(trigger);

// Assert — toggle is disabled and clicking it does not reveal the menu.
expect(trigger).toBeDisabled();
expect(
screen.queryByTestId("automations-view-toggle-list"),
).not.toBeInTheDocument();
});
});
10 changes: 9 additions & 1 deletion src/components/features/automations/automation-view-toggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type { AutomationViewMode } from "./automation-view-mode";
interface AutomationViewToggleProps {
view: AutomationViewMode;
onChange: (view: AutomationViewMode) => void;
disabled?: boolean;
}

const VIEW_OPTIONS: {
Expand Down Expand Up @@ -59,6 +60,7 @@ function ViewMenuItemContent({
export function AutomationViewToggle({
view,
onChange,
disabled = false,
}: AutomationViewToggleProps) {
const { t } = useTranslation("openhands");
const [open, setOpen] = useState(false);
Expand Down Expand Up @@ -156,9 +158,15 @@ export function AutomationViewToggle({
aria-label={t(I18nKey.AUTOMATIONS$VIEW_MODE)}
aria-haspopup="menu"
aria-expanded={open}
onClick={() => setOpen((current) => !current)}
aria-disabled={disabled}
disabled={disabled}
onClick={() => {
if (disabled) return;
setOpen((current) => !current);
}}
className={cn(
"inline-flex size-9 shrink-0 cursor-pointer items-center justify-center rounded-lg border border-[var(--oh-border)] bg-base-secondary text-white transition-colors hover:bg-[var(--oh-interactive-hover)] focus-visible:border-white/40 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-white/20",
"disabled:cursor-not-allowed disabled:opacity-50 disabled:hover:bg-base-secondary",
)}
>
<ActiveIcon className="size-4" aria-hidden />
Expand Down
7 changes: 4 additions & 3 deletions src/routes/automations-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ export default function AutomationsList() {
}, []);

const hasMore = data ? data.total > data.automations.length : false;
const hasNoAutomations =
!isLoading && !isError && data?.automations.length === 0;

// Show loading state while checking health
if (isHealthLoading) {
Expand Down Expand Up @@ -193,6 +195,7 @@ export default function AutomationsList() {
<AutomationViewToggle
view={viewMode}
onChange={handleViewModeChange}
disabled={hasNoAutomations}
/>
</div>

Expand All @@ -208,9 +211,7 @@ export default function AutomationsList() {

{isError && !isLoading && <ErrorState onRetry={refetch} />}

{!isLoading && !isError && data?.automations.length === 0 && (
<EmptyState />
)}
{hasNoAutomations && <EmptyState />}

{!isLoading && !isError && data && data.automations.length > 0 && (
<>
Expand Down
Loading