Files
BanGUI/frontend/src/utils/queryUtils.ts

39 lines
944 B
TypeScript

/**
* Shared query utilities used by pages and hooks.
*/
import type { HistoryQuery } from "../types/history";
import type { TimeRange } from "../types/ban";
/**
* Compare two history query objects for semantic equality.
*
* @param a - First query object.
* @param b - Second query object.
* @returns True when every query field has the same value.
*/
export function areHistoryQueriesEqual(
a: HistoryQuery,
b: HistoryQuery,
): boolean {
return (
a.range === b.range &&
a.origin === b.origin &&
a.jail === b.jail &&
a.ip === b.ip &&
a.source === b.source &&
a.page === b.page &&
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";
}