mirror of
https://github.com/umami-software/umami.git
synced 2026-02-08 06:37:18 +01:00
Add languages table to metrics grid
This commit is contained in:
parent
b5f7aa1813
commit
9a326a33a0
3 changed files with 44 additions and 2 deletions
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} />}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue