11import * as React from 'react' ;
22import { useTranslation } from 'react-i18next' ;
33import { FlowScope } from '../../model/flow-query' ;
4- import { Slider } from './slider' ;
4+ import { Slider , SliderStepObject } from './slider' ;
55
66import './scope-slider.css' ;
77
@@ -15,23 +15,68 @@ export interface ScopeSliderProps {
1515export const ScopeSlider : React . FC < ScopeSliderProps > = ( { scope, setScope, allowedScopes, sizePx } ) => {
1616 const { t } = useTranslation ( 'plugin__netobserv-plugin' ) ;
1717
18- let scopes : [ FlowScope , string ] [ ] = [
19- [ 'resource' , t ( 'Resource' ) ] ,
20- [ 'owner' , t ( 'Owner' ) ] ,
21- [ 'namespace' , t ( 'Namespace' ) ] ,
22- [ 'host' , t ( 'Node' ) ] ,
23- [ 'zone' , t ( 'Zone' ) ] ,
24- [ 'cluster' , t ( 'Cluster' ) ]
25- ] ;
26- scopes = scopes . filter ( s => allowedScopes . includes ( s [ 0 ] ) ) ;
27-
28- const index = scopes . findIndex ( s => s [ 0 ] === scope ) ;
2918 /* TODO: refactor vertical slider
3019 * In between the display is block to working dimensions managing two cases
3120 * Non supported dimensions simply hide the slider from the view
3221 * since we can manage scopes from advanced view
3322 */
34- const canDisplay = sizePx > 450 && sizePx < 2000 ;
23+ if ( sizePx < 250 || sizePx > 2000 ) {
24+ return null ;
25+ }
26+
27+ let scopes : [ FlowScope , SliderStepObject ] [ ] = [
28+ [
29+ 'resource' ,
30+ {
31+ value : 0 ,
32+ label : sizePx > 450 ? t ( 'Resource' ) : t ( 'Res' ) ,
33+ tooltip : t ( 'Base resource, such as a Pod, a Service or a Node' )
34+ }
35+ ] ,
36+ [
37+ 'owner' ,
38+ {
39+ value : 1 ,
40+ label : sizePx > 450 ? t ( 'Owner' ) : t ( 'Own' ) ,
41+ tooltip : t ( 'Controller owner, such as a Deployment' )
42+ }
43+ ] ,
44+ [
45+ 'namespace' ,
46+ {
47+ value : 2 ,
48+ label : sizePx > 450 ? t ( 'Namespace' ) : t ( 'NS' ) ,
49+ tooltip : t ( 'Resource namespace' )
50+ }
51+ ] ,
52+ [
53+ 'host' ,
54+ {
55+ value : 3 ,
56+ label : sizePx > 450 ? t ( 'Node' ) : t ( 'Node' ) ,
57+ tooltip : t ( 'Node on which the resources are running' )
58+ }
59+ ] ,
60+ [
61+ 'zone' ,
62+ {
63+ value : 4 ,
64+ label : sizePx > 450 ? t ( 'Zone' ) : t ( 'AZ' ) ,
65+ tooltip : t ( 'Availability zone' )
66+ }
67+ ] ,
68+ [
69+ 'cluster' ,
70+ {
71+ value : 5 ,
72+ label : sizePx > 450 ? t ( 'Cluster' ) : t ( 'Cl' ) ,
73+ tooltip : t ( 'Cluster name or identifier' )
74+ }
75+ ]
76+ ] ;
77+ scopes = scopes . filter ( s => allowedScopes . includes ( s [ 0 ] ) ) ;
78+
79+ const index = scopes . findIndex ( s => s [ 0 ] === scope ) ;
3580 const isBig = sizePx > 700 ;
3681 return (
3782 < div
@@ -42,16 +87,14 @@ export const ScopeSlider: React.FC<ScopeSliderProps> = ({ scope, setScope, allow
4287 left : - sizePx * ( isBig ? 0.38 : 0.28 )
4388 } }
4489 >
45- { canDisplay && (
46- < Slider
47- value = { index < 0 ? 2 : index }
48- showTicks
49- max = { scopes . length - 1 }
50- customSteps = { scopes . map ( ( s , idx ) => ( { value : idx , label : s [ 1 ] } ) ) }
51- onChange = { ( value : number ) => setScope ( scopes [ value ] [ 0 ] ) }
52- vertical
53- />
54- ) }
90+ < Slider
91+ value = { index < 0 ? 2 : index }
92+ showTicks
93+ max = { scopes . length - 1 }
94+ customSteps = { scopes . map ( s => s [ 1 ] ) }
95+ onChange = { ( value : number ) => setScope ( scopes [ value ] [ 0 ] ) }
96+ vertical
97+ />
5598 </ div >
5699 ) ;
57100} ;
0 commit comments