@panneau/action-duplicate 4.0.65 → 4.0.72

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/dist/index.d.ts CHANGED
@@ -1,18 +1,20 @@
1
1
  import * as react from 'react';
2
2
  import { ReactNode } from 'react';
3
- import { ButtonTheme } from '@panneau/core';
3
+ import { ActionValue, ButtonTheme } from '@panneau/core';
4
4
 
5
5
  interface DuplicateActionProps {
6
6
  id: string;
7
7
  title?: ReactNode | null;
8
8
  description?: ReactNode | null;
9
9
  endpoint?: string;
10
- action?: ((ids: string[]) => Promise<unknown>) | null;
10
+ endpointIdsParamName?: string;
11
+ action?: ((value: ActionValue) => Promise<unknown>) | null;
11
12
  label?: string | null;
12
- value?: boolean | null;
13
+ value?: ActionValue | null;
13
14
  icon?: string;
14
15
  theme?: ButtonTheme;
15
16
  disabled?: boolean;
17
+ multiple?: boolean;
16
18
  onChange?: ((response: unknown) => void) | null;
17
19
  onConfirmed?: ((response: unknown) => void) | null;
18
20
  valueLabelPath?: string | null;
@@ -20,6 +22,6 @@ interface DuplicateActionProps {
20
22
  withConfirmation?: boolean;
21
23
  className?: string | null;
22
24
  }
23
- declare function DuplicateAction({ id, title, description, endpoint, action, label: initialLabel, icon, value, theme, disabled, onChange, onConfirmed, valueLabelPath, modalComponent, withConfirmation, className, ...props }: DuplicateActionProps): react.JSX.Element;
25
+ declare function DuplicateAction({ id, title, description, endpoint, endpointIdsParamName, action, label: initialLabel, icon, value, theme, disabled, multiple, onChange, onConfirmed, valueLabelPath, modalComponent, withConfirmation, className, ...props }: DuplicateActionProps): react.JSX.Element;
24
26
 
25
27
  export { DuplicateAction as default };
package/dist/index.js CHANGED
@@ -1,206 +1,70 @@
1
- import { c } from 'react/compiler-runtime';
2
1
  import { postJSON, getCSRFHeaders } from '@folklore/fetch';
3
- import { useState } from 'react';
2
+ import isArray from 'lodash-es/isArray';
3
+ import { useState, useCallback } from 'react';
4
4
  import { FormattedMessage } from 'react-intl';
5
5
  import { useModalsComponentsManager } from '@panneau/core/contexts';
6
6
  import Button from '@panneau/element-button';
7
- import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
7
+ import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
8
8
 
9
- function DuplicateAction(t0) {
10
- const $ = c(51);
11
- let id;
12
- let props;
13
- let t1;
14
- let t10;
15
- let t11;
16
- let t12;
17
- let t13;
18
- let t14;
19
- let t15;
20
- let t2;
21
- let t3;
22
- let t4;
23
- let t5;
24
- let t6;
25
- let t7;
26
- let t8;
27
- let t9;
28
- if ($[0] !== t0) {
29
- ({
30
- id,
31
- title: t1,
32
- description: t2,
33
- endpoint: t3,
34
- action: t4,
35
- label: t5,
36
- icon: t6,
37
- value: t7,
38
- theme: t8,
39
- disabled: t9,
40
- onChange: t10,
41
- onConfirmed: t11,
42
- valueLabelPath: t12,
43
- modalComponent: t13,
44
- withConfirmation: t14,
45
- className: t15,
46
- ...props
47
- } = t0);
48
- $[0] = t0;
49
- $[1] = id;
50
- $[2] = props;
51
- $[3] = t1;
52
- $[4] = t10;
53
- $[5] = t11;
54
- $[6] = t12;
55
- $[7] = t13;
56
- $[8] = t14;
57
- $[9] = t15;
58
- $[10] = t2;
59
- $[11] = t3;
60
- $[12] = t4;
61
- $[13] = t5;
62
- $[14] = t6;
63
- $[15] = t7;
64
- $[16] = t8;
65
- $[17] = t9;
66
- } else {
67
- id = $[1];
68
- props = $[2];
69
- t1 = $[3];
70
- t10 = $[4];
71
- t11 = $[5];
72
- t12 = $[6];
73
- t13 = $[7];
74
- t14 = $[8];
75
- t15 = $[9];
76
- t2 = $[10];
77
- t3 = $[11];
78
- t4 = $[12];
79
- t5 = $[13];
80
- t6 = $[14];
81
- t7 = $[15];
82
- t8 = $[16];
83
- t9 = $[17];
84
- }
85
- const title = t1 === undefined ? null : t1;
86
- const description = t2 === undefined ? null : t2;
87
- const endpoint = t3 === undefined ? "/duplicate" : t3;
88
- const action = t4 === undefined ? null : t4;
89
- const initialLabel = t5 === undefined ? null : t5;
90
- const icon = t6 === undefined ? "copy" : t6;
91
- const value = t7 === undefined ? null : t7;
92
- const theme = t8 === undefined ? "secondary" : t8;
93
- const disabled = t9 === undefined ? false : t9;
94
- const onChange = t10 === undefined ? null : t10;
95
- const onConfirmed = t11 === undefined ? null : t11;
96
- const valueLabelPath = t12 === undefined ? null : t12;
97
- const modalComponent = t13 === undefined ? "confirm" : t13;
98
- const withConfirmation = t14 === undefined ? false : t14;
99
- const className = t15 === undefined ? null : t15;
100
- let t16;
101
- if ($[18] !== initialLabel) {
102
- t16 = initialLabel || /*#__PURE__*/jsx(FormattedMessage, {
103
- id: "HzCxmr"
104
- });
105
- $[18] = initialLabel;
106
- $[19] = t16;
107
- } else {
108
- t16 = $[19];
109
- }
110
- const label = t16;
9
+ function DuplicateAction({
10
+ id,
11
+ title = null,
12
+ description = null,
13
+ endpoint = '/duplicate',
14
+ endpointIdsParamName = 'ids',
15
+ action = null,
16
+ label: initialLabel = null,
17
+ icon = 'copy',
18
+ value = null,
19
+ theme = 'secondary',
20
+ disabled = false,
21
+ multiple = false,
22
+ onChange = null,
23
+ onConfirmed = null,
24
+ valueLabelPath = null,
25
+ modalComponent = 'confirm',
26
+ withConfirmation = false,
27
+ className = null,
28
+ ...props
29
+ }) {
30
+ const label = initialLabel || /*#__PURE__*/jsx(FormattedMessage, {
31
+ id: "HzCxmr"
32
+ });
111
33
  const ModalComponents = useModalsComponentsManager();
112
- let t17;
113
- if ($[20] !== ModalComponents || $[21] !== modalComponent) {
114
- t17 = ModalComponents.getComponent(modalComponent);
115
- $[20] = ModalComponents;
116
- $[21] = modalComponent;
117
- $[22] = t17;
118
- } else {
119
- t17 = $[22];
120
- }
121
- const ModalComponent = t17;
34
+ const ModalComponent = ModalComponents.getComponent(modalComponent);
122
35
  const [modalOpen, setModalOpen] = useState(false);
123
36
  const [error, setError] = useState(null);
124
- const {
125
- ids,
126
- idLabels,
127
- modalKey
128
- } = useActionProps(id, value, valueLabelPath);
129
- let t18;
130
- if ($[23] === Symbol.for("react.memo_cache_sentinel")) {
131
- t18 = () => {
132
- setModalOpen(true);
133
- };
134
- $[23] = t18;
135
- } else {
136
- t18 = $[23];
137
- }
138
- const onOpen = t18;
139
- let t19;
140
- if ($[24] === Symbol.for("react.memo_cache_sentinel")) {
141
- t19 = () => {
142
- setModalOpen(false);
143
- };
144
- $[24] = t19;
145
- } else {
146
- t19 = $[24];
147
- }
148
- const onClosed = t19;
149
- let t20;
150
- if ($[25] !== action || $[26] !== endpoint || $[27] !== ids || $[28] !== onChange || $[29] !== onConfirmed) {
151
- t20 = () => (action !== null ? action(ids) : postJSON(endpoint, {
152
- ids
153
- }, {
154
- credentials: "include",
155
- headers: getCSRFHeaders()
156
- })).then(response => {
157
- if (onConfirmed !== null) {
158
- onConfirmed(response);
159
- }
160
- if (onChange !== null) {
161
- onChange(response);
162
- }
163
- }).catch(err => {
164
- setError(err);
165
- });
166
- $[25] = action;
167
- $[26] = endpoint;
168
- $[27] = ids;
169
- $[28] = onChange;
170
- $[29] = onConfirmed;
171
- $[30] = t20;
172
- } else {
173
- t20 = $[30];
174
- }
175
- const onConfirm = t20;
176
- const t21 = withConfirmation ? onOpen : null;
177
- const t22 = disabled ? "secondary" : theme;
178
- let t23;
179
- if ($[31] !== className || $[32] !== disabled || $[33] !== icon || $[34] !== label || $[35] !== props || $[36] !== t21 || $[37] !== t22) {
180
- t23 = /*#__PURE__*/jsx(Button, {
37
+ const onOpen = useCallback(() => {
38
+ setModalOpen(true);
39
+ }, [setModalOpen]);
40
+ const onClosed = useCallback(() => {
41
+ setModalOpen(false);
42
+ }, [setModalOpen]);
43
+ const onConfirm = useCallback(() => (action !== null ? action(value) : postJSON(endpoint, {
44
+ [endpointIdsParamName]: (isArray(value) ? value : [value]).filter(it => it !== null).map(it_0 => it_0?.id)
45
+ }, {
46
+ credentials: 'include',
47
+ headers: getCSRFHeaders()
48
+ })).then(response => {
49
+ if (onConfirmed !== null) {
50
+ onConfirmed(response);
51
+ }
52
+ if (onChange !== null) {
53
+ onChange(response);
54
+ }
55
+ }).catch(err => {
56
+ setError(err);
57
+ }), [value, endpoint, action, onChange, setError, onConfirmed]);
58
+ return /*#__PURE__*/jsxs(Fragment, {
59
+ children: [/*#__PURE__*/jsx(Button, {
181
60
  className: className,
182
61
  label: label,
183
62
  icon: icon,
184
- onClick: t21,
63
+ onClick: withConfirmation ? onOpen : null,
185
64
  disabled: disabled,
186
- theme: t22,
65
+ theme: disabled ? 'secondary' : theme,
187
66
  ...props
188
- });
189
- $[31] = className;
190
- $[32] = disabled;
191
- $[33] = icon;
192
- $[34] = label;
193
- $[35] = props;
194
- $[36] = t21;
195
- $[37] = t22;
196
- $[38] = t23;
197
- } else {
198
- t23 = $[38];
199
- }
200
- let t24;
201
- if ($[39] !== ModalComponent || $[40] !== description || $[41] !== error || $[42] !== idLabels || $[43] !== modalKey || $[44] !== modalOpen || $[45] !== onConfirm || $[46] !== title) {
202
- t24 = modalOpen ? /*#__PURE__*/jsxs(ModalComponent, {
203
- id: modalKey,
67
+ }), modalOpen ? /*#__PURE__*/jsxs(ModalComponent, {
204
68
  title: title || /*#__PURE__*/jsx(FormattedMessage, {
205
69
  id: "8T+JE7"
206
70
  }),
@@ -210,7 +74,7 @@ function DuplicateAction(t0) {
210
74
  label: /*#__PURE__*/jsx(FormattedMessage, {
211
75
  id: "UaVu03"
212
76
  }),
213
- theme: "danger"
77
+ theme: 'danger'
214
78
  },
215
79
  cancelButton: {
216
80
  label: /*#__PURE__*/jsx(FormattedMessage, {
@@ -218,40 +82,22 @@ function DuplicateAction(t0) {
218
82
  })
219
83
  },
220
84
  children: [description !== null ? description : /*#__PURE__*/jsx("p", {
221
- children: /*#__PURE__*/jsx(FormattedMessage, {
85
+ children: multiple ? /*#__PURE__*/jsx(FormattedMessage, {
86
+ id: "GKcYDd",
87
+ values: {
88
+ id: value !== null && !isArray(value) ? `#${value?.id}` : ''
89
+ }
90
+ }) : /*#__PURE__*/jsx(FormattedMessage, {
222
91
  id: "XmY7D8",
223
92
  values: {
224
- ids: idLabels
93
+ ids: value !== null && isArray(value) ? value.map(it_1 => `#${it_1?.id}`).join(', ') : ''
225
94
  }
226
95
  })
227
96
  }), error !== null ? /*#__PURE__*/jsx(FormattedMessage, {
228
97
  id: "cutyQH"
229
98
  }) : null]
230
- }) : null;
231
- $[39] = ModalComponent;
232
- $[40] = description;
233
- $[41] = error;
234
- $[42] = idLabels;
235
- $[43] = modalKey;
236
- $[44] = modalOpen;
237
- $[45] = onConfirm;
238
- $[46] = title;
239
- $[47] = t24;
240
- } else {
241
- t24 = $[47];
242
- }
243
- let t25;
244
- if ($[48] !== t23 || $[49] !== t24) {
245
- t25 = /*#__PURE__*/jsxs(Fragment, {
246
- children: [t23, t24]
247
- });
248
- $[48] = t23;
249
- $[49] = t24;
250
- $[50] = t25;
251
- } else {
252
- t25 = $[50];
253
- }
254
- return t25;
99
+ }) : null]
100
+ });
255
101
  }
256
102
 
257
103
  export { DuplicateAction as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@panneau/action-duplicate",
3
- "version": "4.0.65",
3
+ "version": "4.0.72",
4
4
  "description": "Duplicate action",
5
5
  "keywords": [
6
6
  "javascript"
@@ -46,9 +46,9 @@
46
46
  "dependencies": {
47
47
  "@babel/runtime": "^7.28.6",
48
48
  "@folklore/fetch": "^0.1.21",
49
- "@panneau/core": "^4.0.58",
50
- "@panneau/element-button": "^4.0.65",
51
- "@panneau/themes": "^4.0.58",
49
+ "@panneau/core": "^4.0.72",
50
+ "@panneau/element-button": "^4.0.72",
51
+ "@panneau/themes": "^4.0.72",
52
52
  "classnames": "^2.5.1",
53
53
  "react-intl": "^6.0.0 || ^7.0.0 || ^8.0.0 || ^10.0.0"
54
54
  },
@@ -63,5 +63,5 @@
63
63
  "publishConfig": {
64
64
  "access": "public"
65
65
  },
66
- "gitHead": "815e7d1daa4c0b6321caacbff495eae6b7dd7bfa"
66
+ "gitHead": "6ef477fccf4ca9b81fcca140f56eb45413391c87"
67
67
  }