@centreon/ui 23.10.18-MON-17793-create-graph-component-centreon-ui.3 → 23.10.18-MON-17793-create-graph-component-centreon-ui.5

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.3",
3
+ "version": "23.10.18-MON-17793-create-graph-component-centreon-ui.5",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
@@ -2,6 +2,8 @@ import { useEffect, useState } from 'react';
2
2
 
3
3
  import { Meta, StoryObj } from '@storybook/react';
4
4
 
5
+ import Switch from '@mui/material/Switch';
6
+
5
7
  import { useLocaleDateTimeFormat } from '@centreon/ui';
6
8
 
7
9
  import AwesomeTimePeriod from '../TimePeriods';
@@ -67,10 +69,37 @@ const ExternalComponent = (tooltipData): JSX.Element => {
67
69
  );
68
70
  };
69
71
 
72
+ interface TimePeriodSwitchProps {
73
+ getDataSwitch: (value: boolean) => void;
74
+ }
75
+
76
+ const TimePeriodSwitch = ({
77
+ getDataSwitch
78
+ }: TimePeriodSwitchProps): JSX.Element => {
79
+ const [checked, setChecked] = useState(false);
80
+
81
+ const handleChange = (event: React.ChangeEvent<HTMLInputElement>): void => {
82
+ setChecked(event.target.checked);
83
+ };
84
+
85
+ useEffect(() => {
86
+ getDataSwitch?.(checked);
87
+ }, [checked]);
88
+
89
+ return (
90
+ <Switch
91
+ checked={checked}
92
+ inputProps={{ 'aria-label': 'controlled' }}
93
+ onChange={handleChange}
94
+ />
95
+ );
96
+ };
97
+
70
98
  const GraphAndTimePeriod = (args): JSX.Element => {
71
99
  const [currentData, setCurrentData] = useState<GraphData>();
72
100
  const [start, setStart] = useState();
73
101
  const [end, setEnd] = useState();
102
+ const [displayAnnotation, setDisplayAnnotation] = useState();
74
103
  const [adjustedTimePeriodInterval, setAdjustedTimePeriodInterval] =
75
104
  useState<Interval>();
76
105
 
@@ -113,16 +142,27 @@ const GraphAndTimePeriod = (args): JSX.Element => {
113
142
  setAdjustedTimePeriodInterval(interval);
114
143
  };
115
144
 
145
+ const getDataSwitch = (value): void => {
146
+ setDisplayAnnotation(value);
147
+ };
148
+
149
+ const annotationEventData = displayAnnotation && {
150
+ data: annotationData.result
151
+ };
152
+
116
153
  return (
117
154
  <>
118
155
  <AwesomeTimePeriod
119
156
  adjustTimePeriodData={adjustedTimePeriodInterval}
120
157
  getStartEndParameters={getParameters}
158
+ renderExternalComponent={
159
+ <TimePeriodSwitch getDataSwitch={getDataSwitch} />
160
+ }
121
161
  />
122
162
  <WraperGraph
123
163
  data={currentData}
124
164
  {...args}
125
- annotationEvent={{ data: annotationData.result }}
165
+ annotationEvent={annotationEventData}
126
166
  end={end}
127
167
  loading={false}
128
168
  start={start}