1- import * as React from 'react' ;
21import { ChartLegendTooltip , createContainer , getResizeObserver } from '@patternfly/react-charts' ;
32import { TFunction } from 'i18next' ;
3+ import * as React from 'react' ;
44import { NamedMetric , TopologyMetricPeer , TopologyMetrics } from '../../api/loki' ;
5+ import { MetricScope , MetricType } from '../../model/flow-query' ;
56import { NodeData } from '../../model/topology' ;
67import { getDateFromUnix , getFormattedDate } from '../../utils/datetime' ;
78import { getFormattedRateValue , matchPeer } from '../../utils/metrics' ;
8- import { MetricScope , MetricType } from '../../model/flow-query ' ;
9+ import { TruncateLength } from '../dropdowns/truncate-dropdown ' ;
910
1011export type LegendDataItem = {
1112 childName ?: string ;
@@ -51,30 +52,37 @@ export const chartVoronoi = (legendData: LegendDataItem[], metricType: MetricTyp
5152 ) ;
5253} ;
5354
54- //TODO: NETOBSERV-688 add this as tab options
55- // function truncate(input: string) {
56- // const length = doubleWidth ? 64 : showDonut ? 10 : 18;
57- // if (input.length > length) {
58- // return input.substring(0, length / 2) + '…' + input.substring(input.length - length / 2);
59- // }
60- // return input;
61- // }
55+ const truncate = ( input : string , length : number ) => {
56+ if ( input . length > length ) {
57+ return input . substring ( 0 , length / 2 ) + '…' + input . substring ( input . length - length / 2 ) ;
58+ }
59+ return input ;
60+ } ;
61+
62+ const truncateParts = ( input : string , length : number ) => {
63+ if ( length === 0 ) {
64+ return input ;
65+ }
6266
63- // function truncateParts(input: string) {
64- // if (input.includes('.')) {
65- // const splitted = input.split('.');
66- // const result: string[] = [];
67- // splitted.forEach(s => {
68- // result.push(truncate(s));
69- // });
70- // return result.join('.');
71- // }
72- // return truncate(input);
73- // }
67+ if ( input . includes ( '.' ) ) {
68+ const splitted = input . split ( '.' ) ;
69+ const result : string [ ] = [ ] ;
70+ splitted . forEach ( s => {
71+ result . push ( truncate ( s , length / splitted . length ) ) ;
72+ } ) ;
73+ return result . join ( '.' ) ;
74+ }
75+ return truncate ( input , length ) ;
76+ } ;
7477
75- const getPeerName = ( t : TFunction , peer : TopologyMetricPeer , scope : MetricScope ) : string => {
78+ const getPeerName = (
79+ t : TFunction ,
80+ peer : TopologyMetricPeer ,
81+ scope : MetricScope ,
82+ truncateLength : TruncateLength = TruncateLength . OFF
83+ ) : string => {
7684 if ( peer . displayName ) {
77- return peer . displayName ;
85+ return truncateParts ( peer . displayName , truncateLength ) ;
7886 }
7987 if ( scope === 'app' ) {
8088 // No peer distinction here
@@ -90,9 +98,14 @@ const getPeerName = (t: TFunction, peer: TopologyMetricPeer, scope: MetricScope)
9098 }
9199} ;
92100
93- export const toNamedMetric = ( t : TFunction , m : TopologyMetrics , data ?: NodeData ) : NamedMetric => {
94- const srcName = getPeerName ( t , m . source , m . scope ) ;
95- const dstName = getPeerName ( t , m . destination , m . scope ) ;
101+ export const toNamedMetric = (
102+ t : TFunction ,
103+ m : TopologyMetrics ,
104+ data ?: NodeData ,
105+ truncateLength : TruncateLength = TruncateLength . OFF
106+ ) : NamedMetric => {
107+ const srcName = getPeerName ( t , m . source , m . scope , truncateLength ) ;
108+ const dstName = getPeerName ( t , m . destination , m . scope , truncateLength ) ;
96109 if ( srcName === dstName ) {
97110 if ( m . source . displayName ) {
98111 // E.g: namespace "netobserv" to "netobserv"
0 commit comments