mirror of
https://github.com/kremalicious/umami.git
synced 2024-12-18 07:13:37 +01:00
Add languages table to metrics grid
This commit is contained in:
parent
b5f7aa1813
commit
9a326a33a0
31
components/metrics/LanguagesTable.js
Normal file
31
components/metrics/LanguagesTable.js
Normal 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}
|
||||
/>
|
||||
);
|
||||
}
|
@ -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 (
|
||||
<div className={classNames(styles.container, className)}>
|
||||
<div
|
||||
className={classNames(styles.container, className)}
|
||||
style={maxHeight ? { minHeight: 0, maxHeight } : {}}
|
||||
>
|
||||
{!data && loading && <Loading />}
|
||||
{error && <ErrorMessage />}
|
||||
{data && !error && <DataTable {...props} data={filteredData} className={className} />}
|
||||
|
@ -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: <FormattedMessage id="metrics.countries" defaultMessage="Countries" />,
|
||||
value: resolve({ view: 'country' }),
|
||||
},
|
||||
{
|
||||
label: <FormattedMessage id="metrics.languages" defaultMessage="Languages" />,
|
||||
value: resolve({ view: 'language' }),
|
||||
},
|
||||
{
|
||||
label: <FormattedMessage id="metrics.events" defaultMessage="Events" />,
|
||||
value: resolve({ view: 'event' }),
|
||||
@ -147,7 +153,8 @@ export default function WebsiteDetails({ websiteId }) {
|
||||
<WorldMap data={countryData} />
|
||||
</GridColumn>
|
||||
<GridColumn xs={12} md={12} lg={4}>
|
||||
<CountriesTable {...tableProps} onDataLoad={setCountryData} />
|
||||
<CountriesTable maxHeight={265} {...tableProps} onDataLoad={setCountryData} />
|
||||
<LanguagesTable maxHeight={265} {...tableProps} />
|
||||
</GridColumn>
|
||||
</GridRow>
|
||||
<GridRow className={classNames({ [styles.hidden]: !eventsData?.length > 0 })}>
|
||||
|
Loading…
Reference in New Issue
Block a user