@centreon/ui 25.1.0 → 25.1.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": "25.1.0",
3
+ "version": "25.1.2",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -80,6 +80,10 @@ export const useDashboardItemStyles = makeStyles<{ hasHeader: boolean }>()(
80
80
  height: '100%',
81
81
  width: '100%'
82
82
  },
83
+ widgetSubContainer: {
84
+ height: '100%',
85
+ width: '100%'
86
+ },
83
87
  widgetContent: {
84
88
  height: hasHeader
85
89
  ? `calc(100% - ${theme.spacing(3.5)} - ${theme.spacing(0.5)})`
@@ -9,13 +9,13 @@ import {
9
9
  } from 'react';
10
10
 
11
11
  import { useAtomValue } from 'jotai';
12
- import { equals, isNil, prop } from 'ramda';
12
+ import { equals, isNil, prop, type } from 'ramda';
13
13
 
14
14
  import { Card, useTheme } from '@mui/material';
15
-
16
15
  import LoadingSkeleton from '../LoadingSkeleton';
16
+ import ExpandableContainer from '../components/ExpandableContainer';
17
+ import { Parameters } from '../components/ExpandableContainer/models';
17
18
  import { useMemoComponent, useViewportIntersection } from '../utils';
18
-
19
19
  import { useDashboardItemStyles } from './Dashboard.styles';
20
20
  import { isResizingItemAtom } from './atoms';
21
21
 
@@ -25,7 +25,7 @@ interface DashboardItemProps {
25
25
  children: ReactElement;
26
26
  className?: string;
27
27
  disablePadding?: boolean;
28
- header?: ReactElement;
28
+ header?: ReactElement | ((params: Parameters) => ReactElement);
29
29
  id: string;
30
30
  onMouseDown?: (e: MouseEvent<HTMLDivElement>) => void;
31
31
  onMouseUp?: (e: MouseEvent<HTMLDivElement>) => void;
@@ -86,51 +86,76 @@ const Item = forwardRef<HTMLDivElement, DashboardItemProps>(
86
86
  setElement(ref.current);
87
87
  }, [ref]);
88
88
 
89
+ const originStyle = {
90
+ ...style,
91
+ width: `calc(${prop('width', style) || '0px'} - 12px)`
92
+ };
93
+
89
94
  return useMemoComponent({
90
95
  Component: (
91
96
  <div
97
+ ref={ref}
92
98
  {...cardContainerListeners}
93
99
  className={sanitizedReactGridLayoutClassName}
94
- ref={ref}
95
- style={{
96
- ...style,
97
- width: `calc(${prop('width', style) || '0px'} - 12px)`
98
- }}
100
+ style={originStyle}
99
101
  >
100
- <Card
101
- className={classes.widgetContainer}
102
- data-padding={!disablePadding}
103
- >
104
- {header && (
105
- <div className={classes.widgetHeader} data-canMove={canMove}>
106
- {canMove && (
107
- <div
108
- {...listeners}
109
- className={classes.widgetHeaderDraggable}
110
- data-testid={`${id}_move_panel`}
111
- />
112
- )}
113
- {header}
114
- </div>
115
- )}
116
- <div
117
- className={cx(
118
- classes.widgetContent,
119
- !disablePadding && classes.widgetPadding
120
- )}
121
- >
122
- {!isInViewport ? (
123
- <LoadingSkeleton
124
- animation={false}
125
- data-widget-skeleton={id}
126
- height="100%"
127
- width="100%"
128
- />
129
- ) : (
130
- children
131
- )}
132
- </div>
133
- </Card>
102
+ <ExpandableContainer>
103
+ {({ isExpanded, label, key, ...rest }) => {
104
+ const canControl = isExpanded ? false : canMove;
105
+
106
+ const childrenHeader = equals(type(header), 'Function')
107
+ ? (header as (params: Parameters) => ReactElement)({
108
+ isExpanded,
109
+ label,
110
+ ref,
111
+ key,
112
+ ...rest
113
+ })
114
+ : header;
115
+
116
+ return (
117
+ <div key={key} className={classes.widgetSubContainer}>
118
+ <Card
119
+ className={classes.widgetContainer}
120
+ data-padding={!disablePadding}
121
+ >
122
+ {childrenHeader && (
123
+ <div
124
+ className={classes.widgetHeader}
125
+ data-canMove={canControl}
126
+ >
127
+ {canControl && (
128
+ <div
129
+ {...listeners}
130
+ className={classes.widgetHeaderDraggable}
131
+ data-testid={`${id}_move_panel`}
132
+ />
133
+ )}
134
+ {childrenHeader}
135
+ </div>
136
+ )}
137
+ <div
138
+ className={cx(
139
+ classes.widgetContent,
140
+ !disablePadding && classes.widgetPadding
141
+ )}
142
+ >
143
+ {!isInViewport ? (
144
+ <LoadingSkeleton
145
+ animation={false}
146
+ data-widget-skeleton={id}
147
+ height="100%"
148
+ width="100%"
149
+ />
150
+ ) : (
151
+ children
152
+ )}
153
+ </div>
154
+ </Card>
155
+ </div>
156
+ );
157
+ }}
158
+ </ExpandableContainer>
134
159
  </div>
135
160
  ),
136
161
  memoProps: isInViewport
@@ -38,9 +38,9 @@ const UnsavedChangesDialog = ({
38
38
 
39
39
  const labelConfirm = isValidForm ? labelSave : labelResolve;
40
40
 
41
- const labelMessage = `${
42
- isValidForm ? labelIfYouClickOnDiscard : labelThereAreErrorsInTheForm
43
- } ${isValidForm ? '' : labelDoYouWantToQuitWithoutResolving}`;
41
+ const labelMessage = isValidForm
42
+ ? labelIfYouClickOnDiscard
43
+ : `${labelThereAreErrorsInTheForm} ${labelDoYouWantToQuitWithoutResolving}`;
44
44
 
45
45
  if (not(dialogOpened)) {
46
46
  return null;
@@ -0,0 +1,63 @@
1
+ import { OpenInFull } from '@mui/icons-material';
2
+ import { useState } from 'react';
3
+ import { Modal } from '../Modal';
4
+ import { useStyles } from './expandableContainer.styles';
5
+ import { Parameters } from './models';
6
+ import { labelExpand, labelReduce } from './translatedLabels';
7
+
8
+ interface Props {
9
+ children: (params: Omit<Parameters, 'ref'>) => JSX.Element;
10
+ }
11
+
12
+ const ExpandableContainer = ({ children }: Props) => {
13
+ const { classes } = useStyles();
14
+
15
+ const [isExpanded, setIsExpanded] = useState(false);
16
+
17
+ const toggleExpand = (): void => {
18
+ setIsExpanded(!isExpanded);
19
+ };
20
+ const currentMode = isExpanded ? labelExpand : labelReduce;
21
+
22
+ const reducedChildrenData = {
23
+ toggleExpand,
24
+ isExpanded: false,
25
+ label: labelExpand,
26
+ Icon: OpenInFull,
27
+ key: currentMode
28
+ };
29
+
30
+ const expandedChildrenData = {
31
+ toggleExpand,
32
+ isExpanded,
33
+ label: labelReduce,
34
+ Icon: OpenInFull,
35
+ key: currentMode
36
+ };
37
+
38
+ return (
39
+ <>
40
+ {children(reducedChildrenData)}
41
+ {isExpanded && (
42
+ <Modal
43
+ open={isExpanded}
44
+ size="xlarge"
45
+ classes={{
46
+ paper: classes.papper
47
+ }}
48
+ PaperProps={{
49
+ style: {
50
+ width: '90vw',
51
+ maxWidth: '90vw'
52
+ }
53
+ }}
54
+ hasCloseButton={false}
55
+ >
56
+ {children(expandedChildrenData)}
57
+ </Modal>
58
+ )}
59
+ </>
60
+ );
61
+ };
62
+
63
+ export default ExpandableContainer;
@@ -0,0 +1,9 @@
1
+ import { makeStyles } from 'tss-react/mui';
2
+
3
+ export const useStyles = makeStyles()({
4
+ papper: {
5
+ backgroundColor: 'transparent',
6
+ border: 'initial',
7
+ height: '90vh'
8
+ }
9
+ });
@@ -0,0 +1,3 @@
1
+ import ExpandableContainer from './ExpandableContainer';
2
+
3
+ export default ExpandableContainer;
@@ -0,0 +1,12 @@
1
+ import { SvgIconComponent } from '@mui/icons-material';
2
+ import { CSSProperties, ForwardedRef } from 'react';
3
+
4
+ export interface Parameters {
5
+ toggleExpand: () => void;
6
+ Icon: SvgIconComponent;
7
+ isExpanded: boolean;
8
+ label: string;
9
+ style?: CSSProperties;
10
+ ref: ForwardedRef<HTMLDivElement>;
11
+ key: string;
12
+ }
@@ -0,0 +1,2 @@
1
+ export const labelExpand = 'Expand';
2
+ export const labelReduce = 'Reduce';