@centreon/ui 24.10.14 → 24.10.16

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.10.14",
3
+ "version": "24.10.16",
4
4
  "description": "Centreon UI Components",
5
5
  "scripts": {
6
6
  "update:deps": "pnpx npm-check-updates -i --format group",
@@ -1,4 +1,4 @@
1
- import { useCallback, useEffect, useState } from 'react';
1
+ import { ReactElement, useCallback, useEffect, useState } from 'react';
2
2
 
3
3
  import {
4
4
  equals,
@@ -44,7 +44,7 @@ export interface ConnectedAutoCompleteFieldProps<TData> {
44
44
  field: string;
45
45
  getEndpoint: ({ search, page }) => string;
46
46
  decoder?;
47
- getRenderedOptionText: (option: TData) => string;
47
+ getRenderedOptionText?: (option: TData) => ReactElement | string;
48
48
  getRequestHeaders?: HeadersInit;
49
49
  initialPage: number;
50
50
  labelKey?: string;
@@ -53,9 +53,9 @@ export interface ConnectedAutoCompleteFieldProps<TData> {
53
53
  }
54
54
 
55
55
  const ConnectedAutocompleteField = (
56
- AutocompleteField: (props) => JSX.Element,
56
+ AutocompleteField: (props) => ReactElement,
57
57
  multiple: boolean
58
- ): ((props) => JSX.Element) => {
58
+ ): ((props) => ReactElement) => {
59
59
  const InnerConnectedAutocompleteField = <TData extends { name: string }>({
60
60
  initialPage = 1,
61
61
  getEndpoint,
@@ -74,7 +74,7 @@ const ConnectedAutocompleteField = (
74
74
  changeIdValue,
75
75
  ...props
76
76
  }: ConnectedAutoCompleteFieldProps<TData> &
77
- Omit<AutocompleteFieldProps, 'options'>): JSX.Element => {
77
+ Omit<AutocompleteFieldProps, 'options'>): ReactElement => {
78
78
  const [options, setOptions] = useState<Array<TData>>([]);
79
79
  const [page, setPage] = useState(1);
80
80
  const [maxPage, setMaxPage] = useState(initialPage);
@@ -221,7 +221,7 @@ const ConnectedAutocompleteField = (
221
221
  debounce(event.target.value);
222
222
  };
223
223
 
224
- const renderOptions = (renderProps, option, { selected }): JSX.Element => {
224
+ const renderOptions = (renderProps, option, { selected }): ReactElement => {
225
225
  const { value } = props;
226
226
 
227
227
  const lastValue = Array.isArray(value) ? last(value) : value;
@@ -14,6 +14,7 @@ import { UseAutocompleteProps } from '@mui/material/useAutocomplete';
14
14
 
15
15
  import { ThemeMode } from '@centreon/ui-context';
16
16
 
17
+ import type { AutocompleteRenderOptionState } from '@mui/material/Autocomplete';
17
18
  import { ForwardedRef, HTMLAttributes, ReactElement, forwardRef } from 'react';
18
19
  import { SelectEntry } from '..';
19
20
  import { getNormalizedId } from '../../../utils';
@@ -33,6 +34,11 @@ export type Props = {
33
34
  error?: string;
34
35
  getOptionItemLabel?: (option) => string;
35
36
  hideInput?: boolean;
37
+ renderOption?: (
38
+ renderProps: HTMLAttributes<HTMLLIElement>,
39
+ option: SelectEntry,
40
+ state: AutocompleteRenderOptionState
41
+ ) => ReactElement;
36
42
  label: string;
37
43
  loading?: boolean;
38
44
  onTextChange?;
@@ -163,6 +169,7 @@ const AutocompleteField = forwardRef(
163
169
  autoSizeCustomPadding,
164
170
  getOptionItemLabel = (option) => option?.name,
165
171
  forceInputRenderValue = false,
172
+ renderOption,
166
173
  ...autocompleteProps
167
174
  }: Props,
168
175
  ref?: ForwardedRef<HTMLDivElement>
@@ -180,7 +187,24 @@ const AutocompleteField = forwardRef(
180
187
  );
181
188
  };
182
189
 
183
- const renderInput = (params): JSX.Element => {
190
+ const renderOptions = renderOption
191
+ ? renderOption
192
+ : (props, option): ReactElement => {
193
+ return (
194
+ <li
195
+ className={classes.options}
196
+ {...(props as HTMLAttributes<HTMLLIElement>)}
197
+ >
198
+ <Option
199
+ thumbnailUrl={displayOptionThumbnail ? option.url : undefined}
200
+ >
201
+ {getOptionItemLabel(option)}
202
+ </Option>
203
+ </li>
204
+ );
205
+ };
206
+
207
+ const renderInput = (params): ReactElement => {
184
208
  return (
185
209
  <TextField
186
210
  {...params}
@@ -271,20 +295,7 @@ const AutocompleteField = forwardRef(
271
295
  options={options}
272
296
  ref={ref}
273
297
  renderInput={renderInput}
274
- renderOption={(props, option): JSX.Element => {
275
- return (
276
- <li
277
- className={classes.options}
278
- {...(props as HTMLAttributes<HTMLLIElement>)}
279
- >
280
- <Option
281
- thumbnailUrl={displayOptionThumbnail ? option.url : undefined}
282
- >
283
- {getOptionItemLabel(option)}
284
- </Option>
285
- </li>
286
- );
287
- }}
298
+ renderOption={renderOptions}
288
299
  size="small"
289
300
  slotProps={{
290
301
  clearIndicator: {
@@ -1,4 +1,4 @@
1
- import { RefObject, forwardRef } from 'react';
1
+ import { ReactElement, RefObject, forwardRef } from 'react';
2
2
 
3
3
  import { equals, isNil } from 'ramda';
4
4
  import { makeStyles } from 'tss-react/mui';
@@ -28,12 +28,12 @@ const useStyles = makeStyles()((theme) => ({
28
28
 
29
29
  interface Props {
30
30
  checkboxSelected?: boolean;
31
- children: string;
31
+ children: string | ReactElement;
32
32
  thumbnailUrl?: string;
33
33
  }
34
34
 
35
35
  const Option = forwardRef(
36
- ({ children, checkboxSelected, thumbnailUrl }: Props, ref): JSX.Element => {
36
+ ({ children, checkboxSelected, thumbnailUrl }: Props, ref): ReactElement => {
37
37
  const { classes } = useStyles();
38
38
 
39
39
  return (
@@ -8,6 +8,7 @@ import { SelectEntry, SingleConnectedAutocompleteField } from '../../../..';
8
8
  import RoleSelectField from '../common/RoleSelectField';
9
9
  import { Endpoints, Labels } from '../models';
10
10
 
11
+ import { ReactElement } from 'react';
11
12
  import ContactSwitch from './ContactSwitch';
12
13
  import { useShareInputStyles } from './ShareInput.styles';
13
14
  import useShareInput from './useShareInput';
@@ -18,18 +19,18 @@ interface Props {
18
19
  roles: Array<SelectEntry>;
19
20
  }
20
21
 
21
- const ShareInput = ({ labels, endpoints, roles }: Props): JSX.Element => {
22
+ const ShareInput = ({ labels, endpoints, roles }: Props): ReactElement => {
22
23
  const { t } = useTranslation();
23
24
  const { classes } = useShareInputStyles();
24
25
 
25
26
  const {
26
- renderOption,
27
27
  selectedContact,
28
28
  getOptionDisabled,
29
29
  getEndpoint,
30
30
  selectContact,
31
31
  isContactGroup,
32
32
  selectedRole,
33
+ getRenderedOptionText,
33
34
  setSelectedRole,
34
35
  add,
35
36
  changeIdValue
@@ -46,6 +47,7 @@ const ShareInput = ({ labels, endpoints, roles }: Props): JSX.Element => {
46
47
  disableClearable={false}
47
48
  field="name"
48
49
  getEndpoint={getEndpoint}
50
+ getRenderedOptionText={getRenderedOptionText}
49
51
  getOptionDisabled={getOptionDisabled}
50
52
  label={t(
51
53
  isContactGroup
@@ -53,7 +55,6 @@ const ShareInput = ({ labels, endpoints, roles }: Props): JSX.Element => {
53
55
  : t(labels.autocompleteContact)
54
56
  )}
55
57
  queryKey={isContactGroup ? labels.contactGroup : labels.contact}
56
- renderOption={renderOption}
57
58
  value={selectedContact}
58
59
  onChange={selectContact}
59
60
  />
@@ -1,10 +1,15 @@
1
- import { Dispatch, SetStateAction, useEffect, useState } from 'react';
1
+ import {
2
+ Dispatch,
3
+ ReactElement,
4
+ SetStateAction,
5
+ useEffect,
6
+ useState
7
+ } from 'react';
2
8
 
3
9
  import { useAtomValue, useSetAtom } from 'jotai';
4
10
  import { equals, includes, isNil } from 'ramda';
5
11
 
6
12
  import CheckCircleIcon from '@mui/icons-material/CheckCircle';
7
- import { ListItemText, MenuItem } from '@mui/material';
8
13
 
9
14
  import { SelectEntry, buildListingEndpoint } from '../../../..';
10
15
  import {
@@ -20,7 +25,7 @@ interface UseShareInputState {
20
25
  getEndpoint: (parameters) => string;
21
26
  getOptionDisabled: (option) => boolean;
22
27
  isContactGroup: boolean;
23
- renderOption: (attr, option) => JSX.Element;
28
+ getRenderedOptionText: (option: unknown) => ReactElement | string;
24
29
  selectContact: (_, entry) => void;
25
30
  selectedContact: AccessRightInitialValues | null;
26
31
  selectedRole: string;
@@ -40,7 +45,7 @@ const useShareInput = (endpoints: Endpoints): UseShareInputState => {
40
45
 
41
46
  const selectContact = (_, entry): void => {
42
47
  setSelectedContact(entry);
43
- if (equals('editor', entry.most_permissive_role)) {
48
+ if (equals('editor', entry?.most_permissive_role)) {
44
49
  return;
45
50
  }
46
51
  setSelectedRole('viewer');
@@ -71,14 +76,14 @@ const useShareInput = (endpoints: Endpoints): UseShareInputState => {
71
76
  }
72
77
  });
73
78
 
74
- const renderOption = (attr, option): JSX.Element => {
79
+ const getRenderedOptionText = (option): ReactElement => {
75
80
  return (
76
- <MenuItem {...attr}>
77
- <ListItemText>{option.name}</ListItemText>
78
- {includes(option.id, accessRightIds) && (
81
+ <>
82
+ {option?.name}
83
+ {includes(option?.id, accessRightIds) && (
79
84
  <CheckCircleIcon color="success" />
80
85
  )}
81
- </MenuItem>
86
+ </>
82
87
  );
83
88
  };
84
89
 
@@ -102,7 +107,7 @@ const useShareInput = (endpoints: Endpoints): UseShareInputState => {
102
107
  getEndpoint,
103
108
  getOptionDisabled,
104
109
  isContactGroup,
105
- renderOption,
110
+ getRenderedOptionText,
106
111
  selectContact,
107
112
  selectedContact,
108
113
  selectedRole,
@@ -4,14 +4,13 @@ import {
4
4
  ArrowDropDown as ArrowDropDownIcon,
5
5
  Menu as MenuIcon
6
6
  } from '@mui/icons-material';
7
+ import { useStyles } from './MenuButton.styles';
7
8
 
8
9
  import { AriaLabelingAttributes } from '../../../@types/aria-attributes';
9
10
  import { DataTestAttributes } from '../../../@types/data-attributes';
10
11
  import { Button, ButtonProps } from '../../Button';
11
12
  import { useMenu } from '../useMenu';
12
13
 
13
- import { useStyles } from './MenuButton.styles';
14
-
15
14
  type MenuButtonProps = {
16
15
  ariaLabel?: string;
17
16
  children?: ReactNode;