@centreon/ui 23.10.1-sync-dev-23-10-x-develop-oss.0 → 23.10.1-sync-release-34346.0
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.
- package/package.json +6 -1
- package/public/mockServiceWorker.js +2 -2
- package/src/Form/Inputs/ConnectedAutocomplete.tsx +3 -1
- package/src/Form/Inputs/models.ts +1 -0
- package/src/Graph/Gauge/Gauge.stories.tsx +15 -2
- package/src/Graph/HeatMap/HeatMap.stories.tsx +105 -0
- package/src/Graph/HeatMap/HeatMap.styles.tsx +29 -0
- package/src/Graph/HeatMap/HeatMap.tsx +12 -0
- package/src/Graph/HeatMap/HeatMapData.json +137 -0
- package/src/Graph/HeatMap/ResponsiveHeatMap.tsx +98 -0
- package/src/Graph/HeatMap/index.ts +1 -0
- package/src/Graph/HeatMap/model.ts +33 -0
- package/src/Graph/LineChart/BasicComponents/Lines/RegularLines/index.tsx +1 -1
- package/src/Graph/LineChart/BasicComponents/useFilterLines.ts +2 -4
- package/src/Graph/LineChart/Legend/InteractiveValue.tsx +3 -3
- package/src/Graph/LineChart/Legend/Legend.styles.ts +78 -32
- package/src/Graph/LineChart/Legend/LegendContent.tsx +12 -6
- package/src/Graph/LineChart/Legend/LegendHeader.tsx +69 -21
- package/src/Graph/LineChart/Legend/index.tsx +51 -23
- package/src/Graph/LineChart/Legend/models.ts +5 -0
- package/src/Graph/LineChart/Legend/useLegend.ts +9 -10
- package/src/Graph/LineChart/LineChart.tsx +17 -3
- package/src/Graph/index.ts +1 -0
- package/src/InputField/Select/Autocomplete/Connected/Multi/index.test.tsx +1 -0
- package/src/InputField/Select/Autocomplete/Connected/index.test.tsx +1 -0
- package/src/InputField/Select/Autocomplete/Connected/index.tsx +15 -3
- package/src/InputField/Text/index.tsx +6 -1
- package/src/Module/LicensedModule/LicenseCheck/index.tsx +24 -9
- package/src/Module/LicensedModule/index.tsx +7 -1
- package/src/RichTextEditor/RichTextEditor.cypress.spec.tsx +100 -52
- package/src/RichTextEditor/RichTextEditor.tsx +9 -3
- package/src/RichTextEditor/plugins/ToolbarPlugin/AlignPicker.tsx +21 -20
- package/src/RichTextEditor/plugins/ToolbarPlugin/BlockButtons.tsx +35 -77
- package/src/RichTextEditor/plugins/ToolbarPlugin/FormatButtons.tsx +29 -83
- package/src/RichTextEditor/plugins/ToolbarPlugin/LinkButton.tsx +106 -0
- package/src/RichTextEditor/plugins/ToolbarPlugin/ListButton.tsx +155 -0
- package/src/RichTextEditor/plugins/ToolbarPlugin/MacrosButton.tsx +23 -39
- package/src/RichTextEditor/plugins/ToolbarPlugin/ToolbarPlugin.styles.ts +24 -14
- package/src/RichTextEditor/plugins/ToolbarPlugin/UndoRedoButtons.tsx +6 -0
- package/src/RichTextEditor/plugins/ToolbarPlugin/index.tsx +5 -10
- package/src/RichTextEditor/translatedLabels.ts +3 -0
- package/src/ThemeProvider/palettes.ts +4 -4
- package/src/Typography/EllipsisTypography.tsx +18 -0
- package/src/Typography/Subtitle.tsx +55 -0
- package/src/api/buildListingEndpoint/models.ts +2 -1
- package/src/api/customFetch.ts +12 -3
- package/src/api/useFetchQuery/index.ts +22 -5
- package/src/api/useGraphQuery/index.ts +4 -1
- package/src/api/useMutationQuery/index.ts +12 -2
- package/src/components/Form/AccessRightsV2/AccessRights.cypress.spec.tsx +350 -0
- package/src/components/Form/AccessRightsV2/AccessRights.stories.tsx +119 -0
- package/src/components/Form/AccessRightsV2/AccessRights.styles.ts +10 -0
- package/src/components/Form/AccessRightsV2/AccessRights.tsx +60 -0
- package/src/components/Form/AccessRightsV2/Actions/Actions.styles.ts +14 -0
- package/src/components/Form/AccessRightsV2/Actions/Actions.tsx +81 -0
- package/src/components/Form/AccessRightsV2/Actions/useActions.ts +79 -0
- package/src/components/Form/AccessRightsV2/List/Item.tsx +90 -0
- package/src/components/Form/AccessRightsV2/List/List.styles.tsx +45 -0
- package/src/components/Form/AccessRightsV2/List/List.tsx +52 -0
- package/src/components/Form/AccessRightsV2/List/ListItemSkeleton.tsx +18 -0
- package/src/components/Form/AccessRightsV2/List/ListSkeleton.tsx +22 -0
- package/src/components/Form/AccessRightsV2/List/RemoveAccessRight.tsx +38 -0
- package/src/components/Form/AccessRightsV2/List/StateChip.tsx +28 -0
- package/src/components/Form/AccessRightsV2/List/useItem.ts +64 -0
- package/src/components/Form/AccessRightsV2/Provider.tsx +15 -0
- package/src/components/Form/AccessRightsV2/ShareInput/ContactSwitch.tsx +42 -0
- package/src/components/Form/AccessRightsV2/ShareInput/ShareInput.styles.ts +9 -0
- package/src/components/Form/AccessRightsV2/ShareInput/ShareInput.tsx +77 -0
- package/src/components/Form/AccessRightsV2/ShareInput/useShareInput.tsx +109 -0
- package/src/components/Form/AccessRightsV2/Stats/Stats.tsx +36 -0
- package/src/components/Form/AccessRightsV2/atoms.ts +97 -0
- package/src/components/Form/AccessRightsV2/common/RoleSelectField.styles.tsx +7 -0
- package/src/components/Form/AccessRightsV2/common/RoleSelectField.tsx +45 -0
- package/src/components/Form/AccessRightsV2/models.ts +54 -0
- package/src/components/Form/AccessRightsV2/storiesData.ts +221 -0
- package/src/components/Form/AccessRightsV2/useAccessRightsInitValues.ts +51 -0
- package/src/components/Form/index.ts +1 -0
- package/src/components/Header/PageHeader/PageHeader.styles.ts +28 -1
- package/src/components/Header/PageHeader/PageHeaderMessage.tsx +32 -0
- package/src/components/Header/PageHeader/index.ts +2 -0
- package/src/components/ItemComposition/Item.tsx +2 -2
- package/src/components/ItemComposition/ItemComposition.styles.ts +3 -0
- package/src/components/ItemComposition/ItemComposition.tsx +4 -2
- package/src/components/List/Item/ListItem.styles.ts +6 -0
- package/src/components/List/Item/ListItem.tsx +3 -1
- package/src/components/List/Item/Text.tsx +5 -3
- package/src/components/Menu/Button/MenuButton.tsx +4 -2
- package/src/components/Menu/MenuItem.tsx +5 -3
- package/src/components/Menu/MenuItems.tsx +4 -3
- package/src/components/Modal/Modal.styles.ts +4 -2
- package/src/index.ts +5 -0
- package/src/utils/useInfiniteScrollListing.ts +22 -7
- package/src/utils/useLocaleDateTimeFormat/index.ts +3 -0
- package/src/Graph/LineChart/Legend/Marker.tsx +0 -43
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
import { AccessRight, ItemState, Labels } from '../models';
|
|
4
|
+
|
|
5
|
+
interface UseItemState {
|
|
6
|
+
getState: () => { label: string; state: ItemState } | null;
|
|
7
|
+
groupLabel: string | null;
|
|
8
|
+
initials: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export const useItem = ({
|
|
12
|
+
name,
|
|
13
|
+
isAdded,
|
|
14
|
+
isRemoved,
|
|
15
|
+
isUpdated,
|
|
16
|
+
list,
|
|
17
|
+
isContactGroup
|
|
18
|
+
}: Pick<
|
|
19
|
+
AccessRight,
|
|
20
|
+
'name' | 'isAdded' | 'isRemoved' | 'isUpdated' | 'isContactGroup'
|
|
21
|
+
> &
|
|
22
|
+
Pick<Labels, 'list'>): UseItemState => {
|
|
23
|
+
const initials = useMemo(
|
|
24
|
+
() =>
|
|
25
|
+
name
|
|
26
|
+
.split(' ')
|
|
27
|
+
.map((n) => n.charAt(0).toUpperCase())
|
|
28
|
+
.slice(0, 2)
|
|
29
|
+
.join(''),
|
|
30
|
+
[name]
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const getState = useCallback((): {
|
|
34
|
+
label: string;
|
|
35
|
+
state: ItemState;
|
|
36
|
+
} | null => {
|
|
37
|
+
if (isRemoved) {
|
|
38
|
+
return {
|
|
39
|
+
label: list.removed,
|
|
40
|
+
state: ItemState.removed
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
if (isAdded) {
|
|
44
|
+
return {
|
|
45
|
+
label: list.added,
|
|
46
|
+
state: ItemState.added
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (isUpdated) {
|
|
50
|
+
return {
|
|
51
|
+
label: list.updated,
|
|
52
|
+
state: ItemState.updated
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return null;
|
|
57
|
+
}, [isRemoved, isUpdated, isAdded]);
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
getState,
|
|
61
|
+
groupLabel: isContactGroup ? list.group : null,
|
|
62
|
+
initials
|
|
63
|
+
};
|
|
64
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Provider as JotaiProvider, createStore } from 'jotai';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const store = createStore();
|
|
10
|
+
|
|
11
|
+
const Provider = ({ children }: Props): JSX.Element => (
|
|
12
|
+
<JotaiProvider store={store}>{children}</JotaiProvider>
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
export default Provider;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useSetAtom } from 'jotai';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
|
|
4
|
+
import { FormControlLabel, Radio, RadioGroup } from '@mui/material';
|
|
5
|
+
|
|
6
|
+
import { ContactType, Labels } from '../models';
|
|
7
|
+
import { contactTypeAtom } from '../atoms';
|
|
8
|
+
import { Subtitle } from '../../../..';
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
labels: Labels['add'];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const ContactSwitch = ({ labels }: Props): JSX.Element => {
|
|
15
|
+
const { t } = useTranslation();
|
|
16
|
+
|
|
17
|
+
const setContactType = useSetAtom(contactTypeAtom);
|
|
18
|
+
|
|
19
|
+
const change = (event: React.ChangeEvent<HTMLInputElement>): void => {
|
|
20
|
+
setContactType(event.target.value as ContactType);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
return (
|
|
24
|
+
<>
|
|
25
|
+
<Subtitle>{t(labels.title)}</Subtitle>
|
|
26
|
+
<RadioGroup row defaultValue={ContactType.Contact} onChange={change}>
|
|
27
|
+
<FormControlLabel
|
|
28
|
+
control={<Radio />}
|
|
29
|
+
label={labels.contact}
|
|
30
|
+
value={ContactType.Contact}
|
|
31
|
+
/>
|
|
32
|
+
<FormControlLabel
|
|
33
|
+
control={<Radio />}
|
|
34
|
+
label={labels.contactGroup}
|
|
35
|
+
value={ContactType.ContactGroup}
|
|
36
|
+
/>
|
|
37
|
+
</RadioGroup>
|
|
38
|
+
</>
|
|
39
|
+
);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export default ContactSwitch;
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useTranslation } from 'react-i18next';
|
|
2
|
+
import { isNil } from 'ramda';
|
|
3
|
+
|
|
4
|
+
import AddCircleIcon from '@mui/icons-material/AddCircle';
|
|
5
|
+
|
|
6
|
+
import { IconButton } from '../../..';
|
|
7
|
+
import { Endpoints, Labels } from '../models';
|
|
8
|
+
import { SelectEntry, SingleConnectedAutocompleteField } from '../../../..';
|
|
9
|
+
import RoleSelectField from '../common/RoleSelectField';
|
|
10
|
+
|
|
11
|
+
import ContactSwitch from './ContactSwitch';
|
|
12
|
+
import useShareInput from './useShareInput';
|
|
13
|
+
import { useShareInputStyles } from './ShareInput.styles';
|
|
14
|
+
|
|
15
|
+
interface Props {
|
|
16
|
+
endpoints: Endpoints;
|
|
17
|
+
labels: Labels['add'];
|
|
18
|
+
roles: Array<SelectEntry>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const ShareInput = ({ labels, endpoints, roles }: Props): JSX.Element => {
|
|
22
|
+
const { t } = useTranslation();
|
|
23
|
+
const { classes } = useShareInputStyles();
|
|
24
|
+
|
|
25
|
+
const {
|
|
26
|
+
renderOption,
|
|
27
|
+
selectedContact,
|
|
28
|
+
getOptionDisabled,
|
|
29
|
+
getEndpoint,
|
|
30
|
+
selectContact,
|
|
31
|
+
isContactGroup,
|
|
32
|
+
selectedRole,
|
|
33
|
+
setSelectedRole,
|
|
34
|
+
add,
|
|
35
|
+
changeIdValue
|
|
36
|
+
} = useShareInput(endpoints);
|
|
37
|
+
|
|
38
|
+
return (
|
|
39
|
+
<div>
|
|
40
|
+
<ContactSwitch labels={labels} />
|
|
41
|
+
<div className={classes.inputs}>
|
|
42
|
+
<SingleConnectedAutocompleteField
|
|
43
|
+
clearable
|
|
44
|
+
fullWidth
|
|
45
|
+
changeIdValue={changeIdValue}
|
|
46
|
+
disableClearable={false}
|
|
47
|
+
field="name"
|
|
48
|
+
getEndpoint={getEndpoint}
|
|
49
|
+
getOptionDisabled={getOptionDisabled}
|
|
50
|
+
label={t(
|
|
51
|
+
isContactGroup
|
|
52
|
+
? t(labels.autocompleteContactGroup)
|
|
53
|
+
: t(labels.autocompleteContact)
|
|
54
|
+
)}
|
|
55
|
+
renderOption={renderOption}
|
|
56
|
+
value={selectedContact}
|
|
57
|
+
onChange={selectContact}
|
|
58
|
+
/>
|
|
59
|
+
<RoleSelectField
|
|
60
|
+
disabled={isNil(selectedContact)}
|
|
61
|
+
roles={roles}
|
|
62
|
+
testId="add_role"
|
|
63
|
+
value={selectedRole}
|
|
64
|
+
onChange={setSelectedRole}
|
|
65
|
+
/>
|
|
66
|
+
<IconButton
|
|
67
|
+
data-testid="add"
|
|
68
|
+
disabled={isNil(selectedContact)}
|
|
69
|
+
icon={<AddCircleIcon />}
|
|
70
|
+
onClick={add}
|
|
71
|
+
/>
|
|
72
|
+
</div>
|
|
73
|
+
</div>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export default ShareInput;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { Dispatch, SetStateAction, useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useAtomValue, useSetAtom } from 'jotai';
|
|
4
|
+
import { equals, includes, isNil } from 'ramda';
|
|
5
|
+
|
|
6
|
+
import { ListItemText, MenuItem } from '@mui/material';
|
|
7
|
+
import CheckCircleIcon from '@mui/icons-material/CheckCircle';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
accessRightIdsDerivedAtom,
|
|
11
|
+
addAccessRightDerivedAtom,
|
|
12
|
+
contactTypeAtom
|
|
13
|
+
} from '../atoms';
|
|
14
|
+
import { AccessRightInitialValues, ContactType, Endpoints } from '../models';
|
|
15
|
+
import { SelectEntry, buildListingEndpoint } from '../../../..';
|
|
16
|
+
|
|
17
|
+
interface UseShareInputState {
|
|
18
|
+
add: () => void;
|
|
19
|
+
changeIdValue: (entry: SelectEntry) => void;
|
|
20
|
+
getEndpoint: (parameters) => string;
|
|
21
|
+
getOptionDisabled: (option) => boolean;
|
|
22
|
+
isContactGroup: boolean;
|
|
23
|
+
renderOption: (attr, option) => JSX.Element;
|
|
24
|
+
selectContact: (_, entry) => void;
|
|
25
|
+
selectedContact: AccessRightInitialValues | null;
|
|
26
|
+
selectedRole: string;
|
|
27
|
+
setSelectedRole: Dispatch<SetStateAction<string>>;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const useShareInput = (endpoints: Endpoints): UseShareInputState => {
|
|
31
|
+
const [selectedContact, setSelectedContact] =
|
|
32
|
+
useState<AccessRightInitialValues | null>(null);
|
|
33
|
+
const [selectedRole, setSelectedRole] = useState('viewer');
|
|
34
|
+
|
|
35
|
+
const accessRightIds = useAtomValue(accessRightIdsDerivedAtom);
|
|
36
|
+
const contactType = useAtomValue(contactTypeAtom);
|
|
37
|
+
const addAccessRight = useSetAtom(addAccessRightDerivedAtom);
|
|
38
|
+
|
|
39
|
+
const isContactGroup = equals(contactType, ContactType.ContactGroup);
|
|
40
|
+
|
|
41
|
+
const selectContact = (_, entry): void => {
|
|
42
|
+
setSelectedContact(entry);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const add = (): void => {
|
|
46
|
+
if (isNil(selectedContact)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
addAccessRight({
|
|
51
|
+
email: selectedContact.email,
|
|
52
|
+
id: selectedContact.id,
|
|
53
|
+
isContactGroup,
|
|
54
|
+
name: selectedContact.name,
|
|
55
|
+
role: selectedRole
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
setSelectedContact(null);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const getEndpoint = (parameters): string =>
|
|
62
|
+
buildListingEndpoint({
|
|
63
|
+
baseEndpoint: isContactGroup ? endpoints.contactGroup : endpoints.contact,
|
|
64
|
+
parameters: {
|
|
65
|
+
...parameters,
|
|
66
|
+
sort: { name: 'ASC' }
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
const renderOption = (attr, option): JSX.Element => {
|
|
71
|
+
return (
|
|
72
|
+
<MenuItem {...attr}>
|
|
73
|
+
<ListItemText>{option.name}</ListItemText>
|
|
74
|
+
{includes(option.id, accessRightIds) && (
|
|
75
|
+
<CheckCircleIcon color="success" />
|
|
76
|
+
)}
|
|
77
|
+
</MenuItem>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const getOptionDisabled = (option): boolean => {
|
|
82
|
+
return includes(option.id, accessRightIds);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
const changeIdValue = (item: SelectEntry): string => {
|
|
86
|
+
return `${
|
|
87
|
+
isContactGroup ? ContactType.ContactGroup : ContactType.Contact
|
|
88
|
+
}_${item.id}`;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
useEffect(() => {
|
|
92
|
+
setSelectedContact(null);
|
|
93
|
+
}, [contactType]);
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
add,
|
|
97
|
+
changeIdValue,
|
|
98
|
+
getEndpoint,
|
|
99
|
+
getOptionDisabled,
|
|
100
|
+
isContactGroup,
|
|
101
|
+
renderOption,
|
|
102
|
+
selectContact,
|
|
103
|
+
selectedContact,
|
|
104
|
+
selectedRole,
|
|
105
|
+
setSelectedRole
|
|
106
|
+
};
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
export default useShareInput;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { useTranslation } from 'react-i18next';
|
|
2
|
+
import { useAtomValue } from 'jotai';
|
|
3
|
+
import { identity } from 'ramda';
|
|
4
|
+
|
|
5
|
+
import { Typography } from '@mui/material';
|
|
6
|
+
|
|
7
|
+
import { Labels } from '../models';
|
|
8
|
+
import { statsDerivedAtom } from '../atoms';
|
|
9
|
+
|
|
10
|
+
interface Props {
|
|
11
|
+
labels: Labels['list'];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const Stats = ({ labels }: Props): JSX.Element => {
|
|
15
|
+
const { t } = useTranslation();
|
|
16
|
+
const { hasStats, addedItems, updatedItems, removedItems } =
|
|
17
|
+
useAtomValue(statsDerivedAtom);
|
|
18
|
+
|
|
19
|
+
if (!hasStats) {
|
|
20
|
+
return null;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const statsLabels = [
|
|
24
|
+
addedItems && `${addedItems} ${t(labels.added).toLocaleLowerCase()}`,
|
|
25
|
+
updatedItems && `${updatedItems} ${t(labels.updated).toLocaleLowerCase()}`,
|
|
26
|
+
removedItems && `${removedItems} ${t(labels.removed).toLocaleLowerCase()}`
|
|
27
|
+
].filter(identity);
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<Typography textAlign="right">
|
|
31
|
+
<strong>{statsLabels.join(' | ')}</strong>
|
|
32
|
+
</Typography>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export default Stats;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { atom } from 'jotai';
|
|
2
|
+
import { equals, pluck, prop, remove, update } from 'ramda';
|
|
3
|
+
|
|
4
|
+
import { AccessRightInitialValues, AccessRight, ContactType } from './models';
|
|
5
|
+
|
|
6
|
+
export const valuesAtom = atom<Array<AccessRight>>([]);
|
|
7
|
+
export const initialValuesAtom = atom<Array<AccessRightInitialValues>>([]);
|
|
8
|
+
export const contactTypeAtom = atom<ContactType>(ContactType.Contact);
|
|
9
|
+
|
|
10
|
+
export const accessRightIdsDerivedAtom = atom((get) => {
|
|
11
|
+
const values = get(valuesAtom);
|
|
12
|
+
|
|
13
|
+
return pluck('id', values);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
export const addAccessRightDerivedAtom = atom(
|
|
17
|
+
null,
|
|
18
|
+
(get, set, share: AccessRightInitialValues) => {
|
|
19
|
+
const values = get(valuesAtom);
|
|
20
|
+
|
|
21
|
+
set(valuesAtom, [
|
|
22
|
+
{
|
|
23
|
+
...share,
|
|
24
|
+
isAdded: true,
|
|
25
|
+
isRemoved: false,
|
|
26
|
+
isUpdated: false
|
|
27
|
+
},
|
|
28
|
+
...values
|
|
29
|
+
]);
|
|
30
|
+
}
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
export const updateContactRoleDerivedAtom = atom(
|
|
34
|
+
null,
|
|
35
|
+
(get, set, { id, index, newRole }) => {
|
|
36
|
+
const values = get(valuesAtom);
|
|
37
|
+
const initialValues = get(initialValuesAtom);
|
|
38
|
+
|
|
39
|
+
const initialAccesRight = initialValues.find((value) =>
|
|
40
|
+
equals(id, value.id)
|
|
41
|
+
) as AccessRightInitialValues;
|
|
42
|
+
const accessRight = values.find((value) =>
|
|
43
|
+
equals(id, value.id)
|
|
44
|
+
) as AccessRight;
|
|
45
|
+
|
|
46
|
+
set(
|
|
47
|
+
valuesAtom,
|
|
48
|
+
update(
|
|
49
|
+
index,
|
|
50
|
+
{
|
|
51
|
+
...accessRight,
|
|
52
|
+
isUpdated: !equals(initialAccesRight?.role, newRole),
|
|
53
|
+
role: newRole
|
|
54
|
+
},
|
|
55
|
+
values
|
|
56
|
+
)
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
export const removeAccessRightDerivedAtom = atom(
|
|
62
|
+
null,
|
|
63
|
+
(get, set, { index, recover = false }) => {
|
|
64
|
+
const values = get(valuesAtom);
|
|
65
|
+
|
|
66
|
+
const accessRight = values[index];
|
|
67
|
+
|
|
68
|
+
if (accessRight.isAdded) {
|
|
69
|
+
set(valuesAtom, remove(index, 1, values));
|
|
70
|
+
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
set(
|
|
75
|
+
valuesAtom,
|
|
76
|
+
update(index, {
|
|
77
|
+
...accessRight,
|
|
78
|
+
isRemoved: !recover
|
|
79
|
+
})
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
export const statsDerivedAtom = atom((get) => {
|
|
85
|
+
const values = get(valuesAtom);
|
|
86
|
+
|
|
87
|
+
const addedItems = values.filter(prop('isAdded')).length;
|
|
88
|
+
const updatedItems = values.filter(prop('isUpdated')).length;
|
|
89
|
+
const removedItems = values.filter(prop('isRemoved')).length;
|
|
90
|
+
|
|
91
|
+
return {
|
|
92
|
+
addedItems,
|
|
93
|
+
hasStats: Boolean(addedItems || updatedItems || removedItems),
|
|
94
|
+
removedItems,
|
|
95
|
+
updatedItems
|
|
96
|
+
};
|
|
97
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { SelectChangeEvent } from '@mui/material';
|
|
2
|
+
|
|
3
|
+
import SelectField, { SelectEntry } from '../../../../InputField/Select';
|
|
4
|
+
|
|
5
|
+
import { useRoleSelectField } from './RoleSelectField.styles';
|
|
6
|
+
|
|
7
|
+
interface Props {
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
label?: string;
|
|
10
|
+
onChange: (newValue: string) => void;
|
|
11
|
+
roles: Array<SelectEntry>;
|
|
12
|
+
testId: string;
|
|
13
|
+
value: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const RoleSelectField = ({
|
|
17
|
+
roles,
|
|
18
|
+
value,
|
|
19
|
+
onChange,
|
|
20
|
+
testId,
|
|
21
|
+
label,
|
|
22
|
+
disabled
|
|
23
|
+
}: Props): JSX.Element => {
|
|
24
|
+
const { classes } = useRoleSelectField();
|
|
25
|
+
const change = (event: SelectChangeEvent): void => {
|
|
26
|
+
onChange(event.target.value as string);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div className={classes.roleContainer}>
|
|
31
|
+
<SelectField
|
|
32
|
+
fullWidth
|
|
33
|
+
dataTestId={testId}
|
|
34
|
+
disabled={disabled}
|
|
35
|
+
label={label}
|
|
36
|
+
options={roles}
|
|
37
|
+
selectedOptionId={value}
|
|
38
|
+
size="small"
|
|
39
|
+
onChange={change}
|
|
40
|
+
/>
|
|
41
|
+
</div>
|
|
42
|
+
);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export default RoleSelectField;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
export interface AccessRightInitialValues {
|
|
2
|
+
email?: string;
|
|
3
|
+
id: number | string;
|
|
4
|
+
isContactGroup: boolean;
|
|
5
|
+
name: string;
|
|
6
|
+
role: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export interface AccessRight extends AccessRightInitialValues {
|
|
10
|
+
isAdded: boolean;
|
|
11
|
+
isRemoved: boolean;
|
|
12
|
+
isUpdated: boolean;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface Labels {
|
|
16
|
+
actions: {
|
|
17
|
+
cancel: string;
|
|
18
|
+
copyError: string;
|
|
19
|
+
copyLink: string;
|
|
20
|
+
copySuccess: string;
|
|
21
|
+
save: string;
|
|
22
|
+
};
|
|
23
|
+
add: {
|
|
24
|
+
autocompleteContact: string;
|
|
25
|
+
autocompleteContactGroup: string;
|
|
26
|
+
contact: string;
|
|
27
|
+
contactGroup: string;
|
|
28
|
+
title: string;
|
|
29
|
+
};
|
|
30
|
+
list: {
|
|
31
|
+
added: string;
|
|
32
|
+
empty: string;
|
|
33
|
+
group: string;
|
|
34
|
+
removed: string;
|
|
35
|
+
title: string;
|
|
36
|
+
updated: string;
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface Endpoints {
|
|
41
|
+
contact: string;
|
|
42
|
+
contactGroup: string;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export enum ItemState {
|
|
46
|
+
added = 'added',
|
|
47
|
+
removed = 'removed',
|
|
48
|
+
updated = 'updated'
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export enum ContactType {
|
|
52
|
+
Contact = 'contact',
|
|
53
|
+
ContactGroup = 'contactGroup'
|
|
54
|
+
}
|