import type { FC } from 'react'; import { FormControl, InputLabel, Select, MenuItem, FormControlLabel, Checkbox, Box, Autocomplete, TextField, Typography, Chip, } from '@mui/material'; import type { ImpactMetricsSeries } from 'hooks/api/getters/useImpactMetricsMetadata/useImpactMetricsMetadata'; import type { ImpactMetricsLabels } from 'hooks/api/getters/useImpactMetricsData/useImpactMetricsData'; import { Highlighter } from 'component/common/Highlighter/Highlighter'; export interface ImpactMetricsControlsProps { selectedSeries: string; onSeriesChange: (series: string) => void; selectedRange: 'hour' | 'day' | 'week' | 'month'; onRangeChange: (range: 'hour' | 'day' | 'week' | 'month') => void; beginAtZero: boolean; onBeginAtZeroChange: (beginAtZero: boolean) => void; metricSeries: (ImpactMetricsSeries & { name: string })[]; loading?: boolean; selectedLabels: Record; onLabelsChange: (labels: Record) => void; availableLabels?: ImpactMetricsLabels; } export const ImpactMetricsControls: FC = ({ selectedSeries, onSeriesChange, selectedRange, onRangeChange, beginAtZero, onBeginAtZeroChange, metricSeries, loading = false, selectedLabels, onLabelsChange, availableLabels, }) => { const handleLabelChange = (labelKey: string, values: string[]) => { const newLabels = { ...selectedLabels }; if (values.length === 0) { delete newLabels[labelKey]; } else { newLabels[labelKey] = values; } onLabelsChange(newLabels); }; const clearAllLabels = () => { onLabelsChange({}); }; return ( ({ display: 'flex', flexDirection: 'column', gap: theme.spacing(3), maxWidth: 400, })} > Select a custom metric to see its value over time. This can help you understand the impact of your feature rollout on key outcomes, such as system performance, usage patterns or error rates. option.name} value={ metricSeries.find( (option) => option.name === selectedSeries, ) || null } onChange={(_, newValue) => onSeriesChange(newValue?.name || '')} disabled={loading} renderOption={(props, option, { inputValue }) => ( {option.name} {option.help} )} renderInput={(params) => ( )} noOptionsText='No metrics available' sx={{ minWidth: 300 }} /> Time onBeginAtZeroChange(e.target.checked)} /> } label='Begin at zero' /> {availableLabels && Object.keys(availableLabels).length > 0 ? ( Filter by labels {Object.keys(selectedLabels).length > 0 && ( )} {Object.entries(availableLabels).map( ([labelKey, values]) => ( handleLabelChange(labelKey, newValues) } renderTags={(value, getTagProps) => value.map((option, index) => { const { key, ...chipProps } = getTagProps({ index }); return ( ); }) } renderInput={(params) => ( )} sx={{ minWidth: 300 }} /> ), )} ) : null} ); };