@centreon/ui 24.5.2 → 24.5.3

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 (58) hide show
  1. package/package.json +8 -4
  2. package/public/mockServiceWorker.js +81 -100
  3. package/src/ActionsList/index.stories.tsx +7 -1
  4. package/src/Dashboard/Dashboard.styles.ts +3 -2
  5. package/src/Dashboard/Item.tsx +11 -2
  6. package/src/Dashboard/Layout.tsx +4 -2
  7. package/src/Graph/BarStack/BarStack.stories.tsx +8 -6
  8. package/src/Graph/BarStack/ResponsiveBarStack.tsx +3 -3
  9. package/src/Graph/HeatMap/HeatMap.stories.tsx +20 -0
  10. package/src/Graph/LineChart/index.stories.tsx +1 -1
  11. package/src/Graph/PieChart/PieChart.stories.tsx +11 -15
  12. package/src/Graph/PieChart/ResponsivePie.tsx +1 -1
  13. package/src/Graph/Tree/DescendantNodes.tsx +1 -0
  14. package/src/Graph/Tree/Links.tsx +15 -2
  15. package/src/Graph/Tree/Tree.cypress.spec.tsx +24 -0
  16. package/src/Graph/Tree/Tree.stories.tsx +17 -1
  17. package/src/Graph/Tree/models.ts +3 -0
  18. package/src/TimePeriods/index.stories.tsx +7 -12
  19. package/src/TopCounterElements/TopCounterLayout.tsx +3 -4
  20. package/src/TopCounterElements/useCloseOnLegacyPage.tsx +9 -6
  21. package/src/api/QueryProvider.tsx +1 -1
  22. package/src/api/logger.ts +11 -0
  23. package/src/api/useFetchQuery/index.test.ts +0 -5
  24. package/src/api/useFetchQuery/index.ts +2 -5
  25. package/src/api/useGraphQuery/index.ts +7 -1
  26. package/src/api/useMutationQuery/index.ts +2 -5
  27. package/src/api/useRequest/index.test.ts +0 -3
  28. package/src/api/useRequest/index.ts +3 -6
  29. package/src/components/Form/AccessRights/AccessRights.cypress.spec.tsx +27 -13
  30. package/src/components/Form/AccessRights/AccessRights.stories.tsx +0 -19
  31. package/src/components/Form/AccessRights/AccessRights.styles.ts +1 -1
  32. package/src/components/Form/AccessRights/AccessRights.tsx +6 -5
  33. package/src/components/Form/AccessRights/Actions/Actions.styles.ts +3 -7
  34. package/src/components/Form/AccessRights/Actions/Actions.tsx +15 -32
  35. package/src/components/Form/AccessRights/Actions/useActions.ts +4 -37
  36. package/src/components/Form/AccessRights/models.ts +0 -3
  37. package/src/components/Form/AccessRights/storiesData.ts +0 -3
  38. package/src/components/Form/AccessRights/useAccessRightsChange.ts +30 -0
  39. package/src/components/Form/AccessRights/utils.ts +18 -0
  40. package/src/components/Form/Dashboard/translatedLabels.ts +0 -1
  41. package/src/components/List/Item/ListItem.styles.ts +2 -2
  42. package/src/components/Tabs/Tab.styles.ts +25 -0
  43. package/src/components/Tabs/TabPanel.tsx +22 -0
  44. package/src/components/Tabs/Tabs.cypress.spec.tsx +70 -0
  45. package/src/components/Tabs/Tabs.stories.tsx +55 -0
  46. package/src/components/Tabs/Tabs.tsx +55 -0
  47. package/src/components/Tabs/index.ts +6 -0
  48. package/src/components/Zoom/Minimap.tsx +4 -2
  49. package/src/components/Zoom/Zoom.cypress.spec.tsx +13 -13
  50. package/src/components/Zoom/Zoom.tsx +4 -1
  51. package/src/components/Zoom/ZoomContent.tsx +5 -2
  52. package/src/components/index.ts +1 -0
  53. package/src/index.ts +1 -1
  54. package/src/utils/index.ts +1 -0
  55. package/src/utils/resourcesStatusURL.ts +166 -0
  56. package/src/utils/usePluralizedTranslation.test.ts +159 -0
  57. package/src/utils/usePluralizedTranslation.ts +20 -3
  58. package/src/components/Form/Dashboard/DashboardForm.stories.ts +0 -39
@@ -0,0 +1,166 @@
1
+ import {
2
+ always,
3
+ cond,
4
+ equals,
5
+ flatten,
6
+ groupBy,
7
+ identity,
8
+ includes,
9
+ map,
10
+ pipe,
11
+ T
12
+ } from 'ramda';
13
+
14
+ import { SelectEntry } from '..';
15
+
16
+ import { centreonBaseURL } from './centreonBaseURL';
17
+
18
+ export interface Resource {
19
+ resourceType: string;
20
+ resources: Array<SelectEntry>;
21
+ }
22
+
23
+ interface GetResourcesUrlProps {
24
+ allResources: Array<Resource>;
25
+ isForOneResource: boolean;
26
+ resource?;
27
+ states: Array<string>;
28
+ statuses: Array<string>;
29
+ type: string;
30
+ }
31
+
32
+ export const getDetailsPanelQueriers = ({ resource, type }): object => {
33
+ const { id, parentId, uuid } = resource;
34
+
35
+ const resourcesDetailsEndpoint = cond([
36
+ [
37
+ equals('host'),
38
+ always(`${centreonBaseURL}/api/latest/monitoring/resources/hosts/${id}`)
39
+ ],
40
+ [
41
+ equals('service'),
42
+ always(
43
+ `${centreonBaseURL}/api/latest/monitoring/resources/hosts/${parentId}/services/${id}`
44
+ )
45
+ ],
46
+ [
47
+ equals('metaservice'),
48
+ always(
49
+ `${centreonBaseURL}/api/latest/monitoring/resources/metaservices/${id}`
50
+ )
51
+ ],
52
+ [
53
+ equals('anomaly-detection'),
54
+ always(
55
+ `${centreonBaseURL}/api/latest/monitoring/resources/anomaly-detection/${id}`
56
+ )
57
+ ]
58
+ ])(type);
59
+
60
+ const queryParameters = {
61
+ id,
62
+ resourcesDetailsEndpoint,
63
+ selectedTimePeriodId: 'last_24_h',
64
+ tab: 'details',
65
+ tabParameters: {},
66
+ uuid
67
+ };
68
+
69
+ return queryParameters;
70
+ };
71
+
72
+ export const getResourcesUrl = ({
73
+ type,
74
+ statuses,
75
+ states,
76
+ allResources,
77
+ isForOneResource,
78
+ resource
79
+ }: GetResourcesUrlProps): string => {
80
+ const resourcesCriterias = equals(type, 'all')
81
+ ? {
82
+ name: 'resource_types',
83
+ value: [
84
+ { id: 'service', name: 'Service' },
85
+ { id: 'host', name: 'Host' }
86
+ ]
87
+ }
88
+ : {
89
+ name: 'resource_types',
90
+ value: [
91
+ { id: type, name: `${type.charAt(0).toUpperCase()}${type.slice(1)}` }
92
+ ]
93
+ };
94
+
95
+ const formattedStatuses = pipe(
96
+ flatten,
97
+ map((status: string) => {
98
+ return {
99
+ id: status.toLocaleUpperCase(),
100
+ name: `${status.charAt(0).toUpperCase()}${status.slice(1)}`
101
+ };
102
+ })
103
+ )(statuses);
104
+
105
+ const formattedStates = states.map((state) => {
106
+ return {
107
+ id: state,
108
+ name: `${state.charAt(0).toUpperCase()}${state.slice(1)}`
109
+ };
110
+ });
111
+
112
+ const groupedResources = groupBy(
113
+ ({ resourceType }) => resourceType,
114
+ allResources
115
+ );
116
+
117
+ const resourcesFilters = Object.entries(groupedResources).map(
118
+ ([resourceType, res]) => {
119
+ const name = cond<Array<string>, string>([
120
+ [equals('host'), always('parent_name')],
121
+ [equals('service'), always('name')],
122
+ [T, identity]
123
+ ])(resourceType);
124
+
125
+ return {
126
+ name: name.replace('-', '_'),
127
+ value: flatten(
128
+ (res || []).map(({ resources: subResources }) => {
129
+ return subResources.map(({ name: resourceName }) => ({
130
+ id: includes(name, ['name', 'parent_name'])
131
+ ? `\\b${resourceName}\\b`
132
+ : resourceName,
133
+ name: resourceName
134
+ }));
135
+ })
136
+ )
137
+ };
138
+ }
139
+ );
140
+
141
+ const filterQueryParameter = {
142
+ criterias: [
143
+ resourcesCriterias,
144
+ { name: 'statuses', value: formattedStatuses },
145
+ { name: 'states', value: formattedStates },
146
+ ...resourcesFilters,
147
+ { name: 'search', value: '' }
148
+ ]
149
+ };
150
+
151
+ const encodedFilterParams = encodeURIComponent(
152
+ JSON.stringify(filterQueryParameter)
153
+ );
154
+
155
+ if (!isForOneResource) {
156
+ return `/monitoring/resources?filter=${encodedFilterParams}&fromTopCounter=true`;
157
+ }
158
+
159
+ const detailsPanelQueriers = getDetailsPanelQueriers({ resource, type });
160
+
161
+ const encodedDetailsParams = encodeURIComponent(
162
+ JSON.stringify(detailsPanelQueriers)
163
+ );
164
+
165
+ return `/monitoring/resources?details=${encodedDetailsParams}&filter=${encodedFilterParams}&fromTopCounter=true`;
166
+ };
@@ -0,0 +1,159 @@
1
+ import { act, renderHook } from '@testing-library/react';
2
+ import { useAtom } from 'jotai';
3
+
4
+ import { ListingVariant, userAtom } from '@centreon/ui-context';
5
+
6
+ import { usePluralizedTranslation } from './usePluralizedTranslation';
7
+
8
+ const baseUser = {
9
+ alias: 'admin',
10
+ isExportButtonEnabled: false,
11
+ name: 'admin',
12
+ timezone: 'Europe/Paris',
13
+ use_deprecated_pages: false,
14
+ user_interface_density: ListingVariant.compact
15
+ };
16
+
17
+ describe('usePluralizedTranslation', () => {
18
+ describe('English', () => {
19
+ it('returns the plural of a word when the corresponding count is set', () => {
20
+ const { result } = renderHook(() => {
21
+ return {
22
+ pluralizedTranslation: usePluralizedTranslation(),
23
+ userAtom: useAtom(userAtom)
24
+ };
25
+ });
26
+
27
+ act(() => {
28
+ result.current.userAtom[1]({
29
+ ...baseUser,
30
+ locale: 'en'
31
+ });
32
+ });
33
+
34
+ expect(
35
+ result.current.pluralizedTranslation.pluralizedT({
36
+ count: 2,
37
+ label: 'House'
38
+ })
39
+ ).toEqual('Houses');
40
+ });
41
+
42
+ it('returns the singular of a word when the corresponding count is set', () => {
43
+ const { result } = renderHook(() => {
44
+ return {
45
+ pluralizedTranslation: usePluralizedTranslation(),
46
+ userAtom: useAtom(userAtom)
47
+ };
48
+ });
49
+
50
+ act(() => {
51
+ result.current.userAtom[1]({
52
+ ...baseUser,
53
+ locale: 'en'
54
+ });
55
+ });
56
+
57
+ expect(
58
+ result.current.pluralizedTranslation.pluralizedT({
59
+ count: 1,
60
+ label: 'House'
61
+ })
62
+ ).toEqual('House');
63
+ });
64
+
65
+ it('returns the plural of a word when the corresponding count is 0 and the language is english', () => {
66
+ const { result } = renderHook(() => {
67
+ return {
68
+ pluralizedTranslation: usePluralizedTranslation(),
69
+ userAtom: useAtom(userAtom)
70
+ };
71
+ });
72
+
73
+ act(() => {
74
+ result.current.userAtom[1]({
75
+ ...baseUser,
76
+ locale: 'en'
77
+ });
78
+ });
79
+
80
+ expect(
81
+ result.current.pluralizedTranslation.pluralizedT({
82
+ count: 0,
83
+ label: 'House'
84
+ })
85
+ ).toEqual('Houses');
86
+ });
87
+ });
88
+
89
+ describe('French', () => {
90
+ it('returns the plural of a word when the corresponding count is set', () => {
91
+ const { result } = renderHook(() => {
92
+ return {
93
+ pluralizedTranslation: usePluralizedTranslation(),
94
+ userAtom: useAtom(userAtom)
95
+ };
96
+ });
97
+
98
+ act(() => {
99
+ result.current.userAtom[1]({
100
+ ...baseUser,
101
+ locale: 'fr'
102
+ });
103
+ });
104
+
105
+ expect(
106
+ result.current.pluralizedTranslation.pluralizedT({
107
+ count: 2,
108
+ label: 'Maison'
109
+ })
110
+ ).toEqual('Maisons');
111
+ });
112
+
113
+ it('returns the singular of a word when the corresponding count is set', () => {
114
+ const { result } = renderHook(() => {
115
+ return {
116
+ pluralizedTranslation: usePluralizedTranslation(),
117
+ userAtom: useAtom(userAtom)
118
+ };
119
+ });
120
+
121
+ act(() => {
122
+ result.current.userAtom[1]({
123
+ ...baseUser,
124
+ locale: 'fr'
125
+ });
126
+ });
127
+
128
+ expect(
129
+ result.current.pluralizedTranslation.pluralizedT({
130
+ count: 1,
131
+ label: 'Maison'
132
+ })
133
+ ).toEqual('Maison');
134
+ });
135
+
136
+ it('returns the singular of a word when the corresponding count is 0 and the language is english', () => {
137
+ const { result } = renderHook(() => {
138
+ return {
139
+ pluralizedTranslation: usePluralizedTranslation(),
140
+ userAtom: useAtom(userAtom)
141
+ };
142
+ });
143
+
144
+ act(() => {
145
+ result.current.userAtom[1]({
146
+ ...baseUser,
147
+ locale: 'fr'
148
+ });
149
+ });
150
+
151
+ expect(
152
+ result.current.pluralizedTranslation.pluralizedT({
153
+ count: 0,
154
+ label: 'Maison'
155
+ })
156
+ ).toEqual('Maison');
157
+ });
158
+ });
159
+ });
@@ -1,5 +1,11 @@
1
+ import { useCallback } from 'react';
2
+
1
3
  import { useTranslation } from 'react-i18next';
2
4
  import pluralize from 'pluralize';
5
+ import { useAtomValue } from 'jotai';
6
+ import { equals, includes } from 'ramda';
7
+
8
+ import { userAtom } from '@centreon/ui-context';
3
9
 
4
10
  interface TProps {
5
11
  count: number;
@@ -10,10 +16,21 @@ export const usePluralizedTranslation = (): {
10
16
  pluralizedT: (props: TProps) => string;
11
17
  } => {
12
18
  const translation = useTranslation();
19
+ const { locale } = useAtomValue(userAtom);
13
20
 
14
- const pluralizedT = ({ label, count }: TProps): string => {
15
- return pluralize(translation.t(label), count);
16
- };
21
+ const isNotPartitiveLocale = includes('fr', locale);
22
+
23
+ const pluralizedT = useCallback(
24
+ ({ label, count }: TProps): string => {
25
+ const isZero = equals(count, 0);
26
+
27
+ return pluralize(
28
+ translation.t(label),
29
+ isZero && isNotPartitiveLocale ? 1 : count
30
+ );
31
+ },
32
+ [isNotPartitiveLocale]
33
+ );
17
34
 
18
35
  return {
19
36
  pluralizedT
@@ -1,39 +0,0 @@
1
- import { Meta, StoryObj } from '@storybook/react';
2
-
3
- import { DashboardForm } from './DashboardForm';
4
-
5
- const meta: Meta<typeof DashboardForm> = {
6
- component: DashboardForm
7
- };
8
-
9
- export default meta;
10
- type Story = StoryObj<typeof DashboardForm>;
11
-
12
- export const Default: Story = {
13
- args: {
14
- labels: {
15
- actions: {
16
- cancel: 'Cancel',
17
- submit: {
18
- create: 'Create',
19
- update: 'Update'
20
- }
21
- },
22
- entity: {
23
- description: 'Description',
24
- name: 'Name'
25
- }
26
- }
27
- }
28
- };
29
-
30
- export const AsUpdateVariant: Story = {
31
- args: {
32
- ...Default.args,
33
- resource: {
34
- description: 'Description 1',
35
- name: 'Dashboard 1'
36
- },
37
- variant: 'update'
38
- }
39
- };