Refactor shared data source selection for dashboard and map
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { areHistoryQueriesEqual } from "../queryUtils";
|
||||
import { areHistoryQueriesEqual, getDataSource } from "../queryUtils";
|
||||
import type { HistoryQuery } from "../../types/history";
|
||||
|
||||
describe("areHistoryQueriesEqual", () => {
|
||||
@@ -38,3 +38,15 @@ describe("areHistoryQueriesEqual", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getDataSource", () => {
|
||||
it("returns fail2ban for the 24h range", () => {
|
||||
expect(getDataSource("24h")).toBe("fail2ban");
|
||||
});
|
||||
|
||||
it("returns archive for ranges other than 24h", () => {
|
||||
expect(getDataSource("7d")).toBe("archive");
|
||||
expect(getDataSource("30d")).toBe("archive");
|
||||
expect(getDataSource("365d")).toBe("archive");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
|
||||
import type { HistoryQuery } from "../types/history";
|
||||
import type { TimeRange } from "../types/ban";
|
||||
|
||||
/**
|
||||
* Compare two history query objects for semantic equality.
|
||||
@@ -25,3 +26,13 @@ export function areHistoryQueriesEqual(
|
||||
a.page_size === b.page_size
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the data source for the given dashboard time range.
|
||||
*
|
||||
* @param range - The selected time range.
|
||||
* @returns The backend source to query.
|
||||
*/
|
||||
export function getDataSource(range: TimeRange): "fail2ban" | "archive" {
|
||||
return range === "24h" ? "fail2ban" : "archive";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user