From 4642e07fd321536453206039cbbf2110a0304682 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 20 Dec 2020 19:42:37 +0100 Subject: [PATCH] Reduced duplication when defining routes in visits section --- src/visits/ShortUrlVisits.tsx | 1 - src/visits/VisitsStats.tsx | 25 ++++++++++++------------- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/visits/ShortUrlVisits.tsx b/src/visits/ShortUrlVisits.tsx index 4501347a..d7ceb2ef 100644 --- a/src/visits/ShortUrlVisits.tsx +++ b/src/visits/ShortUrlVisits.tsx @@ -28,7 +28,6 @@ const ShortUrlVisits = boundToMercureHub(({ }: ShortUrlVisitsProps) => { const { shortCode } = params; const { domain } = parseQuery<{ domain?: string }>(search); - const loadVisits = (params: Partial) => getShortUrlVisits(shortCode, { ...params, domain }); useEffect(() => { diff --git a/src/visits/VisitsStats.tsx b/src/visits/VisitsStats.tsx index 8816e111..f1b9936a 100644 --- a/src/visits/VisitsStats.tsx +++ b/src/visits/VisitsStats.tsx @@ -31,11 +31,11 @@ export interface VisitsStatsProps { type HighlightableProps = 'referer' | 'country' | 'city'; type Section = 'byTime' | 'byContext' | 'byLocation' | 'list'; -const sections: Record = { - byTime: { title: 'By time', icon: faCalendarAlt }, - byContext: { title: 'By context', subPath: 'by-context', icon: faChartPie }, - byLocation: { title: 'By location', subPath: 'by-location', icon: faMapMarkedAlt }, - list: { title: 'List', subPath: 'list', icon: faList }, +const sections: Record = { + byTime: { title: 'By time', subPath: '', icon: faCalendarAlt }, + byContext: { title: 'By context', subPath: '/by-context', icon: faChartPie }, + byLocation: { title: 'By location', subPath: '/by-location', icon: faMapMarkedAlt }, + list: { title: 'List', subPath: '/list', icon: faList }, }; const highlightedVisitsToStats = ( @@ -61,7 +61,7 @@ const VisitsStats: FC = ({ children, visitsInfo, getVisits, ca const buildSectionUrl = (subPath?: string) => { const query = domain ? `?domain=${domain}` : ''; - return !subPath ? `${baseUrl}${query}` : `${baseUrl}/${subPath}${query}`; + return !subPath ? `${baseUrl}${query}` : `${baseUrl}${subPath}${query}`; }; const { visits, loading, loadingLarge, error, progress } = visitsInfo; const normalizedVisits = useMemo(() => normalizeVisits(visits), [ visits ]); @@ -133,9 +133,8 @@ const VisitsStats: FC = ({ children, visitsInfo, getVisits, ca tag={RouterNavLink} className="visits-stats__nav-link" to={buildSectionUrl(subPath)} - isActive={(_: null, { pathname }: Location) => - (!subPath && pathname.endsWith('/visits')) || (subPath && pathname.endsWith(subPath)) - } + isActive={(_: null, { pathname }: Location) => pathname.endsWith(`/visits${subPath}`)} + replace > {title} @@ -158,7 +157,7 @@ const VisitsStats: FC = ({ children, visitsInfo, getVisits, ca - +
@@ -181,7 +180,7 @@ const VisitsStats: FC = ({ children, visitsInfo, getVisits, ca
- +
= ({ children, visitsInfo, getVisits, ca
- +
= ({ children, visitsInfo, getVisits, ca className="btn-md-block" onClick={() => setSelectedVisits([])} > - Reset selection {highlightedVisits.length > 0 && <>({highlightedVisits.length})} + Clear selection {highlightedVisits.length > 0 && <>({highlightedVisits.length})}
)}