Add languages table to metrics grid

This commit is contained in:
Chris Walsh 2021-12-01 19:32:45 -08:00
parent b5f7aa1813
commit 9a326a33a0
No known key found for this signature in database
GPG Key ID: 28EE0CCA6032019E
3 changed files with 44 additions and 2 deletions

View File

@ -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 (
<div className={locale}>
{languageNames[x] ?? <FormattedMessage id="label.unknown" defaultMessage="Unknown" />}{' '}
</div>
);
}
return (
<MetricsTable
{...props}
title={<FormattedMessage id="metrics.languages" defaultMessage="Languages" />}
type="language"
metric={<FormattedMessage id="metrics.visitors" defaultMessage="Visitors" />}
websiteId={websiteId}
onDataLoad={data => onDataLoad?.(percentFilter(data))}
renderLabel={renderLabel}
/>
);
}

View File

@ -23,6 +23,7 @@ export default function MetricsTable({
filterOptions, filterOptions,
limit, limit,
onDataLoad, onDataLoad,
maxHeight = null,
...props ...props
}) { }) {
const shareToken = useShareToken(); const shareToken = useShareToken();
@ -62,7 +63,10 @@ export default function MetricsTable({
}, [data, error, dataFilter, filterOptions]); }, [data, error, dataFilter, filterOptions]);
return ( return (
<div className={classNames(styles.container, className)}> <div
className={classNames(styles.container, className)}
style={maxHeight ? { minHeight: 0, maxHeight } : {}}
>
{!data && loading && <Loading />} {!data && loading && <Loading />}
{error && <ErrorMessage />} {error && <ErrorMessage />}
{data && !error && <DataTable {...props} data={filteredData} className={className} />} {data && !error && <DataTable {...props} data={filteredData} className={className} />}

View File

@ -16,6 +16,7 @@ import BrowsersTable from '../metrics/BrowsersTable';
import OSTable from '../metrics/OSTable'; import OSTable from '../metrics/OSTable';
import DevicesTable from '../metrics/DevicesTable'; import DevicesTable from '../metrics/DevicesTable';
import CountriesTable from '../metrics/CountriesTable'; import CountriesTable from '../metrics/CountriesTable';
import LanguagesTable from '../metrics/LanguagesTable';
import EventsTable from '../metrics/EventsTable'; import EventsTable from '../metrics/EventsTable';
import EventsChart from '../metrics/EventsChart'; import EventsChart from '../metrics/EventsChart';
import useFetch from 'hooks/useFetch'; import useFetch from 'hooks/useFetch';
@ -30,6 +31,7 @@ const views = {
os: OSTable, os: OSTable,
device: DevicesTable, device: DevicesTable,
country: CountriesTable, country: CountriesTable,
language: LanguagesTable,
event: EventsTable, event: EventsTable,
}; };
@ -82,6 +84,10 @@ export default function WebsiteDetails({ websiteId }) {
label: <FormattedMessage id="metrics.countries" defaultMessage="Countries" />, label: <FormattedMessage id="metrics.countries" defaultMessage="Countries" />,
value: resolve({ view: 'country' }), value: resolve({ view: 'country' }),
}, },
{
label: <FormattedMessage id="metrics.languages" defaultMessage="Languages" />,
value: resolve({ view: 'language' }),
},
{ {
label: <FormattedMessage id="metrics.events" defaultMessage="Events" />, label: <FormattedMessage id="metrics.events" defaultMessage="Events" />,
value: resolve({ view: 'event' }), value: resolve({ view: 'event' }),
@ -147,7 +153,8 @@ export default function WebsiteDetails({ websiteId }) {
<WorldMap data={countryData} /> <WorldMap data={countryData} />
</GridColumn> </GridColumn>
<GridColumn xs={12} md={12} lg={4}> <GridColumn xs={12} md={12} lg={4}>
<CountriesTable {...tableProps} onDataLoad={setCountryData} /> <CountriesTable maxHeight={265} {...tableProps} onDataLoad={setCountryData} />
<LanguagesTable maxHeight={265} {...tableProps} />
</GridColumn> </GridColumn>
</GridRow> </GridRow>
<GridRow className={classNames({ [styles.hidden]: !eventsData?.length > 0 })}> <GridRow className={classNames({ [styles.hidden]: !eventsData?.length > 0 })}>