@panneau/action-duplicate 3.0.169 → 3.0.174

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.
Files changed (3) hide show
  1. package/es/index.js +22 -15
  2. package/lib/index.js +22 -15
  3. package/package.json +6 -6
package/es/index.js CHANGED
@@ -12,24 +12,28 @@ import Confirm from '@panneau/modal-confirm';
12
12
 
13
13
  var styles = {};
14
14
 
15
- var _excluded = ["title", "description", "endpoint", "label", "icon", "value", "theme", "disabled", "onChange", "setSelectedItems", "className"];
15
+ var _excluded = ["title", "description", "endpoint", "action", "label", "icon", "value", "theme", "disabled", "onChange", "onConfirmed", "withConfirmation", "className"];
16
16
  var propTypes = {
17
17
  title: PropTypes.node,
18
18
  description: PropTypes.node,
19
19
  endpoint: PropTypes.string,
20
+ action: PropTypes.func,
21
+ // Promise
20
22
  label: PropTypes.string,
21
23
  value: PropTypes.bool,
22
24
  icon: PropTypes.string,
23
25
  theme: PropTypes.string,
24
26
  disabled: PropTypes.bool,
25
- onChange: PropTypes.func.isRequired,
26
- setSelectedItems: PropTypes.func,
27
+ onChange: PropTypes.func,
28
+ onConfirmed: PropTypes.func,
29
+ withConfirmation: PropTypes.bool,
27
30
  className: PropTypes.string
28
31
  };
29
32
  var defaultProps = {
30
33
  title: null,
31
34
  description: null,
32
35
  endpoint: '/duplicate',
36
+ action: null,
33
37
  label: /*#__PURE__*/React.createElement(FormattedMessage, {
34
38
  id: "HzCxmr",
35
39
  defaultMessage: [{
@@ -41,20 +45,24 @@ var defaultProps = {
41
45
  value: null,
42
46
  theme: 'primary',
43
47
  disabled: false,
44
- setSelectedItems: null,
48
+ onChange: null,
49
+ onConfirmed: null,
50
+ withConfirmation: false,
45
51
  className: null
46
52
  };
47
53
  var DuplicateAction = function DuplicateAction(_ref) {
48
54
  var title = _ref.title,
49
55
  description = _ref.description,
50
56
  endpoint = _ref.endpoint,
57
+ action = _ref.action,
51
58
  label = _ref.label,
52
59
  icon = _ref.icon,
53
60
  value = _ref.value,
54
61
  theme = _ref.theme,
55
62
  disabled = _ref.disabled,
56
63
  onChange = _ref.onChange,
57
- setSelectedItems = _ref.setSelectedItems,
64
+ onConfirmed = _ref.onConfirmed,
65
+ withConfirmation = _ref.withConfirmation,
58
66
  className = _ref.className,
59
67
  props = _objectWithoutProperties(_ref, _excluded);
60
68
  var _useModal = useModal(),
@@ -105,15 +113,14 @@ var DuplicateAction = function DuplicateAction(_ref) {
105
113
  unregister(modalKey);
106
114
  }, [modalKey, unregister]);
107
115
  var onConfirm = useCallback(function () {
108
- postJSON(endpoint, {
116
+ return (action !== null ? action(ids) : postJSON(endpoint, {
109
117
  ids: ids
110
118
  }, {
111
119
  credentials: 'include',
112
- headers: getCSRFHeaders(),
113
- _method: 'DELETE'
114
- }).then(function (response) {
115
- if (setSelectedItems !== null) {
116
- setSelectedItems([]);
120
+ headers: getCSRFHeaders()
121
+ })).then(function (response) {
122
+ if (onConfirmed !== null) {
123
+ onConfirmed(response);
117
124
  }
118
125
  if (onChange !== null) {
119
126
  onChange(response);
@@ -122,15 +129,15 @@ var DuplicateAction = function DuplicateAction(_ref) {
122
129
  })["catch"](function (err) {
123
130
  setError(err);
124
131
  });
125
- }, [ids, endpoint, onChange, onClose, setError]);
126
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, Object.assign({}, props, {
132
+ }, [ids, endpoint, action, onChange, onClose, setError]);
133
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, Object.assign({
127
134
  className: classNames([styles.container, _defineProperty({}, className, className !== null)]),
128
135
  label: label,
129
136
  icon: icon,
130
- onClick: onOpen,
137
+ onClick: withConfirmation ? onOpen : null,
131
138
  disabled: disabled,
132
139
  theme: disabled ? 'secondary' : theme
133
- })), modal !== null ? /*#__PURE__*/React.createElement(Confirm, {
140
+ }, props)), modal !== null ? /*#__PURE__*/React.createElement(Confirm, {
134
141
  id: modalKey,
135
142
  title: title || /*#__PURE__*/React.createElement(FormattedMessage, {
136
143
  id: "8T+JE7",
package/lib/index.js CHANGED
@@ -16,24 +16,28 @@ var Confirm = require('@panneau/modal-confirm');
16
16
 
17
17
  var styles = {};
18
18
 
19
- var _excluded = ["title", "description", "endpoint", "label", "icon", "value", "theme", "disabled", "onChange", "setSelectedItems", "className"];
19
+ var _excluded = ["title", "description", "endpoint", "action", "label", "icon", "value", "theme", "disabled", "onChange", "onConfirmed", "withConfirmation", "className"];
20
20
  var propTypes = {
21
21
  title: PropTypes.node,
22
22
  description: PropTypes.node,
23
23
  endpoint: PropTypes.string,
24
+ action: PropTypes.func,
25
+ // Promise
24
26
  label: PropTypes.string,
25
27
  value: PropTypes.bool,
26
28
  icon: PropTypes.string,
27
29
  theme: PropTypes.string,
28
30
  disabled: PropTypes.bool,
29
- onChange: PropTypes.func.isRequired,
30
- setSelectedItems: PropTypes.func,
31
+ onChange: PropTypes.func,
32
+ onConfirmed: PropTypes.func,
33
+ withConfirmation: PropTypes.bool,
31
34
  className: PropTypes.string
32
35
  };
33
36
  var defaultProps = {
34
37
  title: null,
35
38
  description: null,
36
39
  endpoint: '/duplicate',
40
+ action: null,
37
41
  label: /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
38
42
  id: "HzCxmr",
39
43
  defaultMessage: [{
@@ -45,20 +49,24 @@ var defaultProps = {
45
49
  value: null,
46
50
  theme: 'primary',
47
51
  disabled: false,
48
- setSelectedItems: null,
52
+ onChange: null,
53
+ onConfirmed: null,
54
+ withConfirmation: false,
49
55
  className: null
50
56
  };
51
57
  var DuplicateAction = function DuplicateAction(_ref) {
52
58
  var title = _ref.title,
53
59
  description = _ref.description,
54
60
  endpoint = _ref.endpoint,
61
+ action = _ref.action,
55
62
  label = _ref.label,
56
63
  icon = _ref.icon,
57
64
  value = _ref.value,
58
65
  theme = _ref.theme,
59
66
  disabled = _ref.disabled,
60
67
  onChange = _ref.onChange,
61
- setSelectedItems = _ref.setSelectedItems,
68
+ onConfirmed = _ref.onConfirmed,
69
+ withConfirmation = _ref.withConfirmation,
62
70
  className = _ref.className,
63
71
  props = _objectWithoutProperties(_ref, _excluded);
64
72
  var _useModal = contexts.useModal(),
@@ -109,15 +117,14 @@ var DuplicateAction = function DuplicateAction(_ref) {
109
117
  unregister(modalKey);
110
118
  }, [modalKey, unregister]);
111
119
  var onConfirm = React.useCallback(function () {
112
- fetch.postJSON(endpoint, {
120
+ return (action !== null ? action(ids) : fetch.postJSON(endpoint, {
113
121
  ids: ids
114
122
  }, {
115
123
  credentials: 'include',
116
- headers: fetch.getCSRFHeaders(),
117
- _method: 'DELETE'
118
- }).then(function (response) {
119
- if (setSelectedItems !== null) {
120
- setSelectedItems([]);
124
+ headers: fetch.getCSRFHeaders()
125
+ })).then(function (response) {
126
+ if (onConfirmed !== null) {
127
+ onConfirmed(response);
121
128
  }
122
129
  if (onChange !== null) {
123
130
  onChange(response);
@@ -126,15 +133,15 @@ var DuplicateAction = function DuplicateAction(_ref) {
126
133
  })["catch"](function (err) {
127
134
  setError(err);
128
135
  });
129
- }, [ids, endpoint, onChange, onClose, setError]);
130
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, Object.assign({}, props, {
136
+ }, [ids, endpoint, action, onChange, onClose, setError]);
137
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, Object.assign({
131
138
  className: classNames([styles.container, _defineProperty({}, className, className !== null)]),
132
139
  label: label,
133
140
  icon: icon,
134
- onClick: onOpen,
141
+ onClick: withConfirmation ? onOpen : null,
135
142
  disabled: disabled,
136
143
  theme: disabled ? 'secondary' : theme
137
- })), modal !== null ? /*#__PURE__*/React.createElement(Confirm, {
144
+ }, props)), modal !== null ? /*#__PURE__*/React.createElement(Confirm, {
138
145
  id: modalKey,
139
146
  title: title || /*#__PURE__*/React.createElement(reactIntl.FormattedMessage, {
140
147
  id: "8T+JE7",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panneau/action-duplicate",
3
- "version": "3.0.169",
3
+ "version": "3.0.174",
4
4
  "description": "Duplicate action",
5
5
  "keywords": [
6
6
  "javascript"
@@ -47,10 +47,10 @@
47
47
  "dependencies": {
48
48
  "@babel/runtime": "^7.12.5",
49
49
  "@folklore/fetch": "^0.1.17",
50
- "@panneau/core": "^3.0.169",
51
- "@panneau/element-button": "^3.0.169",
52
- "@panneau/modal-confirm": "^3.0.169",
53
- "@panneau/themes": "^3.0.169",
50
+ "@panneau/core": "^3.0.174",
51
+ "@panneau/element-button": "^3.0.174",
52
+ "@panneau/modal-confirm": "^3.0.174",
53
+ "@panneau/themes": "^3.0.174",
54
54
  "classnames": "^2.5.1",
55
55
  "prop-types": "^15.7.2",
56
56
  "react-intl": "^5.15.8||^6.0.0"
@@ -58,5 +58,5 @@
58
58
  "publishConfig": {
59
59
  "access": "public"
60
60
  },
61
- "gitHead": "a8f4fe4f0b0593485d40e97542c32742242919d4"
61
+ "gitHead": "0b3a328b97ef9e9c02f8cfe731ac50a1611dc854"
62
62
  }