mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-22 12:43:32 +09:00
fix(dashboard): reset the log filters when the tenant or app changes
LogsView kept its filter, pod and container across a scope switch, so the first request for the new tenant still asked for the previous tenant's pod before the picker fell back to All. The view's state is now keyed on the proxy root, so a new tenant or application starts with no filter and All selected. Assisted-by: LLM Signed-off-by: ZverGuy <maximbel2003@gmail.com>
This commit is contained in:
1 parent
711a82eaaf
commit
89194b4f88
2 files changed
+26
-1
No files matched your search
+20
@@ -62,6 +62,26 @@ describe("LogsView with the production query defaults", () => {
|
||||
expect((await screen.findAllByRole("option")).map((o) => o.textContent)).toEqual(["All"])
|
||||
})
|
||||
|
||||
it("starts the next tenant with no filter, pod or container of the previous one", async () => {
|
||||
const { client, raw } = clientWith(defaultHandler)
|
||||
const { switchTo } = renderWithProductionDefaults(client, "tenant-reset-a")
|
||||
await userEvent.type(screen.getByLabelText("LogsQL filter"), "error{Enter}")
|
||||
await userEvent.click(screen.getByRole("combobox", { name: "Pod" }))
|
||||
await userEvent.click(await screen.findByRole("option", { name: "db-1" }))
|
||||
await waitFor(() =>
|
||||
expect(raw.mock.calls.some(([p]) => new URL(p, "http://x").searchParams.get("query") === '{kubernetes_pod_name="db-1"} (error)')).toBe(true),
|
||||
)
|
||||
|
||||
switchTo("tenant-reset-b")
|
||||
|
||||
await waitFor(() => expect(raw.mock.calls.some(([p]) => p.includes("/tenant-reset-b/") && p.includes("select/logsql/query?"))).toBe(true))
|
||||
const first = raw.mock.calls.find(([p]) => p.includes("/tenant-reset-b/") && p.includes("select/logsql/query?"))!
|
||||
expect(new URL(first[0], "http://x").searchParams.get("query")).toBe("*")
|
||||
expect(screen.getByRole("combobox", { name: "Pod" })).toHaveTextContent("All")
|
||||
expect(screen.getByRole("combobox", { name: "Container" })).toHaveTextContent("All")
|
||||
expect(screen.getByLabelText("LogsQL filter")).toHaveValue("")
|
||||
})
|
||||
|
||||
it("keeps the current lines while a new filter in the same tenant loads", async () => {
|
||||
const { client } = clientWith((endpoint, params) =>
|
||||
endpoint.endsWith("query") && params.get("query") === "slow" ? new Promise(() => {}) : defaultHandler(endpoint, params),
|
||||
|
||||
+6
-1
@@ -81,9 +81,14 @@ function placeholderFor({ follow, stopped, loading, failed, longestRange, retry
|
||||
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."} />
|
||||
}
|
||||
|
||||
// Filter, pod and container belong to one scope; a new tenant or application starts clean.
|
||||
export function LogsView({ scope }: { scope: ObservabilityScope }) {
|
||||
const client = useK8sClient()
|
||||
const root = logsRoot(scope)
|
||||
return <ScopedLogsView key={root} root={root} />
|
||||
}
|
||||
|
||||
function ScopedLogsView({ root }: { root: string }) {
|
||||
const client = useK8sClient()
|
||||
const [range, setRange] = useState<LogRangeKey>("1h")
|
||||
const [draft, setDraft] = useState("")
|
||||
const [filter, setFilter] = useState("")
|
||||
|
||||
Reference in new issue
Block a user