From 18e240e3d1799848919f8dd43bd90068a3feb454 Mon Sep 17 00:00:00 2001 From: Yunus M Date: Tue, 15 Oct 2024 19:16:43 +0530 Subject: [PATCH] feat: search series in anomaly response data (#6185) --- .../AnomalyAlertEvaluationView.styles.scss | 20 ++++- .../AnomalyAlertEvaluationView.tsx | 75 ++++++++++++++----- 2 files changed, 74 insertions(+), 21 deletions(-) diff --git a/frontend/src/container/AnomalyAlertEvaluationView/AnomalyAlertEvaluationView.styles.scss b/frontend/src/container/AnomalyAlertEvaluationView/AnomalyAlertEvaluationView.styles.scss index 308dfb68c9..a21e769487 100644 --- a/frontend/src/container/AnomalyAlertEvaluationView/AnomalyAlertEvaluationView.styles.scss +++ b/frontend/src/container/AnomalyAlertEvaluationView/AnomalyAlertEvaluationView.styles.scss @@ -32,7 +32,7 @@ flex-direction: column; gap: 8px; width: 240px; - padding: 8px; + padding: 0px 8px; height: 100%; .anomaly-alert-evaluation-view-series-list { @@ -41,6 +41,10 @@ gap: 8px; height: 100%; + .anomaly-alert-evaluation-view-series-list-search { + margin-bottom: 16px; + } + .anomaly-alert-evaluation-view-series-list-title { margin-top: 12px; font-size: 13px !important; @@ -61,6 +65,20 @@ cursor: pointer; } + + &::-webkit-scrollbar { + width: 0.1rem; + } + &::-webkit-scrollbar-corner { + background: transparent; + } + &::-webkit-scrollbar-thumb { + background: rgb(136, 136, 136); + border-radius: 0.625rem; + } + &::-webkit-scrollbar-track { + background: transparent; + } } } } diff --git a/frontend/src/container/AnomalyAlertEvaluationView/AnomalyAlertEvaluationView.tsx b/frontend/src/container/AnomalyAlertEvaluationView/AnomalyAlertEvaluationView.tsx index 8357d9bd57..93f8a19208 100644 --- a/frontend/src/container/AnomalyAlertEvaluationView/AnomalyAlertEvaluationView.tsx +++ b/frontend/src/container/AnomalyAlertEvaluationView/AnomalyAlertEvaluationView.tsx @@ -2,7 +2,9 @@ import 'uplot/dist/uPlot.min.css'; import './AnomalyAlertEvaluationView.styles.scss'; import { Checkbox, Typography } from 'antd'; +import Search from 'antd/es/input/Search'; import { useIsDarkMode } from 'hooks/useDarkMode'; +import useDebouncedFn from 'hooks/useDebouncedFunction'; import { useResizeObserver } from 'hooks/useDimensions'; import getAxes from 'lib/uPlotLib/utils/getAxes'; import { getUplotChartDataForAnomalyDetection } from 'lib/uPlotLib/utils/getUplotChartData'; @@ -63,12 +65,19 @@ function AnomalyAlertEvaluationView({ const [seriesData, setSeriesData] = useState({}); const [selectedSeries, setSelectedSeries] = useState(null); + const [filteredSeriesKeys, setFilteredSeriesKeys] = useState([]); + const [allSeries, setAllSeries] = useState([]); + const graphRef = useRef(null); const dimensions = useResizeObserver(graphRef); useEffect(() => { const chartData = getUplotChartDataForAnomalyDetection(data); setSeriesData(chartData); + + setAllSeries(Object.keys(chartData)); + + setFilteredSeriesKeys(Object.keys(chartData)); }, [data]); useEffect(() => { @@ -130,8 +139,6 @@ function AnomalyAlertEvaluationView({ }, }; - const allSeries = Object.keys(seriesData); - const initialData = allSeries.length ? [ seriesData[allSeries[0]].data[0], // Shared X-axis @@ -210,6 +217,27 @@ function AnomalyAlertEvaluationView({ axes: getAxes(isDarkMode, yAxisUnit), }; + const handleSearch = (searchText: string): void => { + if (!searchText || searchText.length === 0) { + setFilteredSeriesKeys(allSeries); + return; + } + + const filteredSeries = allSeries.filter((series) => + series.toLowerCase().includes(searchText.toLowerCase()), + ); + + setFilteredSeriesKeys(filteredSeries); + }; + + const handleSearchValueChange = useDebouncedFn((event): void => { + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + const value = event?.target?.value || ''; + + handleSearch(value); + }, 300); + return (
{allSeries.length > 1 && (
- - Select a series - -
- handleSeriesChange(null)} - > - Show All - + - {allSeries.map((seriesKey) => ( +
+ {filteredSeriesKeys.length > 0 && ( + handleSeriesChange(null)} + > + Show All + + )} + + {filteredSeriesKeys.map((seriesKey) => ( ))} + + {filteredSeriesKeys.length === 0 && ( + No series found + )}
)}