corpushub-design-system 0.0.6 → 0.0.8

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.
@@ -8,7 +8,7 @@ export const BackupTexts = {
8
8
  'backup.field.user.name': 'User',
9
9
  'backup.field.log': 'Log',
10
10
  'backup.field.id': 'Date',
11
- 'backup.field.download': 'Actions',
11
+ 'backup.field.download': 'Download',
12
12
  'backup.label.log': 'Log',
13
13
  'backup.status.error': 'error',
14
14
  'backup.status.processing': 'processing',
@@ -31,7 +31,7 @@ export const BackupTexts = {
31
31
  'backup.field.filename': 'Nome do arquivo',
32
32
  'backup.field.user.name': 'Usuário',
33
33
  'backup.field.status': 'Status',
34
- 'backup.field.download': 'Ações',
34
+ 'backup.field.download': 'Baixar',
35
35
  'backup.field.log': 'Log',
36
36
  'backup.label.log': 'Log',
37
37
  'backup.status.error': 'erro',
@@ -56,7 +56,7 @@ export const BackupTexts = {
56
56
  'backup.field.user.name': 'Utente',
57
57
  'backup.field.log': 'Log',
58
58
  'backup.field.id': 'Data',
59
- 'backup.field.download': 'Azioni',
59
+ 'backup.field.download': 'Scarica',
60
60
  'backup.label.log': 'Log',
61
61
  'backup.status.error': 'errore',
62
62
  'backup.status.processing': 'in elaborazione',
@@ -1,26 +1,89 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from 'react';
2
3
  import { useTranslation } from 'react-i18next';
4
+ import AppLoading from '../../../common/AppLoading';
5
+ import AppModal from '../../../common/AppModal';
3
6
  import { useMessageUtils } from '../../../configs/useMessageUtils';
4
- import AppModalConfirm from '../../../common/AppModal/AppModalConfirm';
5
7
  import BackupService from '../BackupService';
6
8
  import './style.scss';
9
+ const POLL_INTERVAL_MS = 2000;
7
10
  export default function BackupCreate({ mode, resourceUid, onClose, onConfirm, }) {
8
11
  const { t } = useTranslation('backup');
9
- const { isLoading, dispatchLoading, dispatchError } = useMessageUtils();
12
+ const { dispatchError, dispatchMessageDirect } = useMessageUtils();
13
+ const [loading, setLoading] = useState(false);
14
+ const mountedRef = useRef(true);
15
+ const pollRef = useRef(null);
16
+ useEffect(() => {
17
+ mountedRef.current = true;
18
+ return () => {
19
+ mountedRef.current = false;
20
+ if (pollRef.current != null) {
21
+ window.clearInterval(pollRef.current);
22
+ pollRef.current = null;
23
+ }
24
+ };
25
+ }, []);
26
+ const stopPolling = () => {
27
+ if (pollRef.current != null) {
28
+ window.clearInterval(pollRef.current);
29
+ pollRef.current = null;
30
+ }
31
+ };
32
+ const pollUntilDone = (backupId) => {
33
+ const tick = () => {
34
+ BackupService.status(backupId)
35
+ .then((r) => {
36
+ if (!mountedRef.current)
37
+ return;
38
+ const backup = r.data;
39
+ if (backup.status === 'PROCESSING')
40
+ return;
41
+ stopPolling();
42
+ setLoading(false);
43
+ if (backup.status === 'FINISHED') {
44
+ onConfirm(backup);
45
+ return;
46
+ }
47
+ dispatchMessageDirect(backup.log || t('backup.status.error'), 'error');
48
+ })
49
+ .catch((err) => {
50
+ if (!mountedRef.current)
51
+ return;
52
+ stopPolling();
53
+ setLoading(false);
54
+ dispatchError({ err, t });
55
+ });
56
+ };
57
+ tick();
58
+ pollRef.current = window.setInterval(tick, POLL_INTERVAL_MS);
59
+ };
10
60
  const handleConfirm = () => {
11
- if (isLoading() || !resourceUid)
61
+ if (loading || !resourceUid)
12
62
  return;
13
- dispatchLoading(true);
63
+ setLoading(true);
14
64
  BackupService.execute(mode, resourceUid)
15
65
  .then((r) => {
16
- onConfirm(r.data);
66
+ if (!mountedRef.current)
67
+ return;
68
+ const backup = r.data;
69
+ if (backup.status === 'FINISHED') {
70
+ setLoading(false);
71
+ onConfirm(backup);
72
+ return;
73
+ }
74
+ if (backup.status === 'ERROR') {
75
+ setLoading(false);
76
+ dispatchMessageDirect(backup.log || t('backup.status.error'), 'error');
77
+ return;
78
+ }
79
+ pollUntilDone(backup.id);
17
80
  })
18
81
  .catch((err) => {
82
+ if (!mountedRef.current)
83
+ return;
84
+ setLoading(false);
19
85
  dispatchError({ err, t });
20
- })
21
- .finally(() => {
22
- dispatchLoading(false);
23
86
  });
24
87
  };
25
- return (_jsx(AppModalConfirm, { title: t('modal.title'), subtitle: t('modal.description'), onClose: onClose, onConfirm: handleConfirm }));
88
+ return (_jsxs(AppModal, { title: t('modal.title'), className: "backup-create-modal", confirm: handleConfirm, close: onClose, disableConfirm: loading, disableClose: loading, disableEscapeClose: loading, disableBackdropClose: loading, children: [_jsx("p", { children: t('modal.description') }), loading && _jsx(AppLoading, {})] }));
26
89
  }
@@ -0,0 +1,5 @@
1
+ .backup-create-modal {
2
+ .loading-container {
3
+ margin: 0% 50%;
4
+ }
5
+ }
@@ -2,15 +2,17 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  import { useState } from 'react';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import AppDropzone from '../../../common/AppDropzone';
5
+ import AppLoading from '../../../common/AppLoading';
5
6
  import AppModal from '../../../common/AppModal';
6
7
  import { useMessageUtils } from '../../../configs/useMessageUtils';
7
8
  import BackupService from '../BackupService';
8
9
  import './style.scss';
9
10
  export default function BackupRestore({ mode, onClose }) {
10
11
  const { t } = useTranslation('backup');
11
- const { isLoading, dispatchLoading, dispatchError } = useMessageUtils();
12
+ const { dispatchError } = useMessageUtils();
12
13
  const [openExists, setOpenExists] = useState(false);
13
14
  const [backup, setBackup] = useState();
15
+ const [loading, setLoading] = useState(false);
14
16
  const handleSuccess = (uploaded) => {
15
17
  BackupService.restore(mode, uploaded)
16
18
  .then((r) => {
@@ -27,18 +29,16 @@ export default function BackupRestore({ mode, onClose }) {
27
29
  });
28
30
  };
29
31
  const handleExecute = (id) => {
30
- if (isLoading())
32
+ if (loading)
31
33
  return;
32
- dispatchLoading(true);
34
+ setLoading(true);
33
35
  BackupService.executeRestore(id)
34
36
  .then(() => {
35
37
  location.reload();
36
38
  })
37
39
  .catch((err) => {
38
40
  dispatchError({ err, t });
39
- })
40
- .finally(() => {
41
- dispatchLoading(false);
41
+ setLoading(false);
42
42
  });
43
43
  };
44
44
  const handleError = () => {
@@ -48,5 +48,5 @@ export default function BackupRestore({ mode, onClose }) {
48
48
  'application/gzip': ['.gz'],
49
49
  'application/x-tar': ['.tar'],
50
50
  'application/x-compressed-tar': ['.tar.gz'],
51
- } }), openExists && (_jsx(AppModal, { title: t('modal.restore.title'), className: "modal-parameter", confirm: () => backup && handleExecute(backup.id), close: () => setOpenExists(false), children: _jsx("div", { className: "alert alert-danger m-b-0", children: _jsxs("p", { children: [_jsx("span", { children: t(`modal.restore.message.${mode}`) }), _jsx("b", { className: "ms-1", children: t('modal.restore.confirm') })] }) }) }))] }));
51
+ } }), openExists && (_jsxs(AppModal, { title: t('modal.restore.title'), className: "modal-parameter", confirm: () => backup && handleExecute(backup.id), close: () => setOpenExists(false), disableConfirm: loading, disableClose: loading, disableEscapeClose: loading, disableBackdropClose: loading, children: [_jsx("div", { className: "alert alert-danger m-b-0", children: _jsxs("p", { children: [_jsx("span", { children: t(`modal.restore.message.${mode}`) }), _jsx("b", { className: "ms-1", children: t('modal.restore.confirm') })] }) }), loading && _jsx(AppLoading, {})] }))] }));
52
52
  }
@@ -5,12 +5,14 @@ import { BackupSearchFilter } from './BackupTable/BackupSearchFilter';
5
5
  import Backup from './types/Backup';
6
6
  declare function page(mode: AccessMode, resourceUid: string, filter: BackupSearchFilter): Promise<import("axios").AxiosResponse<AppPage<Backup>, any, {}, any>>;
7
7
  declare function execute(mode: AccessMode, resourceUid: string): Promise<import("axios").AxiosResponse<Backup, any, {}, any>>;
8
+ declare function status(id: string): Promise<import("axios").AxiosResponse<Backup, any, {}, any>>;
8
9
  declare function restore(mode: AccessMode, uploaded: UploadedFile): Promise<import("axios").AxiosResponse<Backup, any, {}, any>>;
9
10
  declare function executeRestore(id: string): Promise<import("axios").AxiosResponse<Backup, any, {}, any>>;
10
11
  declare function download(id: string): Promise<import("axios").AxiosResponse<string, any, {}, any>>;
11
12
  declare const BackupService: {
12
13
  page: typeof page;
13
14
  execute: typeof execute;
15
+ status: typeof status;
14
16
  download: typeof download;
15
17
  restore: typeof restore;
16
18
  executeRestore: typeof executeRestore;
@@ -17,6 +17,9 @@ function page(mode, resourceUid, filter) {
17
17
  function execute(mode, resourceUid) {
18
18
  return api.get(`${FUNCTIONS_API()}/backup/${resourceUid}/${APP_BY_MODE[mode]}`);
19
19
  }
20
+ function status(id) {
21
+ return api.get(`${FUNCTIONS_API()}/backup/status/${id}`);
22
+ }
20
23
  function restore(mode, uploaded) {
21
24
  return api.post(`${FUNCTIONS_API()}/backup/restore`, {
22
25
  filename: uploaded.path,
@@ -32,6 +35,7 @@ function download(id) {
32
35
  const BackupService = {
33
36
  page,
34
37
  execute,
38
+ status,
35
39
  download,
36
40
  restore,
37
41
  executeRestore,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "corpushub-design-system",
3
3
  "private": false,
4
- "version": "0.0.6",
4
+ "version": "0.0.8",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {