mirror of
https://github.com/Unleash/unleash.git
synced 2025-08-27 13:49:10 +02:00
add search with highilght
This commit is contained in:
parent
73ac8fad8e
commit
b07d013d50
@ -46,6 +46,16 @@ export const ImpactMetrics: FC = () => {
|
|||||||
type: 'constant',
|
type: 'constant',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const metricSeries = useMemo(() => {
|
||||||
|
if (!metadata?.series) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
return Object.entries(metadata.series).map(([name, rest]) => ({
|
||||||
|
name,
|
||||||
|
...rest,
|
||||||
|
}));
|
||||||
|
}, [metadata]);
|
||||||
|
|
||||||
const data = useMemo(() => {
|
const data = useMemo(() => {
|
||||||
if (!timeSeriesData.length) {
|
if (!timeSeriesData.length) {
|
||||||
return {
|
return {
|
||||||
@ -119,7 +129,7 @@ export const ImpactMetrics: FC = () => {
|
|||||||
onRangeChange={setSelectedRange}
|
onRangeChange={setSelectedRange}
|
||||||
beginAtZero={beginAtZero}
|
beginAtZero={beginAtZero}
|
||||||
onBeginAtZeroChange={setBeginAtZero}
|
onBeginAtZeroChange={setBeginAtZero}
|
||||||
metricSeries={metadata.series}
|
metricSeries={metricSeries}
|
||||||
loading={metadataLoading}
|
loading={metadataLoading}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@ import {
|
|||||||
TextField,
|
TextField,
|
||||||
Typography,
|
Typography,
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
|
import type { ImpactMetricsSeries } from 'hooks/api/getters/useImpactMetricsMetadata/useImpactMetricsMetadata';
|
||||||
|
import { Highlighter } from 'component/common/Highlighter/Highlighter';
|
||||||
|
|
||||||
export interface ImpactMetricsControlsProps {
|
export interface ImpactMetricsControlsProps {
|
||||||
selectedSeries: string;
|
selectedSeries: string;
|
||||||
@ -19,7 +21,7 @@ export interface ImpactMetricsControlsProps {
|
|||||||
onRangeChange: (range: 'hour' | 'day' | 'week' | 'month') => void;
|
onRangeChange: (range: 'hour' | 'day' | 'week' | 'month') => void;
|
||||||
beginAtZero: boolean;
|
beginAtZero: boolean;
|
||||||
onBeginAtZeroChange: (beginAtZero: boolean) => void;
|
onBeginAtZeroChange: (beginAtZero: boolean) => void;
|
||||||
metricSeries: string[];
|
metricSeries: (ImpactMetricsSeries & { name: string })[];
|
||||||
loading?: boolean;
|
loading?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -49,9 +51,29 @@ export const ImpactMetricsControls: FC<ImpactMetricsControlsProps> = ({
|
|||||||
|
|
||||||
<Autocomplete
|
<Autocomplete
|
||||||
options={metricSeries}
|
options={metricSeries}
|
||||||
value={selectedSeries || null}
|
getOptionLabel={(option) => option.name}
|
||||||
onChange={(_, newValue) => onSeriesChange(newValue || '')}
|
value={
|
||||||
|
metricSeries.find((option) => option.name === selectedSeries) ||
|
||||||
|
null
|
||||||
|
}
|
||||||
|
onChange={(_, newValue) => onSeriesChange(newValue?.name || '')}
|
||||||
disabled={loading}
|
disabled={loading}
|
||||||
|
renderOption={(props, option, { inputValue }) => (
|
||||||
|
<Box component='li' {...props}>
|
||||||
|
<Box sx={{ display: 'flex', flexDirection: 'column' }}>
|
||||||
|
<Typography variant='body2'>
|
||||||
|
<Highlighter search={inputValue}>
|
||||||
|
{option.name}
|
||||||
|
</Highlighter>
|
||||||
|
</Typography>
|
||||||
|
<Typography variant='caption' color='text.secondary'>
|
||||||
|
<Highlighter search={inputValue}>
|
||||||
|
{option.help}
|
||||||
|
</Highlighter>
|
||||||
|
</Typography>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
)}
|
||||||
renderInput={(params) => (
|
renderInput={(params) => (
|
||||||
<TextField
|
<TextField
|
||||||
{...params}
|
{...params}
|
||||||
|
@ -1,9 +1,13 @@
|
|||||||
import { fetcher, useApiGetter } from '../useApiGetter/useApiGetter.js';
|
import { fetcher, useApiGetter } from '../useApiGetter/useApiGetter.js';
|
||||||
import { formatApiPath } from 'utils/formatPath';
|
import { formatApiPath } from 'utils/formatPath';
|
||||||
|
|
||||||
|
export type ImpactMetricsSeries = {
|
||||||
|
type: string;
|
||||||
|
help: string;
|
||||||
|
};
|
||||||
|
|
||||||
export type ImpactMetricsMetadata = {
|
export type ImpactMetricsMetadata = {
|
||||||
series: string[];
|
series: Record<string, ImpactMetricsSeries>;
|
||||||
labels: string[];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const useImpactMetricsMetadata = () => {
|
export const useImpactMetricsMetadata = () => {
|
||||||
@ -14,7 +18,7 @@ export const useImpactMetricsMetadata = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
metadata: data || { series: [], labels: [] },
|
metadata: data,
|
||||||
refetch,
|
refetch,
|
||||||
loading,
|
loading,
|
||||||
error,
|
error,
|
||||||
|
Loading…
Reference in New Issue
Block a user