@centreon/ui 24.4.1-MON-32852.1 → 24.4.1-MON-33898.9
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/Search/index.tsx +2 -2
- package/src/InputField/Select/IconPopover/index.tsx +1 -1
- package/src/InputField/Text/index.tsx +38 -38
- package/src/Listing/ActionBar/index.tsx +1 -2
- package/src/Panel/index.tsx +1 -1
- package/src/components/Form/{AccessRightsV2 → AccessRights}/AccessRights.cypress.spec.tsx +23 -0
- package/src/components/Form/{AccessRightsV2 → AccessRights}/ShareInput/ContactSwitch.tsx +9 -1
- package/src/components/Form/{AccessRightsV2 → AccessRights}/ShareInput/ShareInput.styles.ts +8 -0
- package/src/components/Form/{AccessRightsV2 → AccessRights}/ShareInput/useShareInput.tsx +4 -0
- package/src/components/Form/{AccessRightsV2 → AccessRights}/models.ts +1 -0
- package/src/components/Form/{AccessRightsV2 → AccessRights}/storiesData.ts +1 -0
- package/src/components/Form/index.ts +2 -2
- package/src/index.ts +0 -1
- package/src/InputField/Number/Number.cypress.spec.tsx +0 -85
- package/src/InputField/Number/Number.stories.tsx +0 -66
- package/src/InputField/Number/Number.tsx +0 -74
- package/src/components/Form/AccessRights/AccessRights.resource.ts +0 -45
- package/src/components/Form/AccessRights/AccessRightsForm.stories.tsx +0 -59
- package/src/components/Form/AccessRights/AccessRightsForm.styles.ts +0 -21
- package/src/components/Form/AccessRights/AccessRightsForm.tsx +0 -67
- package/src/components/Form/AccessRights/AccessRightsFormActions.tsx +0 -80
- package/src/components/Form/AccessRights/Input/AddAction.tsx +0 -31
- package/src/components/Form/AccessRights/Input/ContactAccessRightInput.stories.tsx +0 -54
- package/src/components/Form/AccessRights/Input/ContactAccessRightInput.tsx +0 -72
- package/src/components/Form/AccessRights/Input/ContactAccessRightsInput.styles.ts +0 -22
- package/src/components/Form/AccessRights/Input/ContactInputField.tsx +0 -105
- package/src/components/Form/AccessRights/Input/RoleInputField.tsx +0 -29
- package/src/components/Form/AccessRights/List/ContactAccessRightsList.stories.tsx +0 -97
- package/src/components/Form/AccessRights/List/ContactAccessRightsList.styles.ts +0 -71
- package/src/components/Form/AccessRights/List/ContactAccessRightsList.tsx +0 -51
- package/src/components/Form/AccessRights/List/ContactAccessRightsListItem.stories.tsx +0 -116
- package/src/components/Form/AccessRights/List/ContactAccessRightsListItem.tsx +0 -118
- package/src/components/Form/AccessRights/List/ContactAccessRightsListItemSkeleton.tsx +0 -26
- package/src/components/Form/AccessRights/List/ContactAccessRightsListSkeleton.tsx +0 -28
- package/src/components/Form/AccessRights/Stats/AccessRightsStats.styles.ts +0 -18
- package/src/components/Form/AccessRights/Stats/AccessRightsStats.tsx +0 -41
- package/src/components/Form/AccessRights/__fixtures__/contactAccessRight.mock.ts +0 -54
- package/src/components/Form/AccessRights/common/GroupLabel.styles.ts +0 -18
- package/src/components/Form/AccessRights/common/GroupLabel.tsx +0 -15
- package/src/components/Form/AccessRights/common/Input.styles.ts +0 -48
- package/src/components/Form/AccessRights/common/RoleInputSelect.styles.ts +0 -11
- package/src/components/Form/AccessRights/common/RoleInputSelect.tsx +0 -57
- package/src/components/Form/AccessRights/index.ts +0 -3
- package/src/components/Form/AccessRights/useAccessRightsForm.test.tsx +0 -531
- package/src/components/Form/AccessRights/useAccessRightsForm.tsx +0 -282
- package/src/components/Form/AccessRights/useAccessRightsForm.utils.ts +0 -41
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/AccessRights.stories.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/AccessRights.styles.ts +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/AccessRights.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/Actions/Actions.styles.ts +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/Actions/Actions.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/Actions/useActions.ts +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/Item.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/List.styles.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/List.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/ListItemSkeleton.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/ListSkeleton.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/RemoveAccessRight.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/StateChip.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/List/useItem.ts +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/Provider.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/ShareInput/ShareInput.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/Stats/Stats.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/atoms.ts +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/common/RoleSelectField.styles.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/common/RoleSelectField.tsx +0 -0
- /package/src/components/Form/{AccessRightsV2 → AccessRights}/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 IconButton from '.';
|
|
7
|
+
import { IconButton } from '.';
|
|
8
8
|
|
|
9
9
|
const useStyles = makeStyles()((theme: Theme) => ({
|
|
10
10
|
root: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import IconSearch from '@mui/icons-material/Search';
|
|
2
2
|
|
|
3
|
-
import TextField, {
|
|
3
|
+
import TextField, { Props as TextFieldProps } from '../Text';
|
|
4
4
|
|
|
5
|
-
type Props = Omit<
|
|
5
|
+
type Props = Omit<TextFieldProps, 'StartAdornment'>;
|
|
6
6
|
|
|
7
7
|
const SearchAdornment = (): JSX.Element => <IconSearch />;
|
|
8
8
|
|
|
@@ -15,7 +15,7 @@ import {
|
|
|
15
15
|
} from '@mui/material';
|
|
16
16
|
import IconReset from '@mui/icons-material/RotateLeft';
|
|
17
17
|
|
|
18
|
-
import IconButton from '
|
|
18
|
+
import { IconButton } from '../../..';
|
|
19
19
|
import Option from '../Option';
|
|
20
20
|
import { SelectEntry } from '..';
|
|
21
21
|
|
|
@@ -17,36 +17,38 @@ import { getNormalizedId } from '../../utils';
|
|
|
17
17
|
|
|
18
18
|
import useAutoSize from './useAutoSize';
|
|
19
19
|
|
|
20
|
-
const useStyles = makeStyles
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
20
|
+
const useStyles = makeStyles<{ displayAsBlock: boolean }>()(
|
|
21
|
+
(theme: Theme, { displayAsBlock }) => ({
|
|
22
|
+
autoSizeCompact: {
|
|
23
|
+
paddingRight: theme.spacing(1),
|
|
24
|
+
paddingTop: theme.spacing(0.6)
|
|
25
|
+
},
|
|
26
|
+
hiddenText: {
|
|
27
|
+
display: 'table',
|
|
28
|
+
lineHeight: 0,
|
|
29
|
+
transform: 'scaleY(0)'
|
|
30
|
+
},
|
|
31
|
+
input: {
|
|
32
|
+
fontSize: theme.typography.body1.fontSize
|
|
33
|
+
},
|
|
34
|
+
inputBase: {
|
|
35
|
+
display: displayAsBlock ? 'block' : 'inline-flex',
|
|
36
|
+
justifyItems: 'start',
|
|
37
|
+
paddingRight: theme.spacing(1)
|
|
38
|
+
},
|
|
39
|
+
noLabelInput: {
|
|
40
|
+
padding: theme.spacing(1)
|
|
41
|
+
},
|
|
42
|
+
textField: {
|
|
43
|
+
transition: theme.transitions.create(['width'], {
|
|
44
|
+
duration: theme.transitions.duration.shortest
|
|
45
|
+
})
|
|
46
|
+
},
|
|
47
|
+
transparent: {
|
|
48
|
+
backgroundColor: 'transparent'
|
|
49
|
+
}
|
|
50
|
+
})
|
|
51
|
+
);
|
|
50
52
|
|
|
51
53
|
interface OptionalLabelInputAdornmentProps {
|
|
52
54
|
children: React.ReactNode;
|
|
@@ -70,7 +72,7 @@ const OptionalLabelInputAdornment = ({
|
|
|
70
72
|
|
|
71
73
|
type SizeVariant = 'large' | 'medium' | 'small' | 'compact';
|
|
72
74
|
|
|
73
|
-
export type
|
|
75
|
+
export type Props = {
|
|
74
76
|
EndAdornment?: React.FC;
|
|
75
77
|
StartAdornment?: React.FC;
|
|
76
78
|
ariaLabel?: string;
|
|
@@ -112,18 +114,17 @@ const TextField = forwardRef(
|
|
|
112
114
|
defaultValue,
|
|
113
115
|
required = false,
|
|
114
116
|
containerClassName,
|
|
115
|
-
type,
|
|
116
117
|
...rest
|
|
117
|
-
}:
|
|
118
|
+
}: Props,
|
|
118
119
|
ref: React.ForwardedRef<HTMLDivElement>
|
|
119
120
|
): JSX.Element => {
|
|
120
|
-
const { classes, cx } = useStyles(
|
|
121
|
+
const { classes, cx } = useStyles({
|
|
122
|
+
displayAsBlock: autoSize && isNil(StartAdornment) && isNil(EndAdornment)
|
|
123
|
+
});
|
|
121
124
|
|
|
122
125
|
const { inputRef, width, changeInputValue, innerValue } = useAutoSize({
|
|
123
126
|
autoSize,
|
|
124
|
-
autoSizeCustomPadding
|
|
125
|
-
? Math.max(6, autoSizeCustomPadding || 0)
|
|
126
|
-
: autoSizeCustomPadding,
|
|
127
|
+
autoSizeCustomPadding,
|
|
127
128
|
autoSizeDefaultWidth,
|
|
128
129
|
value: externalValueForAutoSize || rest.value
|
|
129
130
|
});
|
|
@@ -195,7 +196,6 @@ const TextField = forwardRef(
|
|
|
195
196
|
width: autoSize ? width : undefined,
|
|
196
197
|
...rest?.sx
|
|
197
198
|
}}
|
|
198
|
-
type={type}
|
|
199
199
|
/>
|
|
200
200
|
</Tooltip>
|
|
201
201
|
{autoSize && (
|
|
@@ -9,10 +9,9 @@ import Divider from '@mui/material/Divider';
|
|
|
9
9
|
|
|
10
10
|
import { userAtom, ListingVariant } from '@centreon/ui-context';
|
|
11
11
|
|
|
12
|
-
import { ListingProps } from '../..';
|
|
12
|
+
import { ListingProps, IconButton } from '../..';
|
|
13
13
|
import { labelOf, labelRowsPerPage } from '../translatedLabels';
|
|
14
14
|
import { useMemoComponent } from '../../utils';
|
|
15
|
-
import IconButton from '../../Button/Icon/index';
|
|
16
15
|
|
|
17
16
|
import StyledPagination from './Pagination';
|
|
18
17
|
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 IconButton from '
|
|
12
|
+
import { IconButton } from '..';
|
|
13
13
|
|
|
14
14
|
import { minTabHeight } from './Tab';
|
|
15
15
|
|
|
@@ -347,4 +347,27 @@ describe('Access rights', () => {
|
|
|
347
347
|
|
|
348
348
|
cy.makeSnapshot();
|
|
349
349
|
});
|
|
350
|
+
|
|
351
|
+
it('resets the role to "viewer" when the "editor" role is selected and a contact with "viewer" right is selected', () => {
|
|
352
|
+
initialize({});
|
|
353
|
+
|
|
354
|
+
cy.findByLabelText(labels.add.autocompleteContact).click();
|
|
355
|
+
|
|
356
|
+
cy.waitForRequest('@getContacts');
|
|
357
|
+
|
|
358
|
+
cy.contains('Entity 10').click();
|
|
359
|
+
|
|
360
|
+
cy.findByTestId('add_role').parent().click();
|
|
361
|
+
cy.get('li[data-value="editor"]').click();
|
|
362
|
+
|
|
363
|
+
cy.findByLabelText(labels.add.autocompleteContact).click();
|
|
364
|
+
|
|
365
|
+
cy.waitForRequest('@getContacts');
|
|
366
|
+
|
|
367
|
+
cy.contains('Entity 11').click();
|
|
368
|
+
|
|
369
|
+
cy.findByTestId('add_role').should('have.value', 'viewer');
|
|
370
|
+
|
|
371
|
+
cy.makeSnapshot();
|
|
372
|
+
});
|
|
350
373
|
});
|
|
@@ -7,11 +7,14 @@ import { ContactType, Labels } from '../models';
|
|
|
7
7
|
import { contactTypeAtom } from '../atoms';
|
|
8
8
|
import { Subtitle } from '../../../..';
|
|
9
9
|
|
|
10
|
+
import { useContactSwitchStyles } from './ShareInput.styles';
|
|
11
|
+
|
|
10
12
|
interface Props {
|
|
11
13
|
labels: Labels['add'];
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
const ContactSwitch = ({ labels }: Props): JSX.Element => {
|
|
17
|
+
const { classes } = useContactSwitchStyles();
|
|
15
18
|
const { t } = useTranslation();
|
|
16
19
|
|
|
17
20
|
const setContactType = useSetAtom(contactTypeAtom);
|
|
@@ -23,7 +26,12 @@ const ContactSwitch = ({ labels }: Props): JSX.Element => {
|
|
|
23
26
|
return (
|
|
24
27
|
<>
|
|
25
28
|
<Subtitle>{t(labels.title)}</Subtitle>
|
|
26
|
-
<RadioGroup
|
|
29
|
+
<RadioGroup
|
|
30
|
+
row
|
|
31
|
+
className={classes.inputs}
|
|
32
|
+
defaultValue={ContactType.Contact}
|
|
33
|
+
onChange={change}
|
|
34
|
+
>
|
|
27
35
|
<FormControlLabel
|
|
28
36
|
control={<Radio />}
|
|
29
37
|
label={labels.contact}
|
|
@@ -7,3 +7,11 @@ export const useShareInputStyles = makeStyles()((theme) => ({
|
|
|
7
7
|
gridTemplateColumns: `1fr min-content min-content`
|
|
8
8
|
}
|
|
9
9
|
}));
|
|
10
|
+
|
|
11
|
+
export const useContactSwitchStyles = makeStyles()((theme) => ({
|
|
12
|
+
inputs: {
|
|
13
|
+
display: 'flex',
|
|
14
|
+
flexDirection: 'row',
|
|
15
|
+
gap: theme.spacing(2)
|
|
16
|
+
}
|
|
17
|
+
}));
|
|
@@ -40,6 +40,10 @@ const useShareInput = (endpoints: Endpoints): UseShareInputState => {
|
|
|
40
40
|
|
|
41
41
|
const selectContact = (_, entry): void => {
|
|
42
42
|
setSelectedContact(entry);
|
|
43
|
+
if (equals('editor', entry.most_permissive_role)) {
|
|
44
|
+
return;
|
|
45
|
+
}
|
|
46
|
+
setSelectedRole('viewer');
|
|
43
47
|
};
|
|
44
48
|
|
|
45
49
|
const add = (): void => {
|
|
@@ -88,6 +88,7 @@ const buildEntities = (from, isGroup): Array<SelectEntry> => {
|
|
|
88
88
|
.map((_, index) => ({
|
|
89
89
|
email: isGroup ? undefined : faker.internet.email(),
|
|
90
90
|
id: 1000 + index,
|
|
91
|
+
most_permissive_role: index % 3 === 0 ? 'editor' : 'viewer',
|
|
91
92
|
name: `Entity ${isGroup ? 'Group' : ''} ${from + index}`
|
|
92
93
|
}));
|
|
93
94
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from './Form.models';
|
|
2
2
|
export * from './Dashboard';
|
|
3
|
-
export
|
|
4
|
-
export { default as AccessRightsV2 } from './
|
|
3
|
+
export { default as AccessRights } from './AccessRights/AccessRights';
|
|
4
|
+
export { default as AccessRightsV2 } from './AccessRights/AccessRights';
|
package/src/index.ts
CHANGED
|
@@ -23,7 +23,6 @@ export { default as RegexpHelpTooltip } from './InputField/Search/RegexpHelpTool
|
|
|
23
23
|
|
|
24
24
|
export { default as TextField } from './InputField/Text';
|
|
25
25
|
export type { Props as TextFieldProps } from './InputField/Text';
|
|
26
|
-
export { default as NumberField } from './InputField/Number/Number';
|
|
27
26
|
|
|
28
27
|
export type { SelectEntry } from './InputField/Select';
|
|
29
28
|
export { default as SelectField } from './InputField/Select';
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import NumberField, { NumberProps } from './Number';
|
|
2
|
-
|
|
3
|
-
const initialize = (props: NumberProps): void => {
|
|
4
|
-
cy.mount({
|
|
5
|
-
Component: <NumberField {...props} />
|
|
6
|
-
});
|
|
7
|
-
};
|
|
8
|
-
|
|
9
|
-
describe('Number field', () => {
|
|
10
|
-
it('displays the placeholder when the field has no default or fallback values', () => {
|
|
11
|
-
initialize({ dataTestId: 'test', onChange: cy.stub() });
|
|
12
|
-
|
|
13
|
-
cy.get('input').should('have.value', '');
|
|
14
|
-
cy.get('input').should('have.attr', 'placeholder', '0');
|
|
15
|
-
|
|
16
|
-
cy.makeSnapshot();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('displays the fallback value as placeholder when the field as no default value', () => {
|
|
20
|
-
initialize({ dataTestId: 'test', fallbackValue: 25, onChange: cy.stub() });
|
|
21
|
-
|
|
22
|
-
cy.get('input').should('have.value', '');
|
|
23
|
-
cy.get('input').should('have.attr', 'placeholder', '25');
|
|
24
|
-
|
|
25
|
-
cy.makeSnapshot();
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('displays the default value as placeholder when the field as default value', () => {
|
|
29
|
-
initialize({ dataTestId: 'test', defaultValue: 25, onChange: cy.stub() });
|
|
30
|
-
|
|
31
|
-
cy.get('input').should('have.value', '25');
|
|
32
|
-
|
|
33
|
-
cy.makeSnapshot();
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
it('displays the fallback value when the field is cleared out', () => {
|
|
37
|
-
initialize({
|
|
38
|
-
dataTestId: 'test',
|
|
39
|
-
defaultValue: 25,
|
|
40
|
-
fallbackValue: 10,
|
|
41
|
-
onChange: cy.stub()
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
cy.get('input').should('have.value', '25');
|
|
45
|
-
cy.get('input').clear();
|
|
46
|
-
cy.get('input').should('have.value', '');
|
|
47
|
-
cy.get('input').should('have.attr', 'placeholder', '10');
|
|
48
|
-
|
|
49
|
-
cy.makeSnapshot();
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('displays the field using auto size', () => {
|
|
53
|
-
initialize({
|
|
54
|
-
autoSize: true,
|
|
55
|
-
dataTestId: 'test',
|
|
56
|
-
defaultValue: 25,
|
|
57
|
-
onChange: cy.stub()
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
cy.get('input').should('have.value', '25');
|
|
61
|
-
|
|
62
|
-
cy.get('input').type('0');
|
|
63
|
-
|
|
64
|
-
cy.makeSnapshot();
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('sets the value to the minimum value configured when a value less than the minimum value is typed in the field', () => {
|
|
68
|
-
initialize({
|
|
69
|
-
dataTestId: 'test',
|
|
70
|
-
defaultValue: 25,
|
|
71
|
-
inputProps: {
|
|
72
|
-
min: 2
|
|
73
|
-
},
|
|
74
|
-
onChange: cy.stub()
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
cy.get('input').should('have.value', '25');
|
|
78
|
-
|
|
79
|
-
cy.get('input').clear().type('-1');
|
|
80
|
-
|
|
81
|
-
cy.get('input').should('have.value', '2');
|
|
82
|
-
|
|
83
|
-
cy.makeSnapshot();
|
|
84
|
-
});
|
|
85
|
-
});
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
import { Meta, StoryObj } from '@storybook/react';
|
|
3
|
-
|
|
4
|
-
import NumberField from './Number';
|
|
5
|
-
|
|
6
|
-
const meta: Meta<typeof NumberField> = {
|
|
7
|
-
argTypes: {
|
|
8
|
-
defaultValue: {
|
|
9
|
-
defaultValue: 0,
|
|
10
|
-
description:
|
|
11
|
-
'The initial value which will be used by the input for the first render',
|
|
12
|
-
type: 'number'
|
|
13
|
-
},
|
|
14
|
-
fallbackValue: {
|
|
15
|
-
defaultValue: 0,
|
|
16
|
-
description: 'This value will be used when the input is cleared',
|
|
17
|
-
type: 'number'
|
|
18
|
-
},
|
|
19
|
-
onChange: {
|
|
20
|
-
description:
|
|
21
|
-
'The change function with the actual value as parameter. This parameter will be the value when the input is filled but it will be the fallbackValue when the input is cleared out',
|
|
22
|
-
type: 'function'
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
component: NumberField
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
export default meta;
|
|
29
|
-
type Story = StoryObj<typeof NumberField>;
|
|
30
|
-
|
|
31
|
-
export const Default: Story = {
|
|
32
|
-
args: {
|
|
33
|
-
onChange: console.log
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export const WithDefaultValue: Story = {
|
|
38
|
-
args: {
|
|
39
|
-
defaultValue: 25,
|
|
40
|
-
onChange: console.log
|
|
41
|
-
}
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
export const WithFallbackValue: Story = {
|
|
45
|
-
args: {
|
|
46
|
-
fallbackValue: 25,
|
|
47
|
-
onChange: console.log
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const WithFallbackValueAndDefaultValue: Story = {
|
|
52
|
-
args: {
|
|
53
|
-
defaultValue: 10,
|
|
54
|
-
fallbackValue: 25,
|
|
55
|
-
onChange: console.log
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
export const WithFallbackValueAndDefaultValueAutoSize: Story = {
|
|
60
|
-
args: {
|
|
61
|
-
autoSize: true,
|
|
62
|
-
defaultValue: 10,
|
|
63
|
-
fallbackValue: 25,
|
|
64
|
-
onChange: console.log
|
|
65
|
-
}
|
|
66
|
-
};
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import { ChangeEvent, useState } from 'react';
|
|
2
|
-
|
|
3
|
-
import { T, always, cond, isEmpty, isNil } from 'ramda';
|
|
4
|
-
|
|
5
|
-
import TextField, { TextProps } from '../Text';
|
|
6
|
-
|
|
7
|
-
export interface NumberProps
|
|
8
|
-
extends Omit<TextProps, 'defaultValue' | 'onChange'> {
|
|
9
|
-
/**
|
|
10
|
-
* The initial value which will be used by the input for the first render
|
|
11
|
-
*/
|
|
12
|
-
defaultValue?: number;
|
|
13
|
-
/**
|
|
14
|
-
* This value will be used when the input is cleared
|
|
15
|
-
*/
|
|
16
|
-
fallbackValue?: number;
|
|
17
|
-
/**
|
|
18
|
-
* The change function with the actual value as parameter. This parameter will be the value when the input is filled but it will be the fallbackValue when the input is cleared out
|
|
19
|
-
*/
|
|
20
|
-
onChange: (actualValue: number) => void;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const NumberField = ({
|
|
24
|
-
fallbackValue = 0,
|
|
25
|
-
defaultValue,
|
|
26
|
-
onChange,
|
|
27
|
-
...props
|
|
28
|
-
}: NumberProps): JSX.Element => {
|
|
29
|
-
const [placeholder, setPlaceholder] = useState<string | undefined>();
|
|
30
|
-
const [actualValue, setActualValue] = useState(
|
|
31
|
-
defaultValue ? `${defaultValue}` : ''
|
|
32
|
-
);
|
|
33
|
-
|
|
34
|
-
const { inputProps } = props;
|
|
35
|
-
|
|
36
|
-
const changeValue = (event: ChangeEvent<HTMLInputElement>): void => {
|
|
37
|
-
const inputValue = event.target.value;
|
|
38
|
-
|
|
39
|
-
const number = Number(inputValue);
|
|
40
|
-
const campledNumber = cond([
|
|
41
|
-
[() => isEmpty(inputValue), always(fallbackValue)],
|
|
42
|
-
[() => Number.isNaN(number), always(number)],
|
|
43
|
-
[
|
|
44
|
-
T,
|
|
45
|
-
always(
|
|
46
|
-
Math.max(
|
|
47
|
-
!isNil(inputProps?.min) ? inputProps?.min : -Infinity,
|
|
48
|
-
number
|
|
49
|
-
)
|
|
50
|
-
)
|
|
51
|
-
]
|
|
52
|
-
])();
|
|
53
|
-
|
|
54
|
-
onChange(campledNumber);
|
|
55
|
-
setPlaceholder(isEmpty(inputValue) ? `${fallbackValue}` : undefined);
|
|
56
|
-
setActualValue(isEmpty(inputValue) ? inputValue : `${campledNumber}`);
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
return (
|
|
60
|
-
<TextField
|
|
61
|
-
defaultValue={defaultValue}
|
|
62
|
-
type="number"
|
|
63
|
-
value={actualValue}
|
|
64
|
-
onChange={changeValue}
|
|
65
|
-
{...props}
|
|
66
|
-
inputProps={inputProps}
|
|
67
|
-
placeholder={
|
|
68
|
-
placeholder || (!defaultValue ? `${fallbackValue}` : undefined)
|
|
69
|
-
}
|
|
70
|
-
/>
|
|
71
|
-
);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
|
-
export default NumberField;
|
|
@@ -1,45 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,59 +0,0 @@
|
|
|
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
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
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 };
|