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
3 changes: 2 additions & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ coderd/rbac/ @Emyrk
scripts/apitypings/ @Emyrk
scripts/gensite/ @aslilac

site/ @aslilac
site/ @aslilac @Parkreiner
site/src/hooks/ @Parkreiner
# These rules intentionally do not specify any owners. More specific rules
# override less specific rules, so these files are "ignored" by the site/ rule.
Expand All @@ -27,6 +27,7 @@ site/e2e/provisionerGenerated.ts
site/src/api/countriesGenerated.ts
site/src/api/rbacresourcesGenerated.ts
site/src/api/typesGenerated.ts
site/src/testHelpers/entities.ts
site/CLAUDE.md

# The blood and guts of the autostop algorithm, which is quite complex and
Expand Down
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`;
}
1 change: 1 addition & 0 deletions site/src/theme/externalImages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export function getExternalImageStylesFromUrl(
*/
export const defaultParametersForBuiltinIcons = new Map<string, string>([
["/icon/apple-black.svg", "monochrome"],
["/icon/auggie.svg", "monochrome"],
["/icon/aws.png", "whiteWithColor&brightness=1.5"],
["/icon/aws.svg", "blackWithColor&brightness=1.5"],
["/icon/aws-monochrome.svg", "monochrome"],
Expand Down
1 change: 1 addition & 0 deletions site/src/theme/icons.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"apple-black.svg",
"apple-grey.svg",
"argo-workflows.svg",
"auggie.svg",
"aws-dark.svg",
"aws-light.svg",
"aws-monochrome.svg",
Expand Down
8 changes: 8 additions & 0 deletions site/static/icon/auggie.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading