@centreon/ui 24.4.22 → 24.4.24

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": "24.4.22",
3
+ "version": "24.4.24",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
@@ -2,7 +2,7 @@ import { any, isEmpty, isNil, not, or, pipe } from 'ramda';
2
2
  import { makeStyles } from 'tss-react/mui';
3
3
 
4
4
  import { Theme, Tooltip, TypographyProps } from '@mui/material';
5
- import { LoadingButton } from '@mui/lab';
5
+ import { LoadingButton, LoadingButtonProps } from '@mui/lab';
6
6
 
7
7
  import { getNormalizedId } from '../../utils';
8
8
 
@@ -15,7 +15,7 @@ const useStyles = makeStyles()((theme: Theme) => ({
15
15
  }
16
16
  }));
17
17
 
18
- interface Props extends Record<string, unknown> {
18
+ interface Props {
19
19
  className?: string;
20
20
  labelLoading?: string;
21
21
  labelProps?: TypographyProps;
@@ -50,7 +50,7 @@ const SaveButton = ({
50
50
  startIcon = true,
51
51
  labelProps,
52
52
  ...rest
53
- }: Props): JSX.Element => {
53
+ }: Props & LoadingButtonProps): JSX.Element => {
54
54
  const { classes, cx } = useStyles();
55
55
  const hasLabel = hasValue([labelLoading, labelSave, labelSucceeded]);
56
56
 
@@ -43,7 +43,7 @@ export type Props = {
43
43
  dialogTitleClassName?: string;
44
44
  labelCancel?: string | null;
45
45
  labelConfirm?: string | null;
46
- labelTitle?: string | null;
46
+ labelTitle?: ReactNode;
47
47
  onCancel?: () => void;
48
48
  onClose?: () => void;
49
49
  onConfirm: (event, value?) => void;
@@ -141,126 +141,132 @@ type Multiple = boolean;
141
141
  type DisableClearable = boolean;
142
142
  type FreeSolo = boolean;
143
143
 
144
- const AutocompleteField = ({
145
- options,
146
- label,
147
- placeholder,
148
- loading = false,
149
- onTextChange = (): void => undefined,
150
- endAdornment = undefined,
151
- inputValue,
152
- displayOptionThumbnail = false,
153
- required = false,
154
- error,
155
- displayPopupIcon = true,
156
- autoFocus = false,
157
- hideInput = false,
158
- dataTestId,
159
- autoSize = false,
160
- autoSizeDefaultWidth = 0,
161
- autoSizeCustomPadding,
162
- getOptionItemLabel = (option) => option.name,
163
- ...autocompleteProps
164
- }: Props): JSX.Element => {
165
- const { classes, cx } = useStyles({ hideInput });
166
- const { t } = useTranslation();
167
- const theme = useTheme();
144
+ const AutocompleteField = React.forwardRef(
145
+ (
146
+ {
147
+ options,
148
+ label,
149
+ placeholder,
150
+ loading = false,
151
+ onTextChange = (): void => undefined,
152
+ endAdornment = undefined,
153
+ inputValue,
154
+ displayOptionThumbnail = false,
155
+ required = false,
156
+ error,
157
+ displayPopupIcon = true,
158
+ autoFocus = false,
159
+ hideInput = false,
160
+ dataTestId,
161
+ autoSize = false,
162
+ autoSizeDefaultWidth = 0,
163
+ autoSizeCustomPadding,
164
+ getOptionItemLabel = (option) => option.name,
165
+ ...autocompleteProps
166
+ }: Props,
167
+ ref?: React.ForwardedRef<HTMLDivElement>
168
+ ): JSX.Element => {
169
+ const { classes, cx } = useStyles({ hideInput });
170
+ const { t } = useTranslation();
171
+ const theme = useTheme();
168
172
 
169
- const areSelectEntriesEqual = (option, value): boolean => {
170
- const identifyingProps = ['id', 'name'];
173
+ const areSelectEntriesEqual = (option, value): boolean => {
174
+ const identifyingProps = ['id', 'name'];
171
175
 
172
- return equals(
173
- pick(identifyingProps, option),
174
- pick(identifyingProps, value)
176
+ return equals(
177
+ pick(identifyingProps, option),
178
+ pick(identifyingProps, value)
179
+ );
180
+ };
181
+
182
+ const renderInput = (params): JSX.Element => (
183
+ <TextField
184
+ {...params}
185
+ InputLabelProps={{
186
+ classes: {
187
+ marginDense: classes.inputLabel,
188
+ shrink: classes.inputLabelShrink
189
+ }
190
+ }}
191
+ InputProps={{
192
+ ...params.InputProps,
193
+ endAdornment: (
194
+ <>
195
+ {endAdornment && (
196
+ <InputAdornment position="end">{endAdornment}</InputAdornment>
197
+ )}
198
+ {params.InputProps.endAdornment}
199
+ </>
200
+ ),
201
+ style: {
202
+ background: 'transparent',
203
+ paddingRight: theme.spacing(5)
204
+ }
205
+ }}
206
+ autoFocus={autoFocus}
207
+ autoSize={autoSize}
208
+ autoSizeCustomPadding={7 + (autoSizeCustomPadding || 0)}
209
+ autoSizeDefaultWidth={autoSizeDefaultWidth}
210
+ classes={{
211
+ root: classes.textfield
212
+ }}
213
+ error={error}
214
+ externalValueForAutoSize={autocompleteProps?.value?.name}
215
+ inputProps={{
216
+ ...params.inputProps,
217
+ 'aria-label': label,
218
+ 'data-testid': dataTestId || label,
219
+ id: getNormalizedId(label || '')
220
+ }}
221
+ label={label}
222
+ placeholder={isNil(placeholder) ? t(searchLabel) : placeholder}
223
+ required={required}
224
+ value={inputValue || undefined}
225
+ onChange={onTextChange}
226
+ />
175
227
  );
176
- };
177
228
 
178
- const renderInput = (params): JSX.Element => (
179
- <TextField
180
- {...params}
181
- InputLabelProps={{
182
- classes: {
183
- marginDense: classes.inputLabel,
184
- shrink: classes.inputLabelShrink
185
- }
186
- }}
187
- InputProps={{
188
- ...params.InputProps,
189
- endAdornment: (
190
- <>
191
- {endAdornment && (
192
- <InputAdornment position="end">{endAdornment}</InputAdornment>
193
- )}
194
- {params.InputProps.endAdornment}
195
- </>
196
- ),
197
- style: {
198
- background: 'transparent',
199
- paddingRight: theme.spacing(5)
229
+ return (
230
+ <Autocomplete
231
+ disableClearable
232
+ classes={{
233
+ groupLabel: classes.inputLabel,
234
+ inputRoot: cx([
235
+ classes.input,
236
+ label ? classes.inputWithLabel : classes.inputWithoutLabel
237
+ ]),
238
+ popper: classes.popper,
239
+ root: classes.textfield
240
+ }}
241
+ forcePopupIcon={displayPopupIcon}
242
+ getOptionLabel={(option): string =>
243
+ (option as SelectEntry)?.name?.toString() || ''
200
244
  }
201
- }}
202
- autoFocus={autoFocus}
203
- autoSize={autoSize}
204
- autoSizeCustomPadding={7 + (autoSizeCustomPadding || 0)}
205
- autoSizeDefaultWidth={autoSizeDefaultWidth}
206
- classes={{
207
- root: classes.textfield
208
- }}
209
- error={error}
210
- externalValueForAutoSize={autocompleteProps?.value?.name}
211
- inputProps={{
212
- ...params.inputProps,
213
- 'aria-label': label,
214
- 'data-testid': dataTestId || label,
215
- id: getNormalizedId(label || '')
216
- }}
217
- label={label}
218
- placeholder={isNil(placeholder) ? t(searchLabel) : placeholder}
219
- required={required}
220
- value={inputValue || undefined}
221
- onChange={onTextChange}
222
- />
223
- );
224
-
225
- return (
226
- <Autocomplete
227
- disableClearable
228
- classes={{
229
- groupLabel: classes.inputLabel,
230
- inputRoot: cx([
231
- classes.input,
232
- label ? classes.inputWithLabel : classes.inputWithoutLabel
233
- ]),
234
- popper: classes.popper,
235
- root: classes.textfield
236
- }}
237
- forcePopupIcon={displayPopupIcon}
238
- getOptionLabel={(option): string =>
239
- (option as SelectEntry)?.name?.toString() || ''
240
- }
241
- isOptionEqualToValue={areSelectEntriesEqual}
242
- loading={loading}
243
- loadingText={<LoadingIndicator />}
244
- options={options}
245
- renderInput={renderInput}
246
- renderOption={(props, option): JSX.Element => {
247
- return (
248
- <li
249
- className={classes.options}
250
- {...(props as React.HTMLAttributes<HTMLLIElement>)}
251
- >
252
- <Option
253
- thumbnailUrl={displayOptionThumbnail ? option.url : undefined}
245
+ isOptionEqualToValue={areSelectEntriesEqual}
246
+ loading={loading}
247
+ loadingText={<LoadingIndicator />}
248
+ options={options}
249
+ ref={ref}
250
+ renderInput={renderInput}
251
+ renderOption={(props, option): JSX.Element => {
252
+ return (
253
+ <li
254
+ className={classes.options}
255
+ {...(props as React.HTMLAttributes<HTMLLIElement>)}
254
256
  >
255
- {getOptionItemLabel(option)}
256
- </Option>
257
- </li>
258
- );
259
- }}
260
- size="small"
261
- {...autocompleteProps}
262
- />
263
- );
264
- };
257
+ <Option
258
+ thumbnailUrl={displayOptionThumbnail ? option.url : undefined}
259
+ >
260
+ {getOptionItemLabel(option)}
261
+ </Option>
262
+ </li>
263
+ );
264
+ }}
265
+ size="small"
266
+ {...autocompleteProps}
267
+ />
268
+ );
269
+ }
270
+ );
265
271
 
266
272
  export default AutocompleteField;
@@ -155,9 +155,9 @@ const TextField = forwardRef(
155
155
  helperText={displayErrorInTooltip ? undefined : error}
156
156
  id={getNormalizedId(dataTestId || '')}
157
157
  inputProps={{
158
- ...rest.inputProps,
159
158
  'aria-label': ariaLabel,
160
- 'data-testid': dataTestId
159
+ 'data-testid': dataTestId,
160
+ ...rest.inputProps
161
161
  }}
162
162
  label={label}
163
163
  ref={ref}
@@ -4,7 +4,11 @@ import dayjs, { Dayjs } from 'dayjs';
4
4
  import { useAtomValue } from 'jotai';
5
5
  import { equals } from 'ramda';
6
6
 
7
- import { DateTimePicker, LocalizationProvider } from '@mui/x-date-pickers';
7
+ import {
8
+ DateTimePicker,
9
+ DateTimePickerProps,
10
+ LocalizationProvider
11
+ } from '@mui/x-date-pickers';
8
12
  import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
9
13
 
10
14
  import { userAtom } from '@centreon/ui-context';
@@ -23,6 +27,7 @@ interface Props {
23
27
  disabled?: boolean;
24
28
  maxDate?: Date;
25
29
  minDate?: Date;
30
+ minDateTime?: Date;
26
31
  property: CustomTimePeriodProperty | string;
27
32
  }
28
33
 
@@ -30,11 +35,13 @@ const DateTimePickerInput = ({
30
35
  date,
31
36
  maxDate,
32
37
  minDate,
38
+ minDateTime,
33
39
  property,
34
40
  changeDate,
35
41
  disabled = false,
36
- desktopMediaQuery
37
- }: Props): JSX.Element => {
42
+ desktopMediaQuery,
43
+ ...rest
44
+ }: Props & DateTimePickerProps<dayjs.Dayjs>): JSX.Element => {
38
45
  const desktopPickerMediaQuery =
39
46
  '@media (min-width: 1024px) or (pointer: fine)';
40
47
 
@@ -67,8 +74,10 @@ const DateTimePickerInput = ({
67
74
  disabled={disabled}
68
75
  maxDate={maxDate && formatDate(maxDate)}
69
76
  minDate={minDate && formatDate(minDate)}
77
+ minDateTime={minDateTime && formatDate(minDateTime)}
70
78
  value={formatDate(date)}
71
79
  onChange={changeTime}
80
+ {...rest}
72
81
  />
73
82
  </LocalizationProvider>
74
83
  );