From 9a326a33a0b8dfd737f0af4ba7ce83d35ca93e01 Mon Sep 17 00:00:00 2001 From: Chris Walsh Date: Wed, 1 Dec 2021 19:32:45 -0800 Subject: [PATCH] Add languages table to metrics grid --- components/metrics/LanguagesTable.js | 31 ++++++++++++++++++++++++++++ components/metrics/MetricsTable.js | 6 +++++- components/pages/WebsiteDetails.js | 9 +++++++- 3 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 components/metrics/LanguagesTable.js diff --git a/components/metrics/LanguagesTable.js b/components/metrics/LanguagesTable.js new file mode 100644 index 00000000..2b6cd868 --- /dev/null +++ b/components/metrics/LanguagesTable.js @@ -0,0 +1,31 @@ +import React from 'react'; +import MetricsTable from './MetricsTable'; +import { percentFilter } from 'lib/filters'; +import { FormattedMessage } from 'react-intl'; +import useLanguageNames from 'hooks/useLanguageNames'; +import useLocale from 'hooks/useLocale'; + +export default function LanguagesTable({ websiteId, onDataLoad, ...props }) { + const { locale } = useLocale(); + const languageNames = useLanguageNames(locale); + + function renderLabel({ x }) { + return ( +
+ {languageNames[x] ?? }{' '} +
+ ); + } + + return ( + } + type="language" + metric={} + websiteId={websiteId} + onDataLoad={data => onDataLoad?.(percentFilter(data))} + renderLabel={renderLabel} + /> + ); +} diff --git a/components/metrics/MetricsTable.js b/components/metrics/MetricsTable.js index 95eb00c3..608e716d 100644 --- a/components/metrics/MetricsTable.js +++ b/components/metrics/MetricsTable.js @@ -23,6 +23,7 @@ export default function MetricsTable({ filterOptions, limit, onDataLoad, + maxHeight = null, ...props }) { const shareToken = useShareToken(); @@ -62,7 +63,10 @@ export default function MetricsTable({ }, [data, error, dataFilter, filterOptions]); return ( -
+
{!data && loading && } {error && } {data && !error && } diff --git a/components/pages/WebsiteDetails.js b/components/pages/WebsiteDetails.js index a8442ea1..de8c8f06 100644 --- a/components/pages/WebsiteDetails.js +++ b/components/pages/WebsiteDetails.js @@ -16,6 +16,7 @@ import BrowsersTable from '../metrics/BrowsersTable'; import OSTable from '../metrics/OSTable'; import DevicesTable from '../metrics/DevicesTable'; import CountriesTable from '../metrics/CountriesTable'; +import LanguagesTable from '../metrics/LanguagesTable'; import EventsTable from '../metrics/EventsTable'; import EventsChart from '../metrics/EventsChart'; import useFetch from 'hooks/useFetch'; @@ -30,6 +31,7 @@ const views = { os: OSTable, device: DevicesTable, country: CountriesTable, + language: LanguagesTable, event: EventsTable, }; @@ -82,6 +84,10 @@ export default function WebsiteDetails({ websiteId }) { label: , value: resolve({ view: 'country' }), }, + { + label: , + value: resolve({ view: 'language' }), + }, { label: , value: resolve({ view: 'event' }), @@ -147,7 +153,8 @@ export default function WebsiteDetails({ websiteId }) { - + + 0 })}>