corpushub-design-system 0.0.7 → 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.
@@ -1,28 +1,88 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { useState } from 'react';
2
+ import { useEffect, useRef, useState } from 'react';
3
3
  import { useTranslation } from 'react-i18next';
4
4
  import AppLoading from '../../../common/AppLoading';
5
5
  import AppModal from '../../../common/AppModal';
6
6
  import { useMessageUtils } from '../../../configs/useMessageUtils';
7
7
  import BackupService from '../BackupService';
8
8
  import './style.scss';
9
+ const POLL_INTERVAL_MS = 2000;
9
10
  export default function BackupCreate({ mode, resourceUid, onClose, onConfirm, }) {
10
11
  const { t } = useTranslation('backup');
11
- const { dispatchError } = useMessageUtils();
12
+ const { dispatchError, dispatchMessageDirect } = useMessageUtils();
12
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
+ };
13
60
  const handleConfirm = () => {
14
61
  if (loading || !resourceUid)
15
62
  return;
16
63
  setLoading(true);
17
64
  BackupService.execute(mode, resourceUid)
18
65
  .then((r) => {
19
- 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);
20
80
  })
21
81
  .catch((err) => {
22
- dispatchError({ err, t });
23
- })
24
- .finally(() => {
82
+ if (!mountedRef.current)
83
+ return;
25
84
  setLoading(false);
85
+ dispatchError({ err, t });
26
86
  });
27
87
  };
28
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, {})] }));
@@ -0,0 +1,5 @@
1
+ .backup-create-modal {
2
+ .loading-container {
3
+ margin: 0% 50%;
4
+ }
5
+ }
@@ -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.7",
4
+ "version": "0.0.8",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {