@centreon/ui 24.4.1-MON-34407-implement-the-status-chart-widget.26 → 24.4.1-MON-37085-fix-fullscreen.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@centreon/ui",
3
- "version": "24.4.1-MON-34407-implement-the-status-chart-widget.26",
3
+ "version": "24.4.1-MON-37085-fix-fullscreen.2",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
@@ -58,6 +58,11 @@ export const WithoutTitle: Story = {
58
58
  render: Template
59
59
  };
60
60
 
61
+ export const WithPencentage: Story = {
62
+ args: { data, title: 'hosts', unit: 'percentage' },
63
+ render: Template
64
+ };
65
+
61
66
  export const WithoutLegend: Story = {
62
67
  args: { data, displayLegend: false, title: 'hosts' },
63
68
 
@@ -69,11 +74,6 @@ export const withDisplayedValues: Story = {
69
74
  render: Template
70
75
  };
71
76
 
72
- export const WithPencentage: Story = {
73
- args: { data, displayValues: true, title: 'hosts', unit: 'percentage' },
74
- render: Template
75
- };
76
-
77
77
  export const WithTooltip: Story = {
78
78
  args: { TooltipContent, data, title: 'hosts' },
79
79
  render: Template
@@ -16,7 +16,7 @@ export const useBarStackStyles = makeStyles()((theme) => ({
16
16
  svgContainer: {
17
17
  alignItems: 'center',
18
18
  backgroundColor: theme.palette.background.panelGroups,
19
- borderRadius: theme.spacing(1.25),
19
+ borderRadius: theme.shape.borderRadius,
20
20
  display: 'flex',
21
21
  justifyContent: 'center'
22
22
  },
@@ -31,7 +31,6 @@ export const useBarStackStyles = makeStyles()((theme) => ({
31
31
  fontSize: theme.typography.h6.fontSize,
32
32
  fontWeight: theme.typography.fontWeightMedium,
33
33
  margin: 0,
34
- padding: 0,
35
- textAlign: 'center'
34
+ padding: 0
36
35
  }
37
36
  }));
@@ -5,7 +5,6 @@ import { Group } from '@visx/group';
5
5
  import numeral from 'numeral';
6
6
  import { Text } from '@visx/text';
7
7
  import { useTranslation } from 'react-i18next';
8
- import { equals } from 'ramda';
9
8
 
10
9
  import { Typography } from '@mui/material';
11
10
 
@@ -13,7 +12,7 @@ import { Tooltip } from '../../components';
13
12
  import { LegendProps } from '../Legend/models';
14
13
  import { Legend as LegendComponent } from '../Legend';
15
14
  import { getValueByUnit } from '../common/utils';
16
- import { labelNoDataFound as defaultlabelNoDataFound } from '../translatedLabels';
15
+ import { labelNoDataFound } from '../translatedLabels';
17
16
 
18
17
  import { BarStackProps } from './models';
19
18
  import { useBarStackStyles } from './BarStack.styles';
@@ -36,8 +35,7 @@ const BarStack = ({
36
35
  unit = 'number',
37
36
  displayValues,
38
37
  variant = 'vertical',
39
- legendDirection = 'column',
40
- labelNoDataFound = defaultlabelNoDataFound
38
+ legendDirection = 'column'
41
39
  }: BarStackProps & { height: number; width: number }): JSX.Element => {
42
40
  const { t } = useTranslation();
43
41
  const { classes } = useBarStackStyles();
@@ -92,7 +90,7 @@ const BarStack = ({
92
90
  >
93
91
  {title && (
94
92
  <div className={classes.title} data-testid="Title" ref={titleRef}>
95
- {`${numeral(total).format('0a').toUpperCase()} `} {t(title)}
93
+ {`${numeral(total).format('0a').toUpperCase()} `} {title}
96
94
  </div>
97
95
  )}
98
96
  <div
@@ -119,20 +117,6 @@ const BarStack = ({
119
117
  {(barStacks) =>
120
118
  barStacks.map((barStack) =>
121
119
  barStack.bars.map((bar) => {
122
- const shouldDisplayValues = (): boolean => {
123
- if (bar.height < 10) {
124
- return false;
125
- }
126
-
127
- return (
128
- (equals(unit, 'number') && bar.width > 10) ||
129
- (equals(unit, 'percentage') && bar.width > 25)
130
- );
131
- };
132
-
133
- const TextX = bar.x + bar.width / 2;
134
- const TextY = bar.y + bar.height / 2;
135
-
136
120
  const onClick = (): void => {
137
121
  onSingleBarClick?.(bar);
138
122
  };
@@ -160,38 +144,40 @@ const BarStack = ({
160
144
  isVerticalBar ? 'right-start' : 'bottom-start'
161
145
  }
162
146
  >
163
- <g data-testid={bar.key} onClick={onClick}>
147
+ <g data-testid={bar.key}>
164
148
  <rect
165
- cursor="pointer"
166
149
  fill={bar.color}
167
150
  height={
168
151
  isVerticalBar ? bar.height - 1 : bar.height
169
152
  }
170
153
  key={`bar-stack-${barStack.index}-${bar.index}`}
171
- ry={10}
154
+ ry={5}
172
155
  width={isVerticalBar ? bar.width : bar.width - 1}
173
156
  x={bar.x}
174
157
  y={bar.y}
158
+ onClick={onClick}
175
159
  />
176
- {displayValues && shouldDisplayValues() && (
177
- <Text
178
- cursor="pointer"
179
- data-testid="value"
180
- fill="#000"
181
- fontSize={12}
182
- fontWeight={600}
183
- textAnchor="middle"
184
- verticalAnchor="middle"
185
- x={TextX}
186
- y={TextY}
187
- >
188
- {getValueByUnit({
189
- total,
190
- unit,
191
- value: barStack.bars[0].bar.data[barStack.key]
192
- })}
193
- </Text>
194
- )}
160
+ {displayValues &&
161
+ bar.height > 10 &&
162
+ bar.width > 10 && (
163
+ <Text
164
+ cursor="pointer"
165
+ data-testid="value"
166
+ fill="#000"
167
+ fontSize={12}
168
+ textAnchor="middle"
169
+ verticalAnchor="middle"
170
+ x={bar.x + bar.width / 2}
171
+ y={bar.y + bar.height / 2}
172
+ >
173
+ {getValueByUnit({
174
+ total,
175
+ unit,
176
+ value:
177
+ barStack.bars[0].bar.data[barStack.key]
178
+ })}
179
+ </Text>
180
+ )}
195
181
  </g>
196
182
  </Tooltip>
197
183
  );
@@ -10,7 +10,6 @@ export type BarStackProps = {
10
10
  data: Array<BarType>;
11
11
  displayLegend?: boolean;
12
12
  displayValues?: boolean;
13
- labelNoDataFound?: string;
14
13
  legendDirection?: 'row' | 'column';
15
14
  onSingleBarClick?: (barData) => void;
16
15
  size?: number;
@@ -55,7 +55,7 @@ const useResponsiveBarStack = ({
55
55
  const verticalGap = heightOfTitle > 0 ? 8 : 0;
56
56
 
57
57
  const svgWrapperWidth = isVerticalBar
58
- ? size + 36
58
+ ? size + 24
59
59
  : width - widthOfLegend - horizontalGap;
60
60
 
61
61
  const svgContainerSize = {
@@ -72,7 +72,8 @@ const useResponsiveBarStack = ({
72
72
 
73
73
  const yScale = isVerticalBar
74
74
  ? scaleLinear({
75
- domain: [0, total]
75
+ domain: [0, total],
76
+ nice: true
76
77
  })
77
78
  : scaleBand({
78
79
  domain: [0, 0],
@@ -85,7 +86,8 @@ const useResponsiveBarStack = ({
85
86
  padding: 0
86
87
  })
87
88
  : scaleLinear({
88
- domain: [0, total]
89
+ domain: [0, total],
90
+ nice: true
89
91
  });
90
92
 
91
93
  const keys = pluck('label', data);
@@ -13,7 +13,7 @@ import { Tooltip } from '../../components';
13
13
  import { Legend as LegendComponent } from '../Legend';
14
14
  import { LegendProps } from '../Legend/models';
15
15
  import { getValueByUnit } from '../common/utils';
16
- import { labelNoDataFound as defaultlabelNoDataFound } from '../translatedLabels';
16
+ import { labelNoDataFound } from '../translatedLabels';
17
17
 
18
18
  import { PieProps } from './models';
19
19
  import { usePieStyles } from './PieChart.styles';
@@ -54,8 +54,7 @@ const ResponsivePie = ({
54
54
  onArcClick,
55
55
  displayValues,
56
56
  TooltipContent,
57
- legendDirection = 'column',
58
- labelNoDataFound = defaultlabelNoDataFound
57
+ legendDirection = 'column'
59
58
  }: PieProps & { height: number; width: number }): JSX.Element => {
60
59
  const { t } = useTranslation();
61
60
  const theme = useTheme();
@@ -110,7 +109,7 @@ const ResponsivePie = ({
110
109
  >
111
110
  {equals(variant, 'pie') && title && (
112
111
  <div className={classes.title} data-testid="Title" ref={titleRef}>
113
- {`${numeral(total).format('0a').toUpperCase()} `} {t(title)}
112
+ {`${numeral(total).format('0a').toUpperCase()} `} {title}
114
113
  </div>
115
114
  )}
116
115
  <div
@@ -179,7 +178,6 @@ const ResponsivePie = ({
179
178
  >
180
179
  <g data-testid={arc.data.label} onClick={onClick}>
181
180
  <path
182
- cursor="pointer"
183
181
  d={pie.path(arc) as string}
184
182
  fill={arc.data.color}
185
183
  />
@@ -191,7 +189,6 @@ const ResponsivePie = ({
191
189
  dy=".33em"
192
190
  fill="#000"
193
191
  fontSize={12}
194
- fontWeight={600}
195
192
  pointerEvents="none"
196
193
  textAnchor="middle"
197
194
  x={x}
@@ -227,7 +224,7 @@ const ResponsivePie = ({
227
224
  fill={theme.palette.text.primary}
228
225
  textAnchor="middle"
229
226
  >
230
- {t(title)}
227
+ {title}
231
228
  </Text>
232
229
  </>
233
230
  )}
@@ -11,7 +11,6 @@ export interface PieProps {
11
11
  displayLegend?: boolean;
12
12
  displayValues?: boolean;
13
13
  innerRadius?: number;
14
- labelNoDataFound?: string;
15
14
  legendDirection?: 'row' | 'column';
16
15
  onArcClick?: (ardata) => void;
17
16
  title?: string;
@@ -41,11 +41,12 @@ export const useResponsivePie = ({
41
41
  const horizontalGap = widthOfLegend > 0 ? 16 : 0;
42
42
  const verticalGap = heightOfTitle > 0 ? 8 : 0;
43
43
 
44
+ const svgWrapperWidth = width - widthOfLegend - horizontalGap;
45
+
44
46
  const svgContainerSize = Math.min(
45
47
  height - heightOfTitle - verticalGap,
46
48
  width - widthOfLegend - horizontalGap
47
49
  );
48
- const svgWrapperWidth = svgContainerSize;
49
50
 
50
51
  const outerRadius = Math.min(32, svgContainerSize / 6);
51
52
 
@@ -22,6 +22,8 @@ const ChildComponent = (): JSX.Element => {
22
22
  <Button onClick={() => toggleFullscreen(document.body)}>
23
23
  {isFullscreenActivated ? labelExitFullscreen : labelEnterFullscreen}
24
24
  </Button>
25
+ <input id="input" />
26
+ <textarea id="textarea" />
25
27
  </div>
26
28
  );
27
29
  };
@@ -94,16 +96,35 @@ describe('Fullscreen', () => {
94
96
  .should('have.attr', 'data-fullscreenActivated', 'false')
95
97
  .should('have.attr', 'data-fullscreenEnabled', 'true');
96
98
 
97
- cy.get('#test').realPress(['Alt', 'F']);
99
+ cy.get('#test').realPress(['F']);
98
100
 
99
101
  cy.get('#test')
100
102
  .should('have.attr', 'data-fullscreenActivated', 'true')
101
103
  .should('have.attr', 'data-fullscreenEnabled', 'true');
102
104
 
103
- cy.get('#test').realPress(['Alt', 'F']);
105
+ cy.get('#test').realPress(['F']);
104
106
 
105
107
  cy.get('#test')
106
108
  .should('have.attr', 'data-fullscreenActivated', 'false')
107
109
  .should('have.attr', 'data-fullscreenEnabled', 'true');
108
110
  });
111
+
112
+ ['input', 'textarea'].forEach((tag) => {
113
+ it(`cannot toggle fullscreen feature using the shortcut when ${tag === 'input' ? 'an' : 'a'} ${tag} is focused`, () => {
114
+ initialize();
115
+
116
+ cy.get('#test')
117
+ .should('have.attr', 'data-fullscreenActivated', 'false')
118
+ .should('have.attr', 'data-fullscreenEnabled', 'true');
119
+
120
+ cy.get(`#${tag}`).focus();
121
+
122
+ cy.get('#test').realPress(['F']);
123
+
124
+ cy.get('#test')
125
+ .should('have.attr', 'data-fullscreenActivated', 'false')
126
+ .should('have.attr', 'data-fullscreenEnabled', 'true');
127
+ cy.get(`#${tag}`).should('have.value', 'F');
128
+ });
129
+ });
109
130
  });
@@ -1,6 +1,6 @@
1
1
  import { useEffect } from 'react';
2
2
 
3
- import { equals } from 'ramda';
3
+ import { equals, includes } from 'ramda';
4
4
  import { useSearchParams } from 'react-router-dom';
5
5
 
6
6
  import { useDeepCompare } from '../useMemoComponent';
@@ -16,7 +16,10 @@ export const useFullscreenListener = (): boolean => {
16
16
  useFullscreen();
17
17
 
18
18
  const toggle = (event: KeyboardEvent): void => {
19
- if (!event.altKey || !equals(event.code, 'KeyF')) {
19
+ if (
20
+ includes(document.activeElement?.tagName, ['INPUT', 'TEXTAREA']) ||
21
+ !equals(event.code, 'KeyF')
22
+ ) {
20
23
  return;
21
24
  }
22
25