@panneau/action-duplicate 3.0.226 → 3.0.244

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 (2) hide show
  1. package/es/index.js +20 -27
  2. package/package.json +5 -6
package/es/index.js CHANGED
@@ -4,16 +4,15 @@ import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProper
4
4
  import { postJSON, getCSRFHeaders } from '@folklore/fetch';
5
5
  import classNames from 'classnames';
6
6
  import PropTypes from 'prop-types';
7
- import React, { useState, useMemo, useCallback } from 'react';
7
+ import React, { useState, useCallback } from 'react';
8
8
  import { FormattedMessage } from 'react-intl';
9
- import { useModal } from '@panneau/core/contexts';
9
+ import { useModalsComponentsManager } from '@panneau/core/contexts';
10
10
  import { useActionProps } from '@panneau/core/hooks';
11
11
  import Button from '@panneau/element-button';
12
- import Confirm from '@panneau/modal-confirm';
13
12
 
14
13
  var styles = {};
15
14
 
16
- var _excluded = ["id", "title", "description", "endpoint", "action", "label", "icon", "value", "theme", "disabled", "onChange", "onConfirmed", "valueLabelPath", "withConfirmation", "className"];
15
+ var _excluded = ["id", "title", "description", "endpoint", "action", "label", "icon", "value", "theme", "disabled", "onChange", "onConfirmed", "valueLabelPath", "modalComponent", "withConfirmation", "className"];
17
16
  var propTypes = {
18
17
  id: PropTypes.string.isRequired,
19
18
  title: PropTypes.node,
@@ -29,6 +28,7 @@ var propTypes = {
29
28
  onChange: PropTypes.func,
30
29
  onConfirmed: PropTypes.func,
31
30
  valueLabelPath: PropTypes.string,
31
+ modalComponent: PropTypes.string,
32
32
  withConfirmation: PropTypes.bool,
33
33
  className: PropTypes.string
34
34
  };
@@ -51,6 +51,7 @@ var defaultProps = {
51
51
  onChange: null,
52
52
  onConfirmed: null,
53
53
  valueLabelPath: null,
54
+ modalComponent: 'confirm',
54
55
  withConfirmation: false,
55
56
  className: null
56
57
  };
@@ -68,37 +69,30 @@ var DuplicateAction = function DuplicateAction(_ref) {
68
69
  onChange = _ref.onChange,
69
70
  onConfirmed = _ref.onConfirmed,
70
71
  valueLabelPath = _ref.valueLabelPath,
72
+ modalComponent = _ref.modalComponent,
71
73
  withConfirmation = _ref.withConfirmation,
72
74
  className = _ref.className,
73
75
  props = _objectWithoutProperties(_ref, _excluded);
74
- var _useModal = useModal(),
75
- _useModal$modals = _useModal.modals,
76
- modals = _useModal$modals === void 0 ? null : _useModal$modals,
77
- _useModal$register = _useModal.register,
78
- register = _useModal$register === void 0 ? null : _useModal$register,
79
- _useModal$unregister = _useModal.unregister,
80
- unregister = _useModal$unregister === void 0 ? null : _useModal$unregister;
81
- var _useState = useState(null),
76
+ var ModalComponents = useModalsComponentsManager();
77
+ var ModalComponent = ModalComponents.getComponent(modalComponent);
78
+ var _useState = useState(false),
82
79
  _useState2 = _slicedToArray(_useState, 2),
83
- error = _useState2[0],
84
- setError = _useState2[1];
80
+ modalOpen = _useState2[0],
81
+ setModalOpen = _useState2[1];
82
+ var _useState3 = useState(null),
83
+ _useState4 = _slicedToArray(_useState3, 2),
84
+ error = _useState4[0],
85
+ setError = _useState4[1];
85
86
  var _useActionProps = useActionProps(id, value, valueLabelPath),
86
87
  ids = _useActionProps.ids,
87
88
  idLabels = _useActionProps.idLabels,
88
89
  modalKey = _useActionProps.modalKey;
89
- var modal = useMemo(function () {
90
- return (modals || []).find(function (_ref2) {
91
- var _ref2$id = _ref2.id,
92
- modalId = _ref2$id === void 0 ? null : _ref2$id;
93
- return modalId === "".concat(modalKey);
94
- }) || null;
95
- }, [modals, modalKey]);
96
90
  var onOpen = useCallback(function () {
97
- register(modalKey);
98
- }, [modalKey, register]);
91
+ setModalOpen(true);
92
+ }, [setModalOpen]);
99
93
  var onClose = useCallback(function () {
100
- unregister(modalKey);
101
- }, [modalKey, unregister]);
94
+ setModalOpen(false);
95
+ }, [setModalOpen]);
102
96
  var onConfirm = useCallback(function () {
103
97
  return (action !== null ? action(ids) : postJSON(endpoint, {
104
98
  ids: ids
@@ -117,7 +111,6 @@ var DuplicateAction = function DuplicateAction(_ref) {
117
111
  setError(err);
118
112
  });
119
113
  }, [ids, endpoint, action, onChange, onClose, setError]);
120
- console.log('yoo', label);
121
114
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, Object.assign({
122
115
  className: classNames([styles.container, _defineProperty({}, className, className !== null)]),
123
116
  label: label,
@@ -125,7 +118,7 @@ var DuplicateAction = function DuplicateAction(_ref) {
125
118
  onClick: withConfirmation ? onOpen : null,
126
119
  disabled: disabled,
127
120
  theme: disabled ? 'secondary' : theme
128
- }, props)), modal !== null ? /*#__PURE__*/React.createElement(Confirm, {
121
+ }, props)), modalOpen ? /*#__PURE__*/React.createElement(ModalComponent, {
129
122
  id: modalKey,
130
123
  title: title || /*#__PURE__*/React.createElement(FormattedMessage, {
131
124
  id: "8T+JE7",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panneau/action-duplicate",
3
- "version": "3.0.226",
3
+ "version": "3.0.244",
4
4
  "description": "Duplicate action",
5
5
  "keywords": [
6
6
  "javascript"
@@ -52,10 +52,9 @@
52
52
  "dependencies": {
53
53
  "@babel/runtime": "^7.12.5",
54
54
  "@folklore/fetch": "^0.1.17",
55
- "@panneau/core": "^3.0.224",
56
- "@panneau/element-button": "^3.0.226",
57
- "@panneau/modal-confirm": "^3.0.226",
58
- "@panneau/themes": "^3.0.224",
55
+ "@panneau/core": "^3.0.244",
56
+ "@panneau/element-button": "^3.0.244",
57
+ "@panneau/themes": "^3.0.244",
59
58
  "classnames": "^2.5.1",
60
59
  "prop-types": "^15.7.2",
61
60
  "react-intl": "^5.15.8||^6.0.0"
@@ -63,5 +62,5 @@
63
62
  "publishConfig": {
64
63
  "access": "public"
65
64
  },
66
- "gitHead": "9615a4d3021e9ad9b15be01e998dd6f366f8f705"
65
+ "gitHead": "41028d7e3eddfb81b41a4f9c9a80b4a5cf63c2f0"
67
66
  }