@@ -14,11 +14,10 @@ import './forms.css';
1414
1515export type ResourceCalculatorProps = {
1616 flowCollector : K8sResourceKind | null ;
17- changedSampling : number | null ;
18- setChangedSampling : ( sampling : number | null ) => void ;
17+ setSampling ?: ( sampling : number ) => void ;
1918} ;
2019
21- export const Consumption : FC < ResourceCalculatorProps > = ( { flowCollector, changedSampling , setChangedSampling } ) => {
20+ export const Consumption : FC < ResourceCalculatorProps > = ( { flowCollector, setSampling } ) => {
2221 const { t } = useTranslation ( 'plugin__netobserv-plugin' ) ;
2322
2423 const [ receivedPackets , rpLoaded , rpError ] = usePrometheusPoll ( {
@@ -31,19 +30,19 @@ export const Consumption: FC<ResourceCalculatorProps> = ({ flowCollector, change
3130 query : `sort_desc(sum(irate(container_network_transmit_packets_total{cluster="",namespace=~".+"}[4h])) by (node,namespace,pod))`
3231 } ) ;
3332
34- const getCRSampling = React . useCallback ( ( ) => {
35- return ( flowCollector ?. spec ?. agent ?. ebpf ?. sampling as number ) || 50 ;
33+ const getCurrentSampling = React . useCallback ( ( ) => {
34+ return flowCollector ?. spec ?. agent ?. ebpf ?. sampling || 50 ;
3635 } , [ flowCollector ?. spec ?. agent ?. ebpf ?. sampling ] ) ;
3736
3837 const getSamplings = React . useCallback ( ( ) => {
39- const current = getCRSampling ( ) ;
40- let samplings = [ 1 , 25 , 50 , 100 , 125 , 150 ] ;
38+ const current = getCurrentSampling ( ) ;
39+ let samplings = [ 1 , 25 , 50 , 100 , 500 , 1000 ] ;
4140 if ( ! samplings . includes ( current ) ) {
4241 samplings . push ( current ) ;
4342 samplings = _ . sortBy ( samplings ) ;
4443 }
4544 return samplings ;
46- } , [ getCRSampling ] ) ;
45+ } , [ getCurrentSampling ] ) ;
4746
4847 const loadingComponent = ( ) => < Spinner size = "lg" /> ;
4948
@@ -102,9 +101,6 @@ export const Consumption: FC<ResourceCalculatorProps> = ({ flowCollector, change
102101 ] ;
103102 } , [ labelsCount ] ) ;
104103
105- const initialSampling = getCRSampling ( ) ;
106- const currentSampling = changedSampling !== null ? changedSampling : initialSampling ;
107-
108104 return (
109105 < Flex direction = { { default : 'column' } } >
110106 < FlexItem className = "calculator-item" >
@@ -183,23 +179,17 @@ export const Consumption: FC<ResourceCalculatorProps> = ({ flowCollector, change
183179 </ Thead >
184180 < Tbody >
185181 { getSamplings ( ) . map ( ( sampling , i ) => {
186- const isCurrent = currentSampling === sampling ;
187- let extraText = '' ;
188- if ( isCurrent ) {
189- extraText = changedSampling === null ? t ( '(current)' ) : t ( '(new value)' ) ;
190- } else if ( sampling === initialSampling ) {
191- extraText = t ( '(previous value)' ) ;
192- }
182+ const current = getCurrentSampling ( ) === sampling ;
193183 const estimate = getEstimation ( sampling ) ;
194184 return (
195185 < Tr
196186 key = { i }
197- isSelectable
198- isClickable
199- isRowSelected = { isCurrent }
200- onClick = { ( ) => setChangedSampling ( sampling === initialSampling ? null : sampling ) }
187+ isSelectable = { setSampling !== undefined }
188+ isClickable = { setSampling !== undefined }
189+ isRowSelected = { current }
190+ onClick = { ( ) => setSampling && setSampling ( sampling ) }
201191 >
202- < Td > { `${ sampling } ${ extraText } ` } </ Td >
192+ < Td > { `${ sampling } ${ current ? t ( '(current)' ) : '' } ` } </ Td >
203193 < Td > { `${ estimate . cpu } vCPUs` } </ Td >
204194 < Td > { `${ estimate . memory } GiB` } </ Td >
205195 </ Tr >
0 commit comments