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 e9f9d72336..2a579cf369 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,14 +32,22 @@ type TProps = { hops: THop[]; }; -const CLASSNAME = 'HopsSelector--Selector'; +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] + ); -export default class Selector extends PureComponent { - private handleClick(distance: number) { - const { direction, furthestFullDistance, handleClick } = this.props; - handleClick(distance, direction); - trackHopChange(furthestFullDistance, distance, direction); - } private makeBtn = ( { distance, fullness, suffix = 'popover-content' }: THop & { suffix?: string }, @@ -53,24 +61,24 @@ export default class Selector extends PureComponent { - ); - }; + ), + [direction, handleButtonClick] + ); - 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}; - } + const streamText = direction === EDirection.Downstream ? 'Down' : 'Up'; + const streamLabel = `${streamText}stream hops`; + const lowercaseLabel = streamLabel.toLowerCase(); + + 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;