From eeb9aa9165a57aec0cf4b343f60bf5637eb9f3fc Mon Sep 17 00:00:00 2001 From: Mcat12 Date: Sat, 16 Mar 2019 16:49:53 -0700 Subject: [PATCH] Add long term stats support to the top domains table Signed-off-by: Mcat12 --- src/components/dashboard/TopDomains.tsx | 26 ++++++++++++++++++++++--- src/util/api.tsx | 3 +++ 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/components/dashboard/TopDomains.tsx b/src/components/dashboard/TopDomains.tsx index e2813a4..3bbca52 100644 --- a/src/components/dashboard/TopDomains.tsx +++ b/src/components/dashboard/TopDomains.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 TopDomainsData { totalQueries: number; @@ -65,7 +66,11 @@ export const generateRows = (t: i18next.TranslationFunction) => ( }); }; -const TopDomains = ({ t, ...props }: WithNamespaces) => ( +const TopDomains = ({ + apiCall, + t, + ...props +}: WithNamespaces & { apiCall: () => Promise }) => ( ( headers={[t("Domain"), t("Hits"), t("Frequency")]} emptyMessage={t("No Domains Found")} isEmpty={data => data.topDomains.length === 0} - apiCall={api.getTopDomains} + apiCall={apiCall} apiHandler={transformData} generateRows={generateRows(t)} /> ); -export default withNamespaces(["common", "dashboard"])(TopDomains); +const TopDomainsContainer = (props: WithNamespaces) => ( + + {context => ( + + context.range + ? api.getTopDomainsDb(context.range) + : api.getTopDomains() + } + /> + )} + +); + +export default withNamespaces(["common", "dashboard"])(TopDomainsContainer); diff --git a/src/util/api.tsx b/src/util/api.tsx index bda05d6..c5deb97 100644 --- a/src/util/api.tsx +++ b/src/util/api.tsx @@ -71,6 +71,9 @@ export default { getTopDomains(): Promise { return http.get("stats/top_domains"); }, + getTopDomainsDb(range: TimeRange): Promise { + return http.get("stats/database/top_domains?" + timeRangeToParams(range)); + }, getTopBlocked(): Promise { // The API uses a GET parameter to differentiate top domains from top // blocked, but the fake API is not able to handle GET parameters right now.