@centreon/ui 24.4.1-MON-develop-BOOSTER.3 → 24.4.1-MON-32953-improve-responsiveness.4
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 +1 -1
- package/src/InputField/Select/Autocomplete/index.tsx +8 -2
- package/src/components/Modal/Modal.styles.ts +8 -3
- package/src/utils/index.ts +1 -0
- package/src/utils/useFullscreen/Fullscreen.cypress.spec.tsx +109 -0
- package/src/utils/useFullscreen/atoms.ts +3 -0
- package/src/utils/useFullscreen/index.ts +2 -0
- package/src/utils/useFullscreen/translatedLabels.ts +1 -0
- package/src/utils/useFullscreen/useFullscreen.ts +73 -0
- package/src/utils/useFullscreen/useFullscreenListener.ts +54 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
|
|
3
|
-
import { equals, isNil, pick } from 'ramda';
|
|
3
|
+
import { equals, isEmpty, isNil, pick } from 'ramda';
|
|
4
4
|
import { useTranslation } from 'react-i18next';
|
|
5
5
|
import { makeStyles } from 'tss-react/mui';
|
|
6
6
|
|
|
@@ -200,7 +200,13 @@ const AutocompleteField = React.forwardRef(
|
|
|
200
200
|
),
|
|
201
201
|
style: {
|
|
202
202
|
background: 'transparent',
|
|
203
|
-
|
|
203
|
+
minWidth: 0,
|
|
204
|
+
padding: theme.spacing(
|
|
205
|
+
0.75,
|
|
206
|
+
isEmpty(placeholder) ? 0 : 5,
|
|
207
|
+
0.75,
|
|
208
|
+
0.75
|
|
209
|
+
)
|
|
204
210
|
}
|
|
205
211
|
}}
|
|
206
212
|
autoFocus={autoFocus}
|
|
@@ -28,6 +28,7 @@ const useStyles = makeStyles<{
|
|
|
28
28
|
left: props?.left ?? 0,
|
|
29
29
|
margin: 0,
|
|
30
30
|
maxWidth: 'unset',
|
|
31
|
+
paddingBottom: theme.spacing(8),
|
|
31
32
|
position: 'absolute',
|
|
32
33
|
right: props?.right ?? 0,
|
|
33
34
|
top: props?.top ?? 0,
|
|
@@ -50,14 +51,18 @@ const useStyles = makeStyles<{
|
|
|
50
51
|
},
|
|
51
52
|
modalActions: {
|
|
52
53
|
'&[data-fixed="true"]': {
|
|
53
|
-
|
|
54
|
+
background: theme.palette.background.paper,
|
|
55
|
+
position: 'fixed',
|
|
56
|
+
width: '100%'
|
|
54
57
|
},
|
|
55
|
-
bottom:
|
|
58
|
+
bottom: 0,
|
|
56
59
|
display: 'flex',
|
|
57
60
|
flexDirection: 'row',
|
|
58
61
|
gap: theme.spacing(2),
|
|
59
62
|
justifyContent: 'flex-end',
|
|
60
|
-
|
|
63
|
+
padding: theme.spacing(1, 2.5, 2.5, 0),
|
|
64
|
+
right: 0,
|
|
65
|
+
zIndex: theme.zIndex.modal
|
|
61
66
|
},
|
|
62
67
|
modalBody: {
|
|
63
68
|
'& > p': {
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Provider, createStore } from 'jotai';
|
|
2
|
+
import { BrowserRouter } from 'react-router-dom';
|
|
3
|
+
|
|
4
|
+
import { Button } from '@mui/material';
|
|
5
|
+
|
|
6
|
+
import { useFullscreen } from './useFullscreen';
|
|
7
|
+
import { router, useFullscreenListener } from './useFullscreenListener';
|
|
8
|
+
|
|
9
|
+
const labelEnterFullscreen = 'Enter fullscreen';
|
|
10
|
+
const labelExitFullscreen = 'Exit fullscreen';
|
|
11
|
+
|
|
12
|
+
const ChildComponent = (): JSX.Element => {
|
|
13
|
+
const { toggleFullscreen, fullscreenEnabled, isFullscreenActivated } =
|
|
14
|
+
useFullscreen();
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<div
|
|
18
|
+
data-fullscreenActivated={isFullscreenActivated}
|
|
19
|
+
data-fullscreenEnabled={fullscreenEnabled}
|
|
20
|
+
id="test"
|
|
21
|
+
>
|
|
22
|
+
<Button onClick={() => toggleFullscreen(document.body)}>
|
|
23
|
+
{isFullscreenActivated ? labelExitFullscreen : labelEnterFullscreen}
|
|
24
|
+
</Button>
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const TestComponent = (): JSX.Element => {
|
|
30
|
+
useFullscreenListener();
|
|
31
|
+
|
|
32
|
+
return <ChildComponent />;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
const initialize = (): void => {
|
|
36
|
+
const store = createStore();
|
|
37
|
+
|
|
38
|
+
const queryParameters = new Map();
|
|
39
|
+
|
|
40
|
+
cy.stub(router, 'useSearchParams', () => queryParameters);
|
|
41
|
+
|
|
42
|
+
cy.mount({
|
|
43
|
+
Component: (
|
|
44
|
+
<BrowserRouter>
|
|
45
|
+
<Provider store={store}>
|
|
46
|
+
<TestComponent />
|
|
47
|
+
</Provider>
|
|
48
|
+
</BrowserRouter>
|
|
49
|
+
)
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
describe('Fullscreen', () => {
|
|
54
|
+
it('enters fullscreen mode when the button is clicked', () => {
|
|
55
|
+
initialize();
|
|
56
|
+
|
|
57
|
+
cy.get('#test')
|
|
58
|
+
.should('have.attr', 'data-fullscreenActivated', 'false')
|
|
59
|
+
.should('have.attr', 'data-fullscreenEnabled', 'true');
|
|
60
|
+
|
|
61
|
+
cy.contains(labelEnterFullscreen).realClick();
|
|
62
|
+
|
|
63
|
+
cy.get('#test')
|
|
64
|
+
.should('have.attr', 'data-fullscreenActivated', 'true')
|
|
65
|
+
.should('have.attr', 'data-fullscreenEnabled', 'true');
|
|
66
|
+
|
|
67
|
+
cy.contains(labelExitFullscreen).realClick();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('exits fullscreen mode when the button is clicked', () => {
|
|
71
|
+
initialize();
|
|
72
|
+
|
|
73
|
+
cy.get('#test')
|
|
74
|
+
.should('have.attr', 'data-fullscreenActivated', 'false')
|
|
75
|
+
.should('have.attr', 'data-fullscreenEnabled', 'true');
|
|
76
|
+
|
|
77
|
+
cy.contains(labelEnterFullscreen).realClick();
|
|
78
|
+
|
|
79
|
+
cy.get('#test')
|
|
80
|
+
.should('have.attr', 'data-fullscreenActivated', 'true')
|
|
81
|
+
.should('have.attr', 'data-fullscreenEnabled', 'true');
|
|
82
|
+
|
|
83
|
+
cy.contains(labelExitFullscreen).realClick();
|
|
84
|
+
|
|
85
|
+
cy.get('#test')
|
|
86
|
+
.should('have.attr', 'data-fullscreenActivated', 'false')
|
|
87
|
+
.should('have.attr', 'data-fullscreenEnabled', 'true');
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('toggles fullscreen mode when the corresponding shortcut is clicked', () => {
|
|
91
|
+
initialize();
|
|
92
|
+
|
|
93
|
+
cy.get('#test')
|
|
94
|
+
.should('have.attr', 'data-fullscreenActivated', 'false')
|
|
95
|
+
.should('have.attr', 'data-fullscreenEnabled', 'true');
|
|
96
|
+
|
|
97
|
+
cy.get('#test').realPress(['Alt', 'F']);
|
|
98
|
+
|
|
99
|
+
cy.get('#test')
|
|
100
|
+
.should('have.attr', 'data-fullscreenActivated', 'true')
|
|
101
|
+
.should('have.attr', 'data-fullscreenEnabled', 'true');
|
|
102
|
+
|
|
103
|
+
cy.get('#test').realPress(['Alt', 'F']);
|
|
104
|
+
|
|
105
|
+
cy.get('#test')
|
|
106
|
+
.should('have.attr', 'data-fullscreenActivated', 'false')
|
|
107
|
+
.should('have.attr', 'data-fullscreenEnabled', 'true');
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const labelCannotEnterInFullscreen = 'Cannot enter fullscreen mode';
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { useTranslation } from 'react-i18next';
|
|
2
|
+
import { useAtom } from 'jotai';
|
|
3
|
+
|
|
4
|
+
import { useSnackbar } from '../..';
|
|
5
|
+
|
|
6
|
+
import { labelCannotEnterInFullscreen } from './translatedLabels';
|
|
7
|
+
import { isFullscreenActivatedAtom } from './atoms';
|
|
8
|
+
|
|
9
|
+
interface UseFullscreenState {
|
|
10
|
+
enterInFullscreen: (element: HTMLElement | null) => void;
|
|
11
|
+
exitFullscreen: () => void;
|
|
12
|
+
fullscreenEnabled: boolean;
|
|
13
|
+
isFullscreenActivated: boolean;
|
|
14
|
+
resetVariables: () => void;
|
|
15
|
+
toggleFullscreen: (element: HTMLElement | null) => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export const useFullscreen = (): UseFullscreenState => {
|
|
19
|
+
const { t } = useTranslation();
|
|
20
|
+
|
|
21
|
+
const { showErrorMessage } = useSnackbar();
|
|
22
|
+
|
|
23
|
+
const [isFullscreenActivated, setIsFullscreenActivated] = useAtom(
|
|
24
|
+
isFullscreenActivatedAtom
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
const resetVariables = (): void => {
|
|
28
|
+
setIsFullscreenActivated(false);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const enterInFullscreen = (element: HTMLElement | null): void => {
|
|
32
|
+
if (!document.fullscreenEnabled) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (!element) {
|
|
37
|
+
showErrorMessage(t(labelCannotEnterInFullscreen));
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
element
|
|
41
|
+
?.requestFullscreen({ navigationUI: 'show' })
|
|
42
|
+
.then(() => {
|
|
43
|
+
setIsFullscreenActivated(true);
|
|
44
|
+
})
|
|
45
|
+
.catch(() => {
|
|
46
|
+
showErrorMessage(t(labelCannotEnterInFullscreen));
|
|
47
|
+
setIsFullscreenActivated(false);
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
const exitFullscreen = (): void => {
|
|
52
|
+
document.exitFullscreen().then(resetVariables);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const toggleFullscreen = (element: HTMLElement | null): void => {
|
|
56
|
+
if (isFullscreenActivated) {
|
|
57
|
+
exitFullscreen();
|
|
58
|
+
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
enterInFullscreen(element);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
enterInFullscreen,
|
|
67
|
+
exitFullscreen,
|
|
68
|
+
fullscreenEnabled: document.fullscreenEnabled,
|
|
69
|
+
isFullscreenActivated,
|
|
70
|
+
resetVariables,
|
|
71
|
+
toggleFullscreen
|
|
72
|
+
};
|
|
73
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
import { equals } from 'ramda';
|
|
4
|
+
import { useSearchParams } from 'react-router-dom';
|
|
5
|
+
|
|
6
|
+
import { useDeepCompare } from '../useMemoComponent';
|
|
7
|
+
|
|
8
|
+
import { useFullscreen } from './useFullscreen';
|
|
9
|
+
|
|
10
|
+
export const router = {
|
|
11
|
+
useSearchParams
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
export const useFullscreenListener = (): boolean => {
|
|
15
|
+
const { toggleFullscreen, resetVariables, isFullscreenActivated } =
|
|
16
|
+
useFullscreen();
|
|
17
|
+
|
|
18
|
+
const toggle = (event: KeyboardEvent): void => {
|
|
19
|
+
if (!event.altKey || !equals(event.code, 'KeyF')) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
toggleFullscreen(document.querySelector('body'));
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const changeFullscreen = (): void => {
|
|
27
|
+
if (document.fullscreenElement) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
resetVariables();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
useEffect(
|
|
35
|
+
() => {
|
|
36
|
+
document.addEventListener('fullscreenchange', changeFullscreen);
|
|
37
|
+
|
|
38
|
+
return () => {
|
|
39
|
+
document.removeEventListener('fullscreenchange', changeFullscreen);
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
useDeepCompare([document.fullscreenElement])
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
window.addEventListener('keypress', toggle);
|
|
47
|
+
|
|
48
|
+
return () => {
|
|
49
|
+
window.removeEventListener('keypress', toggle);
|
|
50
|
+
};
|
|
51
|
+
}, [isFullscreenActivated]);
|
|
52
|
+
|
|
53
|
+
return isFullscreenActivated;
|
|
54
|
+
};
|