@centreon/ui 23.10.22-MON-19195-save-dashboard-changes.8 → 23.10.22-MON-19279-implement-e2e-tests-from-create-a-new-dashboard.4
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/Save/index.stories.tsx +5 -10
- package/src/Checkbox/Checkbox.tsx +107 -0
- package/src/Checkbox/CheckboxGroup/index.stories.tsx +41 -0
- package/src/Checkbox/CheckboxGroup/index.tsx +66 -0
- package/src/Checkbox/index.stories.tsx +39 -0
- package/src/Checkbox/index.tsx +2 -0
- package/src/Form/CollapsibleGroup.tsx +11 -5
- package/src/Form/Form.stories.tsx +1 -1
- package/src/Form/Form.tsx +24 -9
- package/src/Form/Inputs/Checkbox.tsx +57 -0
- package/src/Form/Inputs/CheckboxGroup.tsx +76 -0
- package/src/Form/Inputs/Grid.tsx +4 -2
- package/src/Form/Inputs/index.tsx +29 -7
- package/src/Form/Inputs/models.ts +13 -1
- package/src/Form/storiesData.tsx +45 -0
- package/src/Panel/index.tsx +6 -4
- package/src/RichTextEditor/ContentEditable.tsx +27 -7
- package/src/RichTextEditor/RichTextEditor.tsx +86 -45
- package/src/ThemeProvider/index.tsx +4 -1
- package/src/ThemeProvider/palettes.ts +7 -0
- package/src/components/Button/Button.tsx +1 -1
- package/src/components/Form/Dashboard/Dashboard.resource.ts +1 -1
- package/src/components/Form/Dashboard/DashboardForm.tsx +6 -10
- package/src/components/Form/Dashboard/translatedLabels.ts +0 -1
- package/src/index.ts +2 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/panelSize.ts +15 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@centreon/ui",
|
|
3
|
-
"version": "23.10.22-MON-
|
|
3
|
+
"version": "23.10.22-MON-19279-implement-e2e-tests-from-create-a-new-dashboard.4",
|
|
4
4
|
"description": "Centreon UI Components",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"eslint": "eslint ./src --ext .js,.jsx,.ts,.tsx --max-warnings 0",
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ComponentStory } from '@storybook/react';
|
|
1
|
+
import { ComponentMeta, ComponentStory } from '@storybook/react';
|
|
2
2
|
import { makeStyles } from 'tss-react/mui';
|
|
3
3
|
|
|
4
4
|
import { Theme } from '@mui/material';
|
|
@@ -13,7 +13,7 @@ const useStyles = makeStyles()((theme: Theme) => ({
|
|
|
13
13
|
}
|
|
14
14
|
}));
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
export default {
|
|
17
17
|
argTypes: {
|
|
18
18
|
labelLoading: { control: 'text' },
|
|
19
19
|
labelSave: { control: 'text' },
|
|
@@ -26,13 +26,8 @@ const meta = {
|
|
|
26
26
|
|
|
27
27
|
component: ButtonSave,
|
|
28
28
|
|
|
29
|
-
parameters: {
|
|
30
|
-
chromatic: { delay: 300 }
|
|
31
|
-
},
|
|
32
29
|
title: 'Button/Save'
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export default meta;
|
|
30
|
+
} as ComponentMeta<typeof ButtonSave>;
|
|
36
31
|
|
|
37
32
|
const TemplateButtonSave: ComponentStory<typeof ButtonSave> = (args) => (
|
|
38
33
|
<ButtonSave {...args} />
|
|
@@ -47,7 +42,7 @@ export const loading = (): JSX.Element => <ButtonSave loading />;
|
|
|
47
42
|
export const succeeded = (): JSX.Element => <ButtonSave succeeded />;
|
|
48
43
|
|
|
49
44
|
export const normalWithText = (): JSX.Element => (
|
|
50
|
-
<ButtonSave labelSave="Save"
|
|
45
|
+
<ButtonSave labelSave="Save" />
|
|
51
46
|
);
|
|
52
47
|
|
|
53
48
|
export const largeWithText = (): JSX.Element => (
|
|
@@ -55,7 +50,7 @@ export const largeWithText = (): JSX.Element => (
|
|
|
55
50
|
);
|
|
56
51
|
|
|
57
52
|
export const loadingWithTextAndMediumSize = (): JSX.Element => (
|
|
58
|
-
<ButtonSave loading labelLoading="Loading"
|
|
53
|
+
<ButtonSave loading labelLoading="Loading" />
|
|
59
54
|
);
|
|
60
55
|
|
|
61
56
|
export const succeededWithText = (): JSX.Element => (
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { makeStyles } from 'tss-react/mui';
|
|
2
|
+
import { T, always, cond, equals } from 'ramda';
|
|
3
|
+
|
|
4
|
+
import { SvgIconComponent } from '@mui/icons-material';
|
|
5
|
+
import {
|
|
6
|
+
FormControlLabel,
|
|
7
|
+
Checkbox as MuiCheckbox,
|
|
8
|
+
Box,
|
|
9
|
+
Typography
|
|
10
|
+
} from '@mui/material';
|
|
11
|
+
|
|
12
|
+
export type LabelPlacement = 'bottom' | 'top' | 'end' | 'start' | undefined;
|
|
13
|
+
|
|
14
|
+
interface StyleProps {
|
|
15
|
+
disabled: boolean;
|
|
16
|
+
hasIcon: boolean;
|
|
17
|
+
labelPlacement: LabelPlacement;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const getLabelSpacing = (labelPlacement, theme): string => {
|
|
21
|
+
return cond([
|
|
22
|
+
[equals('top'), always(theme.spacing(0, 0, 0.5))],
|
|
23
|
+
[equals('end'), always(theme.spacing(0, 0, 0, 0.5))],
|
|
24
|
+
[T, always(0)]
|
|
25
|
+
])(labelPlacement);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const useStyles = makeStyles<StyleProps>()(
|
|
29
|
+
(theme, { disabled, hasIcon, labelPlacement }) => ({
|
|
30
|
+
container: hasIcon
|
|
31
|
+
? {
|
|
32
|
+
alignItems: 'center',
|
|
33
|
+
display: 'flex',
|
|
34
|
+
flexDirection: 'column',
|
|
35
|
+
justifyContent: 'space-between',
|
|
36
|
+
minHeight: theme.spacing(11)
|
|
37
|
+
}
|
|
38
|
+
: {},
|
|
39
|
+
icon: {
|
|
40
|
+
fontSize: theme.spacing(10)
|
|
41
|
+
},
|
|
42
|
+
label: {
|
|
43
|
+
color: disabled
|
|
44
|
+
? theme.palette.action.disabled
|
|
45
|
+
: theme.palette.text.secondary,
|
|
46
|
+
fontSize: theme.typography.body1.fontSize,
|
|
47
|
+
fontWeight: equals(labelPlacement, 'top')
|
|
48
|
+
? theme.typography.fontWeightBold
|
|
49
|
+
: theme.typography.fontWeightMedium,
|
|
50
|
+
padding: getLabelSpacing(labelPlacement, theme)
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
interface Props {
|
|
56
|
+
Icon?: SvgIconComponent;
|
|
57
|
+
checked: boolean;
|
|
58
|
+
className?: string;
|
|
59
|
+
dataTestId?: string;
|
|
60
|
+
disabled?: boolean;
|
|
61
|
+
label: string;
|
|
62
|
+
labelPlacement?: LabelPlacement;
|
|
63
|
+
onChange?: (e) => void;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const Checkbox = ({
|
|
67
|
+
Icon,
|
|
68
|
+
checked,
|
|
69
|
+
label,
|
|
70
|
+
onChange,
|
|
71
|
+
className,
|
|
72
|
+
disabled = false,
|
|
73
|
+
labelPlacement = 'end',
|
|
74
|
+
dataTestId
|
|
75
|
+
}: Props): JSX.Element => {
|
|
76
|
+
const { classes, cx } = useStyles({
|
|
77
|
+
disabled,
|
|
78
|
+
hasIcon: !!Icon,
|
|
79
|
+
labelPlacement
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<Box className={cx(classes.container, className)}>
|
|
84
|
+
{Icon && <Icon className={classes.icon} />}
|
|
85
|
+
<FormControlLabel
|
|
86
|
+
control={
|
|
87
|
+
<MuiCheckbox
|
|
88
|
+
checked={checked}
|
|
89
|
+
color="primary"
|
|
90
|
+
disabled={disabled}
|
|
91
|
+
id={label}
|
|
92
|
+
size="small"
|
|
93
|
+
sx={{ padding: 0 }}
|
|
94
|
+
onChange={onChange}
|
|
95
|
+
/>
|
|
96
|
+
}
|
|
97
|
+
data-testid={dataTestId || ''}
|
|
98
|
+
key={label}
|
|
99
|
+
label={<Typography className={classes.label}>{label}</Typography>}
|
|
100
|
+
labelPlacement={labelPlacement}
|
|
101
|
+
sx={{ margin: 0, padding: 0 }}
|
|
102
|
+
/>
|
|
103
|
+
</Box>
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
export default Checkbox;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { ComponentMeta, ComponentStory } from '@storybook/react';
|
|
2
|
+
|
|
3
|
+
import CheckboxGroup from '.';
|
|
4
|
+
|
|
5
|
+
const options = ['ok', 'warning', 'critical', 'unknown'];
|
|
6
|
+
|
|
7
|
+
const values = ['ok', 'critical'];
|
|
8
|
+
|
|
9
|
+
export default {
|
|
10
|
+
argTypes: {},
|
|
11
|
+
component: CheckboxGroup,
|
|
12
|
+
title: 'Checkbox/Multi'
|
|
13
|
+
} as ComponentMeta<typeof CheckboxGroup>;
|
|
14
|
+
|
|
15
|
+
const Template: ComponentStory<typeof CheckboxGroup> = (args) => (
|
|
16
|
+
<CheckboxGroup {...args} />
|
|
17
|
+
);
|
|
18
|
+
|
|
19
|
+
export const Playground = Template.bind({});
|
|
20
|
+
|
|
21
|
+
Playground.args = {
|
|
22
|
+
options,
|
|
23
|
+
values
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export const Horizontal = Template.bind({});
|
|
27
|
+
|
|
28
|
+
Horizontal.args = {
|
|
29
|
+
direction: 'horizontal',
|
|
30
|
+
options,
|
|
31
|
+
values
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const LabelOnTop = Template.bind({});
|
|
35
|
+
|
|
36
|
+
LabelOnTop.args = {
|
|
37
|
+
direction: 'horizontal',
|
|
38
|
+
labelPlacement: 'top',
|
|
39
|
+
options,
|
|
40
|
+
values
|
|
41
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { equals, includes } from 'ramda';
|
|
2
|
+
import { makeStyles } from 'tss-react/mui';
|
|
3
|
+
|
|
4
|
+
import { FormGroup } from '@mui/material';
|
|
5
|
+
|
|
6
|
+
import Checkbox, { LabelPlacement } from '../Checkbox';
|
|
7
|
+
|
|
8
|
+
interface Props {
|
|
9
|
+
dataTestId?: string;
|
|
10
|
+
direction?: 'horizontal' | 'vertical';
|
|
11
|
+
disabled?: boolean;
|
|
12
|
+
labelPlacement?: LabelPlacement;
|
|
13
|
+
onChange?: (e) => void;
|
|
14
|
+
options: Array<string>;
|
|
15
|
+
values: Array<string>;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const useStyles = makeStyles()((theme) => ({
|
|
19
|
+
checkbox: {
|
|
20
|
+
display: 'flex',
|
|
21
|
+
justifyContent: 'center',
|
|
22
|
+
minWidth: theme.spacing(10)
|
|
23
|
+
},
|
|
24
|
+
container: {
|
|
25
|
+
display: 'flex',
|
|
26
|
+
gap: 1
|
|
27
|
+
}
|
|
28
|
+
}));
|
|
29
|
+
|
|
30
|
+
const CheckboxGroup = ({
|
|
31
|
+
options,
|
|
32
|
+
values,
|
|
33
|
+
direction = 'vertical',
|
|
34
|
+
onChange,
|
|
35
|
+
labelPlacement = 'end',
|
|
36
|
+
disabled = false,
|
|
37
|
+
dataTestId
|
|
38
|
+
}: Props): JSX.Element => {
|
|
39
|
+
const { classes } = useStyles();
|
|
40
|
+
|
|
41
|
+
const row = !equals(direction, 'vertical');
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<FormGroup
|
|
45
|
+
className={classes.container}
|
|
46
|
+
data-testid={dataTestId || ''}
|
|
47
|
+
row={row}
|
|
48
|
+
>
|
|
49
|
+
{options.map((value) => {
|
|
50
|
+
return (
|
|
51
|
+
<Checkbox
|
|
52
|
+
checked={includes(value, values)}
|
|
53
|
+
className={classes.checkbox}
|
|
54
|
+
disabled={disabled}
|
|
55
|
+
key={value}
|
|
56
|
+
label={value}
|
|
57
|
+
labelPlacement={labelPlacement}
|
|
58
|
+
onChange={onChange}
|
|
59
|
+
/>
|
|
60
|
+
);
|
|
61
|
+
})}
|
|
62
|
+
</FormGroup>
|
|
63
|
+
);
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
export default CheckboxGroup;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { ComponentMeta, ComponentStory } from '@storybook/react';
|
|
2
|
+
|
|
3
|
+
import MailIcon from '@mui/icons-material/MailOutline';
|
|
4
|
+
|
|
5
|
+
import Checkbox from './Checkbox';
|
|
6
|
+
|
|
7
|
+
export default {
|
|
8
|
+
argTypes: {},
|
|
9
|
+
component: Checkbox,
|
|
10
|
+
title: 'Checkbox/Single'
|
|
11
|
+
} as ComponentMeta<typeof Checkbox>;
|
|
12
|
+
|
|
13
|
+
const Template: ComponentStory<typeof Checkbox> = (args) => (
|
|
14
|
+
<Checkbox {...args} />
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
export const Playground = Template.bind({});
|
|
18
|
+
|
|
19
|
+
Playground.args = {
|
|
20
|
+
checked: true,
|
|
21
|
+
label: 'Up'
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const WithIcon = Template.bind({});
|
|
25
|
+
|
|
26
|
+
WithIcon.args = {
|
|
27
|
+
Icon: MailIcon,
|
|
28
|
+
checked: true,
|
|
29
|
+
label: 'Mail',
|
|
30
|
+
labelPlacement: 'end'
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const LabelOnTop = Template.bind({});
|
|
34
|
+
|
|
35
|
+
LabelOnTop.args = {
|
|
36
|
+
checked: true,
|
|
37
|
+
label: 'Down',
|
|
38
|
+
labelPlacement: 'top'
|
|
39
|
+
};
|
|
@@ -18,6 +18,7 @@ import { Group } from './Inputs/models';
|
|
|
18
18
|
|
|
19
19
|
interface Props {
|
|
20
20
|
children: React.ReactNode;
|
|
21
|
+
className?: string;
|
|
21
22
|
defaultIsOpen?: boolean;
|
|
22
23
|
group?: Group;
|
|
23
24
|
hasGroupTitle: boolean;
|
|
@@ -50,9 +51,10 @@ const CollapsibleGroup = ({
|
|
|
50
51
|
isCollapsible,
|
|
51
52
|
group,
|
|
52
53
|
hasGroupTitle,
|
|
53
|
-
defaultIsOpen = false
|
|
54
|
+
defaultIsOpen = false,
|
|
55
|
+
className
|
|
54
56
|
}: Props): JSX.Element => {
|
|
55
|
-
const { classes } = useStyles();
|
|
57
|
+
const { classes, cx } = useStyles();
|
|
56
58
|
const { t } = useTranslation();
|
|
57
59
|
|
|
58
60
|
const [isOpen, setIsOpen] = useState(isCollapsible && defaultIsOpen);
|
|
@@ -61,6 +63,8 @@ const CollapsibleGroup = ({
|
|
|
61
63
|
setIsOpen((currentIsOpen) => !currentIsOpen);
|
|
62
64
|
};
|
|
63
65
|
|
|
66
|
+
const containerClassName = className || '';
|
|
67
|
+
|
|
64
68
|
const CollapseIcon = isOpen ? ExpandMore : ChevronRightIcon;
|
|
65
69
|
const ContainerComponent = useCallback(
|
|
66
70
|
({
|
|
@@ -72,13 +76,13 @@ const CollapsibleGroup = ({
|
|
|
72
76
|
disableGutters
|
|
73
77
|
disableRipple
|
|
74
78
|
aria-label={group?.name}
|
|
75
|
-
className={classes.groupTitleContainer}
|
|
79
|
+
className={cx(classes.groupTitleContainer, containerClassName)}
|
|
76
80
|
onClick={toggle}
|
|
77
81
|
>
|
|
78
82
|
{containerComponentChildren}
|
|
79
83
|
</ListItemButton>
|
|
80
84
|
) : (
|
|
81
|
-
<Box className={classes.groupTitleContainer}>
|
|
85
|
+
<Box className={cx(classes.groupTitleContainer, containerClassName)}>
|
|
82
86
|
{containerComponentChildren}
|
|
83
87
|
</Box>
|
|
84
88
|
),
|
|
@@ -91,7 +95,9 @@ const CollapsibleGroup = ({
|
|
|
91
95
|
<ContainerComponent>
|
|
92
96
|
{isCollapsible && <CollapseIcon />}
|
|
93
97
|
<div className={classes.groupTitleIcon}>
|
|
94
|
-
<Typography variant="h5">
|
|
98
|
+
<Typography className="groupText" variant="h5">
|
|
99
|
+
{t(group?.name as string)}
|
|
100
|
+
</Typography>
|
|
95
101
|
{group?.EndIcon && (
|
|
96
102
|
<Tooltip
|
|
97
103
|
classes={{
|
|
@@ -71,7 +71,7 @@ export const basicFormWithHorizontalGroups = (): JSX.Element => (
|
|
|
71
71
|
<Form<BasicForm>
|
|
72
72
|
{...mandatoryProps}
|
|
73
73
|
groupDirection={GroupDirection.Horizontal}
|
|
74
|
-
groups={basicFormGroups}
|
|
74
|
+
groups={basicFormGroups.filter((group) => group.order !== 3)}
|
|
75
75
|
/>
|
|
76
76
|
</Paper>
|
|
77
77
|
);
|
package/src/Form/Form.tsx
CHANGED
|
@@ -18,8 +18,12 @@ export enum GroupDirection {
|
|
|
18
18
|
|
|
19
19
|
export type FormProps<T> = {
|
|
20
20
|
Buttons?: React.ComponentType;
|
|
21
|
+
areGroupsOpen?: boolean;
|
|
22
|
+
children?: JSX.Element;
|
|
23
|
+
className?: string;
|
|
21
24
|
groupDirection?: GroupDirection;
|
|
22
25
|
groups?: Array<Group>;
|
|
26
|
+
groupsClassName?: string;
|
|
23
27
|
initialValues: T;
|
|
24
28
|
inputs: Array<InputProps>;
|
|
25
29
|
isCollapsible?: boolean;
|
|
@@ -30,6 +34,10 @@ export type FormProps<T> = {
|
|
|
30
34
|
} & Omit<FormikSharedConfig<T>, 'isInitialValid'>;
|
|
31
35
|
|
|
32
36
|
const Form = <T extends object>({
|
|
37
|
+
children,
|
|
38
|
+
className,
|
|
39
|
+
groupsClassName,
|
|
40
|
+
areGroupsOpen,
|
|
33
41
|
initialValues,
|
|
34
42
|
validate,
|
|
35
43
|
validationSchema,
|
|
@@ -42,13 +50,15 @@ const Form = <T extends object>({
|
|
|
42
50
|
groupDirection = GroupDirection.Vertical,
|
|
43
51
|
...formikSharedConfig
|
|
44
52
|
}: FormProps<T>): JSX.Element => {
|
|
45
|
-
const { classes } = useStyles();
|
|
53
|
+
const { cx, classes } = useStyles();
|
|
46
54
|
|
|
47
55
|
if (isLoading) {
|
|
48
56
|
return (
|
|
49
57
|
<Inputs
|
|
50
58
|
isLoading
|
|
59
|
+
areGroupsOpen={areGroupsOpen}
|
|
51
60
|
groups={groups}
|
|
61
|
+
groupsClassName={groupsClassName}
|
|
52
62
|
inputs={inputs}
|
|
53
63
|
isCollapsible={isCollapsible}
|
|
54
64
|
/>
|
|
@@ -63,14 +73,19 @@ const Form = <T extends object>({
|
|
|
63
73
|
onSubmit={submit}
|
|
64
74
|
{...formikSharedConfig}
|
|
65
75
|
>
|
|
66
|
-
<div
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
76
|
+
<div>
|
|
77
|
+
{children}
|
|
78
|
+
<div className={cx(className, classes.form)}>
|
|
79
|
+
<Inputs
|
|
80
|
+
areGroupsOpen={areGroupsOpen}
|
|
81
|
+
groupDirection={groupDirection}
|
|
82
|
+
groups={groups}
|
|
83
|
+
groupsClassName={groupsClassName}
|
|
84
|
+
inputs={inputs}
|
|
85
|
+
isCollapsible={isCollapsible}
|
|
86
|
+
/>
|
|
87
|
+
<Buttons />
|
|
88
|
+
</div>
|
|
74
89
|
</div>
|
|
75
90
|
</Formik>
|
|
76
91
|
);
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ChangeEvent } from 'react';
|
|
2
|
+
|
|
3
|
+
import { FormikValues, useFormikContext } from 'formik';
|
|
4
|
+
import { path, split } from 'ramda';
|
|
5
|
+
|
|
6
|
+
import { Box } from '@mui/material';
|
|
7
|
+
|
|
8
|
+
import { Checkbox as CheckboxComponent } from '../../Checkbox';
|
|
9
|
+
import { useMemoComponent } from '../..';
|
|
10
|
+
|
|
11
|
+
import { InputPropsWithoutGroup } from './models';
|
|
12
|
+
|
|
13
|
+
const Checkbox = ({
|
|
14
|
+
checkbox,
|
|
15
|
+
fieldName,
|
|
16
|
+
getDisabled,
|
|
17
|
+
hideInput,
|
|
18
|
+
dataTestId
|
|
19
|
+
}: InputPropsWithoutGroup): JSX.Element => {
|
|
20
|
+
const { values, setFieldValue } = useFormikContext<FormikValues>();
|
|
21
|
+
|
|
22
|
+
const fieldNamePath = split('.', fieldName);
|
|
23
|
+
|
|
24
|
+
const value = path(fieldNamePath, values);
|
|
25
|
+
|
|
26
|
+
const disabled = getDisabled?.(values) || false;
|
|
27
|
+
const hideCheckbox = hideInput?.(values) || false;
|
|
28
|
+
|
|
29
|
+
const handleChange = (event: ChangeEvent<HTMLInputElement>): void => {
|
|
30
|
+
const newValue = {
|
|
31
|
+
...value,
|
|
32
|
+
checked: event.target.checked,
|
|
33
|
+
label: event.target.id
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
setFieldValue(fieldName, newValue);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return useMemoComponent({
|
|
40
|
+
Component: hideCheckbox ? (
|
|
41
|
+
<Box />
|
|
42
|
+
) : (
|
|
43
|
+
<CheckboxComponent
|
|
44
|
+
Icon={value?.Icon}
|
|
45
|
+
checked={value?.checked}
|
|
46
|
+
dataTestId={dataTestId || ''}
|
|
47
|
+
disabled={disabled}
|
|
48
|
+
label={value?.label}
|
|
49
|
+
labelPlacement={checkbox?.labelPlacement || 'end'}
|
|
50
|
+
onChange={handleChange}
|
|
51
|
+
/>
|
|
52
|
+
),
|
|
53
|
+
memoProps: [value, disabled, hideCheckbox]
|
|
54
|
+
});
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export default Checkbox;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ChangeEvent, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
import { FormikValues, useFormikContext } from 'formik';
|
|
4
|
+
import { equals, includes, path, split } from 'ramda';
|
|
5
|
+
|
|
6
|
+
import { Box, Typography } from '@mui/material';
|
|
7
|
+
|
|
8
|
+
import { CheckboxGroup as CheckboxGroupComponent } from '../../Checkbox';
|
|
9
|
+
import { useMemoComponent } from '../..';
|
|
10
|
+
|
|
11
|
+
import { InputPropsWithoutGroup } from './models';
|
|
12
|
+
|
|
13
|
+
const CheckboxGroup = ({
|
|
14
|
+
checkbox,
|
|
15
|
+
fieldName,
|
|
16
|
+
additionalLabel,
|
|
17
|
+
getDisabled,
|
|
18
|
+
hideInput,
|
|
19
|
+
dataTestId
|
|
20
|
+
}: InputPropsWithoutGroup): JSX.Element => {
|
|
21
|
+
const { values, setFieldValue } = useFormikContext<FormikValues>();
|
|
22
|
+
|
|
23
|
+
const fieldNamePath = split('.', fieldName);
|
|
24
|
+
|
|
25
|
+
const value = path(fieldNamePath, values);
|
|
26
|
+
|
|
27
|
+
const disabled = getDisabled?.(values) || false;
|
|
28
|
+
const hideCheckbox = hideInput?.(values) || false;
|
|
29
|
+
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
if (!disabled && !hideCheckbox) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const resetedValue = value?.map((element) => ({
|
|
35
|
+
...element,
|
|
36
|
+
checked: false
|
|
37
|
+
}));
|
|
38
|
+
setFieldValue(fieldName, resetedValue);
|
|
39
|
+
}, [disabled, hideCheckbox]);
|
|
40
|
+
|
|
41
|
+
const handleChange = (event: ChangeEvent<HTMLInputElement>): void => {
|
|
42
|
+
const label = event.target.id;
|
|
43
|
+
if (!includes(label, value)) {
|
|
44
|
+
setFieldValue(fieldName, [...value, label]);
|
|
45
|
+
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
setFieldValue(
|
|
50
|
+
fieldName,
|
|
51
|
+
value?.filter((elm) => !equals(elm, label))
|
|
52
|
+
);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
return useMemoComponent({
|
|
56
|
+
Component: hideCheckbox ? (
|
|
57
|
+
<Box />
|
|
58
|
+
) : (
|
|
59
|
+
<Box>
|
|
60
|
+
{additionalLabel && <Typography>{additionalLabel}</Typography>}
|
|
61
|
+
<CheckboxGroupComponent
|
|
62
|
+
dataTestId={dataTestId || ''}
|
|
63
|
+
direction={checkbox?.direction}
|
|
64
|
+
disabled={disabled}
|
|
65
|
+
labelPlacement={checkbox?.labelPlacement || 'end'}
|
|
66
|
+
options={checkbox?.options as Array<string>}
|
|
67
|
+
values={value}
|
|
68
|
+
onChange={handleChange}
|
|
69
|
+
/>
|
|
70
|
+
</Box>
|
|
71
|
+
),
|
|
72
|
+
memoProps: [value, disabled, hideCheckbox]
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export default CheckboxGroup;
|
package/src/Form/Inputs/Grid.tsx
CHANGED
|
@@ -23,14 +23,16 @@ const useStyles = makeStyles<StylesProps>()(
|
|
|
23
23
|
);
|
|
24
24
|
|
|
25
25
|
const Grid = ({ grid }: InputPropsWithoutGroup): JSX.Element => {
|
|
26
|
-
const { classes } = useStyles({
|
|
26
|
+
const { classes, cx } = useStyles({
|
|
27
27
|
alignItems: grid?.alignItems,
|
|
28
28
|
columns: grid?.columns.length,
|
|
29
29
|
gridTemplateColumns: grid?.gridTemplateColumns
|
|
30
30
|
});
|
|
31
31
|
|
|
32
|
+
const className = grid?.className || '';
|
|
33
|
+
|
|
32
34
|
return (
|
|
33
|
-
<div className={classes.gridFields}>
|
|
35
|
+
<div className={cx(classes.gridFields, className)}>
|
|
34
36
|
{grid?.columns.map((field) => {
|
|
35
37
|
const Input = getInput(field.type);
|
|
36
38
|
|
|
@@ -18,6 +18,8 @@ import TextInput from './Text';
|
|
|
18
18
|
import ConnectedAutocomplete from './ConnectedAutocomplete';
|
|
19
19
|
import FieldsTable from './FieldsTable/FieldsTable';
|
|
20
20
|
import Grid from './Grid';
|
|
21
|
+
import CheckboxGroup from './CheckboxGroup';
|
|
22
|
+
import Checkbox from './Checkbox';
|
|
21
23
|
import Custom from './Custom';
|
|
22
24
|
import LoadingSkeleton from './LoadingSkeleton';
|
|
23
25
|
|
|
@@ -61,7 +63,15 @@ export const getInput = R.cond<
|
|
|
61
63
|
R.always(FieldsTable)
|
|
62
64
|
],
|
|
63
65
|
[R.equals(InputType.Grid) as (b: InputType) => boolean, R.always(Grid)],
|
|
64
|
-
[R.equals(InputType.Custom) as (b: InputType) => boolean, R.always(Custom)]
|
|
66
|
+
[R.equals(InputType.Custom) as (b: InputType) => boolean, R.always(Custom)],
|
|
67
|
+
[
|
|
68
|
+
R.equals(InputType.Checkbox) as (b: InputType) => boolean,
|
|
69
|
+
R.always(Checkbox)
|
|
70
|
+
],
|
|
71
|
+
[
|
|
72
|
+
R.equals(InputType.CheckboxGroup) as (b: InputType) => boolean,
|
|
73
|
+
R.always(CheckboxGroup)
|
|
74
|
+
]
|
|
65
75
|
]);
|
|
66
76
|
|
|
67
77
|
interface StylesProps {
|
|
@@ -89,7 +99,9 @@ const useStyles = makeStyles<StylesProps>()((theme, { groupDirection }) => ({
|
|
|
89
99
|
? 'row'
|
|
90
100
|
: 'column'
|
|
91
101
|
},
|
|
92
|
-
inputWrapper: {
|
|
102
|
+
inputWrapper: {
|
|
103
|
+
width: '100%'
|
|
104
|
+
},
|
|
93
105
|
inputs: {
|
|
94
106
|
display: 'flex',
|
|
95
107
|
flexDirection: 'column',
|
|
@@ -99,8 +111,10 @@ const useStyles = makeStyles<StylesProps>()((theme, { groupDirection }) => ({
|
|
|
99
111
|
}));
|
|
100
112
|
|
|
101
113
|
interface Props {
|
|
114
|
+
areGroupsOpen?: boolean;
|
|
102
115
|
groupDirection?: GroupDirection;
|
|
103
116
|
groups?: Array<Group>;
|
|
117
|
+
groupsClassName?: string;
|
|
104
118
|
inputs: Array<InputProps>;
|
|
105
119
|
isCollapsible: boolean;
|
|
106
120
|
isLoading?: boolean;
|
|
@@ -111,9 +125,11 @@ const Inputs = ({
|
|
|
111
125
|
groups = [],
|
|
112
126
|
isLoading = false,
|
|
113
127
|
isCollapsible,
|
|
114
|
-
groupDirection
|
|
128
|
+
groupDirection,
|
|
129
|
+
groupsClassName,
|
|
130
|
+
areGroupsOpen
|
|
115
131
|
}: Props): JSX.Element => {
|
|
116
|
-
const { classes } = useStyles({ groupDirection });
|
|
132
|
+
const { classes, cx } = useStyles({ groupDirection });
|
|
117
133
|
const { t } = useTranslation();
|
|
118
134
|
const formikContext = useFormikContext<FormikValues>();
|
|
119
135
|
|
|
@@ -178,12 +194,13 @@ const Inputs = ({
|
|
|
178
194
|
? R.find(R.propEq('name', groupName), groups)
|
|
179
195
|
: ({} as Group);
|
|
180
196
|
|
|
181
|
-
const isFirstElement = R.equals(index, 0);
|
|
197
|
+
const isFirstElement = areGroupsOpen || R.equals(index, 0);
|
|
182
198
|
|
|
183
199
|
return (
|
|
184
200
|
<Fragment key={groupName}>
|
|
185
201
|
<div>
|
|
186
202
|
<CollapsibleGroup
|
|
203
|
+
className={groupsClassName}
|
|
187
204
|
defaultIsOpen={isFirstElement}
|
|
188
205
|
group={groupProps}
|
|
189
206
|
hasGroupTitle={hasGroupTitle}
|
|
@@ -209,13 +226,18 @@ const Inputs = ({
|
|
|
209
226
|
>
|
|
210
227
|
{inputProps.additionalLabel && (
|
|
211
228
|
<Typography
|
|
212
|
-
className={
|
|
229
|
+
className={cx(
|
|
230
|
+
classes.additionalLabel,
|
|
231
|
+
inputProps?.additionalLabelClassName
|
|
232
|
+
)}
|
|
213
233
|
variant="body1"
|
|
214
234
|
>
|
|
215
235
|
{t(inputProps.additionalLabel)}
|
|
216
236
|
</Typography>
|
|
217
237
|
)}
|
|
218
|
-
<
|
|
238
|
+
<div className={inputProps?.inputClassName || ''}>
|
|
239
|
+
<Input {...inputProps} />
|
|
240
|
+
</div>
|
|
219
241
|
</div>
|
|
220
242
|
);
|
|
221
243
|
})}
|
|
@@ -16,7 +16,9 @@ export enum InputType {
|
|
|
16
16
|
MultiConnectedAutocomplete,
|
|
17
17
|
FieldsTable,
|
|
18
18
|
Grid,
|
|
19
|
-
Custom
|
|
19
|
+
Custom,
|
|
20
|
+
Checkbox,
|
|
21
|
+
CheckboxGroup
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
interface FieldsTableGetRequiredProps {
|
|
@@ -24,14 +26,22 @@ interface FieldsTableGetRequiredProps {
|
|
|
24
26
|
values: FormikValues;
|
|
25
27
|
}
|
|
26
28
|
|
|
29
|
+
export type LabelPlacement = 'bottom' | 'top' | 'end' | 'start' | undefined;
|
|
30
|
+
|
|
27
31
|
export interface InputProps {
|
|
28
32
|
additionalLabel?: string;
|
|
33
|
+
additionalLabelClassName?: string;
|
|
29
34
|
additionalMemoProps?: Array<unknown>;
|
|
30
35
|
autocomplete?: {
|
|
31
36
|
creatable?: boolean;
|
|
32
37
|
options: Array<SelectEntry>;
|
|
33
38
|
};
|
|
34
39
|
change?: ({ setFieldValue, value }) => void;
|
|
40
|
+
checkbox?: {
|
|
41
|
+
direction?: 'horizontal' | 'vertical';
|
|
42
|
+
labelPlacement?: LabelPlacement;
|
|
43
|
+
options?: Array<string>;
|
|
44
|
+
};
|
|
35
45
|
connectedAutocomplete?: {
|
|
36
46
|
additionalConditionParameters: Array<ConditionsSearchParameter>;
|
|
37
47
|
endpoint?: string;
|
|
@@ -57,11 +67,13 @@ export interface InputProps {
|
|
|
57
67
|
getRequired?: (values: FormikValues) => boolean;
|
|
58
68
|
grid?: {
|
|
59
69
|
alignItems?: string;
|
|
70
|
+
className?: string;
|
|
60
71
|
columns: Array<Omit<InputProps, 'group'>>;
|
|
61
72
|
gridTemplateColumns?: string;
|
|
62
73
|
};
|
|
63
74
|
group: string;
|
|
64
75
|
hideInput?: (values: FormikValues) => boolean;
|
|
76
|
+
inputClassName?: string;
|
|
65
77
|
label: string;
|
|
66
78
|
radio?: {
|
|
67
79
|
options?: Array<{
|
package/src/Form/storiesData.tsx
CHANGED
|
@@ -4,6 +4,7 @@ import { equals, prop } from 'ramda';
|
|
|
4
4
|
|
|
5
5
|
import { Typography } from '@mui/material';
|
|
6
6
|
import HelpOutlineIcon from '@mui/icons-material/HelpOutline';
|
|
7
|
+
import MailIcon from '@mui/icons-material/MailOutline';
|
|
7
8
|
|
|
8
9
|
import { SelectEntry } from '../InputField/Select';
|
|
9
10
|
import { Listing } from '../api/models';
|
|
@@ -113,6 +114,11 @@ export const basicFormInitialValues = {
|
|
|
113
114
|
isForced: false,
|
|
114
115
|
language: 'French',
|
|
115
116
|
name: '',
|
|
117
|
+
notifications: {
|
|
118
|
+
channels: { Icon: MailIcon, checked: true, label: 'mail' },
|
|
119
|
+
hostevents: ['ok', 'warning'],
|
|
120
|
+
includeServices: { checked: true, label: 'Include services for this host' }
|
|
121
|
+
},
|
|
116
122
|
password: '',
|
|
117
123
|
roleMapping: [
|
|
118
124
|
{
|
|
@@ -155,6 +161,10 @@ export const basicFormGroups: Array<Group> = [
|
|
|
155
161
|
TooltipContent: (): JSX.Element => <Typography>Tooltip content</Typography>,
|
|
156
162
|
name: 'Second group',
|
|
157
163
|
order: 2
|
|
164
|
+
},
|
|
165
|
+
{
|
|
166
|
+
name: 'Third group',
|
|
167
|
+
order: 3
|
|
158
168
|
}
|
|
159
169
|
];
|
|
160
170
|
|
|
@@ -203,6 +213,41 @@ export const basicFormInputs: Array<InputProps> = [
|
|
|
203
213
|
},
|
|
204
214
|
type: InputType.Radio
|
|
205
215
|
},
|
|
216
|
+
{
|
|
217
|
+
additionalLabel: 'Notifications',
|
|
218
|
+
fieldName: '',
|
|
219
|
+
grid: {
|
|
220
|
+
alignItems: 'center',
|
|
221
|
+
columns: [
|
|
222
|
+
{
|
|
223
|
+
checkbox: {
|
|
224
|
+
direction: 'horizontal'
|
|
225
|
+
},
|
|
226
|
+
fieldName: 'notifications.channels',
|
|
227
|
+
label: 'channels',
|
|
228
|
+
type: InputType.Checkbox
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
fieldName: 'notifications.includeServices',
|
|
232
|
+
label: 'Iclude services',
|
|
233
|
+
type: InputType.Checkbox
|
|
234
|
+
},
|
|
235
|
+
{
|
|
236
|
+
checkbox: {
|
|
237
|
+
direction: 'horizontal',
|
|
238
|
+
labelPlacement: 'top',
|
|
239
|
+
options: ['ok', 'warning', 'critical', 'unknown']
|
|
240
|
+
},
|
|
241
|
+
fieldName: 'notifications.hostevents',
|
|
242
|
+
label: 'host events',
|
|
243
|
+
type: InputType.CheckboxGroup
|
|
244
|
+
}
|
|
245
|
+
]
|
|
246
|
+
},
|
|
247
|
+
group: 'Third group',
|
|
248
|
+
label: 'Notifications',
|
|
249
|
+
type: InputType.Grid
|
|
250
|
+
},
|
|
206
251
|
{
|
|
207
252
|
fieldName: 'anotherText',
|
|
208
253
|
group: 'First group',
|
package/src/Panel/index.tsx
CHANGED
|
@@ -33,7 +33,7 @@ const useStyles = makeStyles<StylesProps>()(
|
|
|
33
33
|
height: '100%'
|
|
34
34
|
},
|
|
35
35
|
container: {
|
|
36
|
-
backgroundColor: theme.palette.background.
|
|
36
|
+
backgroundColor: theme.palette.background.panel,
|
|
37
37
|
borderTopRightRadius: 0,
|
|
38
38
|
display: 'grid',
|
|
39
39
|
gridTemplate: 'auto auto 1fr / 1fr',
|
|
@@ -85,6 +85,7 @@ export interface Tab {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
export interface Props {
|
|
88
|
+
className?: string;
|
|
88
89
|
header: React.ReactElement;
|
|
89
90
|
headerBackgroundColor?: string;
|
|
90
91
|
labelClose?: string;
|
|
@@ -111,11 +112,12 @@ const Panel = React.forwardRef(
|
|
|
111
112
|
width = 550,
|
|
112
113
|
minWidth = 550,
|
|
113
114
|
headerBackgroundColor,
|
|
114
|
-
onResize
|
|
115
|
+
onResize,
|
|
116
|
+
className
|
|
115
117
|
}: Props,
|
|
116
118
|
ref
|
|
117
119
|
): JSX.Element => {
|
|
118
|
-
const { classes } = useStyles({
|
|
120
|
+
const { classes, cx } = useStyles({
|
|
119
121
|
hasTabs: !isEmpty(tabs),
|
|
120
122
|
headerBackgroundColor,
|
|
121
123
|
width
|
|
@@ -179,7 +181,7 @@ const Panel = React.forwardRef(
|
|
|
179
181
|
exit: 50
|
|
180
182
|
}}
|
|
181
183
|
>
|
|
182
|
-
<Paper className={classes.container} elevation={2}>
|
|
184
|
+
<Paper className={cx(classes.container, className)} elevation={2}>
|
|
183
185
|
{!isNil(onResize) && (
|
|
184
186
|
<div className={classes.dragger} role="none" onMouseDown={resize} />
|
|
185
187
|
)}
|
|
@@ -9,17 +9,20 @@ import { Typography } from '@mui/material';
|
|
|
9
9
|
|
|
10
10
|
interface StyleProps {
|
|
11
11
|
editable: boolean;
|
|
12
|
+
error?: string;
|
|
12
13
|
minInputHeight: number;
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
const useStyles = makeStyles<StyleProps>()(
|
|
16
|
-
(theme, { minInputHeight, editable }) => ({
|
|
17
|
+
(theme, { minInputHeight, editable, error }) => ({
|
|
17
18
|
container: {
|
|
18
19
|
'& p': {
|
|
19
20
|
margin: 0
|
|
20
21
|
},
|
|
21
22
|
backgroundColor: theme.palette.background.paper,
|
|
22
|
-
border:
|
|
23
|
+
border: error
|
|
24
|
+
? `1px solid ${theme.palette.error.main}`
|
|
25
|
+
: '1px solid transparent',
|
|
23
26
|
borderRadius: theme.shape.borderRadius,
|
|
24
27
|
padding: theme.spacing(0.5, 1)
|
|
25
28
|
},
|
|
@@ -31,7 +34,9 @@ const useStyles = makeStyles<StyleProps>()(
|
|
|
31
34
|
outline: '0px solid transparent'
|
|
32
35
|
},
|
|
33
36
|
inputFocused: {
|
|
34
|
-
border:
|
|
37
|
+
border: error
|
|
38
|
+
? `1px solid ${theme.palette.error.main}`
|
|
39
|
+
: `1px solid ${theme.palette.primary.main}`
|
|
35
40
|
},
|
|
36
41
|
placeholder: {
|
|
37
42
|
color: theme.palette.grey[500],
|
|
@@ -41,13 +46,16 @@ const useStyles = makeStyles<StyleProps>()(
|
|
|
41
46
|
);
|
|
42
47
|
|
|
43
48
|
interface Props {
|
|
49
|
+
className?: string;
|
|
44
50
|
editable: boolean;
|
|
45
51
|
editorState?: string;
|
|
52
|
+
error?: string;
|
|
46
53
|
hasInitialTextContent?: boolean;
|
|
47
54
|
initialEditorState?: string;
|
|
48
55
|
inputClassname?: string;
|
|
49
56
|
minInputHeight: number;
|
|
50
57
|
namespace: string;
|
|
58
|
+
onBlur?: (e: string) => void;
|
|
51
59
|
placeholder: string;
|
|
52
60
|
resetEditorToInitialStateCondition?: () => boolean;
|
|
53
61
|
}
|
|
@@ -61,9 +69,12 @@ const ContentEditable = ({
|
|
|
61
69
|
editorState,
|
|
62
70
|
namespace,
|
|
63
71
|
resetEditorToInitialStateCondition,
|
|
64
|
-
initialEditorState
|
|
72
|
+
initialEditorState,
|
|
73
|
+
error,
|
|
74
|
+
onBlur,
|
|
75
|
+
className
|
|
65
76
|
}: Props): JSX.Element => {
|
|
66
|
-
const { classes, cx } = useStyles({ editable, minInputHeight });
|
|
77
|
+
const { classes, cx } = useStyles({ editable, error, minInputHeight });
|
|
67
78
|
const { t } = useTranslation();
|
|
68
79
|
|
|
69
80
|
const [editor] = useLexicalComposerContext();
|
|
@@ -119,9 +130,18 @@ const ContentEditable = ({
|
|
|
119
130
|
|
|
120
131
|
const isTextEmpty = isEmpty(root);
|
|
121
132
|
|
|
133
|
+
const handleBlur = (event: React.FocusEvent<HTMLInputElement>): void => {
|
|
134
|
+
setFocused(false);
|
|
135
|
+
onBlur?.(event);
|
|
136
|
+
};
|
|
137
|
+
|
|
122
138
|
return (
|
|
123
139
|
<div
|
|
124
|
-
className={cx(
|
|
140
|
+
className={cx(
|
|
141
|
+
classes.container,
|
|
142
|
+
className,
|
|
143
|
+
isFocused && classes.inputFocused
|
|
144
|
+
)}
|
|
125
145
|
id={namespace}
|
|
126
146
|
>
|
|
127
147
|
{editable && isTextEmpty && (
|
|
@@ -139,7 +159,7 @@ const ContentEditable = ({
|
|
|
139
159
|
contentEditable={isEditable}
|
|
140
160
|
data-testid={namespace}
|
|
141
161
|
ref={ref}
|
|
142
|
-
onBlur={
|
|
162
|
+
onBlur={handleBlur}
|
|
143
163
|
onFocus={(): void => setFocused(true)}
|
|
144
164
|
/>
|
|
145
165
|
</div>
|
|
@@ -7,6 +7,9 @@ import anylogger from 'anylogger';
|
|
|
7
7
|
import { makeStyles } from 'tss-react/mui';
|
|
8
8
|
import { EditorState } from 'lexical';
|
|
9
9
|
import { LinkPlugin } from '@lexical/react/LexicalLinkPlugin';
|
|
10
|
+
import { equals } from 'ramda';
|
|
11
|
+
|
|
12
|
+
import { Typography } from '@mui/material';
|
|
10
13
|
|
|
11
14
|
import ContentEditable from './ContentEditable';
|
|
12
15
|
import ToolbarPlugin from './plugins/ToolbarPlugin/index';
|
|
@@ -14,15 +17,19 @@ import AutoCompleteLinkPlugin from './plugins/AutoLinkPlugin/index';
|
|
|
14
17
|
import FloatingLinkEditorPlugin from './plugins/FloatingLinkEditorPlugin';
|
|
15
18
|
|
|
16
19
|
export interface RichTextEditorProps {
|
|
20
|
+
contentClassName?: string;
|
|
17
21
|
editable: boolean;
|
|
18
22
|
editorState?: string;
|
|
23
|
+
error?: string;
|
|
19
24
|
getEditorState?: (editorState: EditorState) => void;
|
|
20
25
|
initialEditorState?: string;
|
|
21
26
|
inputClassname?: string;
|
|
22
27
|
minInputHeight?: number;
|
|
23
28
|
namespace?: string;
|
|
29
|
+
onBlur?: (e: string) => void;
|
|
24
30
|
placeholder?: string;
|
|
25
31
|
resetEditorToInitialStateCondition?: () => boolean;
|
|
32
|
+
toolbarPositions?: 'start' | 'end';
|
|
26
33
|
}
|
|
27
34
|
|
|
28
35
|
const log = anylogger('Rich text editor');
|
|
@@ -31,26 +38,46 @@ const onError = (error: Error): void => {
|
|
|
31
38
|
log.error(error.message);
|
|
32
39
|
};
|
|
33
40
|
|
|
34
|
-
const useStyles = makeStyles()(
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
const useStyles = makeStyles<{ toolbarPositions: 'start' | 'end' }>()(
|
|
42
|
+
(theme, { toolbarPositions }) => ({
|
|
43
|
+
bold: {
|
|
44
|
+
fontWeight: theme.typography.fontWeightBold
|
|
45
|
+
},
|
|
46
|
+
container: equals(toolbarPositions, 'end')
|
|
47
|
+
? {
|
|
48
|
+
display: 'flex',
|
|
49
|
+
flexDirection: 'column-reverse'
|
|
50
|
+
}
|
|
51
|
+
: {},
|
|
52
|
+
error: {
|
|
53
|
+
color: theme.palette.error.main,
|
|
54
|
+
fontSize: theme.spacing(1.5),
|
|
55
|
+
fontWeight: '200',
|
|
56
|
+
paddingLeft: theme.spacing(1.5),
|
|
57
|
+
paddingTop: theme.spacing(0.5)
|
|
58
|
+
},
|
|
59
|
+
italic: {
|
|
60
|
+
fontStyle: 'italic'
|
|
61
|
+
},
|
|
62
|
+
link: {
|
|
63
|
+
color: theme.palette.primary.main
|
|
64
|
+
},
|
|
65
|
+
strikethrough: {
|
|
66
|
+
textDecoration: 'line-through'
|
|
67
|
+
},
|
|
68
|
+
toolbar: equals(toolbarPositions, 'end')
|
|
69
|
+
? {
|
|
70
|
+
marginTop: theme.spacing(0.5)
|
|
71
|
+
}
|
|
72
|
+
: {},
|
|
73
|
+
underline: {
|
|
74
|
+
textDecoration: 'underline'
|
|
75
|
+
},
|
|
76
|
+
underlineStrikethrough: {
|
|
77
|
+
textDecoration: 'underline line-through'
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
);
|
|
54
81
|
|
|
55
82
|
const RichTextEditor = ({
|
|
56
83
|
namespace = 'RichTextEditor',
|
|
@@ -61,9 +88,13 @@ const RichTextEditor = ({
|
|
|
61
88
|
initialEditorState,
|
|
62
89
|
editable = true,
|
|
63
90
|
editorState,
|
|
64
|
-
resetEditorToInitialStateCondition
|
|
91
|
+
resetEditorToInitialStateCondition,
|
|
92
|
+
toolbarPositions = 'start',
|
|
93
|
+
error,
|
|
94
|
+
onBlur,
|
|
95
|
+
contentClassName
|
|
65
96
|
}: RichTextEditorProps): JSX.Element => {
|
|
66
|
-
const { classes } = useStyles();
|
|
97
|
+
const { classes } = useStyles({ toolbarPositions });
|
|
67
98
|
|
|
68
99
|
const hasInitialTextContent = initialEditorState
|
|
69
100
|
? JSON.parse(initialEditorState).root?.children.length > 0
|
|
@@ -80,7 +111,7 @@ const RichTextEditor = ({
|
|
|
80
111
|
text: {
|
|
81
112
|
bold: classes.bold,
|
|
82
113
|
italic: classes.italic,
|
|
83
|
-
strikethrough: classes.
|
|
114
|
+
strikethrough: classes.strikethrough,
|
|
84
115
|
underline: classes.underline,
|
|
85
116
|
underlineStrikethrough: classes.underlineStrikethrough
|
|
86
117
|
}
|
|
@@ -89,30 +120,40 @@ const RichTextEditor = ({
|
|
|
89
120
|
|
|
90
121
|
return (
|
|
91
122
|
<LexicalComposer initialConfig={initialConfig}>
|
|
92
|
-
<
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
123
|
+
<div className={classes.container}>
|
|
124
|
+
<div className={classes.toolbar}>
|
|
125
|
+
<ToolbarPlugin editable={editable} getEditorState={getEditorState} />
|
|
126
|
+
</div>
|
|
127
|
+
<div>
|
|
128
|
+
<RichTextPlugin
|
|
129
|
+
ErrorBoundary={LexicalErrorBoundary}
|
|
130
|
+
contentEditable={
|
|
131
|
+
<ContentEditable
|
|
132
|
+
className={contentClassName || ''}
|
|
133
|
+
editable={editable}
|
|
134
|
+
editorState={editorState}
|
|
135
|
+
error={error}
|
|
136
|
+
hasInitialTextContent={hasInitialTextContent}
|
|
137
|
+
initialEditorState={initialEditorState}
|
|
138
|
+
inputClassname={inputClassname}
|
|
139
|
+
minInputHeight={minInputHeight}
|
|
140
|
+
namespace={namespace}
|
|
141
|
+
placeholder={placeholder}
|
|
142
|
+
resetEditorToInitialStateCondition={
|
|
143
|
+
resetEditorToInitialStateCondition
|
|
144
|
+
}
|
|
145
|
+
onBlur={onBlur}
|
|
146
|
+
/>
|
|
107
147
|
}
|
|
148
|
+
placeholder={null}
|
|
108
149
|
/>
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
150
|
+
<HistoryPlugin />
|
|
151
|
+
<LinkPlugin />
|
|
152
|
+
<AutoCompleteLinkPlugin />
|
|
153
|
+
<FloatingLinkEditorPlugin editable={editable} />
|
|
154
|
+
{error && <Typography className={classes.error}>{error}</Typography>}
|
|
155
|
+
</div>
|
|
156
|
+
</div>
|
|
116
157
|
</LexicalComposer>
|
|
117
158
|
);
|
|
118
159
|
};
|
|
@@ -18,6 +18,7 @@ declare module '@mui/material/styles' {
|
|
|
18
18
|
background: {
|
|
19
19
|
default: string;
|
|
20
20
|
listingHeader: string;
|
|
21
|
+
panelGroups: string;
|
|
21
22
|
paper: string;
|
|
22
23
|
};
|
|
23
24
|
pending: {
|
|
@@ -44,6 +45,8 @@ declare module '@mui/material/styles' {
|
|
|
44
45
|
|
|
45
46
|
interface TypeBackground {
|
|
46
47
|
listingHeader: string;
|
|
48
|
+
panel: string;
|
|
49
|
+
panelGroups: string;
|
|
47
50
|
}
|
|
48
51
|
}
|
|
49
52
|
|
|
@@ -79,6 +82,8 @@ export const lightPalette: PaletteOptions = {
|
|
|
79
82
|
background: {
|
|
80
83
|
default: '#F4F4F4',
|
|
81
84
|
listingHeader: '#666666',
|
|
85
|
+
panel: '#EDEDED',
|
|
86
|
+
panelGroups: '#F5F5F5',
|
|
82
87
|
paper: '#FFFFFF'
|
|
83
88
|
},
|
|
84
89
|
divider: '#E3E3E3',
|
|
@@ -148,6 +153,8 @@ export const darkPalette: PaletteOptions = {
|
|
|
148
153
|
background: {
|
|
149
154
|
default: '#4a4a4a',
|
|
150
155
|
listingHeader: '#666666',
|
|
156
|
+
panel: '#4a4a4a',
|
|
157
|
+
panelGroups: '#252525',
|
|
151
158
|
paper: '#212121'
|
|
152
159
|
},
|
|
153
160
|
divider: '#666666',
|
|
@@ -11,8 +11,7 @@ import { useStyles } from './DashboardForm.styles';
|
|
|
11
11
|
import {
|
|
12
12
|
labelMustBeAtLeast,
|
|
13
13
|
labelMustBeMost,
|
|
14
|
-
labelRequired
|
|
15
|
-
labelCharacters
|
|
14
|
+
labelRequired
|
|
16
15
|
} from './translatedLabels';
|
|
17
16
|
import {
|
|
18
17
|
DashboardFormActions,
|
|
@@ -44,7 +43,7 @@ const DashboardForm = ({
|
|
|
44
43
|
|
|
45
44
|
const formProps = useMemo<FormProps<DashboardResource>>(
|
|
46
45
|
() => ({
|
|
47
|
-
initialValues: resource ?? {
|
|
46
|
+
initialValues: resource ?? { name: '' },
|
|
48
47
|
inputs: [
|
|
49
48
|
{
|
|
50
49
|
fieldName: 'name',
|
|
@@ -56,7 +55,7 @@ const DashboardForm = ({
|
|
|
56
55
|
{
|
|
57
56
|
fieldName: 'description',
|
|
58
57
|
group: 'main',
|
|
59
|
-
label: labels?.entity?.description
|
|
58
|
+
label: labels?.entity?.description,
|
|
60
59
|
text: {
|
|
61
60
|
multilineRows: 3
|
|
62
61
|
},
|
|
@@ -66,12 +65,9 @@ const DashboardForm = ({
|
|
|
66
65
|
submit: (values, bag) => onSubmit?.(values, bag),
|
|
67
66
|
validationSchema: Yup.object().shape({
|
|
68
67
|
description: Yup.string()
|
|
69
|
-
.label(labels?.entity?.description
|
|
70
|
-
.max(
|
|
71
|
-
|
|
72
|
-
(p) =>
|
|
73
|
-
`${p.label} ${t(labelMustBeMost)} ${p.max} ${t(labelCharacters)}`
|
|
74
|
-
)
|
|
68
|
+
.label(labels?.entity?.description)
|
|
69
|
+
.max(180, ({ max, label }) => t(labelMustBeMost, { label, max }))
|
|
70
|
+
.optional()
|
|
75
71
|
.nullable(),
|
|
76
72
|
name: Yup.string()
|
|
77
73
|
.label(labels?.entity?.name)
|
package/src/index.ts
CHANGED
|
@@ -2,6 +2,8 @@ import type { Props as SingleAutocompleteFieldProps } from './InputField/Select/
|
|
|
2
2
|
|
|
3
3
|
export { default as IconButton } from './Button/Icon';
|
|
4
4
|
|
|
5
|
+
export { Checkbox, CheckboxGroup } from './Checkbox';
|
|
6
|
+
|
|
5
7
|
export { default as SingleAutocompleteField } from './InputField/Select/Autocomplete';
|
|
6
8
|
export type { SingleAutocompleteFieldProps };
|
|
7
9
|
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { gt } from 'ramda';
|
|
2
|
+
|
|
3
|
+
export enum PanelSize {
|
|
4
|
+
Small = 550,
|
|
5
|
+
Medium = 675,
|
|
6
|
+
Large = 800
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
interface PanelSizeParams {
|
|
10
|
+
currentSize: number;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const togglePanelSize = ({ currentSize }: PanelSizeParams): number => {
|
|
14
|
+
return gt(currentSize, PanelSize.Medium) ? PanelSize.Small : PanelSize.Large;
|
|
15
|
+
};
|