Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Sidebar: no red dot for a failed run whose automation or bot is gone (#4373)

Aditya Umalea65d91e18fc5
diff --git a/src/components/SidebarFooterNav.test.ts b/src/components/SidebarFooterNav.test.ts
index aac1523b33..d66973722b 100644
--- a/src/components/SidebarFooterNav.test.ts
+++ b/src/components/SidebarFooterNav.test.ts
@@ -39,7 +39,7 @@ function render(density: SidebarDensity, { toolsLayout = "rows", ...extra }: { c
beforeEach(() => {
fixture.advanced = false;
fixture.dispatch.mockReset();
- fixture.state = { activeView: "chat", routineRuns: [], pluginsOpen: false };
+ fixture.state = { activeView: "chat", routines: [{ id: "daily", name: "Daily", botId: "scout", enabled: true }], webhooks: [], bots: [{ id: "scout" }], routineRuns: [], pluginsOpen: false };
fixture.toolsLayout = "rows";
fixture.panels = [];
vi.stubGlobal("window", {});
@@ -120,10 +120,20 @@ describe("sidebar footer places", () => {
it("carries the dot for an unseen failed run on Automations, and clears it once seen", () => {
fixture.advanced = true;
- fixture.state.routineRuns = [{ id: "r", status: "failed", scheduledFor: 1 }];
+ fixture.state.routineRuns = [{ id: "r", routineId: "daily", status: "failed", scheduledFor: 1 }];
const html = render("comfortable").html;
expect(html.indexOf('data-testid="routines-attention"')).toBeGreaterThan(html.indexOf('data-sidebar-nav="automations"'));
- fixture.state.routineRuns = [{ id: "r", status: "failed", scheduledFor: 1, seenAt: 1 }];
+ fixture.state.routineRuns = [{ id: "r", routineId: "daily", status: "failed", scheduledFor: 1, seenAt: 1 }];
+ expect(render("comfortable").html).not.toContain('data-testid="routines-attention"');
+ });
+
+ it("leaves the dot off for a failed run whose automation or bot is gone, since Automations has nothing to open and clear", () => {
+ fixture.advanced = true;
+ fixture.state.routineRuns = [{ id: "r", routineId: "deleted-hook", webhookId: "deleted-hook", status: "failed", scheduledFor: 1 }];
+ expect(render("comfortable").html).not.toContain('data-testid="routines-attention"');
+ fixture.state.webhooks = [{ id: "deleted-hook", name: "Orders", botId: "scout", enabled: true }];
+ expect(render("comfortable").html).toContain('data-testid="routines-attention"');
+ fixture.state.bots = [];
expect(render("comfortable").html).not.toContain('data-testid="routines-attention"');
});
@@ -176,7 +186,7 @@ describe("Tools header", () => {
it("shows the failed-run dot on the header only while collapsed", () => {
fixture.advanced = true;
- fixture.state.routineRuns = [{ id: "r", status: "failed", scheduledFor: 1 }];
+ fixture.state.routineRuns = [{ id: "r", routineId: "daily", status: "failed", scheduledFor: 1 }];
const collapsed = render("comfortable", { collapsed: true }).html;
expect(collapsed).toContain('data-testid="section-alert"');
expect(collapsed).not.toContain('data-testid="routines-attention"');
@@ -263,9 +273,9 @@ describe("toolbar tools layout", () => {
it("toolbar shows the failed-run dot and clears it once seen", () => {
fixture.advanced = true;
- fixture.state.routineRuns = [{ id: "r", status: "failed", scheduledFor: 1 }];
+ fixture.state.routineRuns = [{ id: "r", routineId: "daily", status: "failed", scheduledFor: 1 }];
expect(render("comfortable", { toolsLayout: "toolbar" }).html).toContain('data-testid="routines-attention"');
- fixture.state.routineRuns = [{ id: "r", status: "failed", scheduledFor: 1, seenAt: 1 }];
+ fixture.state.routineRuns = [{ id: "r", routineId: "daily", status: "failed", scheduledFor: 1, seenAt: 1 }];
expect(render("comfortable", { toolsLayout: "toolbar" }).html).not.toContain('data-testid="routines-attention"');
});
diff --git a/src/components/SidebarFooterNav.tsx b/src/components/SidebarFooterNav.tsx
index 9d7247f823..6f8cb6a3c6 100644
--- a/src/components/SidebarFooterNav.tsx
+++ b/src/components/SidebarFooterNav.tsx
@@ -1,13 +1,13 @@
import { FolderOpen, Globe, Puzzle, UsersRound, Zap } from "lucide-react";
-import type { ReactNode } from "react";
+import { useMemo, type ReactNode } from "react";
import { useAppTriggers } from "@/lib/app-triggers";
+import { automationsFrom, hasUnseenProblemRun } from "@/lib/automations";
import { cn } from "@/lib/cn";
import { useCloudFilesReady } from "@/lib/cloud-files";
import { t } from "@/lib/i18n";
import { useAdvancedMode } from "@/lib/interface-mode";
import { useWebPanels } from "@/lib/web-panel-preferences";
-import { isRoutineProblemRun } from "@/lib/routines";
import { useSidebarToolsLayout, type SidebarDensity } from "@/lib/sidebar-preferences";
import { useStore } from "@/state/store";
@@ -85,11 +85,15 @@ export function SidebarAppsButton() {
);
}
-/** An unseen failed run, or an app trigger in trouble. */
+/** An unseen failed run of an automation the Automations page lists (the same list, so opening it clears the dot), or an app trigger in trouble. */
export function useAutomationsNeedYou(): boolean {
const { state } = useStore();
const appTriggers = useAppTriggers();
- return state.routineRuns.some((run) => isRoutineProblemRun(run) && !run.seenAt) || appTriggers.triggers.some((trigger) => trigger.enabled && trigger.problem);
+ const routinesOnly = typeof window !== "undefined" && window.ogb?.remoteClient?.active === true;
+ const unseenProblem = useMemo(() => hasUnseenProblemRun(automationsFrom({
+ routines: state.routines, webhooks: routinesOnly ? [] : state.webhooks, appTriggers: appTriggers.triggers, runs: state.routineRuns, bots: state.bots,
+ })), [state.routines, state.webhooks, appTriggers.triggers, state.routineRuns, state.bots, routinesOnly]);
+ return unseenProblem || appTriggers.triggers.some((trigger) => trigger.enabled && trigger.problem);
}
export function SidebarBottomButtons() {
diff --git a/src/lib/automations.ts b/src/lib/automations.ts
index ebdac35803..12b141ca53 100644
--- a/src/lib/automations.ts
+++ b/src/lib/automations.ts
@@ -3,7 +3,7 @@
import { cronScheduleLabel } from "../../shared/cron-label";
import { activeLocale, t } from "@/lib/i18n";
import type { LocaleKey } from "@/locales";
-import type { Routine, RoutineRun, RoutineSchedule } from "@/lib/routines";
+import { isRoutineProblemRun, type Routine, type RoutineRun, type RoutineSchedule } from "@/lib/routines";
import type { WebhookAttempt, WebhookTrigger } from "@/lib/webhooks";
import type { AppTrigger } from "@/lib/app-triggers";
import { appProblem, appStatusParts, appWhen, skippedToday } from "@/lib/app-automations";
@@ -59,6 +59,12 @@ export function automationsFrom(sources: { routines: readonly Routine[]; webhook
].filter((automation) => !botIds || botIds.has(automation.botId));
}
+/** An unseen failed or missed run the person can clear: it belongs to an automation in `automations`, and opening that
+ * automation marks it seen. A run whose automation or bot was deleted has nothing to open, so it never asks for attention. */
+export function hasUnseenProblemRun(automations: readonly Automation[]): boolean {
+ return automations.some((automation) => automation.runs.some((run) => isRoutineProblemRun(run) && !run.seenAt));
+}
+
export function automationFor(ref: { kind: AutomationKind; id: string }, sources: Parameters<typeof automationsFrom>[0]): Automation | null {
return automationsFrom({
routines: ref.kind === "schedule" ? sources.routines.filter((routine) => routine.id === ref.id) : [],