@centreon/ui 23.10.22-MON-18498-cancel-changes.9 → 23.10.22-MON-19195-save-dashboard-changes.2

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-18498-cancel-changes.9",
3
+ "version": "23.10.22-MON-19195-save-dashboard-changes.2",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
@@ -60,18 +60,17 @@ const SaveButton = ({
60
60
  <Tooltip placement="bottom" title={tooltipLabel}>
61
61
  <div>
62
62
  <LoadingButton
63
- aria-label="save button"
63
+ aria-label={labelSave}
64
64
  className={cx(
65
65
  {
66
66
  [classes.loadingButton]: !hasLabel
67
67
  },
68
68
  className
69
69
  )}
70
- color="primary"
71
70
  data-testid={labelSave}
72
71
  id={getNormalizedId(labelSave)}
73
72
  loading={loading}
74
- loadingPosition={labelLoading ? 'start' : 'center'}
73
+ loadingPosition={labelLoading && rest.startIcon ? 'start' : 'center'}
75
74
  size={size}
76
75
  startIcon={<StartIcon startIconConfig={startIconConfig} />}
77
76
  variant="contained"
@@ -1,4 +1,4 @@
1
1
  export type DashboardResource = {
2
- description?: string;
2
+ description?: string | null;
3
3
  name: string;
4
4
  };
@@ -11,7 +11,8 @@ import { useStyles } from './DashboardForm.styles';
11
11
  import {
12
12
  labelMustBeAtLeast,
13
13
  labelMustBeMost,
14
- labelRequired
14
+ labelRequired,
15
+ labelCharacters
15
16
  } from './translatedLabels';
16
17
  import {
17
18
  DashboardFormActions,
@@ -43,7 +44,7 @@ const DashboardForm = ({
43
44
 
44
45
  const formProps = useMemo<FormProps<DashboardResource>>(
45
46
  () => ({
46
- initialValues: resource ?? { name: '' },
47
+ initialValues: resource ?? { description: null, name: '' },
47
48
  inputs: [
48
49
  {
49
50
  fieldName: 'name',
@@ -55,7 +56,7 @@ const DashboardForm = ({
55
56
  {
56
57
  fieldName: 'description',
57
58
  group: 'main',
58
- label: labels?.entity?.description,
59
+ label: labels?.entity?.description || '',
59
60
  text: {
60
61
  multilineRows: 3
61
62
  },
@@ -65,9 +66,12 @@ const DashboardForm = ({
65
66
  submit: (values, bag) => onSubmit?.(values, bag),
66
67
  validationSchema: Yup.object().shape({
67
68
  description: Yup.string()
68
- .label(labels?.entity?.description)
69
- .max(180, ({ max, label }) => t(labelMustBeMost, { label, max }))
70
- .optional()
69
+ .label(labels?.entity?.description || '')
70
+ .max(
71
+ 180,
72
+ (p) =>
73
+ `${p.label} ${t(labelMustBeMost)} ${p.max} ${labelCharacters}`
74
+ )
71
75
  .nullable(),
72
76
  name: Yup.string()
73
77
  .label(labels?.entity?.name)
@@ -3,3 +3,4 @@ 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';
@@ -37,7 +37,35 @@ export const Default: Story = {
37
37
  <Modal.Actions
38
38
  labels={{
39
39
  cancel: 'Cancel',
40
- confirm: 'Confirm'
40
+ confirm: 'Confirm',
41
+ loading: 'Loading'
42
+ }}
43
+ />
44
+ </Modal>
45
+ )
46
+ };
47
+
48
+ export const DefaultWithLoading: Story = {
49
+ args: {
50
+ hasCloseButton: true,
51
+ open: true,
52
+ size: 'small'
53
+ },
54
+ render: (args) => (
55
+ <Modal {...args}>
56
+ <Modal.Header>Modal title</Modal.Header>
57
+ <Modal.Body>
58
+ <p>
59
+ Occaecat consectetur amet officia magna. Eu sunt aute duis duis cillum
60
+ irure mollit ex aute excepteur eu id cillum.
61
+ </p>
62
+ </Modal.Body>
63
+ <Modal.Actions
64
+ isLoading
65
+ labels={{
66
+ cancel: 'Cancel',
67
+ confirm: 'Confirm',
68
+ loading: 'Loading'
41
69
  }}
42
70
  />
43
71
  </Modal>
@@ -62,7 +90,35 @@ export const AsDangerAction: Story = {
62
90
  isDanger
63
91
  labels={{
64
92
  cancel: 'Cancel',
65
- confirm: 'Confirm'
93
+ confirm: 'Confirm',
94
+ loading: 'Loading'
95
+ }}
96
+ />
97
+ </Modal>
98
+ )
99
+ };
100
+
101
+ export const AsDangerActionWithLoading: Story = {
102
+ args: {
103
+ ...Default.args
104
+ },
105
+ render: (args) => (
106
+ <Modal {...args}>
107
+ <Modal.Body>
108
+ <Modal.Body>
109
+ <p>
110
+ Occaecat consectetur amet <strong>officia magna</strong>. Eu sunt
111
+ aute duis duis cillum irure mollit ex aute excepteur eu id cillum.
112
+ </p>
113
+ </Modal.Body>
114
+ </Modal.Body>
115
+ <Modal.Actions
116
+ isDanger
117
+ isLoading
118
+ labels={{
119
+ cancel: 'Cancel',
120
+ confirm: 'Confirm',
121
+ loading: 'Loading'
66
122
  }}
67
123
  />
68
124
  </Modal>
@@ -1,12 +1,14 @@
1
1
  import React, { ReactElement } from 'react';
2
2
 
3
3
  import { Button } from '../Button';
4
+ import { SaveButton } from '../..';
4
5
 
5
6
  import { useStyles } from './Modal.styles';
6
7
 
7
8
  export type ModalActionsProps = {
8
9
  children?: React.ReactNode;
9
10
  isDanger?: boolean;
11
+ isLoading?: boolean;
10
12
  labels?: ModalActionsLabels;
11
13
  onCancel?: () => void;
12
14
  onConfirm?: () => void;
@@ -15,6 +17,7 @@ export type ModalActionsProps = {
15
17
  export type ModalActionsLabels = {
16
18
  cancel: string;
17
19
  confirm: string;
20
+ loading: string;
18
21
  };
19
22
 
20
23
  const ModalActions = ({
@@ -22,10 +25,17 @@ const ModalActions = ({
22
25
  labels,
23
26
  onCancel,
24
27
  onConfirm,
25
- isDanger = false
28
+ isDanger = false,
29
+ isLoading = false
26
30
  }: ModalActionsProps): ReactElement => {
27
31
  const { classes } = useStyles();
28
32
 
33
+ const icon = isDanger
34
+ ? {
35
+ startIcon: undefined
36
+ }
37
+ : null;
38
+
29
39
  return (
30
40
  <div className={classes.modalActions}>
31
41
  {children || (
@@ -33,23 +43,25 @@ const ModalActions = ({
33
43
  <Button
34
44
  aria-label={labels?.cancel}
35
45
  data-testid="cancel_confirmation"
46
+ disabled={isLoading}
36
47
  size="small"
37
48
  variant="ghost"
38
49
  onClick={() => onCancel?.()}
39
50
  >
40
51
  {labels?.cancel}
41
52
  </Button>
42
- <Button
43
- aria-label={labels?.confirm}
53
+ <SaveButton
54
+ aria-label="confirm"
55
+ color={isDanger ? 'error' : 'primary'}
44
56
  data-testid="confirm_confirmation"
45
- isDanger={isDanger}
57
+ labelLoading={labels?.loading}
58
+ labelSave={labels?.confirm}
59
+ loading={isLoading}
46
60
  size="small"
47
61
  type="submit"
48
- variant="primary"
49
62
  onClick={() => onConfirm?.()}
50
- >
51
- {labels?.confirm}
52
- </Button>
63
+ {...icon}
64
+ />
53
65
  </>
54
66
  )}
55
67
  </div>