mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-22 12:43:32 +09:00
fix(dashboard): offer a retry when the log query fails
The console does not refetch on window focus and must not poll, so a failed history query stayed failed until the filter or range changed, even after the store recovered. The failed state now has a Retry button that runs the same query again. Assisted-by: LLM Signed-off-by: ZverGuy <maximbel2003@gmail.com>
This commit is contained in:
1 parent
52087d92dc
commit
ef7312579d
3 files changed
+27
-4
No files matched your search
+3
-1
@@ -4,12 +4,13 @@ import { cn, Spinner } from "@cozystack/ui"
|
||||
interface EmptyStateProps {
|
||||
title: ReactNode
|
||||
hint?: ReactNode
|
||||
action?: ReactNode
|
||||
busy?: boolean
|
||||
tone?: "light" | "dark"
|
||||
className?: string
|
||||
}
|
||||
|
||||
export function EmptyState({ title, hint, busy, tone = "light", className }: EmptyStateProps) {
|
||||
export function EmptyState({ title, hint, action, busy, tone = "light", className }: EmptyStateProps) {
|
||||
const dark = tone === "dark"
|
||||
return (
|
||||
<div
|
||||
@@ -20,6 +21,7 @@ export function EmptyState({ title, hint, busy, tone = "light", className }: Emp
|
||||
{busy && <Spinner className={cn("mb-1 size-5", dark && "text-slate-500")} />}
|
||||
<p className={cn("text-sm", dark ? "text-slate-300" : "text-slate-600")}>{title}</p>
|
||||
{hint && <p className={cn("text-xs", dark ? "text-slate-500" : "text-slate-400")}>{hint}</p>}
|
||||
{action && <div className="mt-2">{action}</div>}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
+13
@@ -224,6 +224,19 @@ describe("LogsView", () => {
|
||||
expect(screen.queryByText("Logs are not available on this cluster.")).toBeNull()
|
||||
})
|
||||
|
||||
it("retries a failed history query on request", async () => {
|
||||
let calls = 0
|
||||
const { client } = clientWith((endpoint, params) =>
|
||||
endpoint.endsWith("query") && calls++ === 0 ? new Response("upstream down", { status: 502 }) : defaultHandler(endpoint, params),
|
||||
)
|
||||
renderWithK8sProvider(<LogsView scope={app} />, { client })
|
||||
|
||||
await userEvent.click(await screen.findByRole("button", { name: "Retry" }))
|
||||
|
||||
expect(await screen.findByText("ready to accept connections")).toBeInTheDocument()
|
||||
expect(screen.queryByRole("button", { name: "Retry" })).toBeNull()
|
||||
})
|
||||
|
||||
it("names the source pod and container of each line", async () => {
|
||||
const { client } = clientWith(defaultHandler)
|
||||
|
||||
|
||||
+11
-3
@@ -59,7 +59,7 @@ function Picker({ label, value, options, onChange }: { label: string; value: str
|
||||
const RANGE_KEYS = Object.keys(LOG_RANGES) as LogRangeKey[]
|
||||
const LONGEST_RANGE = RANGE_KEYS[RANGE_KEYS.length - 1]
|
||||
|
||||
function placeholderFor({ follow, stopped, loading, failed, longestRange }: { follow: boolean; stopped: boolean; loading: boolean; failed: boolean; longestRange: boolean }) {
|
||||
function placeholderFor({ follow, stopped, loading, failed, longestRange, retry }: { follow: boolean; stopped: boolean; loading: boolean; failed: boolean; longestRange: boolean; retry: () => void }) {
|
||||
if (follow) {
|
||||
return stopped ? (
|
||||
<EmptyState tone="dark" title="Follow stopped before any line arrived." />
|
||||
@@ -68,7 +68,15 @@ function placeholderFor({ follow, stopped, loading, failed, longestRange }: { fo
|
||||
)
|
||||
}
|
||||
if (loading) return <EmptyState tone="dark" busy title="Loading log lines…" />
|
||||
if (failed) return <EmptyState tone="dark" title="No log lines to show." />
|
||||
if (failed) {
|
||||
return (
|
||||
<EmptyState
|
||||
tone="dark"
|
||||
title="No log lines to show."
|
||||
action={<Button variant="outline" size="sm" onClick={retry}>Retry</Button>}
|
||||
/>
|
||||
)
|
||||
}
|
||||
return <EmptyState tone="dark" title="No log lines for this range and filter." hint={longestRange ? "Try a broader filter." : "Try a longer range or a broader filter."} />
|
||||
}
|
||||
|
||||
@@ -154,7 +162,7 @@ export function LogsView({ scope }: { scope: ObservabilityScope }) {
|
||||
<LogLines
|
||||
key={followRun ?? "history"}
|
||||
entries={entries}
|
||||
placeholder={placeholderFor({ follow, stopped: tail.state === "stopped", loading: history.isLoading, failed: Boolean(error), longestRange: range === LONGEST_RANGE })}
|
||||
placeholder={placeholderFor({ follow, stopped: tail.state === "stopped", loading: history.isLoading, failed: Boolean(error), longestRange: range === LONGEST_RANGE, retry: () => void history.refetch() })}
|
||||
/>
|
||||
</div>
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user