@centreon/ui 24.4.27 → 24.4.29

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 (97) hide show
  1. package/package.json +19 -14
  2. package/public/mockServiceWorker.js +1 -1
  3. package/src/Button/Icon/index.tsx +1 -1
  4. package/src/Button/Save/StartIcon.tsx +3 -3
  5. package/src/Button/Save/index.tsx +9 -5
  6. package/src/Checkbox/Checkbox.tsx +2 -2
  7. package/src/Checkbox/CheckboxGroup/index.tsx +2 -2
  8. package/src/Dashboard/Item.tsx +1 -1
  9. package/src/Dashboard/Layout.tsx +2 -2
  10. package/src/Dialog/index.tsx +1 -1
  11. package/src/FallbackPage/FallbackPage.tsx +3 -3
  12. package/src/FileDropZone/index.tsx +3 -1
  13. package/src/Form/Form.cypress.spec.tsx +133 -0
  14. package/src/Form/Inputs/CheckboxGroup.tsx +1 -4
  15. package/src/Form/Inputs/List/Content.tsx +62 -0
  16. package/src/Form/Inputs/List/List.styles.ts +29 -0
  17. package/src/Form/Inputs/List/List.tsx +58 -0
  18. package/src/Form/Inputs/List/useList.ts +81 -0
  19. package/src/Form/Inputs/index.tsx +3 -1
  20. package/src/Form/Inputs/models.ts +9 -1
  21. package/src/Graph/LineChart/BasicComponents/Lines/Threshold/Circle.tsx +2 -2
  22. package/src/Graph/LineChart/BasicComponents/Lines/Threshold/index.tsx +5 -4
  23. package/src/Graph/LineChart/BasicComponents/Thresholds.tsx +2 -2
  24. package/src/Graph/LineChart/BasicComponents/useFilterLines.ts +1 -1
  25. package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/GuidingLines.tsx +2 -2
  26. package/src/Graph/LineChart/InteractiveComponents/Annotations/Annotation/index.tsx +2 -3
  27. package/src/Graph/LineChart/InteractiveComponents/Annotations/EventAnnotations.tsx +1 -1
  28. package/src/Graph/LineChart/Legend/useLegend.ts +3 -3
  29. package/src/Graph/LineChart/helpers/doc.ts +16 -13
  30. package/src/Graph/LineChart/helpers/index.ts +1 -1
  31. package/src/Graph/LineChart/index.stories.tsx +4 -2
  32. package/src/Graph/SingleBar/Thresholds.tsx +2 -2
  33. package/src/Graph/Text/Text.stories.tsx +60 -4
  34. package/src/Graph/common/timeSeries/index.ts +3 -3
  35. package/src/InputField/Select/Autocomplete/Connected/index.tsx +10 -7
  36. package/src/InputField/Select/Autocomplete/Draggable/SortableList.tsx +1 -1
  37. package/src/InputField/Select/Autocomplete/Draggable/SortableListContent.tsx +1 -1
  38. package/src/InputField/Select/Autocomplete/Draggable/index.tsx +1 -1
  39. package/src/InputField/Select/Autocomplete/index.tsx +121 -115
  40. package/src/InputField/Select/IconPopover/index.tsx +2 -2
  41. package/src/InputField/Select/index.tsx +1 -1
  42. package/src/InputField/Text/index.tsx +2 -2
  43. package/src/Listing/Cell/DataCell.tsx +15 -1
  44. package/src/Listing/Header/ListingHeader.tsx +1 -1
  45. package/src/Listing/Listing.cypress.spec.tsx +2 -2
  46. package/src/Listing/Listing.styles.ts +2 -3
  47. package/src/Listing/index.stories.tsx +14 -3
  48. package/src/Listing/index.tsx +8 -9
  49. package/src/Module/Module.cypress.spec.tsx +129 -0
  50. package/src/Module/index.tsx +2 -4
  51. package/src/RichTextEditor/RichTextEditor.tsx +12 -1
  52. package/src/SortableItems/index.tsx +2 -7
  53. package/src/ThemeProvider/index.tsx +24 -0
  54. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/PickersStartEndDate.tsx +8 -3
  55. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/models.ts +0 -2
  56. package/src/TimePeriods/DateTimePickerInput.tsx +56 -19
  57. package/src/TimePeriods/TimePeriods.cypress.spec.tsx +9 -33
  58. package/src/TimePeriods/helpers/index.ts +1 -1
  59. package/src/TimePeriods/index.stories.tsx +12 -4
  60. package/src/TimePeriods/index.tsx +2 -2
  61. package/src/api/QueryProvider.tsx +1 -1
  62. package/src/api/TestQueryProvider.tsx +1 -1
  63. package/src/api/useFetchQuery/index.ts +27 -23
  64. package/src/api/useMutationQuery/index.ts +45 -21
  65. package/src/components/Button/Icon/IconButton.tsx +6 -2
  66. package/src/components/DataTable/DataListing.tsx +6 -0
  67. package/src/components/DataTable/DataTable.cypress.spec.tsx +193 -0
  68. package/src/components/DataTable/DataTable.stories.tsx +40 -0
  69. package/src/components/DataTable/DataTable.styles.ts +3 -0
  70. package/src/components/DataTable/DataTable.tsx +3 -3
  71. package/src/components/DataTable/Item/DataTableItem.styles.ts +7 -2
  72. package/src/components/DataTable/Item/DataTableItem.tsx +4 -4
  73. package/src/components/DataTable/index.ts +3 -1
  74. package/src/components/Form/AccessRights/__fixtures__/contactAccessRight.mock.ts +2 -0
  75. package/src/components/Form/AccessRights/useAccessRightsForm.utils.ts +1 -1
  76. package/src/components/Form/Dashboard/DashboardForm.tsx +15 -12
  77. package/src/components/Layout/PageLayout/PageLayout.tsx +1 -1
  78. package/src/components/Layout/PageLayout/PageLayoutActions.tsx +1 -0
  79. package/src/components/Layout/PageLayout/PageLayoutBody.tsx +1 -0
  80. package/src/components/Layout/PageLayout/PageLayoutHeader.tsx +5 -1
  81. package/src/components/Layout/PageLayout/PageQuickAccess.tsx +76 -0
  82. package/src/components/Layout/PageLayout/index.ts +3 -1
  83. package/src/components/Layout/PageLayout.cypress.spec.tsx +66 -0
  84. package/src/components/Modal/Modal.styles.ts +4 -3
  85. package/src/components/Modal/ModalActions.tsx +4 -2
  86. package/src/components/Tooltip/ConfirmationTooltip/ConfirmationTooltip.stories.tsx +3 -3
  87. package/src/components/Tooltip/ConfirmationTooltip/ConfirmationTooltip.tsx +1 -1
  88. package/src/components/Tooltip/ConfirmationTooltip/models.ts +1 -1
  89. package/src/index.ts +2 -2
  90. package/src/queryParameters/url/index.ts +5 -1
  91. package/src/utils/index.ts +1 -1
  92. package/src/utils/{useLicenseExpirationWarning.cypress.spec.tsx → useLicenseExpirationWarning.test.tsx} +48 -37
  93. package/src/utils/useLicenseExpirationWarning.ts +18 -18
  94. package/src/utils/usePluralizedTranslation.ts +21 -0
  95. package/src/screens/dashboard/DashboardsDetail.stories.tsx +0 -108
  96. package/src/screens/dashboard/DashboardsOverview.stories.tsx +0 -281
  97. package/src/utils/useDateTimePickerAdapter.ts +0 -309
@@ -1,11 +1,11 @@
1
- import React, { ReactElement, ReactNode } from 'react';
1
+ import { ReactElement, ReactNode } from 'react';
2
2
 
3
3
  import { useStyles } from './DataTable.styles';
4
4
 
5
5
  type DataTableProps = {
6
- children: ReactNode | Array<ReactNode>;
6
+ children?: ReactNode | Array<ReactNode>;
7
7
  isEmpty?: boolean;
8
- variant?: 'grid';
8
+ variant: 'grid' | 'listing';
9
9
  };
10
10
 
11
11
  /** *
@@ -1,13 +1,18 @@
1
1
  import { makeStyles } from 'tss-react/mui';
2
2
 
3
3
  const useStyles = makeStyles()((theme) => ({
4
+ actions: {
5
+ display: 'flex',
6
+ flexDirection: 'row',
7
+ justifyContent: 'space-between'
8
+ },
4
9
  dataTableItem: {
5
10
  '& .MuiCardActionArea-root': {
6
11
  alignItems: 'flex-start',
7
12
  display: 'flex',
8
13
  flexDirection: 'column',
9
14
  height: '100%',
10
- justifyContent: 'space-between'
15
+ justifyContent: 'flex-start'
11
16
  },
12
17
  '& .MuiCardActions-root': {
13
18
  '& > span': {
@@ -15,13 +20,13 @@ const useStyles = makeStyles()((theme) => ({
15
20
  gap: theme.spacing(1)
16
21
  },
17
22
  display: 'flex',
18
-
19
23
  justifyContent: 'space-between'
20
24
  },
21
25
  borderRadius: theme.shape.borderRadius,
22
26
  display: 'flex',
23
27
  flexDirection: 'column',
24
28
  height: '186px',
29
+ justifyContent: 'space-between',
25
30
  p: {
26
31
  color: theme.palette.text.secondary,
27
32
  letterSpacing: '0',
@@ -22,7 +22,7 @@ export interface DataTableItemProps {
22
22
  description?: string;
23
23
  hasActions?: boolean;
24
24
  hasCardAction?: boolean;
25
- labelsDelete: {
25
+ labelsDelete?: {
26
26
  cancel: string;
27
27
  confirm: {
28
28
  label: string;
@@ -76,20 +76,20 @@ const DataTableItem = forwardRef(
76
76
  {hasActions && (
77
77
  <MuiCardActions>
78
78
  <span>
79
- {onDelete && (
79
+ {onDelete && labelsDelete && (
80
80
  <ConfirmationTooltip
81
81
  confirmVariant="error"
82
82
  labels={labelsDelete}
83
83
  onConfirm={onDelete}
84
84
  >
85
- {(openTooltip) => (
85
+ {({ toggleTooltip }) => (
86
86
  <IconButton
87
87
  aria-label="delete"
88
88
  data-testid="delete"
89
89
  icon={<DeleteIcon />}
90
90
  size="small"
91
91
  variant="ghost"
92
- onClick={openTooltip}
92
+ onClick={toggleTooltip}
93
93
  />
94
94
  )}
95
95
  </ConfirmationTooltip>
@@ -2,9 +2,11 @@ import { DataTable as DataTableRoot } from './DataTable';
2
2
  import { DataTableItem } from './Item/DataTableItem';
3
3
  import { DataTableItemSkeleton } from './Item/DataTableItemSkeleton';
4
4
  import { DataTableEmptyState } from './EmptyState/DataTableEmptyState';
5
+ import { DataListing } from './DataListing';
5
6
 
6
7
  export const DataTable = Object.assign(DataTableRoot, {
7
8
  EmptyState: DataTableEmptyState,
8
9
  Item: DataTableItem,
9
- ItemSkeleton: DataTableItemSkeleton
10
+ ItemSkeleton: DataTableItemSkeleton,
11
+ Listing: DataListing
10
12
  });
@@ -7,6 +7,8 @@ import {
7
7
  RoleResource
8
8
  } from '../AccessRights.resource';
9
9
 
10
+ faker.seed(42);
11
+
10
12
  export const rolesMock = (): Array<RoleResource> => [
11
13
  { role: 'viewer' },
12
14
  { role: 'editor' }
@@ -36,6 +36,6 @@ export const createInitialState = (
36
36
  contactAccessRight,
37
37
  state: 'unchanged',
38
38
  stateHistory: []
39
- } as ContactAccessRightStateResource)
39
+ }) as ContactAccessRightStateResource
40
40
  )
41
41
  .sort(sortOnAddedStateFirstAndContactName);
@@ -1,7 +1,8 @@
1
1
  import { ReactElement, useCallback, useMemo } from 'react';
2
2
 
3
- import * as Yup from 'yup';
3
+ import { string, number, object } from 'yup';
4
4
  import { useTranslation } from 'react-i18next';
5
+ import { equals } from 'ramda';
5
6
 
6
7
  import { InputType } from '../../../Form/Inputs/models';
7
8
  import { Form, FormProps } from '../../../Form';
@@ -84,8 +85,8 @@ const DashboardForm = ({
84
85
  }
85
86
  ],
86
87
  submit: (values, bag) => onSubmit?.(values, bag),
87
- validationSchema: Yup.object().shape({
88
- description: Yup.string()
88
+ validationSchema: object({
89
+ description: string()
89
90
  .label(labels?.entity?.description || '')
90
91
  .max(
91
92
  180,
@@ -93,17 +94,19 @@ const DashboardForm = ({
93
94
  `${p.label} ${t(labelMustBeMost)} ${p.max} ${t(labelCharacters)}`
94
95
  )
95
96
  .nullable(),
96
- globalRefreshInterval: Yup.object().shape({
97
- interval: Yup.number().when('type', {
98
- is: 'global',
99
- otherwise: Yup.number().nullable(),
100
- then: Yup.number()
101
- .min(1, ({ min }) => t(labelMustBeAtLeast, { min }))
102
- .required(t(labelRequired) as string)
97
+ globalRefreshInterval: object({
98
+ interval: number().when('type', ([type], schema) => {
99
+ if (equals(type, 'manual')) {
100
+ schema
101
+ .min(1, ({ min }) => t(labelMustBeAtLeast, { min }))
102
+ .required(t(labelRequired) as string);
103
+ }
104
+
105
+ return schema.nullable();
103
106
  }),
104
- type: Yup.string()
107
+ type: string()
105
108
  }),
106
- name: Yup.string()
109
+ name: string()
107
110
  .label(labels?.entity?.name)
108
111
  .min(3, ({ min, label }) => t(labelMustBeAtLeast, { label, min }))
109
112
  .max(50, ({ max, label }) => t(labelMustBeMost, { label, max }))
@@ -14,7 +14,7 @@ export const PageLayout = ({
14
14
  const { classes } = useStyles();
15
15
 
16
16
  return (
17
- <section className={classes.pageLayout} data-variant={variant}>
17
+ <section className={classes.pageLayout} data-variant={variant} id="page">
18
18
  {children}
19
19
  </section>
20
20
  );
@@ -17,6 +17,7 @@ export const PageLayoutActions = ({
17
17
  <section
18
18
  className={classes.pageLayoutActions}
19
19
  data-row-reverse={rowReverse}
20
+ id="actions"
20
21
  >
21
22
  {children}
22
23
  </section>
@@ -17,6 +17,7 @@ export const PageLayoutBody = ({
17
17
  <section
18
18
  className={classes.pageLayoutBody}
19
19
  data-has-background={hasBackground}
20
+ id="page-body"
20
21
  >
21
22
  {children}
22
23
  </section>
@@ -11,5 +11,9 @@ export const PageLayoutHeader = ({
11
11
  }: PageLayoutHeaderProps): JSX.Element => {
12
12
  const { classes } = useStyles();
13
13
 
14
- return <header className={classes.pageLayoutHeader}>{children}</header>;
14
+ return (
15
+ <header className={classes.pageLayoutHeader} id="header">
16
+ {children}
17
+ </header>
18
+ );
15
19
  };
@@ -0,0 +1,76 @@
1
+ import { useTranslation } from 'react-i18next';
2
+
3
+ import AddIcon from '@mui/icons-material/Add';
4
+ import ArrowBackIcon from '@mui/icons-material/ArrowBack';
5
+
6
+ import { Button, Menu } from '../..';
7
+
8
+ interface NamedEntity {
9
+ id: number | string;
10
+ name: string;
11
+ }
12
+
13
+ type Props = {
14
+ create: () => void;
15
+ elements: Array<NamedEntity>;
16
+ goBack: () => void;
17
+ isActive: (id: number | string) => boolean;
18
+ labels: {
19
+ create: string;
20
+ goBack: string;
21
+ };
22
+ navigateToElement: (id: number | string) => () => void;
23
+ };
24
+
25
+ export const PageQuickAccess = ({
26
+ elements,
27
+ isActive,
28
+ navigateToElement,
29
+ goBack,
30
+ create,
31
+ labels
32
+ }: Props): JSX.Element => {
33
+ const { t } = useTranslation();
34
+
35
+ return (
36
+ <Menu>
37
+ <Menu.Button data-testid="quickaccess" />
38
+ <Menu.Items>
39
+ {elements &&
40
+ elements.map((element) => (
41
+ <Menu.Item
42
+ key={`${element.id}`}
43
+ onClick={navigateToElement(element.id)}
44
+ {...(isActive(element.id) && {
45
+ isActive: true,
46
+ isDisabled: true
47
+ })}
48
+ >
49
+ {element.name}
50
+ </Menu.Item>
51
+ ))}
52
+ <Menu.Divider key="divider" />
53
+ <Menu.Item key="create">
54
+ <>
55
+ <Button
56
+ icon={<ArrowBackIcon />}
57
+ iconVariant="start"
58
+ variant="ghost"
59
+ onClick={goBack}
60
+ >
61
+ {t(labels.goBack)}
62
+ </Button>
63
+ <Button
64
+ icon={<AddIcon />}
65
+ iconVariant="start"
66
+ variant="secondary"
67
+ onClick={create}
68
+ >
69
+ {t(labels.create)}
70
+ </Button>
71
+ </>
72
+ </Menu.Item>
73
+ </Menu.Items>
74
+ </Menu>
75
+ );
76
+ };
@@ -2,9 +2,11 @@ import { PageLayout as PageLayoutRoot } from './PageLayout';
2
2
  import { PageLayoutHeader } from './PageLayoutHeader';
3
3
  import { PageLayoutBody } from './PageLayoutBody';
4
4
  import { PageLayoutActions } from './PageLayoutActions';
5
+ import { PageQuickAccess } from './PageQuickAccess';
5
6
 
6
7
  export const PageLayout = Object.assign(PageLayoutRoot, {
7
8
  Actions: PageLayoutActions,
8
9
  Body: PageLayoutBody,
9
- Header: PageLayoutHeader
10
+ Header: PageLayoutHeader,
11
+ QuickAccess: PageQuickAccess
10
12
  });
@@ -0,0 +1,66 @@
1
+ import { T } from 'ramda';
2
+
3
+ import { PageHeader } from '..';
4
+
5
+ import { AreaIndicator } from './AreaIndicator';
6
+
7
+ import { PageLayout } from '.';
8
+
9
+ const initialize = (): void => {
10
+ cy.mount({
11
+ Component: (
12
+ <PageLayout>
13
+ <PageLayout.Header>
14
+ <PageHeader>
15
+ <PageHeader.Menu>
16
+ <PageLayout.QuickAccess
17
+ create={cy.stub()}
18
+ elements={[
19
+ {
20
+ id: 1,
21
+ name: 'Entity'
22
+ }
23
+ ]}
24
+ goBack={cy.stub()}
25
+ isActive={T}
26
+ labels={{
27
+ create: 'Create',
28
+ goBack: 'Go back'
29
+ }}
30
+ navigateToElement={cy.stub()}
31
+ />
32
+ </PageHeader.Menu>
33
+ <PageHeader.Main>
34
+ <PageHeader.Title description="Description" title="Title" />
35
+ </PageHeader.Main>
36
+ <PageHeader.Actions>Actions</PageHeader.Actions>
37
+ </PageHeader>
38
+ </PageLayout.Header>
39
+ <PageLayout.Body>
40
+ <PageLayout.Actions>
41
+ <AreaIndicator name="Body actions" />
42
+ </PageLayout.Actions>
43
+ <h1>Content</h1>
44
+ </PageLayout.Body>
45
+ </PageLayout>
46
+ )
47
+ });
48
+ };
49
+
50
+ describe('Page layout', () => {
51
+ beforeEach(initialize);
52
+
53
+ it('displays the page layout', () => {
54
+ cy.makeSnapshot();
55
+ });
56
+
57
+ it('opens the quick access poppin when the corresponding logo is displayed', () => {
58
+ cy.findByTestId('quickaccess').click();
59
+
60
+ cy.contains('Entity').should('be.visible');
61
+ cy.contains('Create').should('be.visible');
62
+ cy.contains('Go back').should('be.visible');
63
+
64
+ cy.makeSnapshot();
65
+ });
66
+ });
@@ -49,14 +49,15 @@ const useStyles = makeStyles<{
49
49
  }
50
50
  },
51
51
  modalActions: {
52
- bottom: 0,
52
+ '&[data-fixed="true"]': {
53
+ position: 'fixed'
54
+ },
53
55
  bottom: theme.spacing(2),
54
56
  display: 'flex',
55
57
  flexDirection: 'row',
56
58
  gap: theme.spacing(2),
57
59
  justifyContent: 'flex-end',
58
- position: 'fixed',
59
- right: theme.spacing(2)
60
+ right: theme.spacing(2.5)
60
61
  },
61
62
  modalBody: {
62
63
  '& > p': {
@@ -8,6 +8,7 @@ export type ModalActionsProps = {
8
8
  children?: React.ReactNode;
9
9
  disabled?: boolean;
10
10
  isDanger?: boolean;
11
+ isFixed?: boolean;
11
12
  labels?: ModalActionsLabels;
12
13
  onCancel?: () => void;
13
14
  onConfirm?: () => void;
@@ -24,12 +25,13 @@ const ModalActions = ({
24
25
  onCancel,
25
26
  onConfirm,
26
27
  isDanger = false,
27
- disabled
28
+ disabled,
29
+ isFixed
28
30
  }: ModalActionsProps): ReactElement => {
29
31
  const { classes } = useStyles();
30
32
 
31
33
  return (
32
- <div className={classes.modalActions}>
34
+ <div className={classes.modalActions} data-fixed={isFixed}>
33
35
  {children || (
34
36
  <>
35
37
  <Button
@@ -15,7 +15,7 @@ type Story = StoryObj<typeof ConfirmationTooltip>;
15
15
 
16
16
  export const Default: Story = {
17
17
  args: {
18
- children: (toggleTooltip) => (
18
+ children: ({ toggleTooltip }) => (
19
19
  <IconButton icon={<SaveIcon />} onClick={toggleTooltip} />
20
20
  ),
21
21
  labels: {
@@ -30,7 +30,7 @@ export const Default: Story = {
30
30
 
31
31
  export const WithConfirmVariant: Story = {
32
32
  args: {
33
- children: (toggleTooltip) => (
33
+ children: ({ toggleTooltip }) => (
34
34
  <IconButton icon={<DeleteIcon color="error" />} onClick={toggleTooltip} />
35
35
  ),
36
36
  confirmVariant: 'error',
@@ -46,7 +46,7 @@ export const WithConfirmVariant: Story = {
46
46
 
47
47
  export const WithSecondaryLabel: Story = {
48
48
  args: {
49
- children: (toggleTooltip) => (
49
+ children: ({ toggleTooltip }) => (
50
50
  <IconButton icon={<DeleteIcon color="error" />} onClick={toggleTooltip} />
51
51
  ),
52
52
  confirmVariant: 'error',
@@ -49,7 +49,7 @@ export const ConfirmationTooltip = ({
49
49
  return (
50
50
  <ClickAwayListener onClickAway={close}>
51
51
  <div>
52
- {children(isOpen ? close : open)}
52
+ {children({ isOpen, toggleTooltip: isOpen ? close : open })}
53
53
  <Popper
54
54
  anchorEl={anchorElement}
55
55
  className={classes.popper}
@@ -11,7 +11,7 @@ interface Labels {
11
11
  }
12
12
 
13
13
  export interface Props {
14
- children: (toggleTooltip) => ReactElement;
14
+ children: ({ toggleTooltip, isOpen }) => ReactElement;
15
15
  confirmVariant?: ActionVariants;
16
16
  labels: Labels;
17
17
  onConfirm: () => void;
package/src/index.ts CHANGED
@@ -162,8 +162,8 @@ export * from './Graph/common/timeSeries';
162
162
 
163
163
  export { default as TimePeriods } from './TimePeriods';
164
164
  export { default as SimpleCustomTimePeriod } from './TimePeriods/CustomTimePeriod/SimpleCustomTimePeriod';
165
+ export { default as DateTimePickerInput } from './TimePeriods/DateTimePickerInput';
165
166
  export * from './ParentSize';
166
-
167
+ export { default as Subtitle } from './Typography/Subtitle';
167
168
  export { default as TablePagination } from './Listing/ActionBar/Pagination';
168
169
  export { default as PaginationActions } from './Listing/ActionBar/PaginationActions';
169
- export { default as Subtitle } from './Typography/Subtitle';
@@ -1,4 +1,4 @@
1
- import { fromPairs } from 'ramda';
1
+ import { fromPairs, startsWith } from 'ramda';
2
2
 
3
3
  import { QueryParameter } from '../models';
4
4
 
@@ -25,6 +25,10 @@ const getUrlQueryParameters = <
25
25
 
26
26
  const entries = [...urlParams.entries()].map<[string, string]>(
27
27
  ([key, value]) => {
28
+ if (startsWith('/', value)) {
29
+ return [key, value];
30
+ }
31
+
28
32
  return [key, JSON.parse(value)];
29
33
  }
30
34
  );
@@ -3,7 +3,6 @@ export * from './getNormalizedId';
3
3
  export * from './statuses';
4
4
  export * from './typedMemo';
5
5
  export * from './useCopyToClipboard';
6
- export * from './useDateTimePickerAdapter';
7
6
  export * from './useDebounce';
8
7
  export * from './useDeepCallback';
9
8
  export * from './useDeepMemo';
@@ -20,3 +19,4 @@ export * from './useInfiniteScrollListing';
20
19
  export * from './useLicenseExpirationWarning';
21
20
  export * from './useRefreshInterval';
22
21
  export * from './centreonBaseURL';
22
+ export * from './usePluralizedTranslation';
@@ -1,6 +1,13 @@
1
1
  import dayjs from 'dayjs';
2
+ import { renderHook } from '@testing-library/react';
2
3
 
3
- import { TestQueryProvider, Method, SnackbarProvider } from '@centreon/ui';
4
+ import {
5
+ getFetchCall,
6
+ mockResponse,
7
+ resetMocks,
8
+ waitFor
9
+ } from '../../test/testRenderer';
10
+ import TestQueryProvider from '../api/TestQueryProvider';
4
11
 
5
12
  import { labelLicenseWarning } from './translatedLabel';
6
13
 
@@ -79,59 +86,63 @@ const getMockedResponse = (expirationDate): object => ({
79
86
  });
80
87
 
81
88
  const mockRequest = ({ expirationDate }: { expirationDate }): void => {
82
- cy.interceptAPIRequest({
83
- alias: 'getLicenseInformations',
84
- method: Method.GET,
85
- path: '**internal.php?object=centreon_module&action=list',
86
- response: getMockedResponse(expirationDate)
89
+ resetMocks();
90
+ mockResponse({
91
+ data: getMockedResponse(expirationDate)
87
92
  });
88
93
  };
89
94
 
90
- const TestComponent = (): JSX.Element => {
91
- useLicenseExpirationWarning({
92
- module: 'centreon-autodiscovery-server'
93
- });
95
+ const showMessage = jest.fn();
94
96
 
95
- return <div />;
96
- };
97
-
98
- const TestWithQueryProvider = (): JSX.Element => {
99
- return (
100
- <TestQueryProvider>
101
- <SnackbarProvider>
102
- <TestComponent />
103
- </SnackbarProvider>
104
- </TestQueryProvider>
105
- );
106
- };
97
+ jest.mock('../Snackbar/useSnackbar', () => ({
98
+ __esModule: true,
99
+ default: jest
100
+ .fn()
101
+ .mockImplementation(() => ({ showWarningMessage: showMessage }))
102
+ }));
107
103
 
108
104
  const initialize = (): void => {
109
- cy.viewport('macbook-13');
110
-
111
- cy.mount({
112
- Component: <TestWithQueryProvider />
113
- });
105
+ renderHook(
106
+ () =>
107
+ useLicenseExpirationWarning({
108
+ module: 'centreon-autodiscovery-server'
109
+ }),
110
+ {
111
+ wrapper: TestQueryProvider
112
+ }
113
+ );
114
114
  };
115
115
 
116
116
  const currentDate = dayjs();
117
117
 
118
118
  describe('License', () => {
119
- beforeEach(initialize);
120
-
121
119
  it('does not display any warning message when the license expires in more than 15 days from the current date', () => {
122
120
  mockRequest({ expirationDate: currentDate.add(20, 'day') });
121
+ initialize();
123
122
 
124
- cy.waitForRequest('@getLicenseInformations');
123
+ waitFor(() => {
124
+ expect(getFetchCall(0)).toEqual(
125
+ 'internal.php?object=centreon_module&action=list'
126
+ );
127
+ });
125
128
 
126
- cy.findByText(
127
- labelLicenseWarning('centreon-autodiscovery-server', 20)
128
- ).should('not.exist');
129
+ expect(showMessage).not.toHaveBeenCalled();
129
130
  });
131
+
130
132
  it('displays a warning message when the license expires within 15 days', () => {
131
133
  mockRequest({ expirationDate: currentDate.add(10.5, 'day') });
132
-
133
- cy.findByText(labelLicenseWarning('centreon-autodiscovery-server', 10));
134
-
135
- cy.makeSnapshot();
134
+ initialize();
135
+
136
+ waitFor(() => {
137
+ expect(getFetchCall(0)).toEqual(
138
+ 'internal.php?object=centreon_module&action=list'
139
+ );
140
+ });
141
+
142
+ waitFor(() => {
143
+ expect(showMessage).toHaveBeenCalledWith(
144
+ labelLicenseWarning('centreon-autodiscovery-server', 10)
145
+ );
146
+ });
136
147
  });
137
148
  });
@@ -19,7 +19,7 @@ export const useLicenseExpirationWarning = ({ module }: Props): void => {
19
19
  const { t } = useTranslation();
20
20
  const { showWarningMessage } = useSnackbar();
21
21
 
22
- const { fetchQuery } = useFetchQuery({
22
+ const { data } = useFetchQuery({
23
23
  getEndpoint: () => extensionsEndpoint,
24
24
  getQueryKey: () => [module]
25
25
  });
@@ -28,25 +28,25 @@ export const useLicenseExpirationWarning = ({ module }: Props): void => {
28
28
 
29
29
  const getExpirationDate = pipe(
30
30
  path(['result', 'module', 'entities']),
31
- find(propEq('id', module)),
31
+ find(propEq(module, 'id')),
32
32
  path(['license', 'expiration_date'])
33
33
  ) as (data) => string;
34
34
 
35
35
  useEffect(() => {
36
- fetchQuery().then((response) => {
37
- const expirationDate = getExpirationDate(response);
38
- if (isNil(expirationDate)) {
39
- return;
40
- }
41
-
42
- const daysUntilExpiration = dayjs(expirationDate).diff(
43
- currentDate,
44
- 'day'
45
- );
46
-
47
- if (lt(daysUntilExpiration, 15)) {
48
- showWarningMessage(t(labelLicenseWarning(module, daysUntilExpiration)));
49
- }
50
- });
51
- }, []);
36
+ if (isNil(data)) {
37
+ return;
38
+ }
39
+
40
+ const expirationDate = getExpirationDate(data);
41
+
42
+ if (isNil(expirationDate)) {
43
+ return;
44
+ }
45
+
46
+ const daysUntilExpiration = dayjs(expirationDate).diff(currentDate, 'day');
47
+
48
+ if (lt(daysUntilExpiration, 15)) {
49
+ showWarningMessage(t(labelLicenseWarning(module, daysUntilExpiration)));
50
+ }
51
+ }, [data]);
52
52
  };