@centreon/ui 24.4.7 → 24.4.9

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 (64) hide show
  1. package/package.json +17 -12
  2. package/src/Button/Save/StartIcon.tsx +3 -3
  3. package/src/Dashboard/Item.tsx +1 -1
  4. package/src/Dashboard/Layout.tsx +2 -2
  5. package/src/FileDropZone/index.tsx +3 -1
  6. package/src/Form/Inputs/CheckboxGroup.tsx +1 -4
  7. package/src/Form/Inputs/index.tsx +1 -1
  8. package/src/Graph/LineChart/BasicComponents/Lines/Threshold/Circle.tsx +2 -2
  9. package/src/Graph/LineChart/BasicComponents/Lines/Threshold/index.tsx +5 -4
  10. package/src/Graph/LineChart/BasicComponents/Thresholds.tsx +2 -2
  11. package/src/Graph/LineChart/BasicComponents/useFilterLines.ts +1 -1
  12. package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/GuidingLines.tsx +2 -2
  13. package/src/Graph/LineChart/InteractiveComponents/Annotations/Annotation/index.tsx +2 -3
  14. package/src/Graph/LineChart/InteractiveComponents/Annotations/EventAnnotations.tsx +1 -1
  15. package/src/Graph/LineChart/Legend/useLegend.ts +3 -3
  16. package/src/Graph/LineChart/helpers/doc.ts +16 -13
  17. package/src/Graph/LineChart/helpers/index.ts +1 -1
  18. package/src/Graph/LineChart/index.stories.tsx +4 -2
  19. package/src/Graph/SingleBar/Thresholds.tsx +2 -2
  20. package/src/Graph/Text/Text.stories.tsx +60 -4
  21. package/src/Graph/common/timeSeries/index.ts +3 -3
  22. package/src/InputField/Select/Autocomplete/Connected/index.tsx +10 -7
  23. package/src/InputField/Select/Autocomplete/Draggable/SortableList.tsx +1 -1
  24. package/src/InputField/Select/Autocomplete/Draggable/SortableListContent.tsx +1 -1
  25. package/src/InputField/Select/Autocomplete/Draggable/index.tsx +1 -1
  26. package/src/InputField/Select/IconPopover/index.tsx +2 -2
  27. package/src/InputField/Select/index.tsx +1 -1
  28. package/src/Listing/Header/ListingHeader.tsx +1 -1
  29. package/src/Listing/Listing.styles.ts +2 -3
  30. package/src/Listing/index.stories.tsx +12 -1
  31. package/src/Listing/index.tsx +1 -2
  32. package/src/RichTextEditor/RichTextEditor.tsx +12 -1
  33. package/src/SortableItems/index.tsx +2 -7
  34. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/PickersStartEndDate.tsx +8 -3
  35. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/models.ts +0 -2
  36. package/src/TimePeriods/DateTimePickerInput.tsx +45 -17
  37. package/src/TimePeriods/TimePeriods.cypress.spec.tsx +9 -33
  38. package/src/TimePeriods/helpers/index.ts +1 -1
  39. package/src/TimePeriods/index.stories.tsx +12 -4
  40. package/src/TimePeriods/index.tsx +2 -2
  41. package/src/api/QueryProvider.tsx +1 -1
  42. package/src/api/TestQueryProvider.tsx +1 -1
  43. package/src/api/useFetchQuery/index.ts +27 -23
  44. package/src/api/useMutationQuery/index.ts +39 -17
  45. package/src/components/DataTable/DataListing.tsx +6 -0
  46. package/src/components/DataTable/DataTable.cypress.spec.tsx +193 -0
  47. package/src/components/DataTable/DataTable.stories.tsx +40 -0
  48. package/src/components/DataTable/DataTable.styles.ts +3 -0
  49. package/src/components/DataTable/DataTable.tsx +3 -3
  50. package/src/components/DataTable/Item/DataTableItem.styles.ts +7 -2
  51. package/src/components/DataTable/Item/DataTableItem.tsx +2 -2
  52. package/src/components/DataTable/index.ts +3 -1
  53. package/src/components/Form/AccessRights/__fixtures__/contactAccessRight.mock.ts +2 -0
  54. package/src/components/Form/AccessRights/useAccessRightsForm.utils.ts +1 -1
  55. package/src/components/Form/Dashboard/DashboardForm.tsx +15 -12
  56. package/src/components/Modal/Modal.styles.ts +4 -2
  57. package/src/index.ts +1 -0
  58. package/src/queryParameters/url/index.ts +5 -1
  59. package/src/utils/index.ts +0 -1
  60. package/src/utils/{useLicenseExpirationWarning.cypress.spec.tsx → useLicenseExpirationWarning.test.tsx} +48 -37
  61. package/src/utils/useLicenseExpirationWarning.ts +18 -18
  62. package/src/screens/dashboard/DashboardsDetail.stories.tsx +0 -108
  63. package/src/screens/dashboard/DashboardsOverview.stories.tsx +0 -281
  64. package/src/utils/useDateTimePickerAdapter.ts +0 -309
@@ -12,6 +12,7 @@ import { LinkPlugin } from '@lexical/react/LexicalLinkPlugin';
12
12
  import { equals } from 'ramda';
13
13
  import { ListPlugin } from '@lexical/react/LexicalListPlugin';
14
14
  import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin';
15
+ import { $generateHtmlFromNodes } from '@lexical/html';
15
16
 
16
17
  import { Typography } from '@mui/material';
17
18
 
@@ -38,6 +39,7 @@ export interface RichTextEditorProps {
38
39
  openLinkInNewTab?: boolean;
39
40
  placeholder?: string;
40
41
  resetEditorToInitialStateCondition?: () => boolean;
42
+ setHtmlString?: (htmlString: string) => void;
41
43
  toolbarClassName?: string;
42
44
  toolbarPositions?: 'start' | 'end';
43
45
  }
@@ -143,6 +145,7 @@ const RichTextEditor = ({
143
145
  openLinkInNewTab = true,
144
146
  initialize,
145
147
  displayBlockButtons = true,
148
+ setHtmlString,
146
149
  toolbarClassName
147
150
  }: RichTextEditorProps): JSX.Element => {
148
151
  const { classes } = useStyles({ toolbarPositions });
@@ -178,6 +181,13 @@ const RichTextEditor = ({
178
181
  }
179
182
  };
180
183
 
184
+ const change = (state: EditorState, editor: LexicalEditor): void => {
185
+ editor.update(() => {
186
+ setHtmlString?.($generateHtmlFromNodes(editor, null));
187
+ });
188
+ getEditorState?.(state, editor);
189
+ };
190
+
181
191
  return (
182
192
  <LexicalComposer initialConfig={initialConfig}>
183
193
  <div className={classes.container}>
@@ -210,6 +220,7 @@ const RichTextEditor = ({
210
220
  resetEditorToInitialStateCondition={
211
221
  resetEditorToInitialStateCondition
212
222
  }
223
+ setHtmlString={setHtmlString}
213
224
  onBlur={onBlur}
214
225
  />
215
226
  }
@@ -218,7 +229,7 @@ const RichTextEditor = ({
218
229
  <HistoryPlugin />
219
230
  <LinkPlugin />
220
231
  <ListPlugin />
221
- <OnChangePlugin onChange={getEditorState} />
232
+ <OnChangePlugin onChange={change} />
222
233
  <AutoCompleteLinkPlugin openLinkInNewTab={openLinkInNewTab} />
223
234
  <FloatingLinkEditorPlugin
224
235
  editable={editable}
@@ -15,11 +15,7 @@ import {
15
15
  DragEndEvent,
16
16
  Over
17
17
  } from '@dnd-kit/core';
18
- import {
19
- SortableContext,
20
- sortableKeyboardCoordinates,
21
- SortingStrategy
22
- } from '@dnd-kit/sortable';
18
+ import { SortableContext, SortingStrategy } from '@dnd-kit/sortable';
23
19
  import {
24
20
  equals,
25
21
  find,
@@ -117,7 +113,6 @@ const SortableItems = <T extends { [propertyToFilterItemsOn]: string }>({
117
113
  useSensor(MouseSensor),
118
114
  useSensor(PointerSensor),
119
115
  useSensor(KeyboardSensor, {
120
- coordinateGetter: sortableKeyboardCoordinates,
121
116
  keyboardCodes: {
122
117
  cancel: ['Escape'],
123
118
  end: ['Space', 'Enter'],
@@ -169,7 +164,7 @@ const SortableItems = <T extends { [propertyToFilterItemsOn]: string }>({
169
164
  };
170
165
 
171
166
  const getItemById = (id): T | undefined =>
172
- find(propEq(propertyToFilterItemsOn, id), items);
167
+ find(propEq(id, propertyToFilterItemsOn), items);
173
168
 
174
169
  const activeItem = getItemById(activeId) as Record<string, unknown>;
175
170
 
@@ -2,12 +2,15 @@ import { useAtomValue } from 'jotai';
2
2
  import { makeStyles } from 'tss-react/mui';
3
3
  import { equals } from 'ramda';
4
4
  import { useTranslation } from 'react-i18next';
5
+ import dayjs from 'dayjs';
6
+ import utc from 'dayjs/plugin/utc';
7
+ import timezone from 'dayjs/plugin/timezone';
5
8
 
9
+ import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
6
10
  import { Typography } from '@mui/material';
7
11
  import { LocalizationProvider } from '@mui/x-date-pickers';
8
12
 
9
13
  import { userAtom } from '@centreon/ui-context';
10
- import { useDateTimePickerAdapter } from '@centreon/ui';
11
14
 
12
15
  import DateTimePickerInput from '../../DateTimePickerInput';
13
16
  import {
@@ -20,6 +23,9 @@ import ErrorText from './ErrorText';
20
23
  import { PickersData, PickersStartEndDateDirection } from './models';
21
24
  import { PickersStartEndDateModel } from './usePickersStartEndDate';
22
25
 
26
+ dayjs.extend(utc);
27
+ dayjs.extend(timezone);
28
+
23
29
  const useStyles = makeStyles()((theme) => ({
24
30
  error: {
25
31
  textAlign: 'center'
@@ -104,7 +110,6 @@ const PickersStartEndDate = ({
104
110
  direction = PickersStartEndDateDirection.column
105
111
  }: Props): JSX.Element => {
106
112
  const { classes, cx } = useStyles();
107
- const { Adapter } = useDateTimePickerAdapter();
108
113
 
109
114
  const { locale } = useAtomValue(userAtom);
110
115
  const error = useAtomValue(errorTimePeriodAtom);
@@ -126,7 +131,7 @@ const PickersStartEndDate = ({
126
131
  return (
127
132
  <LocalizationProvider
128
133
  adapterLocale={locale.substring(0, 2)}
129
- dateAdapter={Adapter}
134
+ dateAdapter={AdapterDayjs}
130
135
  >
131
136
  <div className={styleContainer}>
132
137
  <PickerDateWithLabel
@@ -18,8 +18,6 @@ export interface PickersData {
18
18
  getError?: (value: boolean) => void;
19
19
  isDisabledEndPicker?: boolean;
20
20
  isDisabledStartPicker?: boolean;
21
- onCloseEndPicker?: (isClosed: boolean) => void;
22
- onCloseStartPicker?: (isClosed: boolean) => void;
23
21
  rangeEndDate?: RangeDate;
24
22
  rangeStartDate?: RangeDate;
25
23
  }
@@ -1,19 +1,29 @@
1
- import dayjs from 'dayjs';
1
+ import { useCallback } from 'react';
2
2
 
3
- import { DateTimePicker } from '@mui/x-date-pickers';
3
+ import dayjs, { Dayjs } from 'dayjs';
4
+ import { useAtomValue } from 'jotai';
5
+ import { equals } from 'ramda';
4
6
 
5
- import { useDateTimePickerAdapter } from '@centreon/ui';
7
+ import { DateTimePicker, LocalizationProvider } from '@mui/x-date-pickers';
8
+ import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
9
+
10
+ import { userAtom } from '@centreon/ui-context';
6
11
 
7
12
  import { CustomTimePeriodProperty } from './models';
8
13
 
14
+ interface ChangeDateProps {
15
+ date: Date;
16
+ property: CustomTimePeriodProperty | string;
17
+ }
18
+
9
19
  interface Props {
10
- changeDate: (props) => void;
20
+ changeDate: (props: ChangeDateProps) => void;
11
21
  date: Date | null;
12
22
  desktopMediaQuery?: string;
13
23
  disabled?: boolean;
14
24
  maxDate?: Date;
15
25
  minDate?: Date;
16
- property: CustomTimePeriodProperty;
26
+ property: CustomTimePeriodProperty | string;
17
27
  }
18
28
 
19
29
  const DateTimePickerInput = ({
@@ -25,24 +35,42 @@ const DateTimePickerInput = ({
25
35
  disabled = false,
26
36
  desktopMediaQuery
27
37
  }: Props): JSX.Element => {
28
- const { desktopPickerMediaQuery } = useDateTimePickerAdapter();
38
+ const desktopPickerMediaQuery =
39
+ '@media (min-width: 1024px) or (pointer: fine)';
40
+
41
+ const { timezone, locale } = useAtomValue(userAtom);
42
+
43
+ const isUTC = equals(timezone, 'UTC');
29
44
 
30
45
  const changeTime = (newValue: dayjs.Dayjs | null): void => {
31
46
  changeDate({ date: dayjs(newValue).toDate(), property });
32
47
  };
33
48
 
49
+ const formatDate = useCallback(
50
+ (currentDate: Date | null): Dayjs => {
51
+ return isUTC ? dayjs.utc(currentDate) : dayjs.tz(currentDate, timezone);
52
+ },
53
+ [isUTC, timezone]
54
+ );
55
+
34
56
  return (
35
- <DateTimePicker<dayjs.Dayjs>
36
- dayOfWeekFormatter={(day: string): string =>
37
- day.substring(0, 2).toUpperCase()
38
- }
39
- desktopModeMediaQuery={desktopMediaQuery ?? desktopPickerMediaQuery}
40
- disabled={disabled}
41
- maxDate={maxDate && dayjs(maxDate)}
42
- minDate={minDate && dayjs(minDate)}
43
- value={dayjs(date)}
44
- onChange={changeTime}
45
- />
57
+ <LocalizationProvider
58
+ adapterLocale={locale.substring(0, 2)}
59
+ dateAdapter={AdapterDayjs}
60
+ dateLibInstance={dayjs}
61
+ >
62
+ <DateTimePicker<dayjs.Dayjs>
63
+ dayOfWeekFormatter={(dayOfWeek) =>
64
+ dayOfWeek.substring(0, 2).toLocaleUpperCase()
65
+ }
66
+ desktopModeMediaQuery={desktopMediaQuery ?? desktopPickerMediaQuery}
67
+ disabled={disabled}
68
+ maxDate={maxDate && formatDate(maxDate)}
69
+ minDate={minDate && formatDate(minDate)}
70
+ value={formatDate(date)}
71
+ onChange={changeTime}
72
+ />
73
+ </LocalizationProvider>
46
74
  );
47
75
  };
48
76
 
@@ -3,15 +3,10 @@ import localizedFormatPlugin from 'dayjs/plugin/localizedFormat';
3
3
  import timezonePlugin from 'dayjs/plugin/timezone';
4
4
  import utcPlugin from 'dayjs/plugin/utc';
5
5
  import { Provider, createStore } from 'jotai';
6
- import { equals, inc } from 'ramda';
6
+ import { equals } from 'ramda';
7
7
  import { renderHook } from '@testing-library/react';
8
8
 
9
- import { LocalizationProvider } from '@mui/x-date-pickers';
10
-
11
- import {
12
- useLocaleDateTimeFormat,
13
- useDateTimePickerAdapter
14
- } from '@centreon/ui';
9
+ import { useLocaleDateTimeFormat } from '@centreon/ui';
15
10
  import { ListingVariant, userAtom } from '@centreon/ui-context';
16
11
 
17
12
  import { CustomTimePeriodProperty } from './models';
@@ -297,10 +292,6 @@ testData.forEach((item) =>
297
292
  beforeEach(() => {
298
293
  cy.viewport('macbook-13');
299
294
 
300
- const { result } = renderHook(() => useDateTimePickerAdapter());
301
-
302
- const { Adapter } = result.current;
303
-
304
295
  const store = createStore();
305
296
  store.set(userAtom, {
306
297
  ...retrievedUser,
@@ -311,31 +302,16 @@ testData.forEach((item) =>
311
302
  cy.mount({
312
303
  Component: (
313
304
  <Provider store={store}>
314
- <LocalizationProvider adapterLocale="en" dateAdapter={Adapter}>
315
- <DateTimePickerInput
316
- changeDate={cy.stub()}
317
- date={new Date(item.initialDate)}
318
- desktopMediaQuery="@media (min-width: 1024px)"
319
- property={CustomTimePeriodProperty.start}
320
- />
321
- </LocalizationProvider>
305
+ <DateTimePickerInput
306
+ changeDate={cy.stub()}
307
+ date={new Date(item.initialDate)}
308
+ property={CustomTimePeriodProperty.start}
309
+ />
322
310
  </Provider>
323
311
  )
324
312
  });
325
313
  });
326
314
 
327
- it('checks input calendar value contains correct date', () => {
328
- const { result } = renderHook(() => useLocaleDateTimeFormat());
329
- const { format } = result.current;
330
-
331
- const dateInput = format({
332
- date: dayjs(item.initialDate).tz(item.timezone),
333
- formatString: 'L hh:mm A'
334
- });
335
-
336
- cy.get('input').should('have.value', dateInput);
337
- });
338
-
339
315
  it(`displays the correct number of days for the current month when the ${item.button} button is clicked`, () => {
340
316
  cy.get('button').click();
341
317
  item.data.forEach((element) => {
@@ -389,7 +365,7 @@ testData.forEach((item) =>
389
365
 
390
366
  cy.get('[role="rowgroup"]').children().as('listWeeks');
391
367
 
392
- cy.get('@listWeeks').should('have.length', inc(numberWeeks));
368
+ cy.get('@listWeeks').should('have.length', numberWeeks);
393
369
  cy.get('@listWeeks').eq(0).as('firstWeek');
394
370
  cy.get('@firstWeek').children().as('listDaysInFirstWeek');
395
371
 
@@ -416,7 +392,7 @@ testData.forEach((item) =>
416
392
 
417
393
  cy.get('[role="rowgroup"]').children().as('listWeeks');
418
394
 
419
- cy.get('@listWeeks').should('have.length', inc(numberWeeks));
395
+ cy.get('@listWeeks').should('have.length', numberWeeks);
420
396
 
421
397
  cy.get('@listWeeks')
422
398
  .eq(numberWeeks - 1)
@@ -23,4 +23,4 @@ export const getTimePeriodById = ({
23
23
  id,
24
24
  timePeriods
25
25
  }: TimePeriodById): TimePeriod =>
26
- find<TimePeriod>(propEq('id', id))(timePeriods) as TimePeriod;
26
+ find<TimePeriod>(propEq(id, 'id'))(timePeriods) as TimePeriod;
@@ -88,20 +88,27 @@ const args = {
88
88
  ]
89
89
  };
90
90
 
91
+ const parameters = {
92
+ chromatic: { diffThreshold: 0.1 }
93
+ };
94
+
91
95
  export const BasicTimePeriod: Story = {
92
96
  ...Template,
93
- argTypes
97
+ argTypes,
98
+ parameters
94
99
  };
95
100
 
96
101
  export const WithExtraTimePeriods: Story = {
97
102
  ...Template,
98
103
  argTypes,
99
- args
104
+ args,
105
+ parameters
100
106
  };
101
107
 
102
108
  export const WithExternalComponent: Story = {
103
109
  ...TemplateWithExternalComponent,
104
- argTypes
110
+ argTypes,
111
+ parameters
105
112
  };
106
113
 
107
114
  export const SimpleTimePeriod: StorySimpleTimePeriod = {
@@ -109,5 +116,6 @@ export const SimpleTimePeriod: StorySimpleTimePeriod = {
109
116
  args: {
110
117
  endDate: dayjs(Date.now()).toDate(),
111
118
  startDate: dayjs(Date.now()).subtract(29, 'day').toDate()
112
- }
119
+ },
120
+ parameters
113
121
  };
@@ -20,7 +20,7 @@ import { useStyles } from './TimePeriods.styles';
20
20
  import {
21
21
  CustomTimePeriod as CustomTimePeriodModel,
22
22
  EndStartInterval,
23
- TimePeriod
23
+ TimePeriod as TimePeriodModel
24
24
  } from './models';
25
25
  import useTimePeriod from './useTimePeriod';
26
26
 
@@ -34,7 +34,7 @@ interface Parameters extends EndStartInterval {
34
34
  export interface Props {
35
35
  adjustTimePeriodData?: Omit<CustomTimePeriodModel, 'timelineEventsLimit'>;
36
36
  disabled?: boolean;
37
- extraTimePeriods?: Array<Omit<TimePeriod, 'timelineEventsLimit'>>;
37
+ extraTimePeriods?: Array<Omit<TimePeriodModel, 'timelineEventsLimit'>>;
38
38
  getIsError?: (value: boolean) => void;
39
39
  getParameters?: ({ start, end, timelineEventsLimit }: Parameters) => void;
40
40
  renderExternalComponent?: ReactNode;
@@ -7,7 +7,7 @@ const defaultCacheTime = 5 * 1_000;
7
7
  const client = new QueryClient({
8
8
  defaultOptions: {
9
9
  queries: {
10
- cacheTime: defaultCacheTime,
10
+ gcTime: defaultCacheTime,
11
11
  refetchOnWindowFocus: false,
12
12
  staleTime: defaultCacheTime,
13
13
  suspense: true
@@ -5,7 +5,7 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
5
5
  const client = new QueryClient({
6
6
  defaultOptions: {
7
7
  queries: {
8
- cacheTime: 0,
8
+ gcTime: 0,
9
9
  retry: false
10
10
  }
11
11
  }
@@ -26,7 +26,9 @@ export interface UseFetchQueryProps<T> {
26
26
  getQueryKey: () => QueryKey;
27
27
  httpCodesBypassErrorSnackbar?: Array<number>;
28
28
  isPaginated?: boolean;
29
- queryOptions?: Omit<
29
+ queryOptions?: {
30
+ suspense?: boolean;
31
+ } & Omit<
30
32
  UseQueryOptions<T | ResponseError, Error, T | ResponseError, QueryKey>,
31
33
  'queryKey' | 'queryFn'
32
34
  >;
@@ -34,11 +36,12 @@ export interface UseFetchQueryProps<T> {
34
36
 
35
37
  export type UseFetchQueryState<T> = {
36
38
  data?: T;
39
+ error: Omit<ResponseError, 'isError'> | null;
37
40
  fetchQuery: () => Promise<T | ResponseError>;
38
41
  prefetchNextPage: ({ page, getPrefetchQueryKey }) => void;
39
42
  prefetchPreviousPage: ({ page, getPrefetchQueryKey }) => void;
40
43
  prefetchQuery: ({ endpointParams, queryKey }) => void;
41
- } & Omit<QueryObserverBaseResult, 'data'>;
44
+ } & Omit<QueryObserverBaseResult, 'data' | 'error'>;
42
45
 
43
46
  export interface PrefetchEndpointParams {
44
47
  page: number;
@@ -62,9 +65,8 @@ const useFetchQuery = <T extends object>({
62
65
 
63
66
  const { showErrorMessage } = useSnackbar();
64
67
 
65
- const queryData = useQuery<T | ResponseError, Error>(
66
- getQueryKey(),
67
- ({ signal }): Promise<T | ResponseError> =>
68
+ const queryData = useQuery<T | ResponseError, Error>({
69
+ queryFn: ({ signal }): Promise<T | ResponseError> =>
68
70
  customFetch<T>({
69
71
  baseEndpoint,
70
72
  catchError,
@@ -74,10 +76,9 @@ const useFetchQuery = <T extends object>({
74
76
  headers: new Headers(fetchHeaders),
75
77
  signal
76
78
  }),
77
- {
78
- ...queryOptions
79
- }
80
- );
79
+ queryKey: getQueryKey(),
80
+ ...queryOptions
81
+ });
81
82
 
82
83
  const queryClient = useQueryClient();
83
84
 
@@ -97,9 +98,8 @@ const useFetchQuery = <T extends object>({
97
98
  };
98
99
 
99
100
  const prefetchQuery = ({ endpointParams, queryKey }): void => {
100
- queryClient.prefetchQuery(
101
- queryKey,
102
- ({ signal }): Promise<T | ResponseError> =>
101
+ queryClient.prefetchQuery({
102
+ queryFn: ({ signal }): Promise<T | ResponseError> =>
103
103
  customFetch<T>({
104
104
  baseEndpoint,
105
105
  catchError,
@@ -108,8 +108,9 @@ const useFetchQuery = <T extends object>({
108
108
  endpoint: getEndpoint(endpointParams),
109
109
  headers: new Headers(fetchHeaders),
110
110
  signal
111
- })
112
- );
111
+ }),
112
+ queryKey
113
+ });
113
114
  };
114
115
 
115
116
  const prefetchNextPage = ({ page, getPrefetchQueryKey }): void => {
@@ -139,9 +140,8 @@ const useFetchQuery = <T extends object>({
139
140
  };
140
141
 
141
142
  const fetchQuery = (): Promise<T | ResponseError> => {
142
- return queryClient.fetchQuery(
143
- getQueryKey(),
144
- ({ signal }): Promise<T | ResponseError> =>
143
+ return queryClient.fetchQuery({
144
+ queryFn: ({ signal }): Promise<T | ResponseError> =>
145
145
  customFetch<T>({
146
146
  baseEndpoint,
147
147
  catchError,
@@ -150,8 +150,9 @@ const useFetchQuery = <T extends object>({
150
150
  endpoint: getEndpoint(),
151
151
  headers: new Headers(fetchHeaders),
152
152
  signal
153
- })
154
- );
153
+ }),
154
+ queryKey: getQueryKey()
155
+ });
155
156
  };
156
157
 
157
158
  const data = useMemo(
@@ -168,13 +169,16 @@ const useFetchQuery = <T extends object>({
168
169
 
169
170
  useEffect(() => {
170
171
  return (): void => {
171
- queryClient.cancelQueries(getQueryKey());
172
+ queryClient.cancelQueries({ queryKey: getQueryKey() });
172
173
  };
173
174
  }, []);
174
175
 
175
- useEffect(() => {
176
- manageError();
177
- }, useDeepCompare([queryData.data]));
176
+ useEffect(
177
+ () => {
178
+ manageError();
179
+ },
180
+ useDeepCompare([queryData.data])
181
+ );
178
182
 
179
183
  return {
180
184
  ...omit(['data', 'error'], queryData),
@@ -8,7 +8,7 @@ import {
8
8
  } from '@tanstack/react-query';
9
9
  import { JsonDecoder } from 'ts.data.json';
10
10
  import anylogger from 'anylogger';
11
- import { includes } from 'ramda';
11
+ import { includes, omit } from 'ramda';
12
12
 
13
13
  import { CatchErrorProps, customFetch, ResponseError } from '../customFetch';
14
14
  import useSnackbar from '../../Snackbar/useSnackbar';
@@ -31,14 +31,33 @@ export type UseMutationQueryProps<T, TMeta> = {
31
31
  getEndpoint: (_meta: TMeta) => string;
32
32
  httpCodesBypassErrorSnackbar?: Array<number>;
33
33
  method: Method;
34
- } & Omit<UseMutationOptions<T & { _meta?: TMeta }>, 'mutationFn'>;
34
+ onError?: (
35
+ error: ResponseError,
36
+ variables: T & { _meta: TMeta },
37
+ context: unknown
38
+ ) => unknown;
39
+ onMutate?: (variables: T & { _meta: TMeta }) => Promise<unknown> | unknown;
40
+ onSuccess?: (
41
+ data: ResponseError | T,
42
+ variables: T & {
43
+ _meta: TMeta;
44
+ },
45
+ context: unknown
46
+ ) => unknown;
47
+ } & Omit<
48
+ UseMutationOptions<T & { _meta?: TMeta }>,
49
+ 'mutationFn' | 'onError' | 'onMutate' | 'onSuccess'
50
+ >;
35
51
 
36
52
  const log = anylogger('API Request');
37
53
 
38
- export type UseMutationQueryState<T> = {
54
+ export type UseMutationQueryState<T> = Omit<
55
+ UseMutationResult<T | ResponseError>,
56
+ 'isError'
57
+ > & {
39
58
  isError: boolean;
40
59
  isMutating: boolean;
41
- } & UseMutationResult<T | ResponseError>;
60
+ };
42
61
 
43
62
  const useMutationQuery = <T extends object, TMeta>({
44
63
  getEndpoint,
@@ -59,8 +78,10 @@ const useMutationQuery = <T extends object, TMeta>({
59
78
  T | ResponseError,
60
79
  ResponseError,
61
80
  T & { _meta: TMeta }
62
- >(
63
- (_payload: T & { _meta: TMeta }): Promise<T | ResponseError> => {
81
+ >({
82
+ mutationFn: (
83
+ _payload: T & { _meta: TMeta }
84
+ ): Promise<T | ResponseError> => {
64
85
  const { _meta, ...payload } = _payload || {};
65
86
 
66
87
  return customFetch<T>({
@@ -78,12 +99,10 @@ const useMutationQuery = <T extends object, TMeta>({
78
99
  payload
79
100
  });
80
101
  },
81
- {
82
- onError,
83
- onMutate,
84
- onSuccess
85
- }
86
- );
102
+ onError,
103
+ onMutate,
104
+ onSuccess
105
+ });
87
106
 
88
107
  const manageError = (): void => {
89
108
  const data = queryData.data as ResponseError | undefined;
@@ -100,14 +119,17 @@ const useMutationQuery = <T extends object, TMeta>({
100
119
  }
101
120
  };
102
121
 
103
- useEffect(() => {
104
- manageError();
105
- }, useDeepCompare([queryData.data]));
122
+ useEffect(
123
+ () => {
124
+ manageError();
125
+ },
126
+ useDeepCompare([queryData.data])
127
+ );
106
128
 
107
129
  return {
108
- ...queryData,
130
+ ...omit(['isError'], queryData),
109
131
  isError: (queryData.data as ResponseError | undefined)?.isError || false,
110
- isMutating: queryData.isLoading
132
+ isMutating: queryData.isPending
111
133
  };
112
134
  };
113
135
 
@@ -0,0 +1,6 @@
1
+ import { RowId } from '../../Listing/models';
2
+ import { Listing, ListingProps } from '../..';
3
+
4
+ export const DataListing = <TRow extends { id: RowId }>(
5
+ props: ListingProps<TRow>
6
+ ): JSX.Element => <Listing<TRow> {...props} />;