@centreon/ui 26.5.13 → 26.5.15

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 (170) hide show
  1. package/package.json +6 -1
  2. package/src/ActionsList/ActionsList.styles.ts +2 -1
  3. package/src/ActionsList/index.tsx +1 -1
  4. package/src/Button/Icon/index.tsx +1 -1
  5. package/src/Button/Save/useSave.tsx +2 -1
  6. package/src/Checkbox/Checkbox.tsx +14 -9
  7. package/src/Checkbox/CheckboxGroup/index.tsx +1 -1
  8. package/src/Colors/index.tsx +12 -2
  9. package/src/Dashboard/Item.tsx +1 -1
  10. package/src/Dialog/Duplicate/index.tsx +5 -3
  11. package/src/Dialog/index.tsx +4 -1
  12. package/src/Form/Inputs/Autocomplete.tsx +30 -19
  13. package/src/Form/Inputs/ConnectedAutocomplete.tsx +27 -9
  14. package/src/Form/Inputs/FieldsTable/FieldsTable.tsx +24 -13
  15. package/src/Form/Inputs/FieldsTable/Row.tsx +7 -1
  16. package/src/Form/Inputs/List/Content.tsx +2 -2
  17. package/src/Form/Inputs/List/List.tsx +2 -1
  18. package/src/Form/Inputs/List/useList.ts +1 -1
  19. package/src/Form/Inputs/Radio.tsx +4 -1
  20. package/src/Form/Inputs/models.ts +42 -8
  21. package/src/Form/Section/PanelTabs.tsx +1 -1
  22. package/src/Form/storiesData.tsx +2 -2
  23. package/src/Graph/BarChart/Bar.tsx +39 -5
  24. package/src/Graph/BarChart/BarGroup.tsx +9 -5
  25. package/src/Graph/BarChart/BarStack.tsx +17 -4
  26. package/src/Graph/BarChart/useBarStack.ts +16 -8
  27. package/src/Graph/BarStack/Graph.tsx +21 -5
  28. package/src/Graph/BarStack/GraphAndLegend.tsx +2 -1
  29. package/src/Graph/BarStack/models.ts +23 -3
  30. package/src/Graph/BarStack/useGraphAndLegend.ts +10 -6
  31. package/src/Graph/BarStack/useResponsiveBarStack.ts +2 -1
  32. package/src/Graph/Chart/BasicComponents/Lines/Point.tsx +2 -1
  33. package/src/Graph/Chart/BasicComponents/Lines/RegularLines/index.tsx +4 -3
  34. package/src/Graph/Chart/BasicComponents/Lines/RegularLines/useRegularLines.ts +1 -1
  35. package/src/Graph/Chart/BasicComponents/Lines/StackedLines/index.tsx +4 -5
  36. package/src/Graph/Chart/BasicComponents/Lines/StackedLines/useStackedLines.ts +10 -1
  37. package/src/Graph/Chart/BasicComponents/Lines/Threshold/index.tsx +13 -4
  38. package/src/Graph/Chart/BasicComponents/Lines/Threshold/models.ts +2 -2
  39. package/src/Graph/Chart/BasicComponents/Lines/index.tsx +2 -10
  40. package/src/Graph/Chart/InteractiveComponents/AnchorPoint/StackedAnchorPoint.tsx +7 -3
  41. package/src/Graph/Chart/InteractiveComponents/AnchorPoint/models.ts +2 -2
  42. package/src/Graph/Chart/InteractiveComponents/AnchorPoint/useTickGraph.ts +4 -4
  43. package/src/Graph/Chart/InteractiveComponents/Annotations/Annotation/Area.tsx +9 -1
  44. package/src/Graph/Chart/InteractiveComponents/Annotations/Annotation/Line.tsx +9 -1
  45. package/src/Graph/Chart/InteractiveComponents/Annotations/EventAnnotations.tsx +9 -1
  46. package/src/Graph/Chart/InteractiveComponents/Annotations/useAnnotation.ts +1 -5
  47. package/src/Graph/Chart/InteractiveComponents/Tooltip/useGraphTooltip.ts +2 -2
  48. package/src/Graph/Chart/InteractiveComponents/index.tsx +8 -8
  49. package/src/Graph/Chart/Legend/LegendHeader.tsx +6 -1
  50. package/src/Graph/Chart/Legend/index.tsx +5 -2
  51. package/src/Graph/Chart/Legend/useLegend.ts +2 -2
  52. package/src/Graph/Chart/helpers/doc.ts +11 -1
  53. package/src/Graph/Chart/models.ts +2 -2
  54. package/src/Graph/Chart/useChartData.ts +4 -3
  55. package/src/Graph/Chart/useChartIntersection.ts +5 -1
  56. package/src/Graph/Gauge/AnimatedPie.tsx +7 -2
  57. package/src/Graph/Gauge/models.ts +7 -1
  58. package/src/Graph/PieChart/ResponsivePie.tsx +7 -1
  59. package/src/Graph/PieChart/models.ts +22 -3
  60. package/src/Graph/PieChart/useResponsivePie.ts +3 -2
  61. package/src/Graph/SingleBar/ThresholdLine.tsx +5 -1
  62. package/src/Graph/SingleBar/Thresholds.tsx +5 -1
  63. package/src/Graph/Timeline/ResponsiveTimeline.tsx +2 -2
  64. package/src/Graph/Timeline/useTimeline.ts +2 -1
  65. package/src/Graph/Tree/DescendantNodes.tsx +4 -3
  66. package/src/Graph/Tree/Tree.tsx +7 -1
  67. package/src/Graph/Tree/models.ts +2 -2
  68. package/src/Graph/common/Axes/UnitLabel.tsx +1 -1
  69. package/src/Graph/common/Axes/index.tsx +15 -6
  70. package/src/Graph/common/Axes/useAxisY.ts +3 -3
  71. package/src/Graph/common/BaseChart/AdditionalLine.tsx +2 -1
  72. package/src/Graph/common/BaseChart/ChartSvgWrapper.tsx +7 -3
  73. package/src/Graph/common/Grids/index.tsx +9 -3
  74. package/src/Graph/common/Thresholds/ThresholdLine.tsx +7 -1
  75. package/src/Graph/common/Thresholds/Thresholds.tsx +7 -1
  76. package/src/Graph/common/models.ts +9 -1
  77. package/src/Graph/common/timeSeries/index.test.ts +1 -1
  78. package/src/Graph/common/timeSeries/index.ts +72 -26
  79. package/src/Graph/common/timeSeries/models.ts +1 -1
  80. package/src/Graph/common/utils.ts +3 -1
  81. package/src/Image/useLoadImage.ts +6 -1
  82. package/src/InputField/Search/RegexpHelpTooltip.tsx +3 -1
  83. package/src/InputField/Select/Autocomplete/Connected/Multi/utils/index.ts +4 -1
  84. package/src/InputField/Select/Autocomplete/Connected/index.test.tsx +7 -2
  85. package/src/InputField/Select/Autocomplete/Connected/index.tsx +70 -26
  86. package/src/InputField/Select/Autocomplete/Draggable/SortableList.tsx +2 -2
  87. package/src/InputField/Select/Autocomplete/Draggable/SortableListContent.tsx +6 -4
  88. package/src/InputField/Select/Autocomplete/Draggable/index.tsx +35 -10
  89. package/src/InputField/Select/Autocomplete/Multi/Listbox.tsx +12 -2
  90. package/src/InputField/Select/Autocomplete/Multi/Multi.tsx +15 -8
  91. package/src/InputField/Select/Autocomplete/Popover/index.tsx +5 -2
  92. package/src/InputField/Select/Autocomplete/index.tsx +23 -10
  93. package/src/InputField/Select/IconPopover/index.tsx +8 -5
  94. package/src/InputField/Select/index.tsx +4 -3
  95. package/src/InputField/Text/index.tsx +1 -1
  96. package/src/InputField/Text/useAutoSize.ts +0 -2
  97. package/src/Listing/ActionBar/ColumnMultiSelect.tsx +2 -2
  98. package/src/Listing/ActionBar/Pagination.tsx +4 -2
  99. package/src/Listing/ActionBar/PaginationActions.tsx +12 -4
  100. package/src/Listing/ActionBar/index.tsx +19 -7
  101. package/src/Listing/Cell/DataCell.tsx +3 -3
  102. package/src/Listing/Cell/index.tsx +26 -13
  103. package/src/Listing/Header/Cell/ListingHeaderCell.tsx +2 -2
  104. package/src/Listing/Header/Cell/SelectActionListingHeaderCell.tsx +6 -4
  105. package/src/Listing/Header/ListingHeader.tsx +2 -2
  106. package/src/Listing/Header/_internals/PredefinedSelectionList.tsx +3 -1
  107. package/src/Listing/Row/Row.tsx +3 -3
  108. package/src/Listing/index.tsx +48 -28
  109. package/src/Listing/models.ts +11 -9
  110. package/src/MultiSelectEntries/index.tsx +3 -3
  111. package/src/Pagination/Pagination.tsx +3 -1
  112. package/src/Panel/index.tsx +2 -2
  113. package/src/PopoverMenu/index.tsx +3 -3
  114. package/src/RichTextEditor/ContentEditable.tsx +2 -1
  115. package/src/RichTextEditor/RichTextEditor.tsx +1 -1
  116. package/src/RichTextEditor/plugins/FloatingLinkEditorPlugin.tsx +16 -14
  117. package/src/RichTextEditor/plugins/ToolbarPlugin/BlockButtons.tsx +3 -3
  118. package/src/RichTextEditor/plugins/ToolbarPlugin/ListButton.tsx +1 -1
  119. package/src/RichTextEditor/plugins/ToolbarPlugin/MacrosButton.tsx +1 -1
  120. package/src/Snackbar/SnackbarProvider.tsx +1 -1
  121. package/src/Snackbar/index.tsx +4 -2
  122. package/src/Snackbar/useSnackbar.tsx +14 -4
  123. package/src/SortableItems/index.tsx +4 -4
  124. package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.tsx +1 -1
  125. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/models.ts +1 -1
  126. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/usePickersStartEndDate.ts +9 -3
  127. package/src/TimePeriods/CustomTimePeriod/index.tsx +7 -2
  128. package/src/TimePeriods/helpers/index.ts +7 -2
  129. package/src/TimePeriods/models.ts +4 -1
  130. package/src/TimePeriods/useTimePeriod.ts +0 -2
  131. package/src/Wizard/ActionsBar.tsx +1 -1
  132. package/src/Wizard/index.test.tsx +0 -66
  133. package/src/Wizard/index.tsx +10 -5
  134. package/src/Wizard/models.ts +1 -1
  135. package/src/api/buildListingEndpoint/getSearchQueryParameterValue.ts +2 -1
  136. package/src/api/buildListingEndpoint/index.ts +7 -1
  137. package/src/api/customFetch.ts +3 -3
  138. package/src/api/useBulkResponse.ts +31 -9
  139. package/src/api/useFetchQuery/index.ts +28 -6
  140. package/src/api/useGraphQuery/index.ts +1 -1
  141. package/src/api/useRequest/index.ts +7 -7
  142. package/src/components/Button/Button.tsx +1 -1
  143. package/src/components/Button/Icon/IconButton.tsx +1 -1
  144. package/src/components/CrudPage/Listing.tsx +3 -3
  145. package/src/components/CrudPage/utils.ts +1 -1
  146. package/src/components/Form/AccessRights/AccessRights.tsx +4 -1
  147. package/src/components/Form/AccessRights/Actions/Actions.tsx +4 -1
  148. package/src/components/Form/AccessRights/ShareInput/ShareInput.tsx +1 -1
  149. package/src/components/Form/AccessRights/ShareInput/useShareInput.tsx +35 -13
  150. package/src/components/Form/AccessRights/common/RoleSelectField.tsx +1 -1
  151. package/src/components/Form/AccessRights/storiesData.ts +2 -2
  152. package/src/components/ItemComposition/ItemComposition.tsx +1 -1
  153. package/src/components/Menu/Button/MenuButton.tsx +1 -1
  154. package/src/components/Menu/useMenu.tsx +3 -1
  155. package/src/components/Tabs/Tabs.tsx +1 -1
  156. package/src/components/Tooltip/ConfirmationTooltip/models.ts +5 -1
  157. package/src/components/Zoom/useMinimap.ts +16 -10
  158. package/src/components/Zoom/useZoom.ts +12 -6
  159. package/src/components/Zoom/utils.ts +3 -1
  160. package/src/queryParameters/index.ts +8 -2
  161. package/src/utils/resourcesStatusURL.ts +20 -3
  162. package/src/utils/translatedLabel.ts +4 -2
  163. package/src/utils/useDebounce.ts +10 -9
  164. package/src/utils/useInfiniteScrollListing.ts +2 -2
  165. package/src/utils/useIntersectionObserver.ts +2 -2
  166. package/src/utils/useLicenseExpirationWarning.test.tsx +4 -2
  167. package/src/utils/useLoadImage.tsx +7 -2
  168. package/src/utils/useLocaleDateTimeFormat/index.test.tsx +2 -3
  169. package/src/utils/useLocaleDateTimeFormat/localeFallback.test.tsx +2 -3
  170. package/test/testRenderer.tsx +9 -5
