@centreon/ui 23.10.38 → 23.10.40

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 (59) hide show
  1. package/package.json +2 -1
  2. package/src/ThemeProvider/index.tsx +0 -24
  3. package/src/ThemeProvider/palettes.ts +36 -6
  4. package/src/Wizard/index.tsx +13 -3
  5. package/src/Wizard/models.ts +1 -0
  6. package/src/api/useMutationQuery/index.ts +16 -6
  7. package/src/components/Form/AccessRights/AccessRights.resource.ts +45 -0
  8. package/src/components/Form/AccessRights/AccessRightsForm.stories.tsx +59 -0
  9. package/src/components/Form/AccessRights/AccessRightsForm.styles.ts +21 -0
  10. package/src/components/Form/AccessRights/AccessRightsForm.tsx +67 -0
  11. package/src/components/Form/AccessRights/AccessRightsFormActions.tsx +80 -0
  12. package/src/components/Form/AccessRights/Input/AddAction.tsx +31 -0
  13. package/src/components/Form/AccessRights/Input/ContactAccessRightInput.stories.tsx +54 -0
  14. package/src/components/Form/AccessRights/Input/ContactAccessRightInput.tsx +72 -0
  15. package/src/components/Form/AccessRights/Input/ContactAccessRightsInput.styles.ts +22 -0
  16. package/src/components/Form/AccessRights/Input/ContactInputField.tsx +105 -0
  17. package/src/components/Form/AccessRights/Input/RoleInputField.tsx +29 -0
  18. package/src/components/Form/AccessRights/List/ContactAccessRightsList.stories.tsx +97 -0
  19. package/src/components/Form/AccessRights/List/ContactAccessRightsList.styles.ts +71 -0
  20. package/src/components/Form/AccessRights/List/ContactAccessRightsList.tsx +51 -0
  21. package/src/components/Form/AccessRights/List/ContactAccessRightsListItem.stories.tsx +116 -0
  22. package/src/components/Form/AccessRights/List/ContactAccessRightsListItem.tsx +118 -0
  23. package/src/components/Form/AccessRights/List/ContactAccessRightsListItemSkeleton.tsx +26 -0
  24. package/src/components/Form/AccessRights/List/ContactAccessRightsListSkeleton.tsx +28 -0
  25. package/src/components/Form/AccessRights/Stats/AccessRightsStats.styles.ts +18 -0
  26. package/src/components/Form/AccessRights/Stats/AccessRightsStats.tsx +41 -0
  27. package/src/components/Form/AccessRights/__fixtures__/contactAccessRight.mock.ts +52 -0
  28. package/src/components/Form/AccessRights/common/GroupLabel.styles.ts +18 -0
  29. package/src/components/Form/AccessRights/common/GroupLabel.tsx +15 -0
  30. package/src/components/Form/AccessRights/common/Input.styles.ts +48 -0
  31. package/src/components/Form/AccessRights/common/RoleInputSelect.styles.ts +11 -0
  32. package/src/components/Form/AccessRights/common/RoleInputSelect.tsx +57 -0
  33. package/src/components/Form/AccessRights/index.ts +3 -0
  34. package/src/components/Form/AccessRights/useAccessRightsForm.test.tsx +531 -0
  35. package/src/components/Form/AccessRights/useAccessRightsForm.tsx +282 -0
  36. package/src/components/Form/AccessRights/useAccessRightsForm.utils.ts +41 -0
  37. package/src/components/Form/Dashboard/DashboardForm.styles.ts +1 -7
  38. package/src/components/Form/Dashboard/DashboardForm.tsx +9 -12
  39. package/src/components/Form/Form.resource.ts +1 -0
  40. package/src/components/Form/Form.styles.ts +17 -0
  41. package/src/components/Form/{Dashboard/DashboardFormActions.tsx → FormActions.tsx} +17 -16
  42. package/src/components/Form/index.ts +1 -0
  43. package/src/components/Header/PageHeader/PageHeader.stories.tsx +9 -0
  44. package/src/components/List/Item/Avatar.tsx +21 -0
  45. package/src/components/List/Item/AvatarSkeleton.tsx +17 -0
  46. package/src/components/List/Item/ListItem.stories.tsx +41 -0
  47. package/src/components/List/Item/ListItem.styles.ts +57 -0
  48. package/src/components/List/Item/ListItem.tsx +32 -0
  49. package/src/components/List/Item/Text.tsx +25 -0
  50. package/src/components/List/Item/TextSkeleton.tsx +22 -0
  51. package/src/components/List/Item/index.ts +14 -0
  52. package/src/components/List/List.stories.tsx +70 -0
  53. package/src/components/List/List.styles.ts +8 -0
  54. package/src/components/List/List.tsx +19 -0
  55. package/src/components/List/index.ts +6 -0
  56. package/src/components/Modal/ModalActions.tsx +4 -1
  57. package/src/components/index.ts +1 -0
  58. package/src/utils/index.ts +1 -0
  59. package/src/utils/useInfiniteScrollListing.ts +106 -0
@@ -0,0 +1,41 @@
1
+ import { ReactElement, useMemo } from 'react';
2
+
3
+ import { useAccessRightsForm } from '../useAccessRightsForm';
4
+ import { ContactAccessRightState } from '../AccessRights.resource';
5
+
6
+ import { useStyles } from './AccessRightsStats.styles';
7
+
8
+ export type AccessRightsStatsProps = {
9
+ labels: Record<Exclude<ContactAccessRightState, 'unchanged'>, string>;
10
+ };
11
+
12
+ const AccessRightsStats = ({
13
+ labels
14
+ }: AccessRightsStatsProps): ReactElement => {
15
+ const { classes } = useStyles();
16
+
17
+ const { stats } = useAccessRightsForm();
18
+
19
+ const statsElements = useMemo(() => {
20
+ const elements: Array<ReactElement> = [];
21
+
22
+ ['added', 'updated', 'removed'].forEach((state) => {
23
+ if (stats?.[state] > 0)
24
+ elements.push(
25
+ <span key={state}>
26
+ <strong>{stats[state]}</strong> {labels[state]}
27
+ </span>
28
+ );
29
+ });
30
+
31
+ return elements;
32
+ }, [stats]);
33
+
34
+ return (
35
+ <div className={classes.accessRightsStats}>
36
+ {statsElements.length !== 0 && statsElements.map((el) => el)}
37
+ </div>
38
+ );
39
+ };
40
+
41
+ export { AccessRightsStats };
@@ -0,0 +1,52 @@
1
+ import { faker } from '@faker-js/faker';
2
+
3
+ import {
4
+ ContactAccessRightResource,
5
+ ContactGroupResource,
6
+ ContactResource,
7
+ RoleResource
8
+ } from '../AccessRights.resource';
9
+
10
+ export const rolesMock = (): Array<RoleResource> => [
11
+ { role: 'viewer' },
12
+ { role: 'editor' }
13
+ ];
14
+
15
+ export const contactMock = (): ContactResource => ({
16
+ email: faker.internet.email(),
17
+ id: faker.string.uuid(),
18
+ name: faker.person.fullName(),
19
+ type: 'contact'
20
+ });
21
+
22
+ export const contactsMock = (length: number): Array<ContactResource> =>
23
+ [...Array(length).keys()].map(contactMock);
24
+
25
+ export const contactGroupMock = (): ContactGroupResource => ({
26
+ id: faker.string.uuid(),
27
+ name: faker.company.name(),
28
+ type: 'contact_group'
29
+ });
30
+ export const contactGroupsMock = (
31
+ length: number
32
+ ): Array<ContactGroupResource> =>
33
+ [...Array(length).keys()].map(contactGroupMock);
34
+
35
+ export const contactsAndGroupsMock = (
36
+ length: number
37
+ ): Array<ContactResource | ContactGroupResource> =>
38
+ [...Array(length).keys()].map(
39
+ () =>
40
+ faker.helpers.maybe(contactGroupMock, { probability: 0.2 }) ??
41
+ contactMock()
42
+ );
43
+
44
+ export const contactAccessRightsMock = (
45
+ length: number
46
+ ): Array<ContactAccessRightResource> =>
47
+ [...Array(length).keys()].map(() => ({
48
+ contact:
49
+ faker.helpers.maybe(contactGroupMock, { probability: 0.2 }) ??
50
+ contactMock(),
51
+ role: faker.helpers.arrayElement(rolesMock().map(({ role }) => role))
52
+ }));
@@ -0,0 +1,18 @@
1
+ import { makeStyles } from 'tss-react/mui';
2
+
3
+ const useStyles = makeStyles()((theme) => ({
4
+ groupLabel: {
5
+ backgroundColor: theme.palette.chip.color.neutral,
6
+ borderRadius: '0.1875rem',
7
+ color: theme.palette.primary.contrastText,
8
+ fontSize: '0.5625rem',
9
+ fontWeight: 500,
10
+ letterSpacing: '0.05rem',
11
+ marginLeft: theme.spacing(1),
12
+ padding: theme.spacing(0.125, 0.5),
13
+ textTransform: 'uppercase',
14
+ verticalAlign: 'middle'
15
+ }
16
+ }));
17
+
18
+ export { useStyles };
@@ -0,0 +1,15 @@
1
+ import { ReactElement } from 'react';
2
+
3
+ import { useStyles } from './GroupLabel.styles';
4
+
5
+ export type GroupLabelProps = {
6
+ label: string;
7
+ };
8
+
9
+ const GroupLabel = ({ label }: GroupLabelProps): ReactElement => {
10
+ const { classes } = useStyles();
11
+
12
+ return <span className={classes.groupLabel}>{label}</span>;
13
+ };
14
+
15
+ export { GroupLabel };
@@ -0,0 +1,48 @@
1
+ import { makeStyles } from 'tss-react/mui';
2
+
3
+ const useInputStyles = makeStyles()((theme) => ({
4
+ inputDropdown: {
5
+ '& .MuiMenuItem-root': {
6
+ '& > .MuiTouchRipple-root': {
7
+ display: 'none'
8
+ },
9
+
10
+ '&.Mui-disabled': {
11
+ opacity: 0.5
12
+ },
13
+ '&.Mui-selected, &.Mui-selected:hover, &.MuiAutocomplete-option[aria-selected="true"], &.MuiAutocomplete-option[aria-selected="true"].Mui-focused':
14
+ {
15
+ '&.Mui-disabled': {
16
+ opacity: 1
17
+ },
18
+ backgroundColor: theme.palette.menu.item.background.active,
19
+ color: theme.palette.menu.item.color.active,
20
+ opacity: 1
21
+ },
22
+ '&:hover, &.MuiAutocomplete-option.Mui-focused:not(&[aria-selected="true"])':
23
+ {
24
+ backgroundColor: theme.palette.menu.item.background.hover,
25
+ color: theme.palette.menu.item.color.hover
26
+ },
27
+ backgroundColor: theme.palette.menu.item.background.default,
28
+ color: theme.palette.menu.item.color.default,
29
+ fontSize: '0.875rem',
30
+
31
+ minHeight: 'unset',
32
+
33
+ padding: theme.spacing(0.75, 2)
34
+ },
35
+ '&.MuiAutocomplete-popper > .MuiPaper-root, &.MuiPopover-root > .MuiPaper-root':
36
+ {
37
+ '& > ul.MuiAutocomplete-listbox, & > ul.MuiList-root': {
38
+ padding: theme.spacing(1, 0)
39
+ },
40
+ backgroundColor: theme.palette.menu.background,
41
+ borderRadius: '4px',
42
+
43
+ boxShadow: theme.shadows[8]
44
+ }
45
+ }
46
+ }));
47
+
48
+ export { useInputStyles };
@@ -0,0 +1,11 @@
1
+ import { makeStyles } from 'tss-react/mui';
2
+
3
+ const useStyles = makeStyles()(() => ({
4
+ roleInputSelect: {
5
+ flexShrink: 0,
6
+ lineHeight: '1.5',
7
+ minWidth: '6rem'
8
+ }
9
+ }));
10
+
11
+ export { useStyles };
@@ -0,0 +1,57 @@
1
+ import { ReactElement, useCallback } from 'react';
2
+
3
+ import {
4
+ MenuItem as MuiMenuItem,
5
+ Select as MuiSelect,
6
+ SelectProps as MuiSelectProps
7
+ } from '@mui/material';
8
+
9
+ import { useAccessRightsForm } from '../useAccessRightsForm';
10
+ import { RoleResource } from '../AccessRights.resource';
11
+
12
+ import { useStyles } from './RoleInputSelect.styles';
13
+ import { useInputStyles } from './Input.styles';
14
+
15
+ type RoleInputSelectProps = {
16
+ id: string;
17
+ label?: string;
18
+ name: string;
19
+ onChange?: (value: RoleResource['role']) => void;
20
+ } & Pick<MuiSelectProps, 'value' | 'defaultValue' | 'disabled'>;
21
+
22
+ const RoleInputSelect = ({
23
+ label,
24
+ onChange,
25
+ ...props
26
+ }: RoleInputSelectProps): ReactElement => {
27
+ const { classes } = useStyles();
28
+ const { classes: inputClasses } = useInputStyles();
29
+
30
+ const {
31
+ options: { roles }
32
+ } = useAccessRightsForm();
33
+
34
+ const onInputChange = useCallback((e) => onChange?.(e), [onChange]);
35
+
36
+ return (
37
+ <MuiSelect
38
+ size="small"
39
+ {...props}
40
+ {...(label && { label })}
41
+ MenuProps={{
42
+ className: inputClasses.inputDropdown
43
+ }}
44
+ className={classes.roleInputSelect}
45
+ data-testid="role-input"
46
+ onChange={onInputChange}
47
+ >
48
+ {roles.map(({ role }) => (
49
+ <MuiMenuItem key={role} value={role}>
50
+ {role}
51
+ </MuiMenuItem>
52
+ ))}
53
+ </MuiSelect>
54
+ );
55
+ };
56
+
57
+ export { RoleInputSelect };
@@ -0,0 +1,3 @@
1
+ export * from './AccessRightsForm';
2
+ export * from './AccessRights.resource';
3
+ export * from './useAccessRightsForm.utils';