import { useContext } from 'react'; import { firstBy } from 'thenby'; import { ReportContext } from '../[reportId]/Report'; import { CHART_COLORS, UTM_PARAMS } from 'lib/constants'; import PieChart from 'components/charts/PieChart'; import ListTable from 'components/metrics/ListTable'; import styles from './UTMView.module.css'; import { useMessages } from 'components/hooks'; function toArray(data: { [key: string]: number } = {}) { return Object.keys(data) .map(key => { return { name: key, value: data[key] }; }) .sort(firstBy('value', -1)); } export default function UTMView() { const { formatMessage, labels } = useMessages(); const { report } = useContext(ReportContext); const { data } = report || {}; if (!data) { return null; } return (