@centreon/ui 23.10.22-MON-19195-save-dashboard-changes.3 → 23.10.22-MON-19279-implement-e2e-tests-from-create-a-new-dashboard.3

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.22-MON-19195-save-dashboard-changes.3",
3
+ "version": "23.10.22-MON-19279-implement-e2e-tests-from-create-a-new-dashboard.3",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
@@ -1,4 +1,4 @@
1
- import { ComponentStory } from '@storybook/react';
1
+ import { ComponentMeta, ComponentStory } from '@storybook/react';
2
2
  import { makeStyles } from 'tss-react/mui';
3
3
 
4
4
  import { Theme } from '@mui/material';
@@ -13,7 +13,7 @@ const useStyles = makeStyles()((theme: Theme) => ({
13
13
  }
14
14
  }));
15
15
 
16
- const meta = {
16
+ export default {
17
17
  argTypes: {
18
18
  labelLoading: { control: 'text' },
19
19
  labelSave: { control: 'text' },
@@ -26,13 +26,8 @@ const meta = {
26
26
 
27
27
  component: ButtonSave,
28
28
 
29
- parameters: {
30
- chromatic: { delay: 300 }
31
- },
32
29
  title: 'Button/Save'
33
- };
34
-
35
- export default meta;
30
+ } as ComponentMeta<typeof ButtonSave>;
36
31
 
37
32
  const TemplateButtonSave: ComponentStory<typeof ButtonSave> = (args) => (
38
33
  <ButtonSave {...args} />
@@ -47,7 +42,7 @@ export const loading = (): JSX.Element => <ButtonSave loading />;
47
42
  export const succeeded = (): JSX.Element => <ButtonSave succeeded />;
48
43
 
49
44
  export const normalWithText = (): JSX.Element => (
50
- <ButtonSave labelSave="Save" size="medium" />
45
+ <ButtonSave labelSave="Save" />
51
46
  );
52
47
 
53
48
  export const largeWithText = (): JSX.Element => (
@@ -55,7 +50,7 @@ export const largeWithText = (): JSX.Element => (
55
50
  );
56
51
 
57
52
  export const loadingWithTextAndMediumSize = (): JSX.Element => (
58
- <ButtonSave loading labelLoading="Loading" size="medium" />
53
+ <ButtonSave loading labelLoading="Loading" />
59
54
  );
60
55
 
61
56
  export const succeededWithText = (): JSX.Element => (
@@ -17,7 +17,6 @@ const useStyles = makeStyles()((theme: Theme) => ({
17
17
 
18
18
  interface Props extends Record<string, unknown> {
19
19
  className?: string;
20
- hasStartIcon?: boolean;
21
20
  labelLoading?: string;
22
21
  labelSave?: string;
23
22
  labelSucceeded?: string;
@@ -46,7 +45,6 @@ const SaveButton = ({
46
45
  labelSave = '',
47
46
  size = 'small',
48
47
  className,
49
- hasStartIcon = true,
50
48
  ...rest
51
49
  }: Props): JSX.Element => {
52
50
  const { classes, cx } = useStyles();
@@ -62,21 +60,20 @@ const SaveButton = ({
62
60
  <Tooltip placement="bottom" title={tooltipLabel}>
63
61
  <div>
64
62
  <LoadingButton
65
- aria-label={labelSave}
63
+ aria-label="save button"
66
64
  className={cx(
67
65
  {
68
66
  [classes.loadingButton]: !hasLabel
69
67
  },
70
68
  className
71
69
  )}
70
+ color="primary"
72
71
  data-testid={labelSave}
73
72
  id={getNormalizedId(labelSave)}
74
73
  loading={loading}
75
- loadingPosition={labelLoading && hasStartIcon ? 'start' : 'center'}
74
+ loadingPosition={labelLoading ? 'start' : 'center'}
76
75
  size={size}
77
- startIcon={
78
- hasStartIcon && <StartIcon startIconConfig={startIconConfig} />
79
- }
76
+ startIcon={<StartIcon startIconConfig={startIconConfig} />}
80
77
  variant="contained"
81
78
  {...rest}
82
79
  >
@@ -2,69 +2,67 @@ import { makeStyles } from 'tss-react/mui';
2
2
 
3
3
  import { alpha } from '@mui/material';
4
4
 
5
- export const useDashboardLayoutStyles = makeStyles<boolean>()(
6
- (theme, isStatic: boolean) => ({
7
- container: {
8
- '& .react-grid-item': {
9
- borderRadius: theme.shape.borderRadius,
10
- transition: theme.transitions.create('all', {
11
- delay: 0,
12
- duration: 100,
13
- easing: theme.transitions.easing.easeOut
14
- })
15
- },
16
- '& .react-grid-item.react-draggable-dragging': {
17
- boxShadow: theme.shadows[3]
18
- },
19
- '& .react-grid-item.react-grid-placeholder': {
20
- backgroundColor: alpha(theme.palette.primary.main, 0.7)
21
- },
22
- '& .react-grid-item.resizing': {
23
- boxShadow: theme.shadows[3]
24
- },
25
- '& .react-resizable-handle': {
26
- backgroundColor: theme.palette.action.focus,
27
- backgroundImage: 'none',
28
- borderRadius: theme.shape.borderRadius,
29
- display: isStatic ? 'none' : 'block',
30
- opacity: 0,
31
- position: 'absolute'
32
- },
33
- '& .react-resizable-handle.react-resizable-handle-e': {
34
- cursor: 'ew-resize',
35
- height: `calc(100% - ${theme.spacing(3)})`,
36
- marginTop: 0,
37
- right: 0,
38
- top: 0,
39
- transform: 'rotate(0deg)',
40
- width: theme.spacing(1)
41
- },
42
- '& .react-resizable-handle.react-resizable-handle-s': {
43
- bottom: 0,
44
- cursor: 'ns-resize',
45
- height: theme.spacing(1),
46
- left: 0,
47
- marginLeft: 0,
48
- transform: 'rotate(0deg)',
49
- width: `calc(100% - ${theme.spacing(3)})`
50
- },
51
- '& .react-resizable-handle.react-resizable-handle-se': {
52
- bottom: 0,
53
- cursor: 'nwse-resize',
54
- height: theme.spacing(2),
55
- right: 0,
56
- transform: 'rotate(0deg)',
57
- width: theme.spacing(2)
58
- },
59
- '& .react-resizable-handle::after': {
60
- content: 'none'
61
- },
62
- '& .react-resizable-handle:hover': {
63
- opacity: 1
64
- }
5
+ export const useDashboardLayoutStyles = makeStyles()((theme) => ({
6
+ container: {
7
+ '& .react-grid-item': {
8
+ borderRadius: theme.shape.borderRadius,
9
+ transition: theme.transitions.create('all', {
10
+ delay: 0,
11
+ duration: 100,
12
+ easing: theme.transitions.easing.easeOut
13
+ })
14
+ },
15
+ '& .react-grid-item.react-draggable-dragging': {
16
+ boxShadow: theme.shadows[3]
17
+ },
18
+ '& .react-grid-item.react-grid-placeholder': {
19
+ backgroundColor: alpha(theme.palette.primary.main, 0.7)
20
+ },
21
+ '& .react-grid-item.resizing': {
22
+ boxShadow: theme.shadows[3]
23
+ },
24
+ '& .react-resizable-handle': {
25
+ backgroundColor: theme.palette.action.focus,
26
+ backgroundImage: 'none',
27
+ borderRadius: theme.shape.borderRadius,
28
+ display: 'block',
29
+ opacity: 0,
30
+ position: 'absolute'
31
+ },
32
+ '& .react-resizable-handle.react-resizable-handle-e': {
33
+ cursor: 'ew-resize',
34
+ height: `calc(100% - ${theme.spacing(3)})`,
35
+ marginTop: 0,
36
+ right: 0,
37
+ top: 0,
38
+ transform: 'rotate(0deg)',
39
+ width: theme.spacing(1)
40
+ },
41
+ '& .react-resizable-handle.react-resizable-handle-s': {
42
+ bottom: 0,
43
+ cursor: 'ns-resize',
44
+ height: theme.spacing(1),
45
+ left: 0,
46
+ marginLeft: 0,
47
+ transform: 'rotate(0deg)',
48
+ width: `calc(100% - ${theme.spacing(3)})`
49
+ },
50
+ '& .react-resizable-handle.react-resizable-handle-se': {
51
+ bottom: 0,
52
+ cursor: 'nwse-resize',
53
+ height: theme.spacing(2),
54
+ right: 0,
55
+ transform: 'rotate(0deg)',
56
+ width: theme.spacing(2)
57
+ },
58
+ '& .react-resizable-handle::after': {
59
+ content: 'none'
60
+ },
61
+ '& .react-resizable-handle:hover': {
62
+ opacity: 1
65
63
  }
66
- })
67
- );
64
+ }
65
+ }));
68
66
 
69
67
  export const useDashboardItemStyles = makeStyles()((theme) => ({
70
68
  widgetContainer: {
@@ -1,4 +1,4 @@
1
- import { useMemo, ReactElement } from 'react';
1
+ import { ReactElement, useMemo } from 'react';
2
2
 
3
3
  import { Grid as VisxGrid } from '@visx/visx';
4
4
  import { scaleLinear } from '@visx/scale';
@@ -18,7 +18,7 @@ interface DashboardItemProps {
18
18
  children: ReactElement;
19
19
  className?: string;
20
20
  header?: ReactElement;
21
- id: string;
21
+ key: string;
22
22
  onMouseDown?: (e: MouseEvent<HTMLDivElement>) => void;
23
23
  onMouseUp?: (e: MouseEvent<HTMLDivElement>) => void;
24
24
  onTouchEnd?: (e) => void;
@@ -29,13 +29,13 @@ const Item = forwardRef(
29
29
  (
30
30
  {
31
31
  children,
32
+ key,
32
33
  style,
33
34
  className,
34
35
  header,
35
36
  onMouseDown,
36
37
  onMouseUp,
37
- onTouchEnd,
38
- id
38
+ onTouchEnd
39
39
  }: DashboardItemProps,
40
40
  ref: ForwardedRef<HTMLDivElement>
41
41
  ): ReactElement => {
@@ -55,17 +55,14 @@ const Item = forwardRef(
55
55
  Component: (
56
56
  <div
57
57
  className={className}
58
+ key={key}
58
59
  ref={ref}
59
60
  style={style}
60
61
  {...cardContainerListeners}
61
62
  >
62
63
  <Card className={classes.widgetContainer}>
63
64
  {header && (
64
- <div
65
- {...listeners}
66
- className={classes.widgetHeader}
67
- data-testid={`${id}_move_panel`}
68
- >
65
+ <div {...listeners} className={classes.widgetHeader}>
69
66
  {header}
70
67
  </div>
71
68
  )}
@@ -73,7 +70,7 @@ const Item = forwardRef(
73
70
  </Card>
74
71
  </div>
75
72
  ),
76
- memoProps: [style, className, header]
73
+ memoProps: [key, style, className, header]
77
74
  });
78
75
  }
79
76
  );
@@ -1,4 +1,4 @@
1
- import { ReactElement, ReactNode, useMemo } from 'react';
1
+ import React, { ReactElement, ReactNode, useMemo } from 'react';
2
2
 
3
3
  import { Button as MuiButton } from '@mui/material';
4
4
 
@@ -59,7 +59,6 @@ const DataTableItem = forwardRef(
59
59
  <MuiCardActions>
60
60
  <IconButton
61
61
  aria-label="edit"
62
- data-testid="edit"
63
62
  icon={<EditIcon />}
64
63
  size="small"
65
64
  variant="primary"
@@ -67,7 +66,6 @@ const DataTableItem = forwardRef(
67
66
  />
68
67
  <IconButton
69
68
  aria-label="delete"
70
- data-testid="dashboard-delete"
71
69
  icon={<DeleteIcon />}
72
70
  size="small"
73
71
  variant="ghost"
@@ -1,4 +1,4 @@
1
1
  export type DashboardResource = {
2
- description?: string | null;
2
+ description?: string;
3
3
  name: string;
4
4
  };
@@ -11,8 +11,7 @@ import { useStyles } from './DashboardForm.styles';
11
11
  import {
12
12
  labelMustBeAtLeast,
13
13
  labelMustBeMost,
14
- labelRequired,
15
- labelCharacters
14
+ labelRequired
16
15
  } from './translatedLabels';
17
16
  import {
18
17
  DashboardFormActions,
@@ -44,7 +43,7 @@ const DashboardForm = ({
44
43
 
45
44
  const formProps = useMemo<FormProps<DashboardResource>>(
46
45
  () => ({
47
- initialValues: resource ?? { description: null, name: '' },
46
+ initialValues: resource ?? { name: '' },
48
47
  inputs: [
49
48
  {
50
49
  fieldName: 'name',
@@ -56,7 +55,7 @@ const DashboardForm = ({
56
55
  {
57
56
  fieldName: 'description',
58
57
  group: 'main',
59
- label: labels?.entity?.description || '',
58
+ label: labels?.entity?.description,
60
59
  text: {
61
60
  multilineRows: 3
62
61
  },
@@ -66,12 +65,9 @@ const DashboardForm = ({
66
65
  submit: (values, bag) => onSubmit?.(values, bag),
67
66
  validationSchema: Yup.object().shape({
68
67
  description: Yup.string()
69
- .label(labels?.entity?.description || '')
70
- .max(
71
- 180,
72
- (p) =>
73
- `${p.label} ${t(labelMustBeMost)} ${p.max} ${t(labelCharacters)}`
74
- )
68
+ .label(labels?.entity?.description)
69
+ .max(180, ({ max, label }) => t(labelMustBeMost, { label, max }))
70
+ .optional()
75
71
  .nullable(),
76
72
  name: Yup.string()
77
73
  .label(labels?.entity?.name)
@@ -3,4 +3,3 @@ export const labelMustBeMost = '{{label}} can be at most {{max}} characters';
3
3
  export const labelMustBeAtLeast =
4
4
  '{{label}} should be at least {{min}} characters long';
5
5
  export const labelRequired = 'Required';
6
- export const labelCharacters = 'characters';
@@ -1,4 +1,4 @@
1
- import { ReactElement, ReactNode } from 'react';
1
+ import React, { ReactElement, ReactNode } from 'react';
2
2
 
3
3
  import { Typography as MuiTypography } from '@mui/material';
4
4
 
@@ -13,10 +13,7 @@ const meta: Meta<typeof Modal> = {
13
13
  options: ['small', 'medium', 'large']
14
14
  }
15
15
  },
16
- component: Modal,
17
- parameters: {
18
- chromatic: { delay: 300 }
19
- }
16
+ component: Modal
20
17
  };
21
18
 
22
19
  export default meta;
@@ -40,35 +37,7 @@ export const Default: Story = {
40
37
  <Modal.Actions
41
38
  labels={{
42
39
  cancel: 'Cancel',
43
- confirm: 'Confirm',
44
- loading: 'Loading'
45
- }}
46
- />
47
- </Modal>
48
- )
49
- };
50
-
51
- export const DefaultWithLoading: Story = {
52
- args: {
53
- hasCloseButton: true,
54
- open: true,
55
- size: 'small'
56
- },
57
- render: (args) => (
58
- <Modal {...args}>
59
- <Modal.Header>Modal title</Modal.Header>
60
- <Modal.Body>
61
- <p>
62
- Occaecat consectetur amet officia magna. Eu sunt aute duis duis cillum
63
- irure mollit ex aute excepteur eu id cillum.
64
- </p>
65
- </Modal.Body>
66
- <Modal.Actions
67
- isLoading
68
- labels={{
69
- cancel: 'Cancel',
70
- confirm: 'Confirm',
71
- loading: 'Loading'
40
+ confirm: 'Confirm'
72
41
  }}
73
42
  />
74
43
  </Modal>
@@ -93,35 +62,7 @@ export const AsDangerAction: Story = {
93
62
  isDanger
94
63
  labels={{
95
64
  cancel: 'Cancel',
96
- confirm: 'Confirm',
97
- loading: 'Loading'
98
- }}
99
- />
100
- </Modal>
101
- )
102
- };
103
-
104
- export const AsDangerActionWithLoading: Story = {
105
- args: {
106
- ...Default.args
107
- },
108
- render: (args) => (
109
- <Modal {...args}>
110
- <Modal.Body>
111
- <Modal.Body>
112
- <p>
113
- Occaecat consectetur amet <strong>officia magna</strong>. Eu sunt
114
- aute duis duis cillum irure mollit ex aute excepteur eu id cillum.
115
- </p>
116
- </Modal.Body>
117
- </Modal.Body>
118
- <Modal.Actions
119
- isDanger
120
- isLoading
121
- labels={{
122
- cancel: 'Cancel',
123
- confirm: 'Confirm',
124
- loading: 'Loading'
65
+ confirm: 'Confirm'
125
66
  }}
126
67
  />
127
68
  </Modal>
@@ -1,14 +1,12 @@
1
1
  import React, { ReactElement } from 'react';
2
2
 
3
3
  import { Button } from '../Button';
4
- import { SaveButton } from '../..';
5
4
 
6
5
  import { useStyles } from './Modal.styles';
7
6
 
8
7
  export type ModalActionsProps = {
9
8
  children?: React.ReactNode;
10
9
  isDanger?: boolean;
11
- isLoading?: boolean;
12
10
  labels?: ModalActionsLabels;
13
11
  onCancel?: () => void;
14
12
  onConfirm?: () => void;
@@ -17,7 +15,6 @@ export type ModalActionsProps = {
17
15
  export type ModalActionsLabels = {
18
16
  cancel: string;
19
17
  confirm: string;
20
- loading: string;
21
18
  };
22
19
 
23
20
  const ModalActions = ({
@@ -25,8 +22,7 @@ const ModalActions = ({
25
22
  labels,
26
23
  onCancel,
27
24
  onConfirm,
28
- isDanger = false,
29
- isLoading = false
25
+ isDanger = false
30
26
  }: ModalActionsProps): ReactElement => {
31
27
  const { classes } = useStyles();
32
28
 
@@ -35,26 +31,23 @@ const ModalActions = ({
35
31
  {children || (
36
32
  <>
37
33
  <Button
38
- aria-label={labels?.cancel}
39
- data-testid="cancel_confirmation"
40
- disabled={isLoading}
34
+ aria-label="cancel"
41
35
  size="small"
42
- variant="ghost"
36
+ variant="secondary"
43
37
  onClick={() => onCancel?.()}
44
38
  >
45
39
  {labels?.cancel}
46
40
  </Button>
47
- <SaveButton
41
+ <Button
48
42
  aria-label="confirm"
49
- color={isDanger ? 'error' : 'primary'}
50
- data-testid="confirm_confirmation"
51
- hasStartIcon={!isDanger}
52
- labelLoading={labels?.loading}
53
- labelSave={labels?.confirm}
54
- loading={isLoading}
43
+ isDanger={isDanger}
44
+ size="small"
55
45
  type="submit"
46
+ variant="primary"
56
47
  onClick={() => onConfirm?.()}
57
- />
48
+ >
49
+ {labels?.confirm}
50
+ </Button>
58
51
  </>
59
52
  )}
60
53
  </div>