From 9333fdcd0b3ba922febcd84dca33662fb08d81ff Mon Sep 17 00:00:00 2001 From: Rajat Dabade Date: Wed, 15 Nov 2023 19:17:06 +0530 Subject: [PATCH] [Feat]: Uplot Threshold in Time Series. (#3974) * refactor: resolve merge conflict * refactor: added support to value conversion * refactor: linter fixes * refactor: build fixes --- .../FormAlertRules/ChartPreview/index.tsx | 16 +- .../GridCard/FullView/index.tsx | 1 + .../GridCardLayout/GridCard/index.tsx | 2 + .../WidgetGraph/WidgetGraphs.tsx | 2 + .../RightContainer/Threshold/Threshold.tsx | 80 +++-- .../Threshold/ThresholdSelector.tsx | 4 + .../RightContainer/Threshold/types.ts | 4 + .../NewWidget/RightContainer/index.tsx | 1 + frontend/src/lib/getConvertedValue.ts | 283 ++++++++++++++++++ .../src/lib/uPlotLib/getUplotChartData.ts | 62 ++-- 10 files changed, 401 insertions(+), 54 deletions(-) create mode 100644 frontend/src/lib/getConvertedValue.ts diff --git a/frontend/src/container/FormAlertRules/ChartPreview/index.tsx b/frontend/src/container/FormAlertRules/ChartPreview/index.tsx index f2ef361bdc..fb0001c23a 100644 --- a/frontend/src/container/FormAlertRules/ChartPreview/index.tsx +++ b/frontend/src/container/FormAlertRules/ChartPreview/index.tsx @@ -118,10 +118,18 @@ function ChartPreview({ apiResponse: queryResponse?.data?.payload, dimensions: containerDimensions, isDarkMode, - thresholdText: `${t( - 'preview_chart_threshold_label', - )} (y=${thresholdValue} ${query?.unit || ''})`, - thresholdValue, + thresholds: [ + { + index: '0', // no impact + keyIndex: 0, + moveThreshold: (): void => {}, + selectedGraph: PANEL_TYPES.TIME_SERIES, // no impact + thresholdValue, + thresholdLabel: `${t( + 'preview_chart_threshold_label', + )} (y=${thresholdValue} ${query?.unit || ''})`, + }, + ], }), [ query?.unit, diff --git a/frontend/src/container/GridCardLayout/GridCard/FullView/index.tsx b/frontend/src/container/GridCardLayout/GridCard/FullView/index.tsx index e8153620d0..258c73eaab 100644 --- a/frontend/src/container/GridCardLayout/GridCard/FullView/index.tsx +++ b/frontend/src/container/GridCardLayout/GridCard/FullView/index.tsx @@ -113,6 +113,7 @@ function FullView({ onDragSelect, graphsVisibilityStates, setGraphsVisibilityStates, + thresholds: widget.thresholds, }); setChartOptions(newChartOptions); diff --git a/frontend/src/container/GridCardLayout/GridCard/index.tsx b/frontend/src/container/GridCardLayout/GridCard/index.tsx index db265a9f01..ec72477ad2 100644 --- a/frontend/src/container/GridCardLayout/GridCard/index.tsx +++ b/frontend/src/container/GridCardLayout/GridCard/index.tsx @@ -108,10 +108,12 @@ function GridCardGraph({ onDragSelect, yAxisUnit: widget?.yAxisUnit, onClickHandler, + thresholds: widget.thresholds, }), [ widget?.id, widget?.yAxisUnit, + widget.thresholds, queryResponse.data?.payload, containerDimensions, isDarkMode, diff --git a/frontend/src/container/NewWidget/LeftContainer/WidgetGraph/WidgetGraphs.tsx b/frontend/src/container/NewWidget/LeftContainer/WidgetGraph/WidgetGraphs.tsx index af5d6722d4..f82ae652c3 100644 --- a/frontend/src/container/NewWidget/LeftContainer/WidgetGraph/WidgetGraphs.tsx +++ b/frontend/src/container/NewWidget/LeftContainer/WidgetGraph/WidgetGraphs.tsx @@ -61,6 +61,7 @@ function WidgetGraph({ dimensions: containerDimensions, isDarkMode, onDragSelect, + thresholds, fillSpans, }), [ @@ -70,6 +71,7 @@ function WidgetGraph({ containerDimensions, isDarkMode, onDragSelect, + thresholds, fillSpans, ], ); diff --git a/frontend/src/container/NewWidget/RightContainer/Threshold/Threshold.tsx b/frontend/src/container/NewWidget/RightContainer/Threshold/Threshold.tsx index 13021418b3..bc8fc60119 100644 --- a/frontend/src/container/NewWidget/RightContainer/Threshold/Threshold.tsx +++ b/frontend/src/container/NewWidget/RightContainer/Threshold/Threshold.tsx @@ -1,7 +1,16 @@ import './Threshold.styles.scss'; import { CheckOutlined, DeleteOutlined, EditOutlined } from '@ant-design/icons'; -import { Card, Divider, InputNumber, Select, Space, Typography } from 'antd'; +import { + Card, + Divider, + Input, + InputNumber, + Select, + Space, + Typography, +} from 'antd'; +import { PANEL_TYPES } from 'constants/queryBuilder'; import { useIsDarkMode } from 'hooks/useDarkMode'; import { useRef, useState } from 'react'; import { useDrag, useDrop, XYCoord } from 'react-dnd'; @@ -24,6 +33,8 @@ function Threshold({ setThresholds, keyIndex, moveThreshold, + selectedGraph, + thresholdLabel = '', }: ThresholdProps): JSX.Element { const [isEditMode, setIsEditMode] = useState(isEditEnabled); const [operator, setOperator] = useState( @@ -35,6 +46,7 @@ function Threshold({ const [format, setFormat] = useState( thresholdFormat, ); + const [label, setLabel] = useState(thresholdLabel); const isDarkMode = useIsDarkMode(); @@ -54,6 +66,7 @@ function Threshold({ thresholdOperator: operator as ThresholdProps['thresholdOperator'], thresholdUnit: unit, thresholdValue: value, + thresholdLabel: label, }; } return threshold; @@ -148,6 +161,11 @@ function Threshold({ const opacity = isDragging ? 0 : 1; drag(drop(ref)); + const handleLabelChange = ( + event: React.ChangeEvent, + ): void => { + setLabel(event.target.value); + }; return (
- If value is - {isEditMode ? ( - + ) : ( + + )} + + )} + {selectedGraph === PANEL_TYPES.VALUE && ( + <> + If value is + {isEditMode ? ( + - ) : ( - - )} + {isEditMode && selectedGraph === PANEL_TYPES.VALUE ? ( + <> +