Skip to content

Commit 9a996fd

Browse files
committed
NETOBSERV-1920: slider: switch to abbreviated mode with small screens
Also adds a tooltip with more info
1 parent 693d236 commit 9a996fd

File tree

3 files changed

+91
-23
lines changed

3 files changed

+91
-23
lines changed

web/locales/en/plugin__netobserv-plugin.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,17 @@
336336
"Results": "Results",
337337
"Query summary": "Query summary",
338338
"Find in view": "Find in view",
339+
"Res": "Res",
340+
"Base resource, such as a Pod, a Service or a Node": "Base resource, such as a Pod, a Service or a Node",
341+
"Own": "Own",
342+
"Controller owner, such as a Deployment": "Controller owner, such as a Deployment",
343+
"NS": "NS",
344+
"Resource namespace": "Resource namespace",
345+
"Node on which the resources are running": "Node on which the resources are running",
346+
"AZ": "AZ",
347+
"Availability zone": "Availability zone",
348+
"Cl": "Cl",
349+
"Cluster name or identifier": "Cluster name or identifier",
339350
"Show all graphs": "Show all graphs",
340351
"Focus on this graph": "Focus on this graph",
341352
"Show total": "Show total",
Lines changed: 66 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { useTranslation } from 'react-i18next';
33
import { FlowScope } from '../../model/flow-query';
4-
import { Slider } from './slider';
4+
import { Slider, SliderStepObject } from './slider';
55

66
import './scope-slider.css';
77

@@ -15,23 +15,68 @@ export interface ScopeSliderProps {
1515
export 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
};

web/src/components/slider/slider.tsx

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export interface SliderStepObject {
1515
label: string;
1616
/** Value of the step. This value is a percentage of the slider where the tick is drawn. */
1717
value: number;
18+
tooltip?: string;
1819
}
1920

2021
/** The main slider component. */
@@ -426,6 +427,19 @@ export const Slider: React.FunctionComponent<SliderProps> = ({
426427
const maxValue = customSteps[customSteps.length - 1].value;
427428
const stepValue = getStepValue(stepObj.value, minValue, maxValue);
428429

430+
if (stepObj.tooltip) {
431+
return (
432+
<Tooltip content={stepObj.tooltip}>
433+
<SliderStep
434+
key={stepObj.value}
435+
value={stepValue}
436+
label={stepObj.label}
437+
isLabelHidden={stepObj.isLabelHidden}
438+
isActive={stepObj.value <= localValue}
439+
/>
440+
</Tooltip>
441+
);
442+
}
429443
return (
430444
<SliderStep
431445
key={stepObj.value}

0 commit comments

Comments
 (0)