@centreon/ui 23.10.18-MON-17793-create-graph-component-centreon-ui.12 → 23.10.18-MON-17793-create-graph-component-centreon-ui.13

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": "23.10.18-MON-17793-create-graph-component-centreon-ui.12",
3
+ "version": "23.10.18-MON-17793-create-graph-component-centreon-ui.13",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
@@ -31,6 +31,11 @@ const useStyles = makeStyles()((theme) => ({
31
31
  },
32
32
  fill: theme.palette.text.primary,
33
33
  position: 'relative'
34
+ },
35
+ header: {
36
+ display: 'grid',
37
+ gridTemplateColumns: '0.4fr 1fr 0.4fr',
38
+ width: '100%'
34
39
  }
35
40
  }));
36
41
 
@@ -41,7 +41,6 @@ interface Props extends GraphProps {
41
41
  graphInterval: GraphInterval;
42
42
  graphRef: MutableRefObject<HTMLDivElement | null>;
43
43
  legend?: LegendModel;
44
- loading: boolean;
45
44
  shapeLines?: GlobalAreaLines;
46
45
  }
47
46
 
@@ -59,7 +58,8 @@ const Graph = ({
59
58
  annotationEvent,
60
59
  tooltip,
61
60
  legend,
62
- graphRef
61
+ graphRef,
62
+ header
63
63
  }: Props): JSX.Element => {
64
64
  const graphSvgRef = useRef<SVGSVGElement | null>(null);
65
65
 
@@ -231,6 +231,7 @@ const Graph = ({
231
231
  <>
232
232
  <Header
233
233
  displayTimeTick={displayTimeTick}
234
+ header={header}
234
235
  timeTick={timeTick}
235
236
  title={title}
236
237
  />
@@ -4,8 +4,12 @@ import Typography from '@mui/material/Typography';
4
4
 
5
5
  import { useLocaleDateTimeFormat } from '@centreon/ui';
6
6
 
7
+ import { useStyles } from '../Graph.styles';
8
+ import { HeaderGraph } from '../models';
9
+
7
10
  interface Props {
8
11
  displayTimeTick?: boolean;
12
+ header?: HeaderGraph;
9
13
  timeTick?: Date;
10
14
  title: string;
11
15
  }
@@ -13,22 +17,32 @@ interface Props {
13
17
  const Header = ({
14
18
  title,
15
19
  timeTick,
16
- displayTimeTick = true
20
+ displayTimeTick = true,
21
+ header
17
22
  }: Props): JSX.Element => {
23
+ const { classes } = useStyles();
18
24
  const { toDateTime } = useLocaleDateTimeFormat();
19
25
  const time =
20
26
  displayTimeTick && !isNil(timeTick) ? toDateTime(timeTick) : null;
21
27
 
28
+ const displayTitle = header?.displayTitle ?? true;
29
+
22
30
  return (
23
- <>
24
- <Typography align="center" variant="body1">
25
- {title}
26
- </Typography>
27
-
28
- <Typography align="center" style={{ height: 20 }} variant="body1">
29
- {time}
30
- </Typography>
31
- </>
31
+ <div className={classes.header}>
32
+ <div />
33
+ {displayTitle && (
34
+ <div>
35
+ <Typography align="center" variant="body1">
36
+ {title}
37
+ </Typography>
38
+
39
+ <Typography align="center" style={{ height: 20 }} variant="body1">
40
+ {time}
41
+ </Typography>
42
+ </div>
43
+ )}
44
+ {header?.extraComponent}
45
+ </div>
32
46
  );
33
47
  };
34
48
  export default Header;
@@ -42,13 +42,19 @@ const WrapperGraph = ({
42
42
  timeShiftZones,
43
43
  tooltip,
44
44
  annotationEvent,
45
- legend
45
+ legend,
46
+ header
46
47
  }: Props): JSX.Element | null => {
47
48
  const { adjustedData } = useGraphData({ data, end, start });
48
49
  const graphRef = useRef<HTMLDivElement | null>(null);
49
50
 
50
51
  if (loading || !adjustedData) {
51
- return <LoadingSkeleton displayTitleSkeleton graphHeight={height} />;
52
+ return (
53
+ <LoadingSkeleton
54
+ displayTitleSkeleton={header?.displayTitle ?? true}
55
+ graphHeight={height}
56
+ />
57
+ );
52
58
  }
53
59
 
54
60
  return (
@@ -65,6 +71,7 @@ const WrapperGraph = ({
65
71
  graphData={{ ...adjustedData }}
66
72
  graphInterval={{ end, start }}
67
73
  graphRef={graphRef}
74
+ header={header}
68
75
  height={height ?? responsiveHeight}
69
76
  legend={legend}
70
77
  loading={loading}
@@ -84,11 +84,18 @@ export interface AnnotationEvent {
84
84
  data?: Array<TimelineEvent>;
85
85
  }
86
86
 
87
+ export interface HeaderGraph {
88
+ displayTitle?: boolean;
89
+ extraComponent?: ReactNode;
90
+ }
91
+
87
92
  export interface GraphProps {
88
93
  anchorPoint?: AreaAnchorPoint;
89
94
  annotationEvent?: AnnotationEvent;
90
95
  axis?: Axis;
96
+ header?: HeaderGraph;
91
97
  height?: number;
98
+ loading: boolean;
92
99
  timeShiftZones?: InteractedZone;
93
100
  tooltip?: Tooltip;
94
101
  width: number;