@centreon/ui 24.4.36 → 24.4.38

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 (156) hide show
  1. package/package.json +14 -19
  2. package/public/mockServiceWorker.js +1 -1
  3. package/src/Button/Icon/index.stories.tsx +1 -1
  4. package/src/Button/Icon/index.tsx +2 -2
  5. package/src/Button/Save/StartIcon.tsx +3 -3
  6. package/src/Button/Save/index.tsx +5 -9
  7. package/src/Checkbox/Checkbox.tsx +2 -2
  8. package/src/Checkbox/CheckboxGroup/index.tsx +2 -2
  9. package/src/Dashboard/Item.tsx +1 -1
  10. package/src/Dashboard/Layout.tsx +2 -2
  11. package/src/Dialog/index.tsx +1 -1
  12. package/src/FallbackPage/FallbackPage.tsx +3 -3
  13. package/src/FileDropZone/index.tsx +1 -3
  14. package/src/Form/Inputs/CheckboxGroup.tsx +4 -1
  15. package/src/Form/Inputs/index.tsx +1 -3
  16. package/src/Form/Inputs/models.ts +1 -9
  17. package/src/Graph/LineChart/BasicComponents/Lines/Threshold/Circle.tsx +2 -2
  18. package/src/Graph/LineChart/BasicComponents/Lines/Threshold/index.tsx +4 -5
  19. package/src/Graph/LineChart/BasicComponents/Thresholds.tsx +2 -2
  20. package/src/Graph/LineChart/BasicComponents/useFilterLines.ts +1 -1
  21. package/src/Graph/LineChart/InteractiveComponents/AnchorPoint/GuidingLines.tsx +2 -2
  22. package/src/Graph/LineChart/InteractiveComponents/Annotations/Annotation/index.tsx +3 -2
  23. package/src/Graph/LineChart/InteractiveComponents/Annotations/EventAnnotations.tsx +1 -1
  24. package/src/Graph/LineChart/Legend/useLegend.ts +3 -3
  25. package/src/Graph/LineChart/helpers/doc.ts +13 -16
  26. package/src/Graph/LineChart/helpers/index.ts +1 -1
  27. package/src/Graph/LineChart/index.stories.tsx +2 -4
  28. package/src/Graph/SingleBar/Thresholds.tsx +2 -2
  29. package/src/Graph/Text/Text.stories.tsx +4 -60
  30. package/src/Graph/common/timeSeries/index.ts +3 -3
  31. package/src/InputField/Select/Autocomplete/Connected/index.tsx +7 -10
  32. package/src/InputField/Select/Autocomplete/Draggable/SortableList.tsx +1 -1
  33. package/src/InputField/Select/Autocomplete/Draggable/SortableListContent.tsx +1 -1
  34. package/src/InputField/Select/Autocomplete/Draggable/index.tsx +1 -1
  35. package/src/InputField/Select/Autocomplete/index.tsx +115 -121
  36. package/src/InputField/Select/IconPopover/index.tsx +3 -3
  37. package/src/InputField/Select/index.tsx +1 -1
  38. package/src/InputField/Text/index.tsx +2 -2
  39. package/src/Listing/ActionBar/index.tsx +1 -2
  40. package/src/Listing/Cell/DataCell.tsx +1 -15
  41. package/src/Listing/Header/ListingHeader.tsx +1 -1
  42. package/src/Listing/Listing.styles.ts +3 -2
  43. package/src/Listing/index.stories.tsx +1 -12
  44. package/src/Listing/index.tsx +2 -1
  45. package/src/Module/index.tsx +4 -2
  46. package/src/Panel/index.tsx +1 -1
  47. package/src/RichTextEditor/RichTextEditor.tsx +1 -12
  48. package/src/SortableItems/index.tsx +7 -2
  49. package/src/ThemeProvider/index.tsx +0 -24
  50. package/src/TimePeriods/CustomTimePeriod/CompactCustomTimePeriod.styles.ts +7 -6
  51. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/PickersStartEndDate.tsx +3 -8
  52. package/src/TimePeriods/CustomTimePeriod/PopoverCustomTimePeriod/models.ts +2 -0
  53. package/src/TimePeriods/DateTimePickerInput.tsx +19 -56
  54. package/src/TimePeriods/ResolutionTimePeriod.cypress.spec.tsx +9 -12
  55. package/src/TimePeriods/TimePeriods.cypress.spec.tsx +33 -9
  56. package/src/TimePeriods/helpers/index.ts +1 -1
  57. package/src/TimePeriods/index.stories.tsx +4 -12
  58. package/src/TimePeriods/index.tsx +2 -2
  59. package/src/api/QueryProvider.tsx +1 -1
  60. package/src/api/TestQueryProvider.tsx +1 -1
  61. package/src/api/useFetchQuery/index.ts +23 -27
  62. package/src/api/useMutationQuery/index.ts +21 -45
  63. package/src/components/Button/Icon/IconButton.tsx +2 -6
  64. package/src/components/DataTable/DataTable.stories.tsx +0 -40
  65. package/src/components/DataTable/DataTable.styles.ts +0 -3
  66. package/src/components/DataTable/DataTable.tsx +3 -3
  67. package/src/components/DataTable/Item/DataTableItem.styles.ts +2 -7
  68. package/src/components/DataTable/Item/DataTableItem.tsx +4 -4
  69. package/src/components/DataTable/index.ts +1 -3
  70. package/src/components/Form/{AccessRightsV2 → AccessRights}/AccessRights.cypress.spec.tsx +23 -0
  71. package/src/components/Form/{AccessRightsV2 → AccessRights}/ShareInput/ContactSwitch.tsx +9 -1
  72. package/src/components/Form/{AccessRightsV2 → AccessRights}/ShareInput/ShareInput.styles.ts +8 -0
  73. package/src/components/Form/{AccessRightsV2 → AccessRights}/ShareInput/useShareInput.tsx +4 -0
  74. package/src/components/Form/{AccessRightsV2 → AccessRights}/models.ts +1 -0
  75. package/src/components/Form/{AccessRightsV2 → AccessRights}/storiesData.ts +1 -0
  76. package/src/components/Form/Dashboard/DashboardForm.tsx +12 -15
  77. package/src/components/Form/index.ts +2 -2
  78. package/src/components/Layout/PageLayout/PageLayout.tsx +1 -1
  79. package/src/components/Layout/PageLayout/PageLayoutActions.tsx +0 -1
  80. package/src/components/Layout/PageLayout/PageLayoutBody.tsx +0 -1
  81. package/src/components/Layout/PageLayout/PageLayoutHeader.tsx +1 -5
  82. package/src/components/Layout/PageLayout/index.ts +1 -3
  83. package/src/components/Modal/Modal.styles.ts +1 -1
  84. package/src/components/Tooltip/ConfirmationTooltip/ConfirmationTooltip.stories.tsx +3 -3
  85. package/src/components/Tooltip/ConfirmationTooltip/ConfirmationTooltip.tsx +1 -1
  86. package/src/components/Tooltip/ConfirmationTooltip/models.ts +1 -1
  87. package/src/index.ts +2 -2
  88. package/src/queryParameters/url/index.ts +1 -5
  89. package/src/screens/dashboard/DashboardsDetail.stories.tsx +108 -0
  90. package/src/screens/dashboard/DashboardsOverview.stories.tsx +281 -0
  91. package/src/utils/index.ts +1 -2
  92. package/src/utils/useDateTimePickerAdapter.ts +309 -0
  93. package/src/utils/{useLicenseExpirationWarning.test.tsx → useLicenseExpirationWarning.cypress.spec.tsx} +37 -48
  94. package/src/utils/useLicenseExpirationWarning.ts +18 -18
  95. package/src/Form/Form.cypress.spec.tsx +0 -133
  96. package/src/Form/Inputs/List/Content.tsx +0 -62
  97. package/src/Form/Inputs/List/List.styles.ts +0 -29
  98. package/src/Form/Inputs/List/List.tsx +0 -58
  99. package/src/Form/Inputs/List/useList.ts +0 -81
  100. package/src/Module/Module.cypress.spec.tsx +0 -129
  101. package/src/components/DataTable/DataListing.tsx +0 -6
  102. package/src/components/DataTable/DataTable.cypress.spec.tsx +0 -193
  103. package/src/components/Form/AccessRights/AccessRights.resource.ts +0 -45
  104. package/src/components/Form/AccessRights/AccessRightsForm.stories.tsx +0 -59
  105. package/src/components/Form/AccessRights/AccessRightsForm.styles.ts +0 -21
  106. package/src/components/Form/AccessRights/AccessRightsForm.tsx +0 -67
  107. package/src/components/Form/AccessRights/AccessRightsFormActions.tsx +0 -80
  108. package/src/components/Form/AccessRights/Input/AddAction.tsx +0 -31
  109. package/src/components/Form/AccessRights/Input/ContactAccessRightInput.stories.tsx +0 -54
  110. package/src/components/Form/AccessRights/Input/ContactAccessRightInput.tsx +0 -72
  111. package/src/components/Form/AccessRights/Input/ContactAccessRightsInput.styles.ts +0 -22
  112. package/src/components/Form/AccessRights/Input/ContactInputField.tsx +0 -105
  113. package/src/components/Form/AccessRights/Input/RoleInputField.tsx +0 -29
  114. package/src/components/Form/AccessRights/List/ContactAccessRightsList.stories.tsx +0 -97
  115. package/src/components/Form/AccessRights/List/ContactAccessRightsList.styles.ts +0 -71
  116. package/src/components/Form/AccessRights/List/ContactAccessRightsList.tsx +0 -51
  117. package/src/components/Form/AccessRights/List/ContactAccessRightsListItem.stories.tsx +0 -116
  118. package/src/components/Form/AccessRights/List/ContactAccessRightsListItem.tsx +0 -118
  119. package/src/components/Form/AccessRights/List/ContactAccessRightsListItemSkeleton.tsx +0 -26
  120. package/src/components/Form/AccessRights/List/ContactAccessRightsListSkeleton.tsx +0 -28
  121. package/src/components/Form/AccessRights/Stats/AccessRightsStats.styles.ts +0 -18
  122. package/src/components/Form/AccessRights/Stats/AccessRightsStats.tsx +0 -41
  123. package/src/components/Form/AccessRights/__fixtures__/contactAccessRight.mock.ts +0 -54
  124. package/src/components/Form/AccessRights/common/GroupLabel.styles.ts +0 -18
  125. package/src/components/Form/AccessRights/common/GroupLabel.tsx +0 -15
  126. package/src/components/Form/AccessRights/common/Input.styles.ts +0 -48
  127. package/src/components/Form/AccessRights/common/RoleInputSelect.styles.ts +0 -11
  128. package/src/components/Form/AccessRights/common/RoleInputSelect.tsx +0 -57
  129. package/src/components/Form/AccessRights/index.ts +0 -3
  130. package/src/components/Form/AccessRights/useAccessRightsForm.test.tsx +0 -531
  131. package/src/components/Form/AccessRights/useAccessRightsForm.tsx +0 -282
  132. package/src/components/Form/AccessRights/useAccessRightsForm.utils.ts +0 -41
  133. package/src/components/Layout/PageLayout/PageQuickAccess.tsx +0 -76
  134. package/src/components/Layout/PageLayout.cypress.spec.tsx +0 -66
  135. package/src/utils/usePluralizedTranslation.ts +0 -21
  136. /package/src/components/Form/{AccessRightsV2 → AccessRights}/AccessRights.stories.tsx +0 -0
  137. /package/src/components/Form/{AccessRightsV2 → AccessRights}/AccessRights.styles.ts +0 -0
  138. /package/src/components/Form/{AccessRightsV2 → AccessRights}/AccessRights.tsx +0 -0
  139. /package/src/components/Form/{AccessRightsV2 → AccessRights}/Actions/Actions.styles.ts +0 -0
  140. /package/src/components/Form/{AccessRightsV2 → AccessRights}/Actions/Actions.tsx +0 -0
  141. /package/src/components/Form/{AccessRightsV2 → AccessRights}/Actions/useActions.ts +0 -0
  142. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/Item.tsx +0 -0
  143. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/List.styles.tsx +0 -0
  144. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/List.tsx +0 -0
  145. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/ListItemSkeleton.tsx +0 -0
  146. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/ListSkeleton.tsx +0 -0
  147. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/RemoveAccessRight.tsx +0 -0
  148. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/StateChip.tsx +0 -0
  149. /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/useItem.ts +0 -0
  150. /package/src/components/Form/{AccessRightsV2 → AccessRights}/Provider.tsx +0 -0
  151. /package/src/components/Form/{AccessRightsV2 → AccessRights}/ShareInput/ShareInput.tsx +0 -0
  152. /package/src/components/Form/{AccessRightsV2 → AccessRights}/Stats/Stats.tsx +0 -0
  153. /package/src/components/Form/{AccessRightsV2 → AccessRights}/atoms.ts +0 -0
  154. /package/src/components/Form/{AccessRightsV2 → AccessRights}/common/RoleSelectField.styles.tsx +0 -0
  155. /package/src/components/Form/{AccessRightsV2 → AccessRights}/common/RoleSelectField.tsx +0 -0
  156. /package/src/components/Form/{AccessRightsV2 → AccessRights}/useAccessRightsInitValues.ts +0 -0
@@ -1,282 +0,0 @@
1
- import { ReactElement, ReactNode, useEffect, useRef } from 'react';
2
-
3
- import {
4
- atom,
5
- createStore,
6
- Provider,
7
- useAtom,
8
- useAtomValue,
9
- useSetAtom,
10
- useStore
11
- } from 'jotai';
12
-
13
- import {
14
- ContactAccessRightResource,
15
- ContactAccessRightStateResource,
16
- ContactGroupResource,
17
- ContactResource,
18
- RoleResource
19
- } from './AccessRights.resource';
20
- import {
21
- createInitialState,
22
- sortOnAddedStateFirstAndContactName
23
- } from './useAccessRightsForm.utils';
24
-
25
- /** state */
26
-
27
- type loadingState = 'idle' | 'loading';
28
-
29
- const loadingStatusAtom = atom<loadingState>('idle');
30
-
31
- type formOptions = {
32
- contacts: Array<ContactResource | ContactGroupResource>;
33
- roles: Array<RoleResource>;
34
- };
35
-
36
- const formOptionsAtom = atom<formOptions>({
37
- contacts: [],
38
- roles: []
39
- });
40
-
41
- const contactAccessRightsAtom = atom<Array<ContactAccessRightStateResource>>(
42
- []
43
- );
44
-
45
- type StateStats = {
46
- added: number;
47
- removed: number;
48
- updated: number;
49
- };
50
-
51
- const contactAccessRightsStateAtom = atom<{
52
- isDirty: boolean;
53
- isLoading: boolean;
54
- stats: StateStats;
55
- }>((get) => ({
56
- isDirty: get(contactAccessRightsAtom).some(
57
- ({ state }) => state !== 'unchanged'
58
- ),
59
- isLoading: get(loadingStatusAtom) === 'loading',
60
- stats: {
61
- added: get(contactAccessRightsAtom).filter(({ state }) => state === 'added')
62
- .length,
63
- removed: get(contactAccessRightsAtom).filter(
64
- ({ state }) => state === 'removed'
65
- ).length,
66
- updated: get(contactAccessRightsAtom).filter(
67
- ({ state }) => state === 'updated'
68
- ).length
69
- }
70
- }));
71
-
72
- type callbacks = {
73
- onSubmit?: (values: Array<ContactAccessRightStateResource>) => void;
74
- };
75
-
76
- const callbacksAtom = atom<callbacks>({});
77
-
78
- /** provider */
79
-
80
- export type AccessRightsFormProviderProps = {
81
- children: ReactNode;
82
- initialValues?: Array<ContactAccessRightResource>;
83
- loadingStatus?: loadingState;
84
- onSubmit?: callbacks['onSubmit'];
85
- options?: formOptions;
86
- };
87
-
88
- const AccessRightsFormProvider = ({
89
- children,
90
- initialValues,
91
- options,
92
- loadingStatus = 'idle',
93
- onSubmit
94
- }: AccessRightsFormProviderProps): ReactElement => {
95
- const store = useRef(createStore()).current;
96
-
97
- const setLoadingStatus = useSetAtom(loadingStatusAtom, { store });
98
- const setFormOptions = useSetAtom(formOptionsAtom, { store });
99
- const setContactAccessRights = useSetAtom(contactAccessRightsAtom, { store });
100
- const setCallbacks = useSetAtom(callbacksAtom, { store });
101
-
102
- useEffect(() => {
103
- setLoadingStatus(loadingStatus);
104
- }, [loadingStatus]);
105
-
106
- useEffect(() => {
107
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
108
- options && setFormOptions(options);
109
- }, [options]);
110
-
111
- useEffect(() => {
112
- // eslint-disable-next-line @typescript-eslint/no-unused-expressions
113
- onSubmit && setCallbacks({ onSubmit });
114
- }, [onSubmit]);
115
-
116
- useEffect(() => {
117
- setContactAccessRights(
118
- initialValues ? createInitialState(initialValues) : []
119
- );
120
- }, [initialValues]);
121
-
122
- return <Provider store={store}>{children}</Provider>;
123
- };
124
-
125
- /** hook */
126
-
127
- type UseAccessRightsForm = {
128
- addContactAccessRight: (
129
- contactAccessRight: ContactAccessRightResource
130
- ) => void;
131
- contactAccessRights: Array<ContactAccessRightStateResource>;
132
- isDirty: boolean;
133
- isLoading: boolean;
134
- options: formOptions;
135
- removeContactAccessRight: (
136
- contactAccessRight: ContactAccessRightResource,
137
- restore?: boolean
138
- ) => void;
139
- stats: StateStats;
140
- submit: () => void;
141
- updateContactAccessRight: (
142
- contactAccessRight: ContactAccessRightResource
143
- ) => void;
144
- };
145
-
146
- const useAccessRightsForm = (): UseAccessRightsForm => {
147
- const store = useStore();
148
-
149
- const [contactAccessRights, setContactAccessRights] = useAtom(
150
- contactAccessRightsAtom,
151
- { store }
152
- );
153
- const { isLoading, isDirty, stats } = useAtomValue(
154
- contactAccessRightsStateAtom,
155
- { store }
156
- );
157
- const options = useAtomValue(formOptionsAtom, { store });
158
- const callbacks = useAtomValue(callbacksAtom, { store });
159
-
160
- const addContactAccessRight = (
161
- contactAccessRight: ContactAccessRightResource
162
- ): void =>
163
- setContactAccessRights((prev) => {
164
- const isContactAlreadyAdded = prev.some(
165
- ({ contactAccessRight: c }) =>
166
- c.contact?.id === contactAccessRight.contact?.id
167
- );
168
-
169
- return isContactAlreadyAdded
170
- ? prev
171
- : [
172
- ...prev,
173
- {
174
- contactAccessRight,
175
- state: 'added',
176
- stateHistory: []
177
- } as ContactAccessRightStateResource
178
- ].sort(sortOnAddedStateFirstAndContactName);
179
- });
180
-
181
- const removeContactAccessRight = (
182
- contactAccessRight: ContactAccessRightResource,
183
- restore = false
184
- ): void =>
185
- setContactAccessRights((prev) => {
186
- const contactAccessRightIndex = prev.findIndex(
187
- ({ contactAccessRight: prevContactAccessRight }) =>
188
- prevContactAccessRight.contact?.id === contactAccessRight.contact?.id
189
- );
190
-
191
- if (contactAccessRightIndex === -1) {
192
- return prev;
193
- }
194
-
195
- const { stateHistory } = prev[contactAccessRightIndex];
196
-
197
- if (restore) {
198
- return [
199
- ...prev.slice(0, contactAccessRightIndex),
200
- {
201
- ...prev[contactAccessRightIndex],
202
- state: stateHistory[stateHistory.length - 1],
203
- stateHistory: [...stateHistory, prev[contactAccessRightIndex].state]
204
- } as ContactAccessRightStateResource,
205
- ...prev.slice(contactAccessRightIndex + 1)
206
- ];
207
- }
208
-
209
- if (
210
- prev[contactAccessRightIndex].state === 'added' ||
211
- stateHistory[0] === 'added'
212
- ) {
213
- return [
214
- ...prev.slice(0, contactAccessRightIndex),
215
- ...prev.slice(contactAccessRightIndex + 1)
216
- ];
217
- }
218
-
219
- return [
220
- ...prev.slice(0, contactAccessRightIndex),
221
- {
222
- ...prev[contactAccessRightIndex],
223
- state: 'removed',
224
- stateHistory: [...stateHistory, prev[contactAccessRightIndex].state]
225
- } as ContactAccessRightStateResource,
226
- ...prev.slice(contactAccessRightIndex + 1)
227
- ];
228
- });
229
-
230
- const updateContactAccessRight = (
231
- contactAccessRight: ContactAccessRightResource
232
- ): void =>
233
- setContactAccessRights((prev) => {
234
- const contactAccessRightIndex = prev.findIndex(
235
- ({ contactAccessRight: prevContactAccessRight }) =>
236
- prevContactAccessRight.contact?.id === contactAccessRight.contact?.id
237
- );
238
-
239
- if (contactAccessRightIndex === -1) {
240
- return prev;
241
- }
242
-
243
- const { stateHistory } = prev[contactAccessRightIndex];
244
-
245
- const isAdded =
246
- prev[contactAccessRightIndex].state === 'added' ||
247
- stateHistory[0] === 'added';
248
- const isUpdated =
249
- prev[contactAccessRightIndex].state === 'updated' ||
250
- stateHistory.findIndex((state) => state === 'updated') <
251
- stateHistory.findIndex((state) => state === 'unchanged');
252
-
253
- // eslint-disable-next-line no-nested-ternary
254
- const state = isAdded ? 'added' : isUpdated ? 'unchanged' : 'updated';
255
-
256
- return [
257
- ...prev.slice(0, contactAccessRightIndex),
258
- {
259
- contactAccessRight,
260
- state,
261
- stateHistory: [...stateHistory, prev[contactAccessRightIndex].state]
262
- } as ContactAccessRightStateResource,
263
- ...prev.slice(contactAccessRightIndex + 1)
264
- ];
265
- });
266
-
267
- const submit = (): void => callbacks.onSubmit?.(contactAccessRights);
268
-
269
- return {
270
- addContactAccessRight,
271
- contactAccessRights,
272
- isDirty,
273
- isLoading,
274
- options,
275
- removeContactAccessRight,
276
- stats,
277
- submit,
278
- updateContactAccessRight
279
- };
280
- };
281
-
282
- export { AccessRightsFormProvider, useAccessRightsForm };
@@ -1,41 +0,0 @@
1
- import { ContactAccessRightStateResource } from './AccessRights.resource';
2
-
3
- export const sortOnContactName = (
4
- a: ContactAccessRightStateResource,
5
- b: ContactAccessRightStateResource
6
- ): number =>
7
- a.contactAccessRight.contact?.name.localeCompare(
8
- b.contactAccessRight.contact?.name ?? ''
9
- ) || 0;
10
-
11
- export const sortOnAddedStateFirstAndContactName = (
12
- a: ContactAccessRightStateResource,
13
- b: ContactAccessRightStateResource
14
- ): number => {
15
- if (a.state === 'added' && b.state !== 'added') {
16
- return -1;
17
- }
18
- if (a.state !== 'added' && b.state === 'added') {
19
- return 1;
20
- }
21
-
22
- return (
23
- a.contactAccessRight.contact?.name.localeCompare(
24
- b.contactAccessRight.contact?.name ?? ''
25
- ) || 0
26
- );
27
- };
28
-
29
- export const createInitialState = (
30
- values
31
- ): Array<ContactAccessRightStateResource> =>
32
- values
33
- ?.map(
34
- (contactAccessRight) =>
35
- ({
36
- contactAccessRight,
37
- state: 'unchanged',
38
- stateHistory: []
39
- }) as ContactAccessRightStateResource
40
- )
41
- .sort(sortOnAddedStateFirstAndContactName);
@@ -1,76 +0,0 @@
1
- import { useTranslation } from 'react-i18next';
2
-
3
- import AddIcon from '@mui/icons-material/Add';
4
- import ArrowBackIcon from '@mui/icons-material/ArrowBack';
5
-
6
- import { Button, Menu } from '../..';
7
-
8
- interface NamedEntity {
9
- id: number | string;
10
- name: string;
11
- }
12
-
13
- type Props = {
14
- create: () => void;
15
- elements: Array<NamedEntity>;
16
- goBack: () => void;
17
- isActive: (id: number | string) => boolean;
18
- labels: {
19
- create: string;
20
- goBack: string;
21
- };
22
- navigateToElement: (id: number | string) => () => void;
23
- };
24
-
25
- export const PageQuickAccess = ({
26
- elements,
27
- isActive,
28
- navigateToElement,
29
- goBack,
30
- create,
31
- labels
32
- }: Props): JSX.Element => {
33
- const { t } = useTranslation();
34
-
35
- return (
36
- <Menu>
37
- <Menu.Button data-testid="quickaccess" />
38
- <Menu.Items>
39
- {elements &&
40
- elements.map((element) => (
41
- <Menu.Item
42
- key={`${element.id}`}
43
- onClick={navigateToElement(element.id)}
44
- {...(isActive(element.id) && {
45
- isActive: true,
46
- isDisabled: true
47
- })}
48
- >
49
- {element.name}
50
- </Menu.Item>
51
- ))}
52
- <Menu.Divider key="divider" />
53
- <Menu.Item key="create">
54
- <>
55
- <Button
56
- icon={<ArrowBackIcon />}
57
- iconVariant="start"
58
- variant="ghost"
59
- onClick={goBack}
60
- >
61
- {t(labels.goBack)}
62
- </Button>
63
- <Button
64
- icon={<AddIcon />}
65
- iconVariant="start"
66
- variant="secondary"
67
- onClick={create}
68
- >
69
- {t(labels.create)}
70
- </Button>
71
- </>
72
- </Menu.Item>
73
- </Menu.Items>
74
- </Menu>
75
- );
76
- };
@@ -1,66 +0,0 @@
1
- import { T } from 'ramda';
2
-
3
- import { PageHeader } from '..';
4
-
5
- import { AreaIndicator } from './AreaIndicator';
6
-
7
- import { PageLayout } from '.';
8
-
9
- const initialize = (): void => {
10
- cy.mount({
11
- Component: (
12
- <PageLayout>
13
- <PageLayout.Header>
14
- <PageHeader>
15
- <PageHeader.Menu>
16
- <PageLayout.QuickAccess
17
- create={cy.stub()}
18
- elements={[
19
- {
20
- id: 1,
21
- name: 'Entity'
22
- }
23
- ]}
24
- goBack={cy.stub()}
25
- isActive={T}
26
- labels={{
27
- create: 'Create',
28
- goBack: 'Go back'
29
- }}
30
- navigateToElement={cy.stub()}
31
- />
32
- </PageHeader.Menu>
33
- <PageHeader.Main>
34
- <PageHeader.Title description="Description" title="Title" />
35
- </PageHeader.Main>
36
- <PageHeader.Actions>Actions</PageHeader.Actions>
37
- </PageHeader>
38
- </PageLayout.Header>
39
- <PageLayout.Body>
40
- <PageLayout.Actions>
41
- <AreaIndicator name="Body actions" />
42
- </PageLayout.Actions>
43
- <h1>Content</h1>
44
- </PageLayout.Body>
45
- </PageLayout>
46
- )
47
- });
48
- };
49
-
50
- describe('Page layout', () => {
51
- beforeEach(initialize);
52
-
53
- it('displays the page layout', () => {
54
- cy.makeSnapshot();
55
- });
56
-
57
- it('opens the quick access poppin when the corresponding logo is displayed', () => {
58
- cy.findByTestId('quickaccess').click();
59
-
60
- cy.contains('Entity').should('be.visible');
61
- cy.contains('Create').should('be.visible');
62
- cy.contains('Go back').should('be.visible');
63
-
64
- cy.makeSnapshot();
65
- });
66
- });
@@ -1,21 +0,0 @@
1
- import { useTranslation } from 'react-i18next';
2
- import pluralize from 'pluralize';
3
-
4
- interface TProps {
5
- count: number;
6
- label: string;
7
- }
8
-
9
- export const usePluralizedTranslation = (): {
10
- pluralizedT: (props: TProps) => string;
11
- } => {
12
- const translation = useTranslation();
13
-
14
- const pluralizedT = ({ label, count }: TProps): string => {
15
- return pluralize(translation.t(label), count);
16
- };
17
-
18
- return {
19
- pluralizedT
20
- };
21
- };