corpushub-design-system 0.0.7 → 0.0.9

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,
@@ -112,7 +112,7 @@ function PageRenderElementItem({ item, highlight, showLineNumbers, displayTags,
112
112
  case PageRenderElementType.MARK:
113
113
  if (!element.token)
114
114
  return null;
115
- return (_jsx(TokenNode, { refToken: element.token, splitIdx: 0, isMark: true, highlight: highlight, displayTags: displayTags, activeTokenKey: activeTokenKey, selectedTokenKeys: selectedTokenKeys, tokenSelectionKey: tokenSelectionKey, getDisplayValue: getDisplayValue, getTokenStyle: getTokenStyle, getTokenClassName: getTokenClassName, isTokenEdited: isTokenEdited, onTokenClick: onTokenClick, onTokenHover: onTokenHover, wrapToken: wrapToken, renderTokenSuffix: renderTokenSuffix }));
115
+ return (_jsx(TokenNode, { refToken: element.token, splitIdx: undefined, isMark: true, highlight: highlight, displayTags: displayTags, activeTokenKey: activeTokenKey, selectedTokenKeys: selectedTokenKeys, tokenSelectionKey: tokenSelectionKey, getDisplayValue: getDisplayValue, getTokenStyle: getTokenStyle, getTokenClassName: getTokenClassName, isTokenEdited: isTokenEdited, onTokenClick: onTokenClick, onTokenHover: onTokenHover, wrapToken: wrapToken, renderTokenSuffix: renderTokenSuffix }));
116
116
  case PageRenderElementType.JUNCTION_SPLIT:
117
117
  if (!element.token)
118
118
  return null;
@@ -120,7 +120,7 @@ function PageRenderElementItem({ item, highlight, showLineNumbers, displayTags,
120
120
  case PageRenderElementType.TOKEN:
121
121
  if (!element.token)
122
122
  return null;
123
- return (_jsx(TokenNode, { refToken: element.token, splitIdx: 0, highlight: highlight, displayTags: displayTags, activeTokenKey: activeTokenKey, selectedTokenKeys: selectedTokenKeys, tokenSelectionKey: tokenSelectionKey, getDisplayValue: getDisplayValue, getTokenStyle: getTokenStyle, getTokenClassName: getTokenClassName, isTokenEdited: isTokenEdited, onTokenClick: onTokenClick, onTokenHover: onTokenHover, wrapToken: wrapToken, renderTokenSuffix: renderTokenSuffix }));
123
+ return (_jsx(TokenNode, { refToken: element.token, splitIdx: undefined, highlight: highlight, displayTags: displayTags, activeTokenKey: activeTokenKey, selectedTokenKeys: selectedTokenKeys, tokenSelectionKey: tokenSelectionKey, getDisplayValue: getDisplayValue, getTokenStyle: getTokenStyle, getTokenClassName: getTokenClassName, isTokenEdited: isTokenEdited, onTokenClick: onTokenClick, onTokenHover: onTokenHover, wrapToken: wrapToken, renderTokenSuffix: renderTokenSuffix }));
124
124
  default:
125
125
  return null;
126
126
  }
@@ -57,7 +57,7 @@ export type PageRenderTokenContext = {
57
57
  isSplit: boolean;
58
58
  isMark: boolean;
59
59
  isCollapsedJunction: boolean;
60
- splitIdx: number;
60
+ splitIdx: number | undefined;
61
61
  highlight: boolean;
62
62
  selected: boolean;
63
63
  };
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.9",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {