@panneau/action-duplicate 3.0.193 → 3.0.200
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/es/index.js +17 -36
- package/lib/index.js +17 -36
- package/package.json +6 -6
package/es/index.js
CHANGED
|
@@ -3,18 +3,19 @@ import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
|
3
3
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
4
4
|
import { postJSON, getCSRFHeaders } from '@folklore/fetch';
|
|
5
5
|
import classNames from 'classnames';
|
|
6
|
-
import isArray from 'lodash/isArray';
|
|
7
6
|
import PropTypes from 'prop-types';
|
|
8
7
|
import React, { useState, useMemo, useCallback } from 'react';
|
|
9
8
|
import { FormattedMessage } from 'react-intl';
|
|
10
9
|
import { useModal } from '@panneau/core/contexts';
|
|
10
|
+
import { useActionProps } from '@panneau/core/hooks';
|
|
11
11
|
import Button from '@panneau/element-button';
|
|
12
12
|
import Confirm from '@panneau/modal-confirm';
|
|
13
13
|
|
|
14
14
|
var styles = {};
|
|
15
15
|
|
|
16
|
-
var _excluded = ["title", "description", "endpoint", "action", "label", "icon", "value", "theme", "disabled", "onChange", "onConfirmed", "withConfirmation", "className"];
|
|
16
|
+
var _excluded = ["id", "title", "description", "endpoint", "action", "label", "icon", "value", "theme", "disabled", "onChange", "onConfirmed", "valueLabelPath", "withConfirmation", "className"];
|
|
17
17
|
var propTypes = {
|
|
18
|
+
id: PropTypes.string.isRequired,
|
|
18
19
|
title: PropTypes.node,
|
|
19
20
|
description: PropTypes.node,
|
|
20
21
|
endpoint: PropTypes.string,
|
|
@@ -27,6 +28,7 @@ var propTypes = {
|
|
|
27
28
|
disabled: PropTypes.bool,
|
|
28
29
|
onChange: PropTypes.func,
|
|
29
30
|
onConfirmed: PropTypes.func,
|
|
31
|
+
valueLabelPath: PropTypes.string,
|
|
30
32
|
withConfirmation: PropTypes.bool,
|
|
31
33
|
className: PropTypes.string
|
|
32
34
|
};
|
|
@@ -48,11 +50,13 @@ var defaultProps = {
|
|
|
48
50
|
disabled: false,
|
|
49
51
|
onChange: null,
|
|
50
52
|
onConfirmed: null,
|
|
53
|
+
valueLabelPath: null,
|
|
51
54
|
withConfirmation: false,
|
|
52
55
|
className: null
|
|
53
56
|
};
|
|
54
57
|
var DuplicateAction = function DuplicateAction(_ref) {
|
|
55
|
-
var
|
|
58
|
+
var id = _ref.id,
|
|
59
|
+
title = _ref.title,
|
|
56
60
|
description = _ref.description,
|
|
57
61
|
endpoint = _ref.endpoint,
|
|
58
62
|
action = _ref.action,
|
|
@@ -63,6 +67,7 @@ var DuplicateAction = function DuplicateAction(_ref) {
|
|
|
63
67
|
disabled = _ref.disabled,
|
|
64
68
|
onChange = _ref.onChange,
|
|
65
69
|
onConfirmed = _ref.onConfirmed,
|
|
70
|
+
valueLabelPath = _ref.valueLabelPath,
|
|
66
71
|
withConfirmation = _ref.withConfirmation,
|
|
67
72
|
className = _ref.className,
|
|
68
73
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
@@ -77,40 +82,15 @@ var DuplicateAction = function DuplicateAction(_ref) {
|
|
|
77
82
|
_useState2 = _slicedToArray(_useState, 2),
|
|
78
83
|
error = _useState2[0],
|
|
79
84
|
setError = _useState2[1];
|
|
80
|
-
var
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
if (isArray(value)) {
|
|
85
|
-
return value.map(function () {
|
|
86
|
-
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
87
|
-
_ref2$id = _ref2.id,
|
|
88
|
-
id = _ref2$id === void 0 ? null : _ref2$id;
|
|
89
|
-
return id;
|
|
90
|
-
}).filter(function (id) {
|
|
91
|
-
return id !== null;
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
return value !== null ? [value === null || value === void 0 ? void 0 : value.id] : null;
|
|
95
|
-
}, [value]);
|
|
96
|
-
var idKeys = useMemo(function () {
|
|
97
|
-
return (ids || []).map(function (id) {
|
|
98
|
-
return "".concat(id);
|
|
99
|
-
}).join('-');
|
|
100
|
-
}, [ids]);
|
|
101
|
-
var idLabels = useMemo(function () {
|
|
102
|
-
return (ids || []).map(function (id) {
|
|
103
|
-
return "#".concat(id);
|
|
104
|
-
}).join(', ');
|
|
105
|
-
}, [ids]);
|
|
106
|
-
var modalKey = useMemo(function () {
|
|
107
|
-
return "duplicate-".concat(idKeys);
|
|
108
|
-
}, [idKeys]);
|
|
85
|
+
var _useActionProps = useActionProps(id, value, valueLabelPath),
|
|
86
|
+
ids = _useActionProps.ids,
|
|
87
|
+
idLabels = _useActionProps.idLabels,
|
|
88
|
+
modalKey = _useActionProps.modalKey;
|
|
109
89
|
var modal = useMemo(function () {
|
|
110
|
-
return (modals || []).find(function (
|
|
111
|
-
var
|
|
112
|
-
|
|
113
|
-
return
|
|
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);
|
|
114
94
|
}) || null;
|
|
115
95
|
}, [modals, modalKey]);
|
|
116
96
|
var onOpen = useCallback(function () {
|
|
@@ -137,6 +117,7 @@ var DuplicateAction = function DuplicateAction(_ref) {
|
|
|
137
117
|
setError(err);
|
|
138
118
|
});
|
|
139
119
|
}, [ids, endpoint, action, onChange, onClose, setError]);
|
|
120
|
+
console.log('yoo', label);
|
|
140
121
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, Object.assign({
|
|
141
122
|
className: classNames([styles.container, _defineProperty({}, className, className !== null)]),
|
|
142
123
|
label: label,
|
package/lib/index.js
CHANGED
|
@@ -7,18 +7,19 @@ var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
|
|
|
7
7
|
var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
|
|
8
8
|
var fetch = require('@folklore/fetch');
|
|
9
9
|
var classNames = require('classnames');
|
|
10
|
-
var isArray = require('lodash/isArray');
|
|
11
10
|
var PropTypes = require('prop-types');
|
|
12
11
|
var React = require('react');
|
|
13
12
|
var reactIntl = require('react-intl');
|
|
14
13
|
var contexts = require('@panneau/core/contexts');
|
|
14
|
+
var hooks = require('@panneau/core/hooks');
|
|
15
15
|
var Button = require('@panneau/element-button');
|
|
16
16
|
var Confirm = require('@panneau/modal-confirm');
|
|
17
17
|
|
|
18
18
|
var styles = {};
|
|
19
19
|
|
|
20
|
-
var _excluded = ["title", "description", "endpoint", "action", "label", "icon", "value", "theme", "disabled", "onChange", "onConfirmed", "withConfirmation", "className"];
|
|
20
|
+
var _excluded = ["id", "title", "description", "endpoint", "action", "label", "icon", "value", "theme", "disabled", "onChange", "onConfirmed", "valueLabelPath", "withConfirmation", "className"];
|
|
21
21
|
var propTypes = {
|
|
22
|
+
id: PropTypes.string.isRequired,
|
|
22
23
|
title: PropTypes.node,
|
|
23
24
|
description: PropTypes.node,
|
|
24
25
|
endpoint: PropTypes.string,
|
|
@@ -31,6 +32,7 @@ var propTypes = {
|
|
|
31
32
|
disabled: PropTypes.bool,
|
|
32
33
|
onChange: PropTypes.func,
|
|
33
34
|
onConfirmed: PropTypes.func,
|
|
35
|
+
valueLabelPath: PropTypes.string,
|
|
34
36
|
withConfirmation: PropTypes.bool,
|
|
35
37
|
className: PropTypes.string
|
|
36
38
|
};
|
|
@@ -52,11 +54,13 @@ var defaultProps = {
|
|
|
52
54
|
disabled: false,
|
|
53
55
|
onChange: null,
|
|
54
56
|
onConfirmed: null,
|
|
57
|
+
valueLabelPath: null,
|
|
55
58
|
withConfirmation: false,
|
|
56
59
|
className: null
|
|
57
60
|
};
|
|
58
61
|
var DuplicateAction = function DuplicateAction(_ref) {
|
|
59
|
-
var
|
|
62
|
+
var id = _ref.id,
|
|
63
|
+
title = _ref.title,
|
|
60
64
|
description = _ref.description,
|
|
61
65
|
endpoint = _ref.endpoint,
|
|
62
66
|
action = _ref.action,
|
|
@@ -67,6 +71,7 @@ var DuplicateAction = function DuplicateAction(_ref) {
|
|
|
67
71
|
disabled = _ref.disabled,
|
|
68
72
|
onChange = _ref.onChange,
|
|
69
73
|
onConfirmed = _ref.onConfirmed,
|
|
74
|
+
valueLabelPath = _ref.valueLabelPath,
|
|
70
75
|
withConfirmation = _ref.withConfirmation,
|
|
71
76
|
className = _ref.className,
|
|
72
77
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
@@ -81,40 +86,15 @@ var DuplicateAction = function DuplicateAction(_ref) {
|
|
|
81
86
|
_useState2 = _slicedToArray(_useState, 2),
|
|
82
87
|
error = _useState2[0],
|
|
83
88
|
setError = _useState2[1];
|
|
84
|
-
var
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
if (isArray(value)) {
|
|
89
|
-
return value.map(function () {
|
|
90
|
-
var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
91
|
-
_ref2$id = _ref2.id,
|
|
92
|
-
id = _ref2$id === void 0 ? null : _ref2$id;
|
|
93
|
-
return id;
|
|
94
|
-
}).filter(function (id) {
|
|
95
|
-
return id !== null;
|
|
96
|
-
});
|
|
97
|
-
}
|
|
98
|
-
return value !== null ? [value === null || value === void 0 ? void 0 : value.id] : null;
|
|
99
|
-
}, [value]);
|
|
100
|
-
var idKeys = React.useMemo(function () {
|
|
101
|
-
return (ids || []).map(function (id) {
|
|
102
|
-
return "".concat(id);
|
|
103
|
-
}).join('-');
|
|
104
|
-
}, [ids]);
|
|
105
|
-
var idLabels = React.useMemo(function () {
|
|
106
|
-
return (ids || []).map(function (id) {
|
|
107
|
-
return "#".concat(id);
|
|
108
|
-
}).join(', ');
|
|
109
|
-
}, [ids]);
|
|
110
|
-
var modalKey = React.useMemo(function () {
|
|
111
|
-
return "duplicate-".concat(idKeys);
|
|
112
|
-
}, [idKeys]);
|
|
89
|
+
var _useActionProps = hooks.useActionProps(id, value, valueLabelPath),
|
|
90
|
+
ids = _useActionProps.ids,
|
|
91
|
+
idLabels = _useActionProps.idLabels,
|
|
92
|
+
modalKey = _useActionProps.modalKey;
|
|
113
93
|
var modal = React.useMemo(function () {
|
|
114
|
-
return (modals || []).find(function (
|
|
115
|
-
var
|
|
116
|
-
|
|
117
|
-
return
|
|
94
|
+
return (modals || []).find(function (_ref2) {
|
|
95
|
+
var _ref2$id = _ref2.id,
|
|
96
|
+
modalId = _ref2$id === void 0 ? null : _ref2$id;
|
|
97
|
+
return modalId === "".concat(modalKey);
|
|
118
98
|
}) || null;
|
|
119
99
|
}, [modals, modalKey]);
|
|
120
100
|
var onOpen = React.useCallback(function () {
|
|
@@ -141,6 +121,7 @@ var DuplicateAction = function DuplicateAction(_ref) {
|
|
|
141
121
|
setError(err);
|
|
142
122
|
});
|
|
143
123
|
}, [ids, endpoint, action, onChange, onClose, setError]);
|
|
124
|
+
console.log('yoo', label);
|
|
144
125
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, Object.assign({
|
|
145
126
|
className: classNames([styles.container, _defineProperty({}, className, className !== null)]),
|
|
146
127
|
label: label,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@panneau/action-duplicate",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.200",
|
|
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.
|
|
51
|
-
"@panneau/element-button": "^3.0.
|
|
52
|
-
"@panneau/modal-confirm": "^3.0.
|
|
53
|
-
"@panneau/themes": "^3.0.
|
|
50
|
+
"@panneau/core": "^3.0.194",
|
|
51
|
+
"@panneau/element-button": "^3.0.194",
|
|
52
|
+
"@panneau/modal-confirm": "^3.0.200",
|
|
53
|
+
"@panneau/themes": "^3.0.194",
|
|
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": "
|
|
61
|
+
"gitHead": "bd50474467356c14eee01d26089ff66b2e6c4dce"
|
|
62
62
|
}
|