From 9a9ccf1b2c490cacf10ee702ffaa8be1eb7dbc41 Mon Sep 17 00:00:00 2001 From: Himanshu Gupta <114623040+devhimanshuu@users.noreply.github.com> Date: Thu, 18 Apr 2024 00:32:46 +0530 Subject: [PATCH] Update Selector.tsx Signed-off-by: Himanshu Gupta <114623040+devhimanshuu@users.noreply.github.com> --- .../Header/HopsSelector/Selector.tsx | 164 +++++++++--------- 1 file changed, 85 insertions(+), 79 deletions(-) diff --git a/packages/jaeger-ui/src/components/DeepDependencies/Header/HopsSelector/Selector.tsx b/packages/jaeger-ui/src/components/DeepDependencies/Header/HopsSelector/Selector.tsx index 144b37e17e..0cf99c30e7 100644 --- a/packages/jaeger-ui/src/components/DeepDependencies/Header/HopsSelector/Selector.tsx +++ b/packages/jaeger-ui/src/components/DeepDependencies/Header/HopsSelector/Selector.tsx @@ -12,17 +12,17 @@ // See the License for the specific language governing permissions and // limitations under the License. -import React, { PureComponent } from 'react'; +import React, { useState, useCallback } from 'react'; import { Popover } from 'antd'; import { ImSortAmountAsc } from 'react-icons/im'; import { IoChevronForward } from 'react-icons/io5'; - import ChevronDown from '../ChevronDown'; import { trackHopChange } from '../../index.track'; import { ECheckedStatus, EDirection, THop } from '../../../../model/ddg/types'; - import './Selector.css'; +const CLASSNAME = 'HopsSelector--Selector'; + type TProps = { direction: EDirection; furthestDistance: number; @@ -32,92 +32,98 @@ type TProps = { hops: THop[]; }; -const CLASSNAME = 'HopsSelector--Selector'; - -export default class Selector extends PureComponent { - private handleClick(distance: number) { - const { direction, furthestFullDistance, handleClick } = this.props; - handleClick(distance, direction); - trackHopChange(furthestFullDistance, distance, direction); - } +const Selector: React.FC = ({ + direction, + furthestDistance, + furthestFullDistance, + furthestFullness, + handleClick, + hops, +}) => { + const handleButtonClick = useCallback( + (distance: number) => { + handleClick(distance, direction); + trackHopChange(furthestFullDistance, distance, direction); + }, + [direction, furthestFullDistance, handleClick] + ); - private makeBtn = ( - { distance, fullness, suffix = 'popover-content' }: THop & { suffix?: string }, - showChevron?: number - ) => { - const { direction } = this.props; - return ( + const makeBtn = useCallback( + ({ distance, fullness, suffix = 'popover-content' }: THop & { suffix?: string }, showChevron?: number) => ( {Boolean(showChevron) && } - ); - }; - - render() { - const { direction, furthestDistance, furthestFullness, handleClick, hops } = this.props; - const streamText = direction === EDirection.Downstream ? 'Down' : 'Up'; - const streamLabel = `${streamText}stream hops`; - const lowercaseLabel = streamLabel.toLowerCase(); - if (hops.length <= 1) { - return No {lowercaseLabel}; - } + ), + [direction, handleButtonClick] + ); - const decrementBtn = ( - - ); - const incrementBtn = ( - - ); - const delimiterBtn = this.makeBtn({ - ...hops[hops.length - 1], - suffix: 'delimiter', - }); - const furthestBtn = this.makeBtn({ - distance: furthestDistance, - fullness: furthestFullness, - suffix: 'furthest', - }); + const streamText = direction === EDirection.Downstream ? 'Down' : 'Up'; + const streamLabel = `${streamText}stream hops`; + const lowercaseLabel = streamLabel.toLowerCase(); - return ( - - - - {streamLabel} - {furthestBtn} - / - {delimiterBtn} - {/* */} - - - - ); + if (hops.length <= 1) { + return No {lowercaseLabel}; } -} + + const decrementBtn = ( + + ); + + const incrementBtn = ( + + ); + + const delimiterBtn = makeBtn({ + ...hops[hops.length - 1], + suffix: 'delimiter', + }); + + const furthestBtn = makeBtn({ + distance: furthestDistance, + fullness: furthestFullness, + suffix: 'furthest', + }); + + return ( + + + + {streamLabel} + {furthestBtn} + / + {delimiterBtn} + + + + ); +}; + +export default Selector;