@@ -31,12 +31,18 @@ const usePickersStartEndDate = ({
31
31
 
32
32
  const setError = useSetAtom(errorTimePeriodAtom);
33
33
 
34
- const changeDate = ({ property, date }): void => {
35
- const currentDate = customTimePeriod[property];
34
+ const changeDate = ({
35
+ property,
36
+ date
37
+ }: {
38
+ property: CustomTimePeriodProperty | string;
39
+ date: Date;
40
+ }): void => {
41
+ const currentDate = customTimePeriod[property as keyof CustomTimePeriod];
36
42
  cond([
37
43
  [equals(CustomTimePeriodProperty?.start), (): void => setStart(date)],
38
44
  [equals(CustomTimePeriodProperty?.end), (): void => setEnd(date)]
39
- ])(property);
45
+ ])(property as CustomTimePeriodProperty);
40
46
 
41
47
  if (dayjs(date).isSame(dayjs(currentDate)) || !dayjs(date).isValid()) {
42
48
  return;
@@ -25,8 +25,13 @@ const CustomTimePeriod = ({
25
25
  const changeCustomTimePeriod = useSetAtom(changeCustomTimePeriodDerivedAtom);
26
26
 
27
27
  const debouncedChangeDate = useDebounce({
28
- functionToDebounce: ({ property, date }): void =>
29
- changeCustomTimePeriod({ date, property }),
28
+ functionToDebounce: (...args: Array<unknown>): void => {
29
+ const { property, date } = args[0] as {
30
+ property: string;
31
+ date: Date;
32
+ };
33
+ changeCustomTimePeriod({ date, property });
34
+ },
30
35
  wait: 500
31
36
  });
32
37
 
@@ -26,5 +26,10 @@ export const getTimePeriodById = ({
26
26
  }: TimePeriodById): TimePeriod =>
27
27
  find<TimePeriod>(propEq(id, 'id'))(timePeriods) as TimePeriod;
28
28
 
29
- export const isInvalidDate = ({ startDate, endDate }): boolean =>
30
- dayjs(startDate).isSameOrAfter(dayjs(endDate), 'minute');
29
+ export const isInvalidDate = ({
30
+ startDate,
31
+ endDate
32
+ }: {
33
+ startDate: Date | null;
34
+ endDate: Date | null;
35
+ }): boolean => dayjs(startDate).isSameOrAfter(dayjs(endDate), 'minute');
@@ -73,7 +73,10 @@ export interface CustomTimePeriod {
73
73
  }
74
74
 
75
75
  export interface DateTimePickerInputModel {
76
- changeDate: (props) => void;
76
+ changeDate: (props: {
77
+ property: CustomTimePeriodProperty | string;
78
+ date: Date;
79
+ }) => void;
77
80
  date: Date | null;
78
81
  disabled?: boolean;
79
82
  maxDate?: Date;
@@ -4,7 +4,6 @@ import { useEffect } from 'react';
4
4
  import type { WrapperTimePeriodProps } from './models';
5
5
  import {
6
6
  adjustTimePeriodDerivedAtom,
7
- customTimePeriodAtom,
8
7
  errorTimePeriodAtom,
9
8
  getDatesDerivedAtom,
10
9
  selectedTimePeriodAtom
@@ -16,7 +15,6 @@ const useTimePeriod = ({
16
15
  adjustTimePeriodData
17
16
  }: Omit<WrapperTimePeriodProps, 'extraTimePeriods' | 'disabled'>): void => {
18
17
  const selectedTimePeriod = useAtomValue(selectedTimePeriodAtom);
19
- const _customTimePeriod = useAtomValue(customTimePeriodAtom);
20
18
  const getCurrentEndStartInterval = useAtomValue(getDatesDerivedAtom);
21
19
  const errorTimePeriod = useAtomValue(errorTimePeriodAtom);
22
20
  const adjustTimeTimePeriod = useSetAtom(adjustTimePeriodDerivedAtom);
@@ -27,7 +27,7 @@ const ActionsBar = ({
27
27
  }: ActionsBarProps): JSX.Element => {
28
28
  const { classes } = useStyles();
29
29
 
30
- const preventEnterKey = (keyEvent): void => {
30
+ const preventEnterKey = (keyEvent: React.KeyboardEvent): void => {
31
31
  if ((keyEvent.charCode || keyEvent.keyCode) === 13) {
32
32
  keyEvent.preventDefault();
33
33
  }
@@ -1,7 +1,3 @@
1
- import { useEffect } from "react";
2
-
3
- import * as Yup from "yup";
4
-
5
1
  import {
6
2
  fireEvent,
7
3
  type RenderResult,
@@ -10,7 +6,6 @@ import {
10
6
  waitFor,
11
7
  } from "../../test/testRenderer";
12
8
  import Wizard from ".";
13
- import type { StepComponentProps } from "./models";
14
9
 
15
10
  const renderWizardThreeSteps = (): RenderResult =>
16
11
  render(
@@ -50,67 +45,6 @@ const renderWizardOneStep = (): RenderResult =>
50
45
  />,
51
46
  );
52
47
 
53
- const secondStepValidationSchema = Yup.object().shape({
54
- secondInput: Yup.string().required("Required"),
55
- });
56
-
57
- const renderWizardTwoStepsWithFormValidation = (): RenderResult =>
58
- render(
59
- <Wizard
60
- open
61
- initialValues={{ secondInput: "" }}
62
- steps={[
63
- {
64
- Component: (): JSX.Element => <div>Step 1</div>,
65
- skipFormChangeCheck: true,
66
- stepName: "step label 1",
67
- },
68
- {
69
- Component: (): JSX.Element => <div>Step 2</div>,
70
- skipFormChangeCheck: true,
71
- stepName: "step label 2",
72
- validationSchema: secondStepValidationSchema,
73
- },
74
- ]}
75
- />,
76
- );
77
-
78
- const SecondStep = ({
79
- disableNextOnSendingRequests,
80
- }: StepComponentProps): JSX.Element => {
81
- const finishRequests = (): void => {
82
- disableNextOnSendingRequests([false, false, false]);
83
- };
84
-
85
- useEffect(() => {
86
- disableNextOnSendingRequests([true, false, true]);
87
- }, [disableNextOnSendingRequests]);
88
-
89
- return (
90
- <button type="button" onClick={finishRequests}>
91
- Finish requests
92
- </button>
93
- );
94
- };
95
-
96
- const renderWizardTwoStepsWithSendingRequests = (): RenderResult =>
97
- render(
98
- <Wizard
99
- open
100
- steps={[
101
- {
102
- Component: (): JSX.Element => <div>Step 1</div>,
103
- skipFormChangeCheck: true,
104
- stepName: "step label 1",
105
- },
106
- {
107
- Component: SecondStep,
108
- skipFormChangeCheck: true,
109
- stepName: "step label 2",
110
- },
111
- ]}
112
- />,
113
- );
114
48
 
115
49
  describe(Wizard, () => {
116
50
  it("displays the step labels", () => {
@@ -1,6 +1,6 @@
1
1
  import { Dialog, DialogContent } from '@mui/material';
2
2
 
3
- import { Formik } from 'formik';
3
+ import { Formik, type FormikHelpers, type FormikValues } from 'formik';
4
4
  import { dec, equals, filter, inc, isEmpty, length, not, pipe } from 'ramda';
5
5
  import { useState } from 'react';
6
6
  import { makeStyles } from 'tss-react/mui';
@@ -63,13 +63,18 @@ const Wizard = ({
63
63
  setCurrentStep(dec(currentStep));
64
64
  };
65
65
 
66
- const disableNextOnSendingRequests = (sendingRequests): void => {
66
+ const disableNextOnSendingRequests = (
67
+ sendingRequests: Array<boolean>
68
+ ): void => {
67
69
  setSendingRequest(
68
70
  pipe(isEmpty, not)(filter(equals(true), sendingRequests))
69
71
  );
70
72
  };
71
73
 
72
- const submit = (values, bag): void => {
74
+ const submit = (
75
+ values: FormikValues,
76
+ bag: FormikHelpers<FormikValues>
77
+ ): void => {
73
78
  if (isLastStep && onSubmit) {
74
79
  onSubmit(values, bag);
75
80
 
@@ -88,7 +93,7 @@ const Wizard = ({
88
93
  onClose?.();
89
94
  };
90
95
 
91
- const handleClose = (_, reason): void => {
96
+ const handleClose = (_: object, reason: string): void => {
92
97
  if (equals(reason, 'backdropClick')) {
93
98
  controlDisplayConfirmationDialog();
94
99
 
@@ -97,7 +102,7 @@ const Wizard = ({
97
102
  onClose?.();
98
103
  };
99
104
 
100
- const handleCloseConfirm = (confirm): void => {
105
+ const handleCloseConfirm = (confirm: boolean): void => {
101
106
  setOpenConfirm(false);
102
107
  if (!confirm) {
103
108
  return;
@@ -12,7 +12,7 @@ export interface Step {
12
12
  skipFormChangeCheck?: boolean;
13
13
  stepName: string;
14
14
  validate?: (values: FormikValues) => FormikErrors<FormikValues>;
15
- validationSchema?;
15
+ validationSchema?: unknown;
16
16
  }
17
17
 
18
18
  interface ActionsBarLabels {
@@ -15,6 +15,7 @@ import type {
15
15
  ConditionsSearchParameter,
16
16
  GetConditionsSearchQueryParameterValueState,
17
17
  GetListsSearchQueryParameterValueProps,
18
+ ListsSearchParameter,
18
19
  RegexSearchParameter,
19
20
  RegexSearchQueryParameterValue,
20
21
  SearchMatch,
@@ -64,7 +65,7 @@ const getRegexSearchQueryParameterValue = (
64
65
  };
65
66
 
66
67
  const getListsSearchQueryParameterValue = (
67
- lists
68
+ lists: Array<ListsSearchParameter> | undefined
68
69
  ): GetListsSearchQueryParameterValueProps | undefined => {
69
70
  if (lists === undefined) {
70
71
  return undefined;
@@ -34,11 +34,17 @@ const getQueryParameters = ({
34
34
  ];
35
35
  };
36
36
 
37
+ interface BuildEndpointProps {
38
+ apiFormat: 'Standard' | 'JSON-LD';
39
+ baseEndpoint?: string;
40
+ queryParameters: Array<QueryParameter>;
41
+ }
42
+
37
43
  const buildEndpoint = ({
38
44
  baseEndpoint,
39
45
  queryParameters,
40
46
  apiFormat
41
- }): string => {
47
+ }: BuildEndpointProps): string => {
42
48
  return `${baseEndpoint}?${toRawQueryParameters({ apiFormat, queryParameters })}`;
43
49
  };
44
50
 
@@ -9,8 +9,8 @@ interface ApiErrorResponse {
9
9
  }
10
10
 
11
11
  export interface ResponseError {
12
- additionalInformation?;
13
- data?;
12
+ additionalInformation?: unknown;
13
+ data?: unknown;
14
14
  isError: boolean;
15
15
  message: string;
16
16
  statusCode: number;
@@ -30,7 +30,7 @@ interface CustomFetchProps<T> {
30
30
  headers?: Headers;
31
31
  isMutation?: boolean;
32
32
  method?: string;
33
- payload?;
33
+ payload?: unknown;
34
34
  signal?: AbortSignal;
35
35
  }
36
36
 
@@ -4,7 +4,6 @@ import {
4
4
  isEmpty,
5
5
  isNil,
6
6
  last,
7
- length,
8
7
  prop,
9
8
  propEq,
10
9
  split
@@ -12,6 +11,24 @@ import {
12
11
 
13
12
  import useSnackbar from '../Snackbar/useSnackbar';
14
13
 
14
+ interface BulkResponseItem {
15
+ id: number | string;
16
+ name: string;
17
+ }
18
+
19
+ interface BulkResponseData {
20
+ href?: string;
21
+ status: number;
22
+ }
23
+
24
+ interface HandleBulkResponseProps {
25
+ data: Array<BulkResponseData> | undefined;
26
+ items: Array<BulkResponseItem>;
27
+ labelFailed: string;
28
+ labelSuccess: string;
29
+ labelWarning: string;
30
+ }
31
+
15
32
  const useBulkResponse = () => {
16
33
  const { showSuccessMessage, showErrorMessage, showWarningMessage } =
17
34
  useSnackbar();
@@ -22,17 +39,17 @@ const useBulkResponse = () => {
22
39
  labelWarning,
23
40
  labelFailed,
24
41
  items
25
- }) => {
42
+ }: HandleBulkResponseProps) => {
26
43
  const successfullResponses =
27
44
  data?.filter(propEq(204, 'status')) || isNil(data);
28
45
 
29
46
  const failedResponses = data?.filter(complement(propEq(204, 'status')));
30
47
 
31
- const failedResponsesIds = failedResponses
48
+ const failedResponsesIds = (failedResponses
32
49
  ?.map(prop('href'))
33
- ?.map((item: string) =>
34
- Number.parseInt(last(split('/', item || '')) as string, 10)
35
- );
50
+ ?.map((item) =>
51
+ Number.parseInt(last(split('/', (item as string) || '')) as string, 10)
52
+ ) || []) as Array<number>;
36
53
 
37
54
  if (isEmpty(successfullResponses)) {
38
55
  showErrorMessage(labelFailed);
@@ -40,10 +57,15 @@ const useBulkResponse = () => {
40
57
  return;
41
58
  }
42
59
 
43
- if (length(successfullResponses) < length(data)) {
60
+ const successCount = (successfullResponses as Array<BulkResponseData>)
61
+ .length;
62
+ const totalCount = data?.length ?? 0;
63
+ if (successCount < totalCount) {
44
64
  const failedResponsesNames = items
45
- ?.filter((item) => includes(item.id, failedResponsesIds))
46
- .map((item) => item.name);
65
+ ?.filter((item: BulkResponseItem) =>
66
+ includes(item.id, failedResponsesIds)
67
+ )
68
+ .map((item: BulkResponseItem) => item.name);
47
69
 
48
70
  showWarningMessage(`${labelWarning}: ${failedResponsesNames.join(', ')}`);
49
71
 
@@ -38,13 +38,26 @@ export interface UseFetchQueryProps<T> {
38
38
  useLongCache?: boolean;
39
39
  }
40
40
 
41
+ export interface PrefetchPageParams {
42
+ getPrefetchQueryKey: (page: number) => QueryKey;
43
+ page: number;
44
+ }
45
+
46
+ export interface PrefetchQueryParams {
47
+ endpointParams?: PrefetchEndpointParams;
48
+ queryKey: QueryKey;
49
+ }
50
+
41
51
  export type UseFetchQueryState<T> = {
42
52
  data?: T;
43
53
  error: Omit<ResponseError, 'isError'> | null;
44
54
  fetchQuery: () => Promise<T | ResponseError>;
45
- prefetchNextPage: ({ page, getPrefetchQueryKey }) => void;
46
- prefetchPreviousPage: ({ page, getPrefetchQueryKey }) => void;
47
- prefetchQuery: ({ endpointParams, queryKey }) => void;
55
+ prefetchNextPage: ({ page, getPrefetchQueryKey }: PrefetchPageParams) => void;
56
+ prefetchPreviousPage: ({
57
+ page,
58
+ getPrefetchQueryKey
59
+ }: PrefetchPageParams) => void;
60
+ prefetchQuery: ({ endpointParams, queryKey }: PrefetchQueryParams) => void;
48
61
  } & Omit<QueryObserverBaseResult, 'data' | 'error'>;
49
62
 
50
63
  export interface PrefetchEndpointParams {
@@ -107,7 +120,10 @@ const useFetchQuery = <T extends object>({
107
120
  }
108
121
  };
109
122
 
110
- const prefetchQuery = ({ endpointParams, queryKey }): void => {
123
+ const prefetchQuery = ({
124
+ endpointParams,
125
+ queryKey
126
+ }: PrefetchQueryParams): void => {
111
127
  queryClient.prefetchQuery({
112
128
  queryFn: ({ signal }): Promise<T | ResponseError> =>
113
129
  customFetch<T>({
@@ -123,7 +139,10 @@ const useFetchQuery = <T extends object>({
123
139
  });
124
140
  };
125
141
 
126
- const prefetchNextPage = ({ page, getPrefetchQueryKey }): void => {
142
+ const prefetchNextPage = ({
143
+ page,
144
+ getPrefetchQueryKey
145
+ }: PrefetchPageParams): void => {
127
146
  if (!isPaginated) {
128
147
  return;
129
148
  }
@@ -136,7 +155,10 @@ const useFetchQuery = <T extends object>({
136
155
  });
137
156
  };
138
157
 
139
- const prefetchPreviousPage = ({ page, getPrefetchQueryKey }): void => {
158
+ const prefetchPreviousPage = ({
159
+ page,
160
+ getPrefetchQueryKey
161
+ }: PrefetchPageParams): void => {
140
162
  if (!isPaginated) {
141
163
  return;
142
164
  }
@@ -74,7 +74,7 @@ interface PerformanceGraphData extends Omit<LineChartData, 'global'> {
74
74
  base: number;
75
75
  }
76
76
 
77
- export const resourceTypeQueryParameter = {
77
+ export const resourceTypeQueryParameter: Record<string, string> = {
78
78
  [WidgetResourceType.host]: 'host.id',
79
79
  [WidgetResourceType.hostCategory]: 'hostcategory.id',
80
80
  [WidgetResourceType.hostGroup]: 'hostgroup.id',
@@ -1,4 +1,4 @@
1
- import axios from 'axios';
1
+ import axios, { type CancelToken } from 'axios';
2
2
  import { defaultTo, includes, or, path, pathOr } from 'ramda';
3
3
  import { useEffect, useState } from 'react';
4
4
  import type { JsonDecoder } from 'ts.data.json';
@@ -10,13 +10,13 @@ import useCancelTokenSource from '../useCancelTokenSource';
10
10
  export interface RequestParams<TResult> {
11
11
  decoder?: JsonDecoder.Decoder<TResult>;
12
12
  defaultFailureMessage?: string;
13
- getErrorMessage?: (error) => string;
13
+ getErrorMessage?: (error: unknown) => string;
14
14
  httpCodesBypassErrorSnackbar?: Array<number>;
15
- request: (token) => (params?) => Promise<TResult>;
15
+ request: (token: CancelToken) => (params?: unknown) => Promise<TResult>;
16
16
  }
17
17
 
18
18
  export interface RequestResult<TResult> {
19
- sendRequest: (params?) => Promise<TResult>;
19
+ sendRequest: (params?: unknown) => Promise<TResult>;
20
20
  sending: boolean;
21
21
  }
22
22
 
@@ -36,8 +36,8 @@ const useRequest = <TResult>({
36
36
  return (): void => cancel();
37
37
  }, [cancel]);
38
38
 
39
- const showRequestErrorMessage = (error): void => {
40
- errorLog(error.message);
39
+ const showRequestErrorMessage = (error: { message?: string }): void => {
40
+ errorLog(error.message ?? '');
41
41
 
42
42
  const message = or(
43
43
  pathOr(undefined, ['response', 'data', 'message'], error),
@@ -49,7 +49,7 @@ const useRequest = <TResult>({
49
49
  showErrorMessage(errorMessage as string);
50
50
  };
51
51
 
52
- const sendRequest = (params): Promise<TResult> => {
52
+ const sendRequest = (params?: unknown): Promise<TResult> => {
53
53
  setSending(true);
54
54
 
55
55
  return request(token)(params)
@@ -26,7 +26,7 @@ export type ButtonProps = AriaLabelingAttributes &
26
26
  icon?: string | ReactNode;
27
27
  iconVariant?: 'none' | 'start' | 'end';
28
28
  isDanger?: boolean;
29
- onClick?: (e) => void;
29
+ onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;
30
30
  ref?: React.Ref<HTMLButtonElement>;
31
31
  size?: 'small' | 'medium' | 'large';
32
32
  type?: 'button' | 'submit' | 'reset';
@@ -21,7 +21,7 @@ const muiColorMap: Record<
21
21
  type IconButtonProps = {
22
22
  disabled?: boolean;
23
23
  icon?: string | ReactNode;
24
- onClick?: (e) => void;
24
+ onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void;
25
25
  size?: 'small' | 'medium' | 'large';
26
26
  variant?: 'primary' | 'secondary' | 'ghost';
27
27
  } & AriaLabelingAttributes &
@@ -1,6 +1,6 @@
1
1
  import { useAtom, useAtomValue, useSetAtom } from 'jotai';
2
2
 
3
- import { ColumnType } from '../../../';
3
+ import { type Column, ColumnType } from '../../../';
4
4
  import { MemoizedListing } from '../../Listing';
5
5
  import Actions from './Actions/Actions';
6
6
  import {
@@ -34,7 +34,7 @@ const Listing = <TData extends { id: number; name: string }>({
34
34
  const changeSort = useSetAtom(changeSortAtom);
35
35
 
36
36
  const listingColumns = columns.concat({
37
- Component: ColumnActions,
37
+ Component: ColumnActions as Column['Component'],
38
38
  clickable: true,
39
39
  id: 'actions',
40
40
  label: '',
@@ -50,7 +50,7 @@ const Listing = <TData extends { id: number; name: string }>({
50
50
  isActionBarVisible
51
51
  limit={limit}
52
52
  loading={isLoading}
53
- onLimitChange={setLimit}
53
+ onLimitChange={(newLimit) => setLimit(Number(newLimit))}
54
54
  onPaginate={setPage}
55
55
  onSort={changeSort}
56
56
  rows={rows}
@@ -1,4 +1,4 @@
1
1
  import { equals, type } from 'ramda';
2
2
 
3
- export const isAFunction = (property): boolean =>
3
+ export const isAFunction = (property: unknown): boolean =>
4
4
  equals('Function', type(property));
@@ -11,7 +11,10 @@ import { useAccessRightsChange } from './useAccessRightsChange';
11
11
  import { useAccessRightsInitValues } from './useAccessRightsInitValues';
12
12
 
13
13
  interface Props {
14
- cancel?: ({ dirty, values }) => void;
14
+ cancel?: (params: {
15
+ dirty: boolean;
16
+ values: Array<AccessRightInitialValues>;
17
+ }) => void;
15
18
  endpoints: Endpoints;
16
19
  initialValues: Array<AccessRightInitialValues>;
17
20
  isSubmitting?: boolean;
@@ -8,7 +8,10 @@ import { useActionsStyles } from './Actions.styles';
8
8
  import { useActions } from './useActions';
9
9
 
10
10
  interface Props {
11
- cancel?: ({ dirty, values }) => void;
11
+ cancel?: (params: {
12
+ dirty: boolean;
13
+ values: Array<AccessRightInitialValues>;
14
+ }) => void;
12
15
  clear: () => void;
13
16
  isSubmitting?: boolean;
14
17
  labels: Labels['actions'];
@@ -43,8 +43,8 @@ const ShareInput = ({ labels, endpoints, roles }: Props): ReactElement => {
43
43
  <ContactSwitch labels={labels} />
44
44
  <div className={classes.inputs}>
45
45
  <SingleConnectedAutocompleteField
46
+ {...({ clearable: true } as Record<string, unknown>)}
46
47
  changeIdValue={changeIdValue}
47
- clearable
48
48
  disableClearable={false}
49
49
  field="name"
50
50
  fullWidth
@@ -2,6 +2,7 @@ import CheckCircleIcon from '@mui/icons-material/CheckCircle';
2
2
 
3
3
  import { useAtomValue, useSetAtom } from 'jotai';
4
4
  import { equals, includes, isNil } from 'ramda';
5
+ import type React from 'react';
5
6
  import {
6
7
  type Dispatch,
7
8
  type ReactElement,
@@ -11,6 +12,7 @@ import {
11
12
  } from 'react';
12
13
 
13
14
  import { buildListingEndpoint, type SelectEntry } from '../../../..';
15
+ import type { SearchParameter } from '../../../../api/buildListingEndpoint/models';
14
16
  import {
15
17
  accessRightIdsDerivedAtom,
16
18
  addAccessRightDerivedAtom,
@@ -22,14 +24,28 @@ import {
22
24
  type Endpoints
23
25
  } from '../models';
24
26
 
27
+ interface ShareInputOption {
28
+ id: number | string;
29
+ most_permissive_role?: 'editor' | 'viewer';
30
+ name: string;
31
+ }
32
+
33
+ interface ShareInputEndpointParameters {
34
+ page: number;
35
+ search?: SearchParameter;
36
+ }
37
+
25
38
  interface UseShareInputState {
26
39
  add: () => void;
27
- changeIdValue: (entry: SelectEntry) => void;
28
- getEndpoint: (parameters) => string;
29
- getOptionDisabled: (option) => boolean;
40
+ changeIdValue: (entry: SelectEntry) => string;
41
+ getEndpoint: (parameters: ShareInputEndpointParameters) => string;
42
+ getOptionDisabled: (option: SelectEntry) => boolean;
30
43
  isContactGroup: boolean;
31
- getRenderedOptionText: (option: unknown) => ReactElement | string;
32
- selectContact: (_, entry) => void;
44
+ getRenderedOptionText: (option: SelectEntry) => ReactElement | string;
45
+ selectContact: (
46
+ _: React.SyntheticEvent,
47
+ entry: AccessRightInitialValues | null | unknown
48
+ ) => void;
33
49
  selectedContact: AccessRightInitialValues | null;
34
50
  selectedRole: string;
35
51
  setSelectedRole: Dispatch<SetStateAction<string>>;
@@ -46,9 +62,13 @@ const useShareInput = (endpoints: Endpoints): UseShareInputState => {
46
62
 
47
63
  const isContactGroup = equals(contactType, ContactType.ContactGroup);
48
64
 
49
- const selectContact = (_, entry): void => {
50
- setSelectedContact(entry);
51
- if (equals('editor', entry?.most_permissive_role)) {
65
+ const selectContact = (
66
+ _: React.SyntheticEvent,
67
+ entry: AccessRightInitialValues | null | unknown
68
+ ): void => {
69
+ const value = entry as AccessRightInitialValues | null;
70
+ setSelectedContact(value);
71
+ if (equals('editor', value?.most_permissive_role)) {
52
72
  return;
53
73
  }
54
74
  setSelectedRole('viewer');
@@ -70,7 +90,7 @@ const useShareInput = (endpoints: Endpoints): UseShareInputState => {
70
90
  setSelectedContact(null);
71
91
  };
72
92
 
73
- const getEndpoint = (parameters): string =>
93
+ const getEndpoint = (parameters: ShareInputEndpointParameters): string =>
74
94
  buildListingEndpoint({
75
95
  baseEndpoint: isContactGroup ? endpoints.contactGroup : endpoints.contact,
76
96
  parameters: {
@@ -79,18 +99,20 @@ const useShareInput = (endpoints: Endpoints): UseShareInputState => {
79
99
  }
80
100
  });
81
101
 
82
- const getRenderedOptionText = (option): ReactElement => {
102
+ const getRenderedOptionText = (option: SelectEntry): ReactElement => {
103
+ const value = option as ShareInputOption | undefined;
104
+
83
105
  return (
84
106
  <>
85
- {option?.name}
86
- {includes(option?.id, accessRightIds) && (
107
+ {value?.name}
108
+ {includes(value?.id, accessRightIds) && (
87
109
  <CheckCircleIcon color="success" />
88
110
  )}
89
111
  </>
90
112
  );
91
113
  };
92
114
 
93
- const getOptionDisabled = (option): boolean => {
115
+ const getOptionDisabled = (option: SelectEntry): boolean => {
94
116
  return includes(option.id, accessRightIds);
95
117
  };
96
118