@centreon/ui 24.4.1-MON-33898.8 → 24.4.1-MON-30966.1
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 +1 -1
- package/src/Button/Icon/index.stories.tsx +1 -1
- package/src/Button/Icon/index.tsx +1 -1
- package/src/InputField/Select/IconPopover/index.tsx +1 -1
- package/src/Listing/ActionBar/index.tsx +2 -1
- package/src/Panel/index.tsx +1 -1
- package/src/components/DataTable/Item/DataTableItem.tsx +2 -2
- package/src/components/Form/AccessRights/AccessRights.resource.ts +45 -0
- package/src/components/Form/AccessRights/AccessRightsForm.stories.tsx +59 -0
- package/src/components/Form/AccessRights/AccessRightsForm.styles.ts +21 -0
- package/src/components/Form/AccessRights/AccessRightsForm.tsx +67 -0
- package/src/components/Form/AccessRights/AccessRightsFormActions.tsx +80 -0
- package/src/components/Form/AccessRights/Input/AddAction.tsx +31 -0
- package/src/components/Form/AccessRights/Input/ContactAccessRightInput.stories.tsx +54 -0
- package/src/components/Form/AccessRights/Input/ContactAccessRightInput.tsx +72 -0
- package/src/components/Form/AccessRights/Input/ContactAccessRightsInput.styles.ts +22 -0
- package/src/components/Form/AccessRights/Input/ContactInputField.tsx +105 -0
- package/src/components/Form/AccessRights/Input/RoleInputField.tsx +29 -0
- package/src/components/Form/AccessRights/List/ContactAccessRightsList.stories.tsx +97 -0
- package/src/components/Form/AccessRights/List/ContactAccessRightsList.styles.ts +71 -0
- package/src/components/Form/AccessRights/List/ContactAccessRightsList.tsx +51 -0
- package/src/components/Form/AccessRights/List/ContactAccessRightsListItem.stories.tsx +116 -0
- package/src/components/Form/AccessRights/List/ContactAccessRightsListItem.tsx +118 -0
- package/src/components/Form/AccessRights/List/ContactAccessRightsListItemSkeleton.tsx +26 -0
- package/src/components/Form/AccessRights/List/ContactAccessRightsListSkeleton.tsx +28 -0
- package/src/components/Form/AccessRights/Stats/AccessRightsStats.styles.ts +18 -0
- package/src/components/Form/AccessRights/Stats/AccessRightsStats.tsx +41 -0
- package/src/components/Form/AccessRights/__fixtures__/contactAccessRight.mock.ts +54 -0
- package/src/components/Form/AccessRights/common/GroupLabel.styles.ts +18 -0
- package/src/components/Form/AccessRights/common/GroupLabel.tsx +15 -0
- package/src/components/Form/AccessRights/common/Input.styles.ts +48 -0
- package/src/components/Form/AccessRights/common/RoleInputSelect.styles.ts +11 -0
- package/src/components/Form/AccessRights/common/RoleInputSelect.tsx +57 -0
- package/src/components/Form/AccessRights/index.ts +3 -0
- package/src/components/Form/AccessRights/useAccessRightsForm.test.tsx +531 -0
- package/src/components/Form/AccessRights/useAccessRightsForm.tsx +282 -0
- package/src/components/Form/AccessRights/useAccessRightsForm.utils.ts +41 -0
- package/src/components/Form/{AccessRights → AccessRightsV2}/AccessRights.cypress.spec.tsx +0 -23
- package/src/components/Form/{AccessRights → AccessRightsV2}/ShareInput/ContactSwitch.tsx +1 -9
- package/src/components/Form/{AccessRights → AccessRightsV2}/ShareInput/ShareInput.styles.ts +0 -8
- package/src/components/Form/{AccessRights → AccessRightsV2}/ShareInput/useShareInput.tsx +0 -4
- package/src/components/Form/{AccessRights → AccessRightsV2}/models.ts +0 -1
- package/src/components/Form/{AccessRights → AccessRightsV2}/storiesData.ts +0 -1
- package/src/components/Form/index.ts +2 -2
- package/src/components/Tooltip/ConfirmationTooltip/ConfirmationTooltip.stories.tsx +3 -3
- package/src/components/Tooltip/ConfirmationTooltip/ConfirmationTooltip.tsx +1 -1
- package/src/components/Tooltip/ConfirmationTooltip/models.ts +1 -1
- /package/src/components/Form/{AccessRights → AccessRightsV2}/AccessRights.stories.tsx +0 -0
- /package/src/components/Form/{AccessRights → AccessRightsV2}/AccessRights.styles.ts +0 -0
- /package/src/components/Form/{AccessRights → AccessRightsV2}/AccessRights.tsx +0 -0
- /package/src/components/Form/{AccessRights → AccessRightsV2}/Actions/Actions.styles.ts +0 -0
- /package/src/components/Form/{AccessRights → AccessRightsV2}/Actions/Actions.tsx +0 -0
- /package/src/components/Form/{AccessRights → AccessRightsV2}/Actions/useActions.ts +0 -0
- /package/src/components/Form/{AccessRights → AccessRightsV2}/List/Item.tsx +0 -0
- /package/src/components/Form/{AccessRights → AccessRightsV2}/List/List.styles.tsx +0 -0
- /package/src/components/Form/{AccessRights → AccessRightsV2}/List/List.tsx +0 -0
- /package/src/components/Form/{AccessRights → AccessRightsV2}/List/ListItemSkeleton.tsx +0 -0
- /package/src/components/Form/{AccessRights → AccessRightsV2}/List/ListSkeleton.tsx +0 -0
- /package/src/components/Form/{AccessRights → AccessRightsV2}/List/RemoveAccessRight.tsx +0 -0
- /package/src/components/Form/{AccessRights → AccessRightsV2}/List/StateChip.tsx +0 -0
- /package/src/components/Form/{AccessRights → AccessRightsV2}/List/useItem.ts +0 -0
- /package/src/components/Form/{AccessRights → AccessRightsV2}/Provider.tsx +0 -0
- /package/src/components/Form/{AccessRights → AccessRightsV2}/ShareInput/ShareInput.tsx +0 -0
- /package/src/components/Form/{AccessRights → AccessRightsV2}/Stats/Stats.tsx +0 -0
- /package/src/components/Form/{AccessRights → AccessRightsV2}/atoms.ts +0 -0
- /package/src/components/Form/{AccessRights → AccessRightsV2}/common/RoleSelectField.styles.tsx +0 -0
- /package/src/components/Form/{AccessRights → AccessRightsV2}/common/RoleSelectField.tsx +0 -0
- /package/src/components/Form/{AccessRights → AccessRightsV2}/useAccessRightsInitValues.ts +0 -0
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ import { makeStyles } from 'tss-react/mui';
|
|
|
4
4
|
import AccessibilityIcon from '@mui/icons-material/Accessibility';
|
|
5
5
|
import { Theme } from '@mui/material';
|
|
6
6
|
|
|
7
|
-
import
|
|
7
|
+
import IconButton from '.';
|
|
8
8
|
|
|
9
9
|
const useStyles = makeStyles()((theme: Theme) => ({
|
|
10
10
|
root: {
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
} from '@mui/material';
|
|
16
16
|
import IconReset from '@mui/icons-material/RotateLeft';
|
|
17
17
|
|
|
18
|
-
import
|
|
18
|
+
import IconButton from '../../../Button/Icon';
|
|
19
19
|
import Option from '../Option';
|
|
20
20
|
import { SelectEntry } from '..';
|
|
21
21
|
|
|
@@ -9,9 +9,10 @@ import Divider from '@mui/material/Divider';
|
|
|
9
9
|
|
|
10
10
|
import { userAtom, ListingVariant } from '@centreon/ui-context';
|
|
11
11
|
|
|
12
|
-
import { ListingProps
|
|
12
|
+
import { ListingProps } from '../..';
|
|
13
13
|
import { labelOf, labelRowsPerPage } from '../translatedLabels';
|
|
14
14
|
import { useMemoComponent } from '../../utils';
|
|
15
|
+
import IconButton from '../../Button/Icon/index';
|
|
15
16
|
|
|
16
17
|
import StyledPagination from './Pagination';
|
|
17
18
|
import PaginationActions from './PaginationActions';
|
package/src/Panel/index.tsx
CHANGED
|
@@ -9,7 +9,7 @@ import { makeStyles } from 'tss-react/mui';
|
|
|
9
9
|
import { Paper, Slide, Divider, AppBar, Tabs } from '@mui/material';
|
|
10
10
|
import IconClose from '@mui/icons-material/Clear';
|
|
11
11
|
|
|
12
|
-
import
|
|
12
|
+
import IconButton from '../Button/Icon';
|
|
13
13
|
|
|
14
14
|
import { minTabHeight } from './Tab';
|
|
15
15
|
|
|
@@ -82,14 +82,14 @@ const DataTableItem = forwardRef(
|
|
|
82
82
|
labels={labelsDelete}
|
|
83
83
|
onConfirm={onDelete}
|
|
84
84
|
>
|
|
85
|
-
{(
|
|
85
|
+
{({ toggleTooltip }) => (
|
|
86
86
|
<IconButton
|
|
87
87
|
aria-label="delete"
|
|
88
88
|
data-testid="delete"
|
|
89
89
|
icon={<DeleteIcon />}
|
|
90
90
|
size="small"
|
|
91
91
|
variant="ghost"
|
|
92
|
-
onClick={
|
|
92
|
+
onClick={toggleTooltip}
|
|
93
93
|
/>
|
|
94
94
|
)}
|
|
95
95
|
</ConfirmationTooltip>
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
export type ContactAccessRightState =
|
|
2
|
+
| 'added'
|
|
3
|
+
| 'updated'
|
|
4
|
+
| 'removed'
|
|
5
|
+
| 'unchanged';
|
|
6
|
+
|
|
7
|
+
export type ContactAccessRightStateResource = {
|
|
8
|
+
contactAccessRight: ContactAccessRightResource;
|
|
9
|
+
state: ContactAccessRightState;
|
|
10
|
+
stateHistory: Array<ContactAccessRightState>;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type ContactAccessRightResource = {
|
|
14
|
+
contact: ContactResource | ContactGroupResource | null;
|
|
15
|
+
role: RoleResource['role'];
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export type ContactResource = {
|
|
19
|
+
email?: string;
|
|
20
|
+
id?: number | string;
|
|
21
|
+
name: string;
|
|
22
|
+
type: 'contact';
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export const isContactResource = (
|
|
26
|
+
resource: ContactResource | ContactGroupResource | null
|
|
27
|
+
): resource is ContactResource => {
|
|
28
|
+
return resource?.type === 'contact';
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export type ContactGroupResource = {
|
|
32
|
+
id?: number | string;
|
|
33
|
+
name: string;
|
|
34
|
+
type: 'contact_group';
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
export const isContactGroupResource = (
|
|
38
|
+
resource: ContactResource | ContactGroupResource | null
|
|
39
|
+
): resource is ContactResource => {
|
|
40
|
+
return resource?.type === 'contact_group';
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type RoleResource = {
|
|
44
|
+
role: 'viewer' | 'editor' | string;
|
|
45
|
+
};
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
2
|
+
|
|
3
|
+
import { AccessRightsForm } from './AccessRightsForm';
|
|
4
|
+
import { Default as DefaultContactAccessRightsListStory } from './List/ContactAccessRightsList.stories';
|
|
5
|
+
import { Default as DefaultContactAccessRightInputStory } from './Input/ContactAccessRightInput.stories';
|
|
6
|
+
import { ContactAccessRightsListProps } from './List/ContactAccessRightsList';
|
|
7
|
+
import { ContactAccessRightInputProps } from './Input/ContactAccessRightInput';
|
|
8
|
+
import {
|
|
9
|
+
contactAccessRightsMock,
|
|
10
|
+
contactsAndGroupsMock
|
|
11
|
+
} from './__fixtures__/contactAccessRight.mock';
|
|
12
|
+
|
|
13
|
+
const meta: Meta<typeof AccessRightsForm> = {
|
|
14
|
+
component: AccessRightsForm
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export default meta;
|
|
18
|
+
type Story = StoryObj<typeof AccessRightsForm>;
|
|
19
|
+
|
|
20
|
+
export const Default: Story = {
|
|
21
|
+
args: {
|
|
22
|
+
initialValues: contactAccessRightsMock(12),
|
|
23
|
+
labels: {
|
|
24
|
+
actions: {
|
|
25
|
+
cancel: 'Cancel',
|
|
26
|
+
copyLink: 'Copy link',
|
|
27
|
+
copyLinkMessages: {
|
|
28
|
+
error: 'Unable to copy link',
|
|
29
|
+
success: 'Link copied'
|
|
30
|
+
},
|
|
31
|
+
submit: 'Update'
|
|
32
|
+
},
|
|
33
|
+
input: {
|
|
34
|
+
...DefaultContactAccessRightInputStory.args?.labels
|
|
35
|
+
} as ContactAccessRightInputProps['labels'],
|
|
36
|
+
list: {
|
|
37
|
+
...DefaultContactAccessRightsListStory.args?.labels
|
|
38
|
+
} as ContactAccessRightsListProps['labels'],
|
|
39
|
+
stats: {
|
|
40
|
+
added: 'added',
|
|
41
|
+
removed: 'removed',
|
|
42
|
+
updated: 'updated'
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
options: {
|
|
46
|
+
contacts: contactsAndGroupsMock(25),
|
|
47
|
+
roles: [{ role: 'viewer' }, { role: 'editor' }]
|
|
48
|
+
},
|
|
49
|
+
resourceLink: 'https://app.centreon.com/resource/1'
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export const AsEmptyState: Story = {
|
|
54
|
+
args: {
|
|
55
|
+
labels: Default.args?.labels,
|
|
56
|
+
options: Default.args?.options,
|
|
57
|
+
resourceLink: Default.args?.resourceLink
|
|
58
|
+
}
|
|
59
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { makeStyles } from 'tss-react/mui';
|
|
2
|
+
|
|
3
|
+
const useStyles = makeStyles()((theme) => ({
|
|
4
|
+
accessRightsForm: {
|
|
5
|
+
display: 'flex',
|
|
6
|
+
flexDirection: 'column',
|
|
7
|
+
gap: theme.spacing(6),
|
|
8
|
+
|
|
9
|
+
maxWidth: '520px',
|
|
10
|
+
paddingTop: theme.spacing(3),
|
|
11
|
+
|
|
12
|
+
width: '100%'
|
|
13
|
+
},
|
|
14
|
+
accessRightsFormList: {
|
|
15
|
+
display: 'flex',
|
|
16
|
+
flexDirection: 'column',
|
|
17
|
+
gap: theme.spacing(1)
|
|
18
|
+
}
|
|
19
|
+
}));
|
|
20
|
+
|
|
21
|
+
export { useStyles };
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useStyles } from './AccessRightsForm.styles';
|
|
4
|
+
import {
|
|
5
|
+
AccessRightsFormProvider,
|
|
6
|
+
AccessRightsFormProviderProps
|
|
7
|
+
} from './useAccessRightsForm';
|
|
8
|
+
import {
|
|
9
|
+
ContactAccessRightInput,
|
|
10
|
+
ContactAccessRightInputProps
|
|
11
|
+
} from './Input/ContactAccessRightInput';
|
|
12
|
+
import {
|
|
13
|
+
ContactAccessRightsList,
|
|
14
|
+
ContactAccessRightsListProps
|
|
15
|
+
} from './List/ContactAccessRightsList';
|
|
16
|
+
import {
|
|
17
|
+
AccessRightsFormActions,
|
|
18
|
+
AccessRightsFormActionsProps
|
|
19
|
+
} from './AccessRightsFormActions';
|
|
20
|
+
import {
|
|
21
|
+
AccessRightsStats,
|
|
22
|
+
AccessRightsStatsProps
|
|
23
|
+
} from './Stats/AccessRightsStats';
|
|
24
|
+
|
|
25
|
+
export type AccessRightsFormProps = {
|
|
26
|
+
labels: AccessRightsFormLabels;
|
|
27
|
+
onCancel?: AccessRightsFormActionsProps['onCancel'];
|
|
28
|
+
resourceLink: string;
|
|
29
|
+
} & Pick<
|
|
30
|
+
AccessRightsFormProviderProps,
|
|
31
|
+
'initialValues' | 'onSubmit' | 'options' | 'loadingStatus'
|
|
32
|
+
>;
|
|
33
|
+
|
|
34
|
+
export type AccessRightsFormLabels = {
|
|
35
|
+
actions: AccessRightsFormActionsProps['labels'];
|
|
36
|
+
input: ContactAccessRightInputProps['labels'];
|
|
37
|
+
list: ContactAccessRightsListProps['labels'];
|
|
38
|
+
stats: AccessRightsStatsProps['labels'];
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const AccessRightsForm = ({
|
|
42
|
+
labels,
|
|
43
|
+
onCancel,
|
|
44
|
+
resourceLink,
|
|
45
|
+
...providerProps
|
|
46
|
+
}: AccessRightsFormProps): ReactElement => {
|
|
47
|
+
const { classes } = useStyles();
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<AccessRightsFormProvider {...providerProps}>
|
|
51
|
+
<div className={classes.accessRightsForm}>
|
|
52
|
+
<ContactAccessRightInput labels={labels.input} />
|
|
53
|
+
<span className={classes.accessRightsFormList}>
|
|
54
|
+
<ContactAccessRightsList labels={labels.list} />
|
|
55
|
+
<AccessRightsStats labels={labels.stats} />
|
|
56
|
+
</span>
|
|
57
|
+
<AccessRightsFormActions
|
|
58
|
+
labels={labels.actions}
|
|
59
|
+
resourceLink={resourceLink}
|
|
60
|
+
onCancel={onCancel}
|
|
61
|
+
/>
|
|
62
|
+
</div>
|
|
63
|
+
</AccessRightsFormProvider>
|
|
64
|
+
);
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export { AccessRightsForm };
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Link as LinkIcon } from '@mui/icons-material';
|
|
4
|
+
|
|
5
|
+
import { Button } from '../../Button';
|
|
6
|
+
import { useStyles } from '../Form.styles';
|
|
7
|
+
import { useCopyToClipboard } from '../../../utils';
|
|
8
|
+
|
|
9
|
+
import { useAccessRightsForm } from './useAccessRightsForm';
|
|
10
|
+
|
|
11
|
+
export type AccessRightsFormActionsProps = {
|
|
12
|
+
labels: AccessRightsFormActionsLabels;
|
|
13
|
+
onCancel?: () => void;
|
|
14
|
+
resourceLink: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
type AccessRightsFormActionsLabels = {
|
|
18
|
+
cancel: string;
|
|
19
|
+
copyLink: string;
|
|
20
|
+
copyLinkMessages: {
|
|
21
|
+
error: string;
|
|
22
|
+
success: string;
|
|
23
|
+
};
|
|
24
|
+
submit: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const AccessRightsFormActions = ({
|
|
28
|
+
labels,
|
|
29
|
+
onCancel,
|
|
30
|
+
resourceLink
|
|
31
|
+
}: AccessRightsFormActionsProps): ReactElement => {
|
|
32
|
+
const { classes } = useStyles();
|
|
33
|
+
const { isDirty, submit } = useAccessRightsForm();
|
|
34
|
+
const { copy } = useCopyToClipboard({
|
|
35
|
+
errorMessage: labels.copyLinkMessages.error,
|
|
36
|
+
successMessage: labels.copyLinkMessages.success
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
return (
|
|
40
|
+
<div className={classes.actions}>
|
|
41
|
+
<span>
|
|
42
|
+
<Button
|
|
43
|
+
aria-label={labels.copyLink}
|
|
44
|
+
data-testid="copy-link"
|
|
45
|
+
icon={<LinkIcon />}
|
|
46
|
+
iconVariant="start"
|
|
47
|
+
size="small"
|
|
48
|
+
variant="ghost"
|
|
49
|
+
onClick={() => copy(resourceLink)}
|
|
50
|
+
>
|
|
51
|
+
{labels.copyLink}
|
|
52
|
+
</Button>
|
|
53
|
+
</span>
|
|
54
|
+
<span>
|
|
55
|
+
<Button
|
|
56
|
+
aria-label={labels.cancel}
|
|
57
|
+
data-testid="cancel"
|
|
58
|
+
size="medium"
|
|
59
|
+
variant="secondary"
|
|
60
|
+
onClick={() => onCancel?.()}
|
|
61
|
+
>
|
|
62
|
+
{labels.cancel}
|
|
63
|
+
</Button>
|
|
64
|
+
<Button
|
|
65
|
+
aria-label={labels.submit}
|
|
66
|
+
data-testid="submit"
|
|
67
|
+
disabled={!isDirty}
|
|
68
|
+
size="medium"
|
|
69
|
+
type="submit"
|
|
70
|
+
variant="primary"
|
|
71
|
+
onClick={submit}
|
|
72
|
+
>
|
|
73
|
+
{labels.submit}
|
|
74
|
+
</Button>
|
|
75
|
+
</span>
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export { AccessRightsFormActions };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useFormikContext } from 'formik';
|
|
4
|
+
|
|
5
|
+
import { Add as AddIcon } from '@mui/icons-material';
|
|
6
|
+
|
|
7
|
+
import { ContactAccessRightResource } from '../AccessRights.resource';
|
|
8
|
+
import { IconButton } from '../../../Button';
|
|
9
|
+
|
|
10
|
+
type AddActionProps = {
|
|
11
|
+
label?: string;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const AddAction = ({ label }: AddActionProps): ReactElement => {
|
|
15
|
+
const { dirty, isValid, submitForm } =
|
|
16
|
+
useFormikContext<Partial<ContactAccessRightResource>>();
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<IconButton
|
|
20
|
+
aria-label={label}
|
|
21
|
+
data-testid="add"
|
|
22
|
+
disabled={!dirty || !isValid}
|
|
23
|
+
icon={<AddIcon />}
|
|
24
|
+
size="medium"
|
|
25
|
+
variant="primary"
|
|
26
|
+
onClick={submitForm}
|
|
27
|
+
/>
|
|
28
|
+
);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export { AddAction };
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ReactElement, ReactNode } from 'react';
|
|
2
|
+
|
|
3
|
+
import { Meta, StoryObj } from '@storybook/react';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
AccessRightsFormProvider,
|
|
7
|
+
AccessRightsFormProviderProps
|
|
8
|
+
} from '../useAccessRightsForm';
|
|
9
|
+
import { contactsAndGroupsMock } from '../__fixtures__/contactAccessRight.mock';
|
|
10
|
+
|
|
11
|
+
import { ContactAccessRightInput } from './ContactAccessRightInput';
|
|
12
|
+
|
|
13
|
+
const meta: Meta<typeof ContactAccessRightInput> = {
|
|
14
|
+
component: ContactAccessRightInput,
|
|
15
|
+
title: 'components/Form/AccessRights/ContactAccessRightInput'
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
export default meta;
|
|
19
|
+
type Story = StoryObj<typeof ContactAccessRightInput>;
|
|
20
|
+
|
|
21
|
+
const Wrapper = ({ children }: { children: ReactNode }): ReactElement => {
|
|
22
|
+
const options: AccessRightsFormProviderProps['options'] = {
|
|
23
|
+
contacts: contactsAndGroupsMock(25),
|
|
24
|
+
roles: [{ role: 'viewer' }, { role: 'editor' }]
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
return (
|
|
28
|
+
<AccessRightsFormProvider options={options}>
|
|
29
|
+
{children}
|
|
30
|
+
</AccessRightsFormProvider>
|
|
31
|
+
);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const Default: Story = {
|
|
35
|
+
args: {
|
|
36
|
+
labels: {
|
|
37
|
+
actions: {
|
|
38
|
+
add: 'Add'
|
|
39
|
+
},
|
|
40
|
+
fields: {
|
|
41
|
+
contact: {
|
|
42
|
+
group: 'group',
|
|
43
|
+
noOptionsText: 'No contacts found',
|
|
44
|
+
placeholder: 'Add Contact...'
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
render: (args) => (
|
|
50
|
+
<Wrapper>
|
|
51
|
+
<ContactAccessRightInput labels={args.labels} />
|
|
52
|
+
</Wrapper>
|
|
53
|
+
)
|
|
54
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
import { FormikProvider, useFormik } from 'formik';
|
|
4
|
+
import { mixed, object } from 'yup';
|
|
5
|
+
|
|
6
|
+
import { useAccessRightsForm } from '../useAccessRightsForm';
|
|
7
|
+
import { ContactAccessRightResource } from '../AccessRights.resource';
|
|
8
|
+
|
|
9
|
+
import { useStyles } from './ContactAccessRightsInput.styles';
|
|
10
|
+
import { ContactInputField, ContactInputFieldProps } from './ContactInputField';
|
|
11
|
+
import { AddAction } from './AddAction';
|
|
12
|
+
import { RoleInputField } from './RoleInputField';
|
|
13
|
+
|
|
14
|
+
export type ContactAccessRightInputProps = {
|
|
15
|
+
labels: ContactAccessRightInputLabels;
|
|
16
|
+
onAddContactAccessRight?: (value: ContactAccessRightResource) => void;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
type ContactAccessRightInputLabels = {
|
|
20
|
+
actions?: {
|
|
21
|
+
add: string;
|
|
22
|
+
};
|
|
23
|
+
fields: {
|
|
24
|
+
contact: ContactInputFieldProps['labels'];
|
|
25
|
+
role?: {
|
|
26
|
+
label: string;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const ContactAccessRightInput = ({
|
|
32
|
+
labels,
|
|
33
|
+
onAddContactAccessRight
|
|
34
|
+
}: ContactAccessRightInputProps): ReactElement => {
|
|
35
|
+
const { classes } = useStyles();
|
|
36
|
+
const { addContactAccessRight, options } = useAccessRightsForm();
|
|
37
|
+
|
|
38
|
+
const formik = useFormik<ContactAccessRightResource>({
|
|
39
|
+
initialValues: { contact: null, role: 'viewer' },
|
|
40
|
+
onSubmit: (values, { resetForm }) => {
|
|
41
|
+
addContactAccessRight(values);
|
|
42
|
+
onAddContactAccessRight?.(values);
|
|
43
|
+
resetForm();
|
|
44
|
+
},
|
|
45
|
+
validationSchema: object({
|
|
46
|
+
contact: mixed()
|
|
47
|
+
.test(
|
|
48
|
+
'is-available-contact',
|
|
49
|
+
(d) => `${d.path} is not a contact available from the list`,
|
|
50
|
+
(value) => !!options.contacts?.find((c) => c.id === value?.id)
|
|
51
|
+
)
|
|
52
|
+
.required(),
|
|
53
|
+
role: mixed().oneOf(['viewer', 'editor']).required()
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
return (
|
|
58
|
+
<div className={classes.contactAccessRightsInput}>
|
|
59
|
+
<FormikProvider value={formik}>
|
|
60
|
+
<ContactInputField
|
|
61
|
+
id="contact"
|
|
62
|
+
labels={labels.fields.contact}
|
|
63
|
+
name="contact"
|
|
64
|
+
/>
|
|
65
|
+
<RoleInputField id="role" name="role" {...labels?.fields?.role} />
|
|
66
|
+
<AddAction />
|
|
67
|
+
</FormikProvider>
|
|
68
|
+
</div>
|
|
69
|
+
);
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export { ContactAccessRightInput };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { makeStyles } from 'tss-react/mui';
|
|
2
|
+
|
|
3
|
+
const useStyles = makeStyles()((theme) => ({
|
|
4
|
+
contactAccessRightsInput: {
|
|
5
|
+
alignItems: 'center',
|
|
6
|
+
display: 'flex',
|
|
7
|
+
flexGrow: 1,
|
|
8
|
+
gap: theme.spacing(2),
|
|
9
|
+
maxWidth: '520px',
|
|
10
|
+
|
|
11
|
+
width: '100%'
|
|
12
|
+
},
|
|
13
|
+
contactInput: {
|
|
14
|
+
'& .MuiOutlinedInput-root, & .MuiInputBase-input.MuiOutlinedInput-input': {
|
|
15
|
+
height: 'unset',
|
|
16
|
+
lineHeight: '1.5'
|
|
17
|
+
},
|
|
18
|
+
flexGrow: 1
|
|
19
|
+
}
|
|
20
|
+
}));
|
|
21
|
+
|
|
22
|
+
export { useStyles };
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { ReactElement, useCallback, useEffect, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useField } from 'formik';
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
Autocomplete as MuiAutocomplete,
|
|
7
|
+
MenuItem as MuiMenuItem,
|
|
8
|
+
TextField as MuiTextField
|
|
9
|
+
} from '@mui/material';
|
|
10
|
+
|
|
11
|
+
import { useAccessRightsForm } from '../useAccessRightsForm';
|
|
12
|
+
import {
|
|
13
|
+
ContactGroupResource,
|
|
14
|
+
ContactResource,
|
|
15
|
+
isContactGroupResource
|
|
16
|
+
} from '../AccessRights.resource';
|
|
17
|
+
import { useInputStyles } from '../common/Input.styles';
|
|
18
|
+
import { GroupLabel } from '../common/GroupLabel';
|
|
19
|
+
|
|
20
|
+
import { useStyles } from './ContactAccessRightsInput.styles';
|
|
21
|
+
|
|
22
|
+
export type ContactInputFieldProps = {
|
|
23
|
+
id: string;
|
|
24
|
+
labels: ContactInputFieldLabels;
|
|
25
|
+
name: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type ContactInputFieldLabels = {
|
|
29
|
+
group: string;
|
|
30
|
+
noOptionsText: string;
|
|
31
|
+
placeholder: string;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const ContactInputField = ({
|
|
35
|
+
labels,
|
|
36
|
+
...props
|
|
37
|
+
}: ContactInputFieldProps): ReactElement => {
|
|
38
|
+
const { classes } = useStyles();
|
|
39
|
+
const { classes: inputClasses } = useInputStyles();
|
|
40
|
+
|
|
41
|
+
const {
|
|
42
|
+
options: { contacts }
|
|
43
|
+
} = useAccessRightsForm();
|
|
44
|
+
|
|
45
|
+
const [field, meta, helpers] = useField(props);
|
|
46
|
+
|
|
47
|
+
const [value, setValue] = useState<
|
|
48
|
+
ContactResource | ContactGroupResource | null
|
|
49
|
+
>(meta.initialValue ?? null);
|
|
50
|
+
|
|
51
|
+
const onInputChange = useCallback(
|
|
52
|
+
(_, _value) => {
|
|
53
|
+
helpers.setValue(_value);
|
|
54
|
+
},
|
|
55
|
+
[helpers]
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
const renderInput = useCallback(
|
|
59
|
+
(params) => (
|
|
60
|
+
<MuiTextField
|
|
61
|
+
{...props}
|
|
62
|
+
{...params}
|
|
63
|
+
placeholder={labels.placeholder}
|
|
64
|
+
size="small"
|
|
65
|
+
/>
|
|
66
|
+
),
|
|
67
|
+
[labels, props]
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
useEffect(() => {
|
|
71
|
+
setValue(field.value ?? null);
|
|
72
|
+
}, [field.value]);
|
|
73
|
+
|
|
74
|
+
return (
|
|
75
|
+
<MuiAutocomplete<ContactResource | ContactGroupResource, false, false, true>
|
|
76
|
+
autoComplete
|
|
77
|
+
autoHighlight
|
|
78
|
+
openOnFocus
|
|
79
|
+
className={classes.contactInput}
|
|
80
|
+
componentsProps={{
|
|
81
|
+
popper: {
|
|
82
|
+
className: inputClasses.inputDropdown
|
|
83
|
+
}
|
|
84
|
+
}}
|
|
85
|
+
getOptionLabel={(option) =>
|
|
86
|
+
typeof option === 'string' ? option : option.name
|
|
87
|
+
}
|
|
88
|
+
noOptionsText={labels.noOptionsText}
|
|
89
|
+
options={contacts}
|
|
90
|
+
renderInput={renderInput}
|
|
91
|
+
renderOption={(attr, option) => (
|
|
92
|
+
<MuiMenuItem {...attr} key={`${option.type}--${option.name}`}>
|
|
93
|
+
{option.name}{' '}
|
|
94
|
+
{isContactGroupResource(option) && (
|
|
95
|
+
<GroupLabel label={labels.group} />
|
|
96
|
+
)}
|
|
97
|
+
</MuiMenuItem>
|
|
98
|
+
)}
|
|
99
|
+
value={value}
|
|
100
|
+
onChange={onInputChange}
|
|
101
|
+
/>
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export { ContactInputField };
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ReactElement, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
import { useField } from 'formik';
|
|
4
|
+
|
|
5
|
+
import { RoleInputSelect } from '../common/RoleInputSelect';
|
|
6
|
+
|
|
7
|
+
type RoleFieldProps = {
|
|
8
|
+
id: string;
|
|
9
|
+
label?: string;
|
|
10
|
+
name: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const RoleInputField = ({ label, ...props }: RoleFieldProps): ReactElement => {
|
|
14
|
+
const [field, meta] = useField(props);
|
|
15
|
+
|
|
16
|
+
const onInputChange = useCallback((e) => field.onChange(e), [field]);
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<RoleInputSelect
|
|
20
|
+
defaultValue={meta.initialValue}
|
|
21
|
+
{...field}
|
|
22
|
+
{...props}
|
|
23
|
+
{...(label && { label })}
|
|
24
|
+
onChange={onInputChange}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export { RoleInputField };
|