diff --git a/src/components/dashboard/TopClients.tsx b/src/components/dashboard/TopClients.tsx index 8fa551e..bf789ac 100644 --- a/src/components/dashboard/TopClients.tsx +++ b/src/components/dashboard/TopClients.tsx @@ -13,6 +13,7 @@ import { WithNamespaces, withNamespaces } from "react-i18next"; import api from "../../util/api"; import TopTable from "./TopTable"; import i18next from "i18next"; +import { TimeRangeContext } from "../common/context/TimeRangeContext"; export interface TopClientsData { totalQueries: number; @@ -65,7 +66,11 @@ export const generateRows = (t: i18next.TranslationFunction) => ( }); }; -const TopClients = ({ t, ...props }: WithNamespaces) => ( +const TopClients = ({ + apiCall, + t, + ...props +}: WithNamespaces & { apiCall: () => Promise }) => ( ( headers={[t("Client"), t("Requests"), t("Frequency")]} emptyMessage={t("No Clients Found")} isEmpty={data => data.topClients.length === 0} - apiCall={api.getTopClients} + apiCall={apiCall} apiHandler={transformData} generateRows={generateRows(t)} /> ); -export default withNamespaces(["common", "dashboard"])(TopClients); +const TopClientsContainer = (props: WithNamespaces) => ( + + {context => ( + + context.range + ? api.getTopClientsDb(context.range) + : api.getTopClients() + } + /> + )} + +); + +export default withNamespaces(["common", "dashboard"])(TopClientsContainer); diff --git a/src/util/api.tsx b/src/util/api.tsx index 042fa11..ff97457 100644 --- a/src/util/api.tsx +++ b/src/util/api.tsx @@ -91,6 +91,9 @@ export default { getTopClients(): Promise { return http.get("stats/top_clients"); }, + getTopClientsDb(range: TimeRange): Promise { + return http.get("stats/database/top_clients?" + timeRangeToParams(range)); + }, getHistory(params: any): Promise { return http.get("stats/history?" + paramsToString(params)); },