Skip to content

feat: display the number of idle tasks in the navbar #19471

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Aug 22, 2025
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
55 changes: 53 additions & 2 deletions site/src/modules/dashboard/Navbar/NavbarView.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
import { chromaticWithTablet } from "testHelpers/chromatic";
import { MockUserMember, MockUserOwner } from "testHelpers/entities";
import {
MockUserMember,
MockUserOwner,
MockWorkspace,
MockWorkspaceAppStatus,
} from "testHelpers/entities";
import { withDashboardProvider } from "testHelpers/storybook";
import type { Meta, StoryObj } from "@storybook/react-vite";
import { userEvent, within } from "storybook/test";
import { NavbarView } from "./NavbarView";

const tasksFilter = {
username: MockUserOwner.username,
};

const meta: Meta<typeof NavbarView> = {
title: "modules/dashboard/NavbarView",
parameters: { chromatic: chromaticWithTablet, layout: "fullscreen" },
parameters: {
chromatic: chromaticWithTablet,
layout: "fullscreen",
queries: [
{
key: ["tasks", tasksFilter],
data: [],
},
],
},
component: NavbarView,
args: {
user: MockUserOwner,
Expand Down Expand Up @@ -78,3 +96,36 @@ export const CustomLogo: Story = {
logo_url: "/icon/github.svg",
},
};

export const IdleTasks: Story = {
parameters: {
queries: [
{
key: ["tasks", tasksFilter],
data: [
{
prompt: "Task 1",
workspace: {
...MockWorkspace,
latest_app_status: {
...MockWorkspaceAppStatus,
state: "idle",
},
},
},
{
prompt: "Task 2",
workspace: MockWorkspace,
},
{
prompt: "Task 3",
workspace: {
...MockWorkspace,
latest_app_status: MockWorkspaceAppStatus,
},
},
],
},
],
},
};
112 changes: 86 additions & 26 deletions site/src/modules/dashboard/Navbar/NavbarView.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { API } from "api/api";
import type * as TypesGen from "api/typesGenerated";
import { Badge } from "components/Badge/Badge";
import { Button } from "components/Button/Button";
import { ExternalImage } from "components/ExternalImage/ExternalImage";
import { CoderIcon } from "components/Icons/CoderIcon";
import {
Tooltip,
TooltipContent,
TooltipProvider,
TooltipTrigger,
} from "components/Tooltip/Tooltip";
import type { ProxyContextValue } from "contexts/ProxyContext";
import { useWebpushNotifications } from "contexts/useWebpushNotifications";
import { useEmbeddedMetadata } from "hooks/useEmbeddedMetadata";
import { NotificationsInbox } from "modules/notifications/NotificationsInbox/NotificationsInbox";
import type { FC } from "react";
import { useQuery } from "react-query";
import { NavLink, useLocation } from "react-router";
import { cn } from "utils/cn";
import { DeploymentDropdown } from "./DeploymentDropdown";
Expand All @@ -17,7 +25,7 @@ import { UserDropdown } from "./UserDropdown/UserDropdown";

interface NavbarViewProps {
logo_url?: string;
user?: TypesGen.User;
user: TypesGen.User;
buildInfo?: TypesGen.BuildInfoResponse;
supportLinks?: readonly TypesGen.LinkConfig[];
onSignOut: () => void;
Expand Down Expand Up @@ -60,7 +68,7 @@ export const NavbarView: FC<NavbarViewProps> = ({
)}
</NavLink>

<NavItems className="ml-4" />
<NavItems className="ml-4" user={user} />

<div className="flex items-center gap-3 ml-auto">
{proxyContextValue && (
Expand Down Expand Up @@ -109,16 +117,14 @@ export const NavbarView: FC<NavbarViewProps> = ({
}
/>

{user && (
<div className="hidden md:block">
<UserDropdown
user={user}
buildInfo={buildInfo}
supportLinks={supportLinks}
onSignOut={onSignOut}
/>
</div>
)}
<div className="hidden md:block">
<UserDropdown
user={user}
buildInfo={buildInfo}
supportLinks={supportLinks}
onSignOut={onSignOut}
/>
</div>

<div className="md:hidden">
<MobileMenu
Expand All @@ -140,11 +146,11 @@ export const NavbarView: FC<NavbarViewProps> = ({

interface NavItemsProps {
className?: string;
user: TypesGen.User;
}

const NavItems: FC<NavItemsProps> = ({ className }) => {
const NavItems: FC<NavItemsProps> = ({ className, user }) => {
const location = useLocation();
const { metadata } = useEmbeddedMetadata();

return (
<nav className={cn("flex items-center gap-4 h-full", className)}>
Expand All @@ -153,30 +159,84 @@ const NavItems: FC<NavItemsProps> = ({ className }) => {
if (location.pathname.startsWith("/@")) {
isActive = true;
}
return cn(linkStyles.default, isActive ? linkStyles.active : "");
return cn(linkStyles.default, { [linkStyles.active]: isActive });
}}
to="/workspaces"
>
Workspaces
</NavLink>
<NavLink
className={({ isActive }) => {
return cn(linkStyles.default, isActive ? linkStyles.active : "");
return cn(linkStyles.default, { [linkStyles.active]: isActive });
}}
to="/templates"
>
Templates
</NavLink>
{metadata["tasks-tab-visible"].value && (
<NavLink
className={({ isActive }) => {
return cn(linkStyles.default, isActive ? linkStyles.active : "");
}}
to="/tasks"
>
Tasks
</NavLink>
)}
<TasksNavItem user={user} />
</nav>
);
};

type TasksNavItemProps = {
user: TypesGen.User;
};

const TasksNavItem: FC<TasksNavItemProps> = ({ user }) => {
const { metadata } = useEmbeddedMetadata();
const canSeeTasks = Boolean(
metadata["tasks-tab-visible"].value ||
process.env.NODE_ENV === "development" ||
process.env.STORYBOOK,
);
const filter = {
username: user.username,
};
const { data: idleCount } = useQuery({
queryKey: ["tasks", filter],
queryFn: () => API.experimental.getTasks(filter),
refetchInterval: 1_000 * 60,
enabled: canSeeTasks,
refetchOnWindowFocus: true,
initialData: [],
select: (data) =>
data.filter((task) => task.workspace.latest_app_status?.state === "idle")
.length,
});

if (!canSeeTasks) {
return null;
}

return (
<NavLink
to="/tasks"
className={({ isActive }) => {
return cn(linkStyles.default, { [linkStyles.active]: isActive });
}}
>
Tasks
{idleCount > 0 && (
<TooltipProvider>
<Tooltip>
<TooltipTrigger asChild>
<Badge
variant="info"
size="xs"
className="ml-2"
aria-label={idleTasksLabel(idleCount)}
>
{idleCount}
</Badge>
</TooltipTrigger>
<TooltipContent>{idleTasksLabel(idleCount)}</TooltipContent>
</Tooltip>
</TooltipProvider>
)}
</NavLink>
);
};

function idleTasksLabel(count: number) {
return `You have ${count} ${count === 1 ? "task" : "tasks"} waiting for input`;
}
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy