cozy-ui 127.11.0 → 127.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/package.json +1 -1
- package/react/Contacts/GroupsSelect/GroupCreation.jsx +95 -0
- package/react/Contacts/GroupsSelect/GroupsSelect.jsx +159 -0
- package/react/Contacts/GroupsSelect/GroupsSelect.spec.jsx +248 -0
- package/react/Contacts/GroupsSelect/GroupsSelectProvider.jsx +39 -0
- package/react/Contacts/GroupsSelect/Readme.md +1 -0
- package/react/Contacts/GroupsSelect/SelectBox/Control.jsx +36 -0
- package/react/Contacts/GroupsSelect/SelectBox/EditGroupName.jsx +52 -0
- package/react/Contacts/GroupsSelect/SelectBox/Menu.jsx +26 -0
- package/react/Contacts/GroupsSelect/SelectBox/Option.jsx +67 -0
- package/react/Contacts/GroupsSelect/SelectBox/SelectContainer.jsx +15 -0
- package/react/Contacts/GroupsSelect/SelectBox/styles.styl +2 -0
- package/react/Contacts/GroupsSelect/helpers.js +25 -0
- package/react/Contacts/GroupsSelect/locales/en.json +21 -0
- package/react/Contacts/GroupsSelect/locales/fr.json +21 -0
- package/react/Contacts/GroupsSelect/locales/index.jsx +7 -0
- package/react/Contacts/GroupsSelect/styles.styl +47 -0
- package/react/Contacts/GroupsSelect/useGroupSelect.jsx +88 -0
- package/react/Contacts/Header/GroupsSelection.jsx +74 -0
- package/react/Contacts/Header/ImportDropdown.jsx +78 -0
- package/react/Contacts/Header/Readme.md +40 -0
- package/react/Contacts/Header/SearchInput.jsx +19 -0
- package/react/Contacts/Header/index.jsx +79 -0
- package/react/Contacts/Header/locales/en.json +15 -0
- package/react/Contacts/Header/locales/fr.json +15 -0
- package/react/Contacts/Header/locales/index.jsx +7 -0
- package/react/Contacts/Readme.md +1 -0
- package/react/ContactsList/ContactCell.jsx +1 -1
- package/react/ContactsList/Contacts/ContactIdentity.jsx +5 -1
- package/react/ContactsList/ContactsList.jsx +3 -1
- package/react/ContactsList/helpers.js +11 -10
- package/react/ContactsList/helpers.spec.js +11 -2
- package/react/ContactsList/locales/en.json +6 -4
- package/react/ContactsList/locales/fr.json +7 -5
- package/transpiled/react/Contacts/GroupsSelect/GroupCreation.d.ts +3 -0
- package/transpiled/react/Contacts/GroupsSelect/GroupCreation.js +133 -0
- package/transpiled/react/Contacts/GroupsSelect/GroupsSelect.d.ts +56 -0
- package/transpiled/react/Contacts/GroupsSelect/GroupsSelect.js +181 -0
- package/transpiled/react/Contacts/GroupsSelect/GroupsSelect.spec.d.ts +22 -0
- package/transpiled/react/Contacts/GroupsSelect/GroupsSelectProvider.d.ts +5 -0
- package/transpiled/react/Contacts/GroupsSelect/GroupsSelectProvider.js +38 -0
- package/transpiled/react/Contacts/GroupsSelect/SelectBox/Control.d.ts +14 -0
- package/transpiled/react/Contacts/GroupsSelect/SelectBox/Control.js +37 -0
- package/transpiled/react/Contacts/GroupsSelect/SelectBox/EditGroupName.d.ts +7 -0
- package/transpiled/react/Contacts/GroupsSelect/SelectBox/EditGroupName.js +71 -0
- package/transpiled/react/Contacts/GroupsSelect/SelectBox/Menu.d.ts +7 -0
- package/transpiled/react/Contacts/GroupsSelect/SelectBox/Menu.js +34 -0
- package/transpiled/react/Contacts/GroupsSelect/SelectBox/Option.d.ts +18 -0
- package/transpiled/react/Contacts/GroupsSelect/SelectBox/Option.js +66 -0
- package/transpiled/react/Contacts/GroupsSelect/SelectBox/SelectContainer.d.ts +2 -0
- package/transpiled/react/Contacts/GroupsSelect/SelectBox/SelectContainer.js +12 -0
- package/transpiled/react/Contacts/GroupsSelect/helpers.d.ts +9 -0
- package/transpiled/react/Contacts/GroupsSelect/helpers.js +30 -0
- package/transpiled/react/Contacts/GroupsSelect/locales/index.d.ts +6 -0
- package/transpiled/react/Contacts/GroupsSelect/locales/index.js +46 -0
- package/transpiled/react/Contacts/GroupsSelect/useGroupSelect.d.ts +11 -0
- package/transpiled/react/Contacts/GroupsSelect/useGroupSelect.js +179 -0
- package/transpiled/react/Contacts/Header/GroupsSelection.d.ts +7 -0
- package/transpiled/react/Contacts/Header/GroupsSelection.js +84 -0
- package/transpiled/react/Contacts/Header/ImportDropdown.d.ts +4 -0
- package/transpiled/react/Contacts/Header/ImportDropdown.js +88 -0
- package/transpiled/react/Contacts/Header/SearchInput.d.ts +4 -0
- package/transpiled/react/Contacts/Header/SearchInput.js +24 -0
- package/transpiled/react/Contacts/Header/index.d.ts +26 -0
- package/transpiled/react/Contacts/Header/index.js +72 -0
- package/transpiled/react/Contacts/Header/locales/index.d.ts +6 -0
- package/transpiled/react/Contacts/Header/locales/index.js +34 -0
- package/transpiled/react/ContactsList/ContactCell.js +1 -1
- package/transpiled/react/ContactsList/Contacts/ContactIdentity.js +1 -1
- package/transpiled/react/ContactsList/ContactsList.js +4 -1
- package/transpiled/react/ContactsList/helpers.js +10 -10
- package/transpiled/react/ContactsList/locales/withContactsListLocales.js +12 -8
- package/transpiled/react/stylesheet.css +1 -1
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import React, { useRef } from 'react';
|
|
5
|
+
import Input from "cozy-ui/transpiled/react/Input";
|
|
6
|
+
|
|
7
|
+
var EditGroupName = function EditGroupName(_ref) {
|
|
8
|
+
var groupId = _ref.groupId,
|
|
9
|
+
groupName = _ref.groupName,
|
|
10
|
+
setEditedGroupId = _ref.setEditedGroupId,
|
|
11
|
+
renameGroup = _ref.renameGroup;
|
|
12
|
+
var inputRef = useRef();
|
|
13
|
+
|
|
14
|
+
var stopPropagation = function stopPropagation(e) {
|
|
15
|
+
e.stopPropagation();
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
var exitEditMode = function exitEditMode() {
|
|
19
|
+
return setEditedGroupId('');
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
var handleKeyDown = /*#__PURE__*/function () {
|
|
23
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(e) {
|
|
24
|
+
var ENTER_KEY_CODE;
|
|
25
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
26
|
+
while (1) {
|
|
27
|
+
switch (_context.prev = _context.next) {
|
|
28
|
+
case 0:
|
|
29
|
+
ENTER_KEY_CODE = 13;
|
|
30
|
+
|
|
31
|
+
if (e.keyCode == ENTER_KEY_CODE) {
|
|
32
|
+
exitEditMode();
|
|
33
|
+
renameGroup(groupId, inputRef.current.value);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
stopPropagation(e);
|
|
37
|
+
|
|
38
|
+
case 3:
|
|
39
|
+
case "end":
|
|
40
|
+
return _context.stop();
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}, _callee);
|
|
44
|
+
}));
|
|
45
|
+
|
|
46
|
+
return function handleKeyDown(_x) {
|
|
47
|
+
return _ref2.apply(this, arguments);
|
|
48
|
+
};
|
|
49
|
+
}();
|
|
50
|
+
|
|
51
|
+
return /*#__PURE__*/React.createElement(Input, {
|
|
52
|
+
id: "editGroupInput",
|
|
53
|
+
ref: inputRef,
|
|
54
|
+
type: "text",
|
|
55
|
+
defaultValue: groupName,
|
|
56
|
+
size: "tiny",
|
|
57
|
+
autoComplete: "off",
|
|
58
|
+
autoFocus: true,
|
|
59
|
+
onKeyDown: handleKeyDown,
|
|
60
|
+
onClick: stopPropagation,
|
|
61
|
+
onFocus: stopPropagation,
|
|
62
|
+
onMouseDown: stopPropagation,
|
|
63
|
+
onBlur: exitEditMode
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
Option.propTypes = {
|
|
68
|
+
groupName: PropTypes.string.isRequired,
|
|
69
|
+
setEditedGroupId: PropTypes.string.isRequired
|
|
70
|
+
};
|
|
71
|
+
export default EditGroupName;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["children", "selectProps", "className"],
|
|
4
|
+
_excluded2 = ["createGroup"];
|
|
5
|
+
import cx from 'classnames';
|
|
6
|
+
import React from 'react';
|
|
7
|
+
var styles = {
|
|
8
|
+
"menu": "styles__menu___120ui"
|
|
9
|
+
};
|
|
10
|
+
import { components } from "cozy-ui/transpiled/react/SelectBox";
|
|
11
|
+
import Typography from "cozy-ui/transpiled/react/Typography";
|
|
12
|
+
import GroupCreation from "cozy-ui/transpiled/react/Contacts/GroupsSelect/GroupCreation";
|
|
13
|
+
|
|
14
|
+
var Menu = function Menu(_ref) {
|
|
15
|
+
var children = _ref.children,
|
|
16
|
+
selectProps = _ref.selectProps,
|
|
17
|
+
className = _ref.className,
|
|
18
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
19
|
+
|
|
20
|
+
var createGroup = selectProps.createGroup,
|
|
21
|
+
restSelectProps = _objectWithoutProperties(selectProps, _excluded2);
|
|
22
|
+
|
|
23
|
+
return /*#__PURE__*/React.createElement(components.Menu, _extends({}, props, {
|
|
24
|
+
className: cx(className, styles['menu']),
|
|
25
|
+
selectProps: restSelectProps
|
|
26
|
+
}), /*#__PURE__*/React.createElement(Typography, {
|
|
27
|
+
variant: "body1",
|
|
28
|
+
component: "div"
|
|
29
|
+
}, children, /*#__PURE__*/React.createElement(GroupCreation, {
|
|
30
|
+
createGroup: createGroup
|
|
31
|
+
})));
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export default Menu;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export default Option;
|
|
2
|
+
declare function Option(props: any): JSX.Element;
|
|
3
|
+
declare namespace Option {
|
|
4
|
+
namespace propTypes {
|
|
5
|
+
const selectProps: PropTypes.Requireable<PropTypes.InferProps<{
|
|
6
|
+
editedGroupId: PropTypes.Validator<string>;
|
|
7
|
+
deleteGroup: PropTypes.Validator<(...args: any[]) => any>;
|
|
8
|
+
setEditedGroupId: PropTypes.Validator<(...args: any[]) => any>;
|
|
9
|
+
withCheckbox: PropTypes.Requireable<boolean>;
|
|
10
|
+
}>>;
|
|
11
|
+
const data: PropTypes.Requireable<PropTypes.InferProps<{
|
|
12
|
+
name: PropTypes.Validator<string>;
|
|
13
|
+
id: PropTypes.Requireable<string>;
|
|
14
|
+
withNoAction: PropTypes.Requireable<boolean>;
|
|
15
|
+
}>>;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
import PropTypes from "prop-types";
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import PropTypes from 'prop-types';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import EditGroupName from "cozy-ui/transpiled/react/Contacts/GroupsSelect/SelectBox/EditGroupName";
|
|
5
|
+
import { ActionsOption, Option as DefaultOption } from "cozy-ui/transpiled/react/SelectBox";
|
|
6
|
+
|
|
7
|
+
var Option = function Option(props) {
|
|
8
|
+
var _props$data = props.data,
|
|
9
|
+
groupName = _props$data.name,
|
|
10
|
+
groupId = _props$data.id,
|
|
11
|
+
withNoAction = _props$data.withNoAction;
|
|
12
|
+
var _props$selectProps = props.selectProps,
|
|
13
|
+
editedGroupId = _props$selectProps.editedGroupId,
|
|
14
|
+
setEditedGroupId = _props$selectProps.setEditedGroupId,
|
|
15
|
+
deleteGroup = _props$selectProps.deleteGroup,
|
|
16
|
+
renameGroup = _props$selectProps.renameGroup,
|
|
17
|
+
withCheckbox = _props$selectProps.withCheckbox;
|
|
18
|
+
|
|
19
|
+
if (editedGroupId === groupId) {
|
|
20
|
+
return /*#__PURE__*/React.createElement(EditGroupName, {
|
|
21
|
+
groupId: groupId,
|
|
22
|
+
groupName: groupName,
|
|
23
|
+
setEditedGroupId: setEditedGroupId,
|
|
24
|
+
renameGroup: renameGroup
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (withNoAction) {
|
|
29
|
+
return /*#__PURE__*/React.createElement(DefaultOption, props);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return /*#__PURE__*/React.createElement(ActionsOption, _extends({}, props, {
|
|
33
|
+
withCheckbox: withCheckbox,
|
|
34
|
+
actions: [{
|
|
35
|
+
icon: 'pen',
|
|
36
|
+
onClick: function onClick(_ref) {
|
|
37
|
+
var data = _ref.data;
|
|
38
|
+
return setEditedGroupId(data.id);
|
|
39
|
+
},
|
|
40
|
+
iconProps: {
|
|
41
|
+
'data-testid': "ActionsOption_".concat(props.children, "-icon_pen")
|
|
42
|
+
}
|
|
43
|
+
}, {
|
|
44
|
+
icon: 'trash',
|
|
45
|
+
onClick: function onClick(_ref2) {
|
|
46
|
+
var data = _ref2.data;
|
|
47
|
+
return deleteGroup(data);
|
|
48
|
+
}
|
|
49
|
+
}]
|
|
50
|
+
}));
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
Option.propTypes = {
|
|
54
|
+
selectProps: PropTypes.shape({
|
|
55
|
+
editedGroupId: PropTypes.string.isRequired,
|
|
56
|
+
deleteGroup: PropTypes.func.isRequired,
|
|
57
|
+
setEditedGroupId: PropTypes.func.isRequired,
|
|
58
|
+
withCheckbox: PropTypes.bool
|
|
59
|
+
}),
|
|
60
|
+
data: PropTypes.shape({
|
|
61
|
+
name: PropTypes.string.isRequired,
|
|
62
|
+
id: PropTypes.string,
|
|
63
|
+
withNoAction: PropTypes.bool
|
|
64
|
+
})
|
|
65
|
+
};
|
|
66
|
+
export default Option;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { components } from "cozy-ui/transpiled/react/SelectBox";
|
|
5
|
+
|
|
6
|
+
var SelectContainer = function SelectContainer(props) {
|
|
7
|
+
return /*#__PURE__*/React.createElement(components.SelectContainer, _extends({}, props, {
|
|
8
|
+
className: classNames(props.className, 'react-select__custom__container')
|
|
9
|
+
}));
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export default SelectContainer;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export function isExistingGroup(groupsAlreadyCreated: any, groupToCreate: any): boolean;
|
|
2
|
+
export namespace defaultSelectedGroup {
|
|
3
|
+
const name: string;
|
|
4
|
+
const withNoAction: boolean;
|
|
5
|
+
}
|
|
6
|
+
export function translatedDefaultSelectedGroup(t: Function): {
|
|
7
|
+
name: any;
|
|
8
|
+
withNoAction: boolean;
|
|
9
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
+
|
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
+
|
|
7
|
+
export var isExistingGroup = function isExistingGroup(groupsAlreadyCreated, groupToCreate) {
|
|
8
|
+
var isNameAlreadyUsed = groupsAlreadyCreated.find(function (group) {
|
|
9
|
+
return group.name.toLowerCase() === groupToCreate.name.toLowerCase();
|
|
10
|
+
}) !== undefined;
|
|
11
|
+
return isNameAlreadyUsed;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Returns the group defined as default in the group filter
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export var defaultSelectedGroup = {
|
|
18
|
+
name: 'Contacts.GroupsSelect.filter.all-groups',
|
|
19
|
+
withNoAction: true
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* Returns the translated group defined as default in the group filter
|
|
23
|
+
* @param {function} t - Translate
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
export var translatedDefaultSelectedGroup = function translatedDefaultSelectedGroup(t) {
|
|
27
|
+
return _objectSpread(_objectSpread({}, defaultSelectedGroup), {}, {
|
|
28
|
+
name: t(defaultSelectedGroup.name)
|
|
29
|
+
});
|
|
30
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
var en = {
|
|
2
|
+
Contacts: {
|
|
3
|
+
GroupsSelect: {
|
|
4
|
+
create: "Create a group",
|
|
5
|
+
name: "Name of the group",
|
|
6
|
+
already_exists: "The group %{name} already exists.",
|
|
7
|
+
manage: "Groups",
|
|
8
|
+
filter: {
|
|
9
|
+
"all-groups": "All groups"
|
|
10
|
+
},
|
|
11
|
+
created: {
|
|
12
|
+
success: "The group has been created correctly.",
|
|
13
|
+
error: "The group has not been created."
|
|
14
|
+
},
|
|
15
|
+
renamed: {
|
|
16
|
+
success: "The group has been renamed correctly.",
|
|
17
|
+
error: "The group has not been renamed."
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
var fr = {
|
|
23
|
+
Contacts: {
|
|
24
|
+
GroupsSelect: {
|
|
25
|
+
create: "Cr\xE9er un groupe",
|
|
26
|
+
name: "Nom du groupe",
|
|
27
|
+
already_exists: "Le groupe %{name} existe d\xE9j\xE0.",
|
|
28
|
+
manage: "Groupes",
|
|
29
|
+
filter: {
|
|
30
|
+
"all-groups": "Tous les groupes"
|
|
31
|
+
},
|
|
32
|
+
created: {
|
|
33
|
+
success: "Le groupe a bien \xE9t\xE9 cr\xE9\xE9.",
|
|
34
|
+
error: "Le groupe n'a pas \xE9t\xE9 cr\xE9\xE9."
|
|
35
|
+
},
|
|
36
|
+
renamed: {
|
|
37
|
+
success: "Le groupe a bien \xE9t\xE9 renomm\xE9.",
|
|
38
|
+
error: "Le groupe n'a pas \xE9t\xE9 renomm\xE9."
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
export var locales = {
|
|
44
|
+
en: en,
|
|
45
|
+
fr: fr
|
|
46
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export default useGroupsSelect;
|
|
2
|
+
declare function useGroupsSelect({ allGroups, onGroupCreated, client, onGroupCreate, onGroupUpdate }: {
|
|
3
|
+
allGroups: any;
|
|
4
|
+
onGroupCreated: any;
|
|
5
|
+
client: any;
|
|
6
|
+
onGroupCreate: any;
|
|
7
|
+
onGroupUpdate: any;
|
|
8
|
+
}): {
|
|
9
|
+
createGroup: (group: any) => Promise<void>;
|
|
10
|
+
renameGroup: (groupId: any, newName: any) => Promise<void>;
|
|
11
|
+
};
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
3
|
+
|
|
4
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5
|
+
|
|
6
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
7
|
+
|
|
8
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
9
|
+
import get from 'lodash/get';
|
|
10
|
+
import { useSelectedGroup } from "cozy-ui/transpiled/react/Contacts/GroupsSelect/GroupsSelectProvider";
|
|
11
|
+
import { isExistingGroup } from "cozy-ui/transpiled/react/Contacts/GroupsSelect/helpers";
|
|
12
|
+
import { locales } from "cozy-ui/transpiled/react/Contacts/GroupsSelect/locales";
|
|
13
|
+
import { useAlert } from "cozy-ui/transpiled/react/providers/Alert";
|
|
14
|
+
import { useI18n, useExtendI18n } from "cozy-ui/transpiled/react/providers/I18n";
|
|
15
|
+
|
|
16
|
+
var useGroupsSelect = function useGroupsSelect(_ref) {
|
|
17
|
+
var allGroups = _ref.allGroups,
|
|
18
|
+
onGroupCreated = _ref.onGroupCreated,
|
|
19
|
+
client = _ref.client,
|
|
20
|
+
onGroupCreate = _ref.onGroupCreate,
|
|
21
|
+
onGroupUpdate = _ref.onGroupUpdate;
|
|
22
|
+
|
|
23
|
+
var _useSelectedGroup = useSelectedGroup(),
|
|
24
|
+
selectedGroup = _useSelectedGroup.selectedGroup,
|
|
25
|
+
setSelectedGroup = _useSelectedGroup.setSelectedGroup;
|
|
26
|
+
|
|
27
|
+
var _useAlert = useAlert(),
|
|
28
|
+
showAlert = _useAlert.showAlert;
|
|
29
|
+
|
|
30
|
+
useExtendI18n(locales);
|
|
31
|
+
|
|
32
|
+
var _useI18n = useI18n(),
|
|
33
|
+
t = _useI18n.t;
|
|
34
|
+
|
|
35
|
+
var createGroupSelf = /*#__PURE__*/function () {
|
|
36
|
+
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(group) {
|
|
37
|
+
var _yield$onGroupCreate, createdGroup;
|
|
38
|
+
|
|
39
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
40
|
+
while (1) {
|
|
41
|
+
switch (_context.prev = _context.next) {
|
|
42
|
+
case 0:
|
|
43
|
+
if (group.name) {
|
|
44
|
+
_context.next = 2;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return _context.abrupt("return");
|
|
49
|
+
|
|
50
|
+
case 2:
|
|
51
|
+
if (!isExistingGroup(allGroups, group)) {
|
|
52
|
+
_context.next = 4;
|
|
53
|
+
break;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return _context.abrupt("return", showAlert({
|
|
57
|
+
severity: 'error',
|
|
58
|
+
message: t('Contacts.GroupsSelect.already_exists', {
|
|
59
|
+
name: group.name
|
|
60
|
+
})
|
|
61
|
+
}));
|
|
62
|
+
|
|
63
|
+
case 4:
|
|
64
|
+
_context.prev = 4;
|
|
65
|
+
_context.next = 7;
|
|
66
|
+
return onGroupCreate(client, group);
|
|
67
|
+
|
|
68
|
+
case 7:
|
|
69
|
+
_yield$onGroupCreate = _context.sent;
|
|
70
|
+
createdGroup = _yield$onGroupCreate.data;
|
|
71
|
+
|
|
72
|
+
if (onGroupCreated) {
|
|
73
|
+
onGroupCreated(createdGroup);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return _context.abrupt("return", showAlert({
|
|
77
|
+
severity: 'success',
|
|
78
|
+
message: t('Contacts.GroupsSelect.created.success')
|
|
79
|
+
}));
|
|
80
|
+
|
|
81
|
+
case 13:
|
|
82
|
+
_context.prev = 13;
|
|
83
|
+
_context.t0 = _context["catch"](4);
|
|
84
|
+
return _context.abrupt("return", showAlert({
|
|
85
|
+
severity: 'error',
|
|
86
|
+
message: t('Contacts.GroupsSelect.created.error')
|
|
87
|
+
}));
|
|
88
|
+
|
|
89
|
+
case 16:
|
|
90
|
+
case "end":
|
|
91
|
+
return _context.stop();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}, _callee, null, [[4, 13]]);
|
|
95
|
+
}));
|
|
96
|
+
|
|
97
|
+
return function createGroupSelf(_x) {
|
|
98
|
+
return _ref2.apply(this, arguments);
|
|
99
|
+
};
|
|
100
|
+
}();
|
|
101
|
+
|
|
102
|
+
var renameGroupSelf = /*#__PURE__*/function () {
|
|
103
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(groupId, newName) {
|
|
104
|
+
var group, allOtherGroups, isRenamedGroupSelected, _yield$onGroupUpdate, data;
|
|
105
|
+
|
|
106
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
107
|
+
while (1) {
|
|
108
|
+
switch (_context2.prev = _context2.next) {
|
|
109
|
+
case 0:
|
|
110
|
+
group = allGroups.find(function (group) {
|
|
111
|
+
return group.id === groupId;
|
|
112
|
+
});
|
|
113
|
+
allOtherGroups = allGroups.filter(function (group) {
|
|
114
|
+
return group.id !== groupId;
|
|
115
|
+
});
|
|
116
|
+
isRenamedGroupSelected = get(group, '_id') === get(selectedGroup, '_id');
|
|
117
|
+
|
|
118
|
+
if (!isExistingGroup(allOtherGroups, {
|
|
119
|
+
name: newName
|
|
120
|
+
})) {
|
|
121
|
+
_context2.next = 5;
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
return _context2.abrupt("return", showAlert({
|
|
126
|
+
severity: 'error',
|
|
127
|
+
message: t('Contacts.GroupsSelect.already_exists', {
|
|
128
|
+
name: newName
|
|
129
|
+
})
|
|
130
|
+
}));
|
|
131
|
+
|
|
132
|
+
case 5:
|
|
133
|
+
_context2.prev = 5;
|
|
134
|
+
_context2.next = 8;
|
|
135
|
+
return onGroupUpdate(client, _objectSpread(_objectSpread({}, group), {}, {
|
|
136
|
+
name: newName
|
|
137
|
+
}));
|
|
138
|
+
|
|
139
|
+
case 8:
|
|
140
|
+
_yield$onGroupUpdate = _context2.sent;
|
|
141
|
+
data = _yield$onGroupUpdate.data;
|
|
142
|
+
|
|
143
|
+
if (isRenamedGroupSelected) {
|
|
144
|
+
setSelectedGroup(data);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return _context2.abrupt("return", showAlert({
|
|
148
|
+
severity: 'success',
|
|
149
|
+
message: t('Contacts.GroupsSelect.renamed.success')
|
|
150
|
+
}));
|
|
151
|
+
|
|
152
|
+
case 14:
|
|
153
|
+
_context2.prev = 14;
|
|
154
|
+
_context2.t0 = _context2["catch"](5);
|
|
155
|
+
return _context2.abrupt("return", showAlert({
|
|
156
|
+
severity: 'error',
|
|
157
|
+
message: t('Contacts.GroupsSelect.renamed.error')
|
|
158
|
+
}));
|
|
159
|
+
|
|
160
|
+
case 17:
|
|
161
|
+
case "end":
|
|
162
|
+
return _context2.stop();
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}, _callee2, null, [[5, 14]]);
|
|
166
|
+
}));
|
|
167
|
+
|
|
168
|
+
return function renameGroupSelf(_x2, _x3) {
|
|
169
|
+
return _ref3.apply(this, arguments);
|
|
170
|
+
};
|
|
171
|
+
}();
|
|
172
|
+
|
|
173
|
+
return {
|
|
174
|
+
createGroup: createGroupSelf,
|
|
175
|
+
renameGroup: renameGroupSelf
|
|
176
|
+
};
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
export default useGroupsSelect;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
|
|
4
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5
|
+
|
|
6
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
7
|
+
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import { locales } from "cozy-ui/transpiled/react/Contacts/Header/locales";
|
|
10
|
+
import { ControlDefault } from "cozy-ui/transpiled/react/SelectBox";
|
|
11
|
+
import { useBreakpoints } from "cozy-ui/transpiled/react/providers/Breakpoints";
|
|
12
|
+
import { useI18n, useExtendI18n } from "cozy-ui/transpiled/react/providers/I18n";
|
|
13
|
+
import GroupsSelect from "cozy-ui/transpiled/react/Contacts/GroupsSelect/GroupsSelect";
|
|
14
|
+
import { useSelectedGroup } from "cozy-ui/transpiled/react/Contacts/GroupsSelect/GroupsSelectProvider";
|
|
15
|
+
import { translatedDefaultSelectedGroup } from "cozy-ui/transpiled/react/Contacts/GroupsSelect/helpers";
|
|
16
|
+
|
|
17
|
+
var setGroupsSelectOptions = function setGroupsSelectOptions(allGroups, defaultSelectedGroup) {
|
|
18
|
+
return allGroups.length > 0 ? [defaultSelectedGroup].concat(allGroups) : allGroups;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
var useGroupsSelectCustomStyles = function useGroupsSelectCustomStyles() {
|
|
22
|
+
var _useBreakpoints = useBreakpoints(),
|
|
23
|
+
isMobile = _useBreakpoints.isMobile;
|
|
24
|
+
|
|
25
|
+
return {
|
|
26
|
+
container: function container(base) {
|
|
27
|
+
return _objectSpread(_objectSpread({}, base), {}, {
|
|
28
|
+
width: isMobile ? '100%' : '50%'
|
|
29
|
+
});
|
|
30
|
+
},
|
|
31
|
+
noOptionsMessage: function noOptionsMessage(base) {
|
|
32
|
+
return _objectSpread(_objectSpread({}, base), {}, {
|
|
33
|
+
textAlign: 'left'
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
var ControlDefaultWithTestId = function ControlDefaultWithTestId(_ref) {
|
|
40
|
+
var props = _extends({}, _ref);
|
|
41
|
+
|
|
42
|
+
return /*#__PURE__*/React.createElement(ControlDefault, _extends({}, props, {
|
|
43
|
+
innerProps: _objectSpread(_objectSpread({}, props.innerProps), {}, {
|
|
44
|
+
'data-testid': 'selectBox-controlDefault',
|
|
45
|
+
className: 'u-bdrs-4'
|
|
46
|
+
})
|
|
47
|
+
}));
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
var GroupsSelection = function GroupsSelection(_ref2) {
|
|
51
|
+
var allGroups = _ref2.allGroups,
|
|
52
|
+
onGroupCreate = _ref2.onGroupCreate,
|
|
53
|
+
onGroupUpdate = _ref2.onGroupUpdate,
|
|
54
|
+
onGroupDelete = _ref2.onGroupDelete;
|
|
55
|
+
useExtendI18n(locales);
|
|
56
|
+
|
|
57
|
+
var _useI18n = useI18n(),
|
|
58
|
+
t = _useI18n.t;
|
|
59
|
+
|
|
60
|
+
var _useSelectedGroup = useSelectedGroup(),
|
|
61
|
+
selectedGroup = _useSelectedGroup.selectedGroup,
|
|
62
|
+
setSelectedGroup = _useSelectedGroup.setSelectedGroup;
|
|
63
|
+
|
|
64
|
+
var groupsSelectOptions = setGroupsSelectOptions(allGroups, translatedDefaultSelectedGroup(t));
|
|
65
|
+
var groupsSelectCustomStyles = useGroupsSelectCustomStyles();
|
|
66
|
+
return /*#__PURE__*/React.createElement(GroupsSelect, {
|
|
67
|
+
allGroups: groupsSelectOptions,
|
|
68
|
+
value: selectedGroup,
|
|
69
|
+
noOptionsMessage: function noOptionsMessage() {
|
|
70
|
+
return t('Contacts.Header.filter.no-group');
|
|
71
|
+
},
|
|
72
|
+
styles: groupsSelectCustomStyles,
|
|
73
|
+
closeMenuOnSelect: true,
|
|
74
|
+
components: {
|
|
75
|
+
Control: ControlDefaultWithTestId
|
|
76
|
+
},
|
|
77
|
+
onChange: setSelectedGroup,
|
|
78
|
+
onGroupCreate: onGroupCreate,
|
|
79
|
+
onGroupUpdate: onGroupUpdate,
|
|
80
|
+
onGroupDelete: onGroupDelete
|
|
81
|
+
});
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export default GroupsSelection;
|