diff --git a/packages/system/dashboard/images/console/apps/console/src/components/observability/EmptyState.test.tsx b/packages/system/dashboard/images/console/apps/console/src/components/observability/EmptyState.test.tsx
new file mode 100644
index 000000000..8872f4d43
--- /dev/null
+++ b/packages/system/dashboard/images/console/apps/console/src/components/observability/EmptyState.test.tsx
@@ -0,0 +1,17 @@
+import { describe, it, expect } from "vitest"
+import { render, screen } from "@testing-library/react"
+import { EmptyState } from "./EmptyState.tsx"
+
+describe("EmptyState", () => {
+ it("announces its message as a status", () => {
+ render()
+
+ expect(screen.getByRole("status")).toHaveTextContent("No data for this range.Pick a longer range.")
+ })
+
+ it("marks itself busy while something is loading", () => {
+ render()
+
+ expect(screen.getByRole("status")).toHaveAttribute("aria-busy", "true")
+ })
+})
diff --git a/packages/system/dashboard/images/console/apps/console/src/components/observability/EmptyState.tsx b/packages/system/dashboard/images/console/apps/console/src/components/observability/EmptyState.tsx
new file mode 100644
index 000000000..0cf58224b
--- /dev/null
+++ b/packages/system/dashboard/images/console/apps/console/src/components/observability/EmptyState.tsx
@@ -0,0 +1,25 @@
+import type { ReactNode } from "react"
+import { cn, Spinner } from "@cozystack/ui"
+
+interface EmptyStateProps {
+ title: ReactNode
+ hint?: ReactNode
+ busy?: boolean
+ tone?: "light" | "dark"
+ className?: string
+}
+
+export function EmptyState({ title, hint, busy, tone = "light", className }: EmptyStateProps) {
+ const dark = tone === "dark"
+ return (
+
+ {busy &&
}
+
{title}
+ {hint &&
{hint}
}
+
+ )
+}
diff --git a/packages/system/dashboard/images/console/apps/console/src/components/observability/LogLines.test.tsx b/packages/system/dashboard/images/console/apps/console/src/components/observability/LogLines.test.tsx
index 7110fe464..dd8c503eb 100644
--- a/packages/system/dashboard/images/console/apps/console/src/components/observability/LogLines.test.tsx
+++ b/packages/system/dashboard/images/console/apps/console/src/components/observability/LogLines.test.tsx
@@ -10,40 +10,59 @@ function sized(list: HTMLElement, scrollHeight: number) {
}
describe("LogLines", () => {
+ it("keeps the console frame and shows the placeholder inside it when there are no lines", () => {
+ render()
+
+ const frame = screen.getByRole("region", { name: "Log lines" })
+ expect(frame).toHaveTextContent("Waiting for new log lines…")
+ expect(screen.queryByRole("list")).toBeNull()
+ })
+
+ it("puts the lines in the same frame once they arrive", () => {
+ const { rerender } = render()
+ const frame = screen.getByRole("region", { name: "Log lines" })
+
+ rerender()
+
+ expect(screen.getByRole("region", { name: "Log lines" })).toBe(frame)
+ expect(frame).toContainElement(screen.getByRole("list"))
+ expect(frame).not.toHaveTextContent("Waiting")
+ })
+
it("keeps following the newest line while the reader is at the bottom", () => {
- const { rerender } = render()
+ const { rerender } = render()
const list = screen.getByRole("list")
sized(list, 500)
- rerender()
+ rerender()
expect(list.scrollTop).toBe(500)
})
it("leaves the position alone once the reader scrolls up", () => {
- const { rerender } = render()
+ const { rerender } = render()
const list = screen.getByRole("list")
sized(list, 500)
list.scrollTop = 120
fireEvent.scroll(list)
- rerender()
+ rerender()
expect(list.scrollTop).toBe(120)
})
it("follows again once the list is cleared for a new run", () => {
- const { rerender } = render()
+ const { rerender } = render()
const first = screen.getByRole("list")
sized(first, 500)
first.scrollTop = 120
fireEvent.scroll(first)
- rerender()
- rerender()
+ rerender()
+ rerender()
const second = screen.getByRole("list")
sized(second, 300)
- rerender()
+ rerender()
expect(second.scrollTop).toBe(300)
})
diff --git a/packages/system/dashboard/images/console/apps/console/src/components/observability/LogLines.tsx b/packages/system/dashboard/images/console/apps/console/src/components/observability/LogLines.tsx
index 452faac72..14b941ab2 100644
--- a/packages/system/dashboard/images/console/apps/console/src/components/observability/LogLines.tsx
+++ b/packages/system/dashboard/images/console/apps/console/src/components/observability/LogLines.tsx
@@ -1,10 +1,10 @@
-import { useEffect, useRef } from "react"
+import { useEffect, useRef, type ReactNode } from "react"
import { CONTAINER_FIELD, POD_FIELD } from "../../lib/observability/logs.ts"
import type { LogEntry } from "../../lib/observability/proxy.ts"
const BOTTOM_SLACK_PX = 24
-export function LogLines({ entries }: { entries: LogEntry[] }) {
+export function LogLines({ entries, placeholder }: { entries: LogEntry[]; placeholder: ReactNode }) {
const ref = useRef(null)
const pinned = useRef(true)
@@ -13,23 +13,31 @@ export function LogLines({ entries }: { entries: LogEntry[] }) {
else if (ref.current && pinned.current) ref.current.scrollTop = ref.current.scrollHeight
}, [entries])
- if (entries.length === 0) return No log lines for this range and filter.
return (
- {
- const el = e.currentTarget
- pinned.current = el.scrollHeight - el.scrollTop - el.clientHeight <= BOTTOM_SLACK_PX
- }}
- className="max-h-[60vh] overflow-auto rounded-md bg-slate-950 p-3 font-mono text-xs leading-5 text-slate-100"
+
- {entries.map((e, i) => (
- -
- {new Date(e._time).toLocaleTimeString()}{" "}
- {`${e[POD_FIELD] ?? ""}/${e[CONTAINER_FIELD] ?? ""}`}{" "}
- {e._msg}
-
- ))}
-
+ {entries.length === 0 ? (
+ placeholder
+ ) : (
+ {
+ const el = e.currentTarget
+ pinned.current = el.scrollHeight - el.scrollTop - el.clientHeight <= BOTTOM_SLACK_PX
+ }}
+ className="h-full overflow-auto p-3"
+ >
+ {entries.map((e, i) => (
+ -
+ {new Date(e._time).toLocaleTimeString()}{" "}
+ {`${e[POD_FIELD] ?? ""}/${e[CONTAINER_FIELD] ?? ""}`}{" "}
+ {e._msg}
+
+ ))}
+
+ )}
+
)
}
diff --git a/packages/system/dashboard/images/console/apps/console/src/components/observability/LogsView.test.tsx b/packages/system/dashboard/images/console/apps/console/src/components/observability/LogsView.test.tsx
index 526efeb23..31c6fac0e 100644
--- a/packages/system/dashboard/images/console/apps/console/src/components/observability/LogsView.test.tsx
+++ b/packages/system/dashboard/images/console/apps/console/src/components/observability/LogsView.test.tsx
@@ -1,5 +1,5 @@
import { describe, it, expect, vi } from "vitest"
-import { screen, waitFor } from "@testing-library/react"
+import { screen, waitFor, within } from "@testing-library/react"
import userEvent from "@testing-library/user-event"
import { K8sClient } from "@cozystack/k8s-client"
import { renderWithK8sProvider } from "../../test-utils/render.tsx"
@@ -47,9 +47,9 @@ describe("LogsView", () => {
it("narrows to the picked pod with a stream filter", async () => {
const { client, raw } = clientWith(defaultHandler)
renderWithK8sProvider(, { client })
- await screen.findByRole("option", { name: "db-1" })
- await userEvent.selectOptions(screen.getByLabelText("Pod"), "db-1")
+ await userEvent.click(screen.getByRole("combobox", { name: "Pod" }))
+ await userEvent.click(await screen.findByRole("option", { name: "db-1" }))
await waitFor(() =>
expect(
@@ -58,6 +58,50 @@ describe("LogsView", () => {
)
})
+ it("offers All next to every pod and starts on it", async () => {
+ const { client } = clientWith(defaultHandler)
+ renderWithK8sProvider(, { client })
+ const pod = screen.getByRole("combobox", { name: "Pod" })
+ expect(pod).toHaveTextContent("All")
+
+ await userEvent.click(pod)
+
+ expect(await screen.findByRole("option", { name: "db-1" })).toBeInTheDocument()
+ expect(screen.getAllByRole("option").map((o) => o.textContent)).toEqual(["All", "db-0", "db-1"])
+ })
+
+ it("keeps the log console and says so inside it when nothing matches", async () => {
+ const { client } = clientWith((endpoint, params) =>
+ endpoint.endsWith("query") ? new Response("") : defaultHandler(endpoint, params),
+ )
+
+ renderWithK8sProvider(, { client })
+
+ const frame = screen.getByRole("region", { name: "Log lines" })
+ expect(await within(frame).findByText("No log lines for this range and filter.")).toBeInTheDocument()
+ })
+
+ it("shows loading inside the log console", () => {
+ const { client } = clientWith((endpoint, params) =>
+ endpoint.endsWith("query") ? new Promise(() => {}) : defaultHandler(endpoint, params),
+ )
+
+ renderWithK8sProvider(, { client })
+
+ const frame = screen.getByRole("region", { name: "Log lines" })
+ expect(within(frame).getByRole("status")).toHaveAttribute("aria-busy", "true")
+ })
+
+ it("says it is waiting while Follow has no line yet", async () => {
+ const { client } = clientWith(defaultHandler)
+ renderWithK8sProvider(, { client })
+
+ await userEvent.click(screen.getByRole("button", { name: "Follow" }))
+
+ const frame = screen.getByRole("region", { name: "Log lines" })
+ expect(within(frame).getByText("Waiting for new log lines…")).toBeInTheDocument()
+ })
+
it("applies the LogsQL filter on submit", async () => {
const { client, raw } = clientWith(defaultHandler)
renderWithK8sProvider(, { client })
diff --git a/packages/system/dashboard/images/console/apps/console/src/components/observability/LogsView.tsx b/packages/system/dashboard/images/console/apps/console/src/components/observability/LogsView.tsx
index a27ca41c5..d2a000010 100644
--- a/packages/system/dashboard/images/console/apps/console/src/components/observability/LogsView.tsx
+++ b/packages/system/dashboard/images/console/apps/console/src/components/observability/LogsView.tsx
@@ -1,7 +1,9 @@
import { useState } from "react"
import { useQuery } from "@tanstack/react-query"
import { useK8sClient } from "@cozystack/k8s-client"
-import { Button, Spinner } from "@cozystack/ui"
+import { Button } from "@cozystack/ui"
+import { Input } from "../ui/input.tsx"
+import { SelectItem, SelectLabel, SelectPopup, SelectRoot, SelectTrigger, SelectValue } from "../ui/select.tsx"
import {
CONTAINER_FIELD,
LOG_RANGES,
@@ -20,6 +22,7 @@ import { useLogTail } from "../../lib/observability/use-log-tail.ts"
import { ProxyNotice } from "./ProxyNotice.tsx"
import { RangePicker } from "./RangePicker.tsx"
import { LogLines } from "./LogLines.tsx"
+import { EmptyState } from "./EmptyState.tsx"
const HISTORY_LIMIT = 500
const FOLLOW_CAP = 1000
@@ -30,27 +33,42 @@ function windowFor(range: LogRangeKey) {
return { start: new Date(end - LOG_RANGES[range] * 1000).toISOString(), end: new Date(end).toISOString() }
}
+const ALL = ""
+
function Picker({ label, value, options, onChange }: { label: string; value: string; options: string[]; onChange: (v: string) => void }) {
+ const items = [{ value: ALL, label: "All" }, ...options.map((o) => ({ value: o, label: o }))]
return (
-
+
+
)
}
+function placeholderFor({ follow, stopped, loading, failed }: { follow: boolean; stopped: boolean; loading: boolean; failed: boolean }) {
+ if (follow) {
+ return stopped ? (
+
+ ) : (
+
+ )
+ }
+ if (loading) return
+ if (failed) return
+ return
+}
+
export function LogsView({ scope }: { scope: ObservabilityScope }) {
const client = useK8sClient()
const root = logsRoot(scope)
@@ -107,12 +125,12 @@ export function LogsView({ scope }: { scope: ObservabilityScope }) {
setFilter(draft)
}}
>
- setDraft(e.target.value)}
+ onValueChange={setDraft}
placeholder='LogsQL filter, e.g. error or "connection refused"'
- className="w-full rounded-md border border-slate-200 px-2.5 py-1.5 font-mono text-xs"
+ className="font-mono"
/>
{ setPod(v); setContainer("") }} />
@@ -129,7 +147,11 @@ export function LogsView({ scope }: { scope: ObservabilityScope }) {
)}
{error ? : null}
- {!follow && history.isLoading ? : }
+
)
}