cozy-ui 139.0.0 → 139.0.2

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 CHANGED
@@ -1,3 +1,17 @@
1
+ ## [139.0.2](https://github.com/cozy/cozy-ui/compare/v139.0.1...v139.0.2) (2026-06-02)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **useSubmitWithLoader:** Avoid double submit ([c65b431](https://github.com/cozy/cozy-ui/commit/c65b431))
7
+
8
+ ## [139.0.1](https://github.com/cozy/cozy-ui/compare/v139.0.0...v139.0.1) (2026-06-01)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * **Table:** Disable double click when `disableClick` is true in column config ([6da0985](https://github.com/cozy/cozy-ui/commit/6da0985))
14
+
1
15
  # [139.0.0](https://github.com/cozy/cozy-ui/compare/v138.13.1...v139.0.0) (2026-06-01)
2
16
 
3
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cozy-ui",
3
- "version": "139.0.0",
3
+ "version": "139.0.2",
4
4
  "description": "Cozy apps UI SDK",
5
5
  "main": "./index.js",
6
6
  "bin": {
@@ -121,8 +121,8 @@ const ExampleTable = ({ variant, ...props }) => {
121
121
  row.id !== 1
122
122
  ? console.info(`long press on cell. Row ${row['id']}, Column ${column['id']}`)
123
123
  : undefined
124
- },
125
- },
124
+ }
125
+ }
126
126
  }}
127
127
  />
128
128
  </div>
@@ -70,7 +70,9 @@ const Cell = ({
70
70
  align={column.textAlign ?? 'left'}
71
71
  padding={column.disablePadding ? 'none' : 'normal'}
72
72
  onClick={handleClick}
73
- onDoubleClick={() => onDoubleClick?.(row, column)}
73
+ onDoubleClick={() =>
74
+ column.disableClick ? undefined : onDoubleClick?.(row, column)
75
+ }
74
76
  onContextMenu={isLongPress ? ev => ev.preventDefault() : undefined}
75
77
  >
76
78
  {children
@@ -9,6 +9,8 @@ export const useSubmitWithLoader = () => {
9
9
  const { t } = useI18n()
10
10
 
11
11
  const onSubmit = async ({ submit, success, error }) => {
12
+ if (isLoading) return
13
+
12
14
  setIsLoading(true)
13
15
 
14
16
  try {
@@ -0,0 +1,74 @@
1
+ import { renderHook, act } from '@testing-library/react-hooks'
2
+ import React from 'react'
3
+ import I18n from 'twake-i18n'
4
+
5
+ import { useSubmitWithLoader } from './index'
6
+ import AlertProvider from '../../providers/Alert'
7
+
8
+ jest.mock('../../Snackbar', () => ({
9
+ __esModule: true,
10
+ default: ({ children }) => children
11
+ }))
12
+
13
+ const renderUseSubmitWithLoader = () =>
14
+ renderHook(() => useSubmitWithLoader(), {
15
+ wrapper: ({ children }) => (
16
+ <I18n lang="en" dictRequire={() => ({})}>
17
+ <AlertProvider>{children}</AlertProvider>
18
+ </I18n>
19
+ )
20
+ })
21
+
22
+ describe('useSubmitWithLoader', () => {
23
+ it('should not execute submit when isLoading is true', async () => {
24
+ const { result } = renderUseSubmitWithLoader()
25
+ const submit = jest.fn()
26
+
27
+ act(() => {
28
+ result.current.onSubmit({ submit, success: { message: 'ok' }, error: {} })
29
+ })
30
+ expect(result.current.isLoading).toBe(true)
31
+
32
+ await act(async () => {
33
+ await result.current.onSubmit({
34
+ submit,
35
+ success: { message: 'ok' },
36
+ error: {}
37
+ })
38
+ })
39
+
40
+ expect(submit).toHaveBeenCalledTimes(1)
41
+ })
42
+
43
+ it('should call success.action when submit succeeds', async () => {
44
+ const { result } = renderUseSubmitWithLoader()
45
+ const successAction = jest.fn()
46
+ const submit = jest.fn().mockResolvedValue(undefined)
47
+
48
+ await act(async () => {
49
+ await result.current.onSubmit({
50
+ submit,
51
+ success: { message: 'Success', action: successAction },
52
+ error: {}
53
+ })
54
+ })
55
+
56
+ expect(successAction).toHaveBeenCalled()
57
+ })
58
+
59
+ it('should call error.action when submit throws', async () => {
60
+ const { result } = renderUseSubmitWithLoader()
61
+ const errorAction = jest.fn()
62
+ const submit = jest.fn().mockRejectedValue(new Error('fail'))
63
+
64
+ await act(async () => {
65
+ await result.current.onSubmit({
66
+ submit,
67
+ success: {},
68
+ error: { message: () => 'Error', action: errorAction }
69
+ })
70
+ })
71
+
72
+ expect(errorAction).toHaveBeenCalled()
73
+ })
74
+ })
@@ -88,7 +88,7 @@ var Cell = function Cell(_ref4) {
88
88
  padding: column.disablePadding ? 'none' : 'normal',
89
89
  onClick: handleClick,
90
90
  onDoubleClick: function onDoubleClick() {
91
- return _onDoubleClick === null || _onDoubleClick === void 0 ? void 0 : _onDoubleClick(row, column);
91
+ return column.disableClick ? undefined : _onDoubleClick === null || _onDoubleClick === void 0 ? void 0 : _onDoubleClick(row, column);
92
92
  },
93
93
  onContextMenu: isLongPress ? function (ev) {
94
94
  return ev.preventDefault();
@@ -25,23 +25,32 @@ export var useSubmitWithLoader = function useSubmitWithLoader() {
25
25
  switch (_context.prev = _context.next) {
26
26
  case 0:
27
27
  submit = _ref.submit, success = _ref.success, error = _ref.error;
28
+
29
+ if (!isLoading) {
30
+ _context.next = 3;
31
+ break;
32
+ }
33
+
34
+ return _context.abrupt("return");
35
+
36
+ case 3:
28
37
  setIsLoading(true);
29
- _context.prev = 2;
30
- _context.next = 5;
38
+ _context.prev = 4;
39
+ _context.next = 7;
31
40
  return submit();
32
41
 
33
- case 5:
42
+ case 7:
34
43
  showAlert({
35
44
  severity: 'success',
36
45
  message: (success === null || success === void 0 ? void 0 : success.message) || t('useSubmitWithLoader.success')
37
46
  });
38
47
  success === null || success === void 0 ? void 0 : (_success$action = success.action) === null || _success$action === void 0 ? void 0 : _success$action.call(success);
39
- _context.next = 13;
48
+ _context.next = 15;
40
49
  break;
41
50
 
42
- case 9:
43
- _context.prev = 9;
44
- _context.t0 = _context["catch"](2);
51
+ case 11:
52
+ _context.prev = 11;
53
+ _context.t0 = _context["catch"](4);
45
54
  showAlert({
46
55
  severity: 'error',
47
56
  message: (error === null || error === void 0 ? void 0 : (_error$message = error.message) === null || _error$message === void 0 ? void 0 : _error$message.call(error, _context.t0)) || t('useSubmitWithLoader.error', {
@@ -50,17 +59,17 @@ export var useSubmitWithLoader = function useSubmitWithLoader() {
50
59
  });
51
60
  error === null || error === void 0 ? void 0 : (_error$action = error.action) === null || _error$action === void 0 ? void 0 : _error$action.call(error);
52
61
 
53
- case 13:
54
- _context.prev = 13;
62
+ case 15:
63
+ _context.prev = 15;
55
64
  setIsLoading(false);
56
- return _context.finish(13);
65
+ return _context.finish(15);
57
66
 
58
- case 16:
67
+ case 18:
59
68
  case "end":
60
69
  return _context.stop();
61
70
  }
62
71
  }
63
- }, _callee, null, [[2, 9, 13, 16]]);
72
+ }, _callee, null, [[4, 11, 15, 18]]);
64
73
  }));
65
74
 
66
75
  return function onSubmit(_x) {