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

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.
Files changed (58) hide show
  1. package/package.json +1 -2
  2. package/src/Graph/Axes/UnitLabel.tsx +0 -20
  3. package/src/Graph/Axes/index.tsx +0 -99
  4. package/src/Graph/Axes/models.ts +0 -26
  5. package/src/Graph/Axes/useAxisY.ts +0 -100
  6. package/src/Graph/Graph.tsx +0 -231
  7. package/src/Graph/Grids/index.tsx +0 -20
  8. package/src/Graph/Header/index.tsx +0 -34
  9. package/src/Graph/InteractionWithGraph/AnchorPoint/RegularAnchorPoint.tsx +0 -88
  10. package/src/Graph/InteractionWithGraph/AnchorPoint/StackedAnchorPoint.tsx +0 -97
  11. package/src/Graph/InteractionWithGraph/AnchorPoint/index.tsx +0 -56
  12. package/src/Graph/InteractionWithGraph/AnchorPoint/models.ts +0 -25
  13. package/src/Graph/InteractionWithGraph/AnchorPoint/useAnchorPoint.ts +0 -109
  14. package/src/Graph/InteractionWithGraph/Bar.tsx +0 -21
  15. package/src/Graph/InteractionWithGraph/ZoomPreview/index.tsx +0 -38
  16. package/src/Graph/InteractionWithGraph/ZoomPreview/models.ts +0 -17
  17. package/src/Graph/InteractionWithGraph/ZoomPreview/useZoomPreview.ts +0 -101
  18. package/src/Graph/InteractionWithGraph/ZoomPreview/zoomPreviewAtoms.ts +0 -5
  19. package/src/Graph/InteractionWithGraph/index.tsx +0 -93
  20. package/src/Graph/InteractionWithGraph/interactionWithGraphAtoms.ts +0 -7
  21. package/src/Graph/InteractionWithGraph/mouseTimeValueAtoms.ts +0 -49
  22. package/src/Graph/Lines/RegularLines/index.tsx +0 -99
  23. package/src/Graph/Lines/RegularLines/useRegularLines.ts +0 -15
  24. package/src/Graph/Lines/StackedLines/index.tsx +0 -74
  25. package/src/Graph/Lines/StackedLines/useStackedLines.ts +0 -39
  26. package/src/Graph/Lines/index.tsx +0 -153
  27. package/src/Graph/Lines/models.ts +0 -32
  28. package/src/Graph/LoadingProgress.tsx +0 -46
  29. package/src/Graph/common/index.ts +0 -33
  30. package/src/Graph/data.json +0 -1338
  31. package/src/Graph/helpers/doc.ts +0 -323
  32. package/src/Graph/helpers/index.ts +0 -15
  33. package/src/Graph/index.stories.tsx +0 -30
  34. package/src/Graph/index.tsx +0 -66
  35. package/src/Graph/models.ts +0 -68
  36. package/src/Graph/timeSeries/index.test.ts +0 -484
  37. package/src/Graph/timeSeries/index.ts +0 -512
  38. package/src/Graph/timeSeries/models.ts +0 -119
  39. package/src/Graph/useGraphData.ts +0 -117
  40. package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.styles.ts +0 -57
  41. package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.tsx +0 -78
  42. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/ErrorText.tsx +0 -14
  43. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/PickersStartEndDate.tsx +0 -169
  44. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/index.tsx +0 -76
  45. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/models.ts +0 -61
  46. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/usePickersStartEndDate.ts +0 -91
  47. package/src/TimePeriods/CustomTimePeriod/index.tsx +0 -63
  48. package/src/TimePeriods/DateTimePickerInput.tsx +0 -99
  49. package/src/TimePeriods/SelectedTimePeriod.tsx +0 -99
  50. package/src/TimePeriods/TimePeriods.cypress.spec.tsx +0 -497
  51. package/src/TimePeriods/helpers/index.ts +0 -25
  52. package/src/TimePeriods/index.stories.tsx +0 -74
  53. package/src/TimePeriods/index.tsx +0 -77
  54. package/src/TimePeriods/models.ts +0 -103
  55. package/src/TimePeriods/timePeriods.styles.ts +0 -20
  56. package/src/TimePeriods/timePeriodsAtoms.ts +0 -113
  57. package/src/TimePeriods/useDateTimePickerAdapter.ts +0 -329
  58. package/src/TimePeriods/useSortTimePeriods.ts +0 -24
@@ -1,497 +0,0 @@
1
- import React from 'react';
2
-
3
- import { renderHook } from '@testing-library/react-hooks/dom';
4
- import dayjs from 'dayjs';
5
- import localizedFormatPlugin from 'dayjs/plugin/localizedFormat';
6
- import timezonePlugin from 'dayjs/plugin/timezone';
7
- import utcPlugin from 'dayjs/plugin/utc';
8
- import { useAtomValue } from 'jotai';
9
- import { equals } from 'ramda';
10
-
11
- import { LocalizationProvider } from '@mui/x-date-pickers';
12
-
13
- import { useLocaleDateTimeFormat } from '@centreon/ui';
14
- import { userAtom } from '@centreon/ui-context';
15
-
16
- import DateTimePickerInput from './DateTimePickerInput';
17
- import useDateTimePickerAdapter from './useDateTimePickerAdapter';
18
- import { CustomTimePeriodProperty } from './models';
19
-
20
- dayjs.extend(timezonePlugin);
21
- dayjs.extend(utcPlugin);
22
- dayjs.extend(localizedFormatPlugin);
23
-
24
- const numberDaysInWeek = 7;
25
-
26
- const days = [
27
- 'Sunday',
28
- 'Monday',
29
- 'Tuesday',
30
- 'Wednesday',
31
- 'Thursday',
32
- 'Friday',
33
- 'Saturday'
34
- ];
35
-
36
- const months2023 = [
37
- {
38
- January: {
39
- date: '2023-01-01T12:59:41.041Z',
40
- firstDay: { day: days[0], indexDayInRowWeek: 0, value: 1 },
41
- lastDay: { day: days[2], indexDayInRowWeek: 2, value: 31 },
42
- numberWeeks: 5
43
- }
44
- },
45
- {
46
- February: {
47
- date: '2023-02-01T12:59:41.041Z',
48
- firstDay: { day: days[3], indexDayInRowWeek: 3, value: 1 },
49
- lastDay: { day: days[2], indexDayInRowWeek: 2, value: 28 },
50
- numberWeeks: 5
51
- }
52
- },
53
- {
54
- March: {
55
- date: '2023-03-01T12:59:41.041Z',
56
- firstDay: { day: days[3], indexDayInRowWeek: 3, value: 1 },
57
- lastDay: { day: days[5], indexDayInRowWeek: 5, value: 31 },
58
- numberWeeks: 5
59
- }
60
- },
61
- {
62
- April: {
63
- date: '2023-04-01T12:59:41.041Z',
64
- firstDay: { day: days[6], indexDayInRowWeek: 6, value: 1 },
65
- lastDay: { day: days[0], indexDayInRowWeek: 0, value: 30 },
66
- numberWeeks: 6
67
- }
68
- },
69
- {
70
- May: {
71
- date: '2023-05-01T12:59:41.041Z',
72
- firstDay: { day: days[1], indexDayInRowWeek: 1, value: 1 },
73
- lastDay: { day: days[3], indexDayInRowWeek: 3, value: 31 },
74
- numberWeeks: 5
75
- }
76
- },
77
- {
78
- June: {
79
- date: '2023-06-01T12:59:41.041Z',
80
- firstDay: { day: days[4], indexDayInRowWeek: 4, value: 1 },
81
- lastDay: { day: days[5], indexDayInRowWeek: 5, value: 30 },
82
- numberWeeks: 5
83
- }
84
- },
85
- {
86
- July: {
87
- date: '2023-07-01T12:59:41.041Z',
88
- firstDay: { day: days[6], indexDayInRowWeek: 6, value: 1 },
89
- lastDay: { day: days[1], indexDayInRowWeek: 1, value: 31 },
90
- numberWeeks: 6
91
- }
92
- },
93
- {
94
- August: {
95
- date: '2023-08-01T12:59:41.041Z',
96
- firstDay: { day: days[2], indexDayInRowWeek: 2, value: 1 },
97
- lastDay: { day: days[4], indexDayInRowWeek: 4, value: 31 },
98
- numberWeeks: 5
99
- }
100
- },
101
- {
102
- September: {
103
- date: '2023-09-01T12:59:41.041Z',
104
- firstDay: { day: days[5], indexDayInRowWeek: 5, value: 1 },
105
- lastDay: { day: days[6], indexDayInRowWeek: 6, value: 30 },
106
- numberWeeks: 5
107
- }
108
- },
109
- {
110
- October: {
111
- date: '2023-10-01T12:59:41.041Z',
112
- firstDay: { day: days[0], indexDayInRowWeek: 0, value: 1 },
113
- lastDay: { day: days[2], indexDayInRowWeek: 2, value: 31 },
114
- numberWeeks: 5
115
- }
116
- },
117
- {
118
- November: {
119
- date: '2023-11-01T12:59:41.041Z',
120
- firstDay: { day: days[3], indexDayInRowWeek: 3, value: 1 },
121
- lastDay: { day: days[4], indexDayInRowWeek: 4, value: 30 },
122
- numberWeeks: 5
123
- }
124
- },
125
- {
126
- December: {
127
- date: '2023-12-01T12:59:41.041Z',
128
- firstDay: { day: days[5], indexDayInRowWeek: 5, value: 1 },
129
- lastDay: { day: days[0], indexDayInRowWeek: 0, value: 31 },
130
- numberWeeks: 6
131
- }
132
- }
133
- ];
134
-
135
- const month2023Reverse = [
136
- {
137
- December: {
138
- date: '2023-12-01T12:59:41.041Z',
139
- firstDay: { day: days[5], indexDayInRowWeek: 5, value: 1 },
140
- lastDay: { day: days[0], indexDayInRowWeek: 0, value: 31 },
141
- numberWeeks: 6
142
- }
143
- },
144
- {
145
- November: {
146
- date: '2023-11-01T12:59:41.041Z',
147
- firstDay: { day: days[3], indexDayInRowWeek: 3, value: 1 },
148
- lastDay: { day: days[4], indexDayInRowWeek: 4, value: 30 },
149
- numberWeeks: 5
150
- }
151
- },
152
- {
153
- October: {
154
- date: '2023-10-01T12:59:41.041Z',
155
- firstDay: { day: days[0], indexDayInRowWeek: 0, value: 1 },
156
- lastDay: { day: days[2], indexDayInRowWeek: 2, value: 31 },
157
- numberWeeks: 5
158
- }
159
- },
160
- {
161
- September: {
162
- date: '2023-09-01T12:59:41.041Z',
163
- firstDay: { day: days[5], indexDayInRowWeek: 5, value: 1 },
164
- lastDay: { day: days[6], indexDayInRowWeek: 6, value: 30 },
165
- numberWeeks: 5
166
- }
167
- },
168
- {
169
- August: {
170
- date: '2023-08-01T12:59:41.041Z',
171
- firstDay: { day: days[2], indexDayInRowWeek: 2, value: 1 },
172
- lastDay: { day: days[4], indexDayInRowWeek: 4, value: 31 },
173
- numberWeeks: 5
174
- }
175
- },
176
- {
177
- July: {
178
- date: '2023-07-01T12:59:41.041Z',
179
- firstDay: { day: days[6], indexDayInRowWeek: 6, value: 1 },
180
- lastDay: { day: days[1], indexDayInRowWeek: 1, value: 31 },
181
- numberWeeks: 6
182
- }
183
- },
184
- {
185
- June: {
186
- date: '2023-06-01T12:59:41.041Z',
187
- firstDay: { day: days[4], indexDayInRowWeek: 4, value: 1 },
188
- lastDay: { day: days[5], indexDayInRowWeek: 5, value: 30 },
189
- numberWeeks: 5
190
- }
191
- },
192
- {
193
- May: {
194
- date: '2023-05-01T12:59:41.041Z',
195
- firstDay: { day: days[1], indexDayInRowWeek: 1, value: 1 },
196
- lastDay: { day: days[3], indexDayInRowWeek: 3, value: 31 },
197
- numberWeeks: 5
198
- }
199
- },
200
- {
201
- April: {
202
- date: '2023-04-01T12:59:41.041Z',
203
- firstDay: { day: days[6], indexDayInRowWeek: 6, value: 1 },
204
- lastDay: { day: days[0], indexDayInRowWeek: 0, value: 30 },
205
- numberWeeks: 6
206
- }
207
- },
208
- {
209
- March: {
210
- date: '2023-03-01T12:59:41.041Z',
211
- firstDay: { day: days[3], indexDayInRowWeek: 3, value: 1 },
212
- lastDay: { day: days[5], indexDayInRowWeek: 5, value: 31 },
213
- numberWeeks: 5
214
- }
215
- },
216
- {
217
- February: {
218
- date: '2023-02-01T12:59:41.041Z',
219
- firstDay: { day: days[3], indexDayInRowWeek: 3, value: 1 },
220
- lastDay: { day: days[2], indexDayInRowWeek: 2, value: 28 },
221
- numberWeeks: 5
222
- }
223
- },
224
- {
225
- January: {
226
- date: '2023-01-01T12:59:41.041Z',
227
- firstDay: { day: days[0], indexDayInRowWeek: 0, value: 1 },
228
- lastDay: { day: days[2], indexDayInRowWeek: 2, value: 31 },
229
- numberWeeks: 5
230
- }
231
- }
232
- ];
233
-
234
- const testData = [
235
- {
236
- button: 'Next month',
237
- data: months2023,
238
- initialDate: '2023-01-01T12:59:41.041Z',
239
- timezone: 'Europe/Paris'
240
- },
241
- {
242
- button: 'Previous month',
243
- data: month2023Reverse,
244
- initialDate: '2023-12-01T12:59:41.041Z',
245
- timezone: 'Europe/Paris'
246
- }
247
- ];
248
-
249
- enum ButtonCalendar {
250
- NMONTH = 'Next month',
251
- PMONTH = 'Previous month'
252
- }
253
- interface GetPreviousNextMonth {
254
- currentMonth: string;
255
- labelButton: string;
256
- }
257
-
258
- const getNextMonth = ({
259
- currentMonth,
260
- labelButton
261
- }: GetPreviousNextMonth): Cypress.Chainable | null => {
262
- if (equals(currentMonth, 'December')) {
263
- return null;
264
- }
265
-
266
- return cy.get(`[aria-label="${labelButton}"]`).click();
267
- };
268
-
269
- const getPreviousMonth = ({
270
- currentMonth,
271
- labelButton
272
- }: GetPreviousNextMonth): Cypress.Chainable | null => {
273
- if (equals(currentMonth, 'January')) {
274
- return null;
275
- }
276
-
277
- return cy.get(`[aria-label="${labelButton}"]`).click();
278
- };
279
-
280
- const changeDate = (): void => undefined;
281
-
282
- const setStart = undefined;
283
- const checkIfDuplicateExists = (arr: Array<unknown>): boolean => {
284
- return new Set(arr).size !== arr.length;
285
- };
286
-
287
- testData.forEach((item) =>
288
- describe(`DateTimePicker ${item.button}`, () => {
289
- before(() => {
290
- const userData = renderHook(() => useAtomValue(userAtom));
291
-
292
- userData.result.current.timezone = item.timezone;
293
- userData.result.current.locale = 'en_US';
294
- });
295
-
296
- beforeEach(() => {
297
- const { result } = renderHook(() => useDateTimePickerAdapter());
298
-
299
- const { Adapter } = result.current;
300
- cy.mount({
301
- Component: (
302
- <LocalizationProvider adapterLocale="en" dateAdapter={Adapter}>
303
- <DateTimePickerInput
304
- changeDate={changeDate}
305
- date={new Date(item.initialDate)}
306
- property={CustomTimePeriodProperty.start}
307
- setDate={setStart}
308
- />
309
- </LocalizationProvider>
310
- )
311
- });
312
- });
313
-
314
- it('checks input calendar value contains correct date', () => {
315
- const { result } = renderHook(() => useLocaleDateTimeFormat());
316
- const { format } = result.current;
317
-
318
- const dateInput = format({
319
- date: dayjs(item.initialDate).tz(item.timezone),
320
- formatString: 'L hh:mm A'
321
- });
322
-
323
- cy.get('input').should('have.value', dateInput);
324
- });
325
-
326
- it(`displays the correct number of days for the current month when the ${item.button} button is clicked`, () => {
327
- cy.get('button').click();
328
- item.data.forEach((element) => {
329
- const { lastDay } = Object.values(element)[0];
330
-
331
- cy.get('[role="rowgroup"]').children().as('listWeeks');
332
- cy.get('@listWeeks').children('button').as('days');
333
- cy.get('@days').should('have.length', lastDay.value);
334
-
335
- const currentMonth = Object.keys(element)[0];
336
-
337
- if (equals(item.button, ButtonCalendar.PMONTH)) {
338
- getPreviousMonth({ currentMonth, labelButton: item.button });
339
- } else {
340
- getNextMonth({ currentMonth, labelButton: item.button });
341
- }
342
- });
343
- });
344
-
345
- it(`does not duplicate days in any of the month in the year when the ${item.button} button is clicked`, () => {
346
- cy.get('button').click();
347
- item.data.forEach((element) => {
348
- const daysInCurrentMonth: Array<string> = [];
349
- cy.get('[role="rowgroup"]').first().children().as('listWeeks');
350
- cy.get('@listWeeks').children('button').as('days');
351
-
352
- cy.get('@days')
353
- .each(($day) => daysInCurrentMonth.push($day.text()))
354
- .as('currentDays');
355
-
356
- cy.get('@currentDays').then(() => {
357
- const isDuplicateExist = checkIfDuplicateExists(daysInCurrentMonth);
358
-
359
- return expect(isDuplicateExist).to.be.false;
360
- });
361
-
362
- const currentMonth = Object.keys(element)[0];
363
- if (equals(item.button, ButtonCalendar.PMONTH)) {
364
- getPreviousMonth({ currentMonth, labelButton: item.button });
365
- } else {
366
- getNextMonth({ currentMonth, labelButton: item.button });
367
- }
368
- });
369
- });
370
-
371
- it(`displays the first day as the start of the week when the ${item.button} button is clicked`, () => {
372
- cy.get('button').click();
373
-
374
- item.data.forEach((element) => {
375
- const { firstDay, numberWeeks } = Object.values(element)[0];
376
-
377
- cy.get('[role="rowgroup"]').children().as('listWeeks');
378
-
379
- cy.get('@listWeeks').should('have.length', numberWeeks);
380
- cy.get('@listWeeks').eq(0).as('firstWeek');
381
- cy.get('@firstWeek').children().as('listDaysInFirstWeek');
382
-
383
- cy.get('@listDaysInFirstWeek').should('have.length', numberDaysInWeek);
384
- cy.get('@listDaysInFirstWeek')
385
- .eq(firstDay.indexDayInRowWeek)
386
- .as('firstDayInWeek');
387
- cy.get('@firstDayInWeek').contains(firstDay.value);
388
-
389
- const currentMonth = Object.keys(element)[0];
390
- if (equals(item.button, ButtonCalendar.PMONTH)) {
391
- getPreviousMonth({ currentMonth, labelButton: item.button });
392
- } else {
393
- getNextMonth({ currentMonth, labelButton: item.button });
394
- }
395
- });
396
- });
397
-
398
- it(`displays the last day as the end of the week when the ${item.button} button is clicked`, () => {
399
- cy.get('button').click();
400
-
401
- item.data.forEach((element) => {
402
- const { lastDay, numberWeeks } = Object.values(element)[0];
403
-
404
- cy.get('[role="rowgroup"]').children().as('listWeeks');
405
-
406
- cy.get('@listWeeks').should('have.length', numberWeeks);
407
-
408
- cy.get('@listWeeks')
409
- .eq(numberWeeks - 1)
410
- .as('lastWeek');
411
-
412
- cy.get('@lastWeek').children().as('listDaysInLastWeek');
413
- cy.get('@listDaysInLastWeek').should('have.length', numberDaysInWeek);
414
-
415
- cy.get('@listDaysInLastWeek')
416
- .eq(lastDay.indexDayInRowWeek)
417
- .as('lastDayInWeek');
418
- cy.get('@lastDayInWeek').contains(lastDay.value);
419
- const currentMonth = Object.keys(element)[0];
420
- if (equals(item.button, ButtonCalendar.PMONTH)) {
421
- getPreviousMonth({ currentMonth, labelButton: item.button });
422
- } else {
423
- getNextMonth({ currentMonth, labelButton: item.button });
424
- }
425
- });
426
- });
427
-
428
- it(`displays the month and the year in the calendar's header when the ${item.button} button is clicked`, () => {
429
- cy.get('button').click();
430
- const { result } = renderHook(() => useLocaleDateTimeFormat());
431
-
432
- item.data.forEach((element) => {
433
- const { date } = Object.values(element)[0];
434
-
435
- const { format } = result.current;
436
- const monthAndYear = format({
437
- date: dayjs(date).tz(item.timezone),
438
- formatString: 'MMMM YYYY'
439
- });
440
- cy.contains(monthAndYear);
441
- const currentMonth = Object.keys(element)[0];
442
- if (equals(item.button, ButtonCalendar.PMONTH)) {
443
- getPreviousMonth({ currentMonth, labelButton: item.button });
444
- } else {
445
- getNextMonth({ currentMonth, labelButton: item.button });
446
- }
447
- });
448
- });
449
-
450
- it(`displays the correct day name on calendar's header when the ${item.button} button is clicked`, () => {
451
- cy.get('button').click();
452
- const { result } = renderHook(() => useLocaleDateTimeFormat());
453
-
454
- item.data.forEach((element) => {
455
- const { date } = Object.values(element)[0];
456
- const dateByTimeZone = dayjs(date).tz(item.timezone);
457
- const firstDay = dateByTimeZone.isUTC()
458
- ? dateByTimeZone.utc().startOf('month').startOf('week')
459
- : dateByTimeZone.startOf('month').startOf('week');
460
-
461
- const { format } = result.current;
462
- const daysArray = [0, 1, 2, 3, 4, 5, 6].map((diff) =>
463
- format({
464
- date: firstDay.add(diff, 'day'),
465
- formatString: 'dd'
466
- })
467
- );
468
- daysArray.forEach((day) => cy.contains(day.toUpperCase()));
469
- const currentMonth = Object.keys(element)[0];
470
- if (equals(item.button, ButtonCalendar.PMONTH)) {
471
- getPreviousMonth({ currentMonth, labelButton: item.button });
472
- } else {
473
- getNextMonth({ currentMonth, labelButton: item.button });
474
- }
475
- });
476
- });
477
-
478
- it(`displays the calendar for the timezone ${item.timezone} when the ${item.button} button is clicked`, () => {
479
- cy.get('button').click();
480
-
481
- item.data.forEach((element) => {
482
- const currentMonth = Object.keys(element)[0];
483
- if (equals(item.button, ButtonCalendar.PMONTH)) {
484
- getPreviousMonth({ currentMonth, labelButton: item.button });
485
- } else {
486
- getNextMonth({ currentMonth, labelButton: item.button });
487
- }
488
-
489
- cy.matchImageSnapshot(
490
- `calendar-${item.timezone}-${
491
- Object.keys(element)[0]
492
- }-when-clicking-on-${item.button}`
493
- );
494
- });
495
- });
496
- })
497
- );
@@ -1,25 +0,0 @@
1
- import { find, propEq } from 'ramda';
2
-
3
- import {
4
- CustomTimePeriod,
5
- TimePeriod,
6
- TimePeriodById,
7
- lastDayPeriod
8
- } from '../models';
9
-
10
- export const defaultTimePeriod = lastDayPeriod;
11
-
12
- export const getTimePeriodFromNow = (
13
- timePeriod: TimePeriod | null
14
- ): CustomTimePeriod => {
15
- return {
16
- end: new Date(Date.now()),
17
- start: new Date(timePeriod?.getStart() || 0)
18
- };
19
- };
20
-
21
- export const getTimePeriodById = ({
22
- id,
23
- timePeriods
24
- }: TimePeriodById): TimePeriod =>
25
- find<TimePeriod>(propEq('id', id))(timePeriods) as TimePeriod;
@@ -1,74 +0,0 @@
1
- import { Meta, StoryObj } from '@storybook/react';
2
- import dayjs from 'dayjs';
3
-
4
- import { dateFormat } from './models';
5
-
6
- import AwesomeTimePeriod from '.';
7
-
8
- const meta: Meta<typeof AwesomeTimePeriod> = {
9
- component: AwesomeTimePeriod,
10
- tags: ['autodocs']
11
- };
12
-
13
- export default meta;
14
-
15
- type Story = StoryObj<typeof AwesomeTimePeriod>;
16
-
17
- const Template: Story = {
18
- render: (args) => <AwesomeTimePeriod {...args} />
19
- };
20
-
21
- const args = {
22
- extraTimePeriods: [
23
- {
24
- dateTimeFormat: dateFormat,
25
- getStart: (): Date => dayjs(Date.now()).subtract(29, 'day').toDate(),
26
- id: 'last_29_days',
27
- largeName: 'last 29 days',
28
- name: '29 days'
29
- }
30
- ]
31
- };
32
-
33
- const argTypes = {
34
- disabled: {
35
- control: 'boolean',
36
- description: 'If true, the component is disabled.',
37
- table: {
38
- defaultValue: { summary: false },
39
- type: { summary: 'boolean' }
40
- }
41
- },
42
- extraTimePeriods: {
43
- control: 'object',
44
- description: 'soon',
45
- table: {
46
- defaultValue: { summary: '[]' },
47
- type: { detail: 'extra selected time periods', summary: 'array' }
48
- }
49
- },
50
- getIsError: {
51
- description:
52
- 'Callback fired when The end date is smaller or equal to the start date',
53
- table: {
54
- category: 'Events',
55
- type: { detail: '(value:boolean)=>void', summary: 'function' }
56
- }
57
- },
58
- getStartEndParameters: {
59
- description: 'Callback fired when the the user select or pick a date',
60
- table: {
61
- category: 'Events',
62
- type: {
63
- detail: '({start:isoString,end:isoString})=>void',
64
- summary: 'function'
65
- }
66
- }
67
- }
68
- };
69
-
70
- export const Playground: Story = {
71
- ...Template,
72
- argTypes,
73
- args
74
- };
@@ -1,77 +0,0 @@
1
- import { useEffect } from 'react';
2
-
3
- import { Responsive } from '@visx/visx';
4
- import isSameOrAfter from 'dayjs/plugin/isSameOrAfter';
5
- import dayjs from 'dayjs';
6
- import timezonePlugin from 'dayjs/plugin/timezone';
7
- import utcPlugin from 'dayjs/plugin/utc';
8
- import duration from 'dayjs/plugin/duration';
9
- import { useAtomValue } from 'jotai';
10
-
11
- import { Paper } from '@mui/material';
12
-
13
- import { useStyles } from './timePeriods.styles';
14
- import CustomTimePeriod from './CustomTimePeriod';
15
- import SelectedTimePeriod from './SelectedTimePeriod';
16
- import { EndStartInterval, TimePeriod } from './models';
17
- import {
18
- customTimePeriodAtom,
19
- getDatesDerivedAtom,
20
- selectedTimePeriodAtom,
21
- errorTimePeriodAtom
22
- } from './timePeriodsAtoms';
23
-
24
- dayjs.extend(isSameOrAfter);
25
- dayjs.extend(utcPlugin);
26
- dayjs.extend(timezonePlugin);
27
- dayjs.extend(duration);
28
-
29
- interface Props {
30
- disabled?: boolean;
31
- extraTimePeriods?: Array<TimePeriod>;
32
- getIsError?: (value: boolean) => void;
33
- getStartEndParameters?: ({ start, end }: EndStartInterval) => void;
34
- }
35
-
36
- const AwesomeTimePeriod = ({
37
- extraTimePeriods,
38
- disabled = false,
39
- getStartEndParameters,
40
- getIsError
41
- }: Props): JSX.Element => {
42
- const { classes } = useStyles({ disabled });
43
-
44
- const selectedTimePeriod = useAtomValue(selectedTimePeriodAtom);
45
- const customTimePeriod = useAtomValue(customTimePeriodAtom);
46
- const getCurrentEndStartInterval = useAtomValue(getDatesDerivedAtom);
47
- const errorTimePeriod = useAtomValue(errorTimePeriodAtom);
48
-
49
- useEffect(() => {
50
- const [start, end] = getCurrentEndStartInterval(selectedTimePeriod);
51
- getStartEndParameters?.({ end, start });
52
- }, [customTimePeriod, selectedTimePeriod]);
53
-
54
- useEffect(() => {
55
- getIsError?.(errorTimePeriod);
56
- }, [errorTimePeriod]);
57
-
58
- return (
59
- <div>
60
- <Responsive.ParentSize>
61
- {({ width }): JSX.Element => {
62
- return (
63
- <Paper className={classes.header} style={{ width }}>
64
- <SelectedTimePeriod
65
- disabled={disabled}
66
- extraTimePeriods={extraTimePeriods}
67
- width={width}
68
- />
69
- <CustomTimePeriod disabled={disabled} width={width} />
70
- </Paper>
71
- );
72
- }}
73
- </Responsive.ParentSize>
74
- </div>
75
- );
76
- };
77
- export default AwesomeTimePeriod;