@ablogcms/background-process 3.2.28-beta.0
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/README.md +18 -0
- package/dist/background-process.d.ts +23 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.mjs +73 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +47 -0
package/README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# @ablogcms/background-process
|
|
2
|
+
|
|
3
|
+
バックグラウンド処理(インポート/エクスポート/バックアップ/システム更新など)の進捗を
|
|
4
|
+
`ACMS_POST_Logger_ProgressJson` へのポーリングで取得し、進捗バー・完了メッセージ・処理項目一覧を
|
|
5
|
+
表示するコンポーネント。
|
|
6
|
+
|
|
7
|
+
## 使い方
|
|
8
|
+
|
|
9
|
+
```tsx
|
|
10
|
+
import { BackgroundProcess } from '@ablogcms/background-process';
|
|
11
|
+
|
|
12
|
+
<BackgroundProcess type="backup_db" successMessage="バックアップが完了しました" errorMessage="バックアップに失敗しました" />;
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
- `type`: `ACMS_POST_Logger_ProgressJson` に渡す処理種別。
|
|
16
|
+
- `interval`(既定 1000ms): ポーリング間隔。
|
|
17
|
+
- `timeout`(既定 180000ms): 最終更新からの経過時間がこれを超えるとタイムアウト扱いにする。
|
|
18
|
+
- `showProcessList`(既定 true): 処理項目一覧(失敗項目は `[Error]` 付き)を表示するか。
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface ProcessItem {
|
|
2
|
+
status: string;
|
|
3
|
+
message: string;
|
|
4
|
+
}
|
|
5
|
+
export interface ProgressResponse {
|
|
6
|
+
processing: boolean;
|
|
7
|
+
success: boolean;
|
|
8
|
+
error: string;
|
|
9
|
+
percentage: number;
|
|
10
|
+
inProcess: string;
|
|
11
|
+
updatedAt: string;
|
|
12
|
+
processList: ProcessItem[];
|
|
13
|
+
}
|
|
14
|
+
export interface BackgroundProcessProps {
|
|
15
|
+
type: string;
|
|
16
|
+
successMessage: string;
|
|
17
|
+
errorMessage: string;
|
|
18
|
+
interval?: number;
|
|
19
|
+
timeout?: number;
|
|
20
|
+
showProcessList?: boolean;
|
|
21
|
+
}
|
|
22
|
+
declare function BackgroundProcess({ type, successMessage, errorMessage, interval, timeout, showProcessList, }: BackgroundProcessProps): import("react").JSX.Element | null;
|
|
23
|
+
export default BackgroundProcess;
|
package/dist/index.d.ts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
// src/background-process.tsx
|
|
2
|
+
import { useState, useEffect, useCallback } from "react";
|
|
3
|
+
import Alert from "@ablogcms/components/alert";
|
|
4
|
+
import ProgressBar from "@ablogcms/components/progress-bar";
|
|
5
|
+
import { fetchClient } from "@ablogcms/fetch-client";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
function BackgroundProcess({
|
|
8
|
+
type,
|
|
9
|
+
successMessage,
|
|
10
|
+
errorMessage,
|
|
11
|
+
interval = 1e3,
|
|
12
|
+
timeout = 18e4,
|
|
13
|
+
showProcessList = true
|
|
14
|
+
}) {
|
|
15
|
+
const [json, setJson] = useState(null);
|
|
16
|
+
const [stopped, setStopped] = useState(false);
|
|
17
|
+
const poll = useCallback(async () => {
|
|
18
|
+
try {
|
|
19
|
+
const data = new FormData();
|
|
20
|
+
data.append("ACMS_POST_Logger_ProgressJson", "exec");
|
|
21
|
+
data.append("type", type);
|
|
22
|
+
data.append("formToken", window.csrfToken);
|
|
23
|
+
const response = await fetchClient.post(ACMS.Config.root, data);
|
|
24
|
+
const result = response.data;
|
|
25
|
+
const updatedAt = new Date(result.updatedAt).getTime();
|
|
26
|
+
const now = Date.now();
|
|
27
|
+
if (now - updatedAt > timeout) {
|
|
28
|
+
result.error = "\u30BF\u30A4\u30E0\u30A2\u30A6\u30C8\u3057\u307E\u3057\u305F\u3002\u30EA\u30ED\u30FC\u30C9\u3057\u3066\u51E6\u7406\u304C\u5B8C\u4E86\u3057\u3066\u3044\u308B\u304B\u78BA\u8A8D\u3057\u3066\u304F\u3060\u3055\u3044\u3002";
|
|
29
|
+
setStopped(true);
|
|
30
|
+
}
|
|
31
|
+
setJson(result);
|
|
32
|
+
if (!result.processing) {
|
|
33
|
+
setStopped(true);
|
|
34
|
+
}
|
|
35
|
+
} catch {
|
|
36
|
+
setStopped(true);
|
|
37
|
+
}
|
|
38
|
+
}, [type, timeout]);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
const id = setInterval(() => {
|
|
41
|
+
poll();
|
|
42
|
+
}, interval);
|
|
43
|
+
if (stopped) {
|
|
44
|
+
clearInterval(id);
|
|
45
|
+
}
|
|
46
|
+
return () => clearInterval(id);
|
|
47
|
+
}, [poll, interval, stopped]);
|
|
48
|
+
if (!json) {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
const { processing, success, error, percentage, inProcess, processList } = json;
|
|
52
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
53
|
+
processing && /* @__PURE__ */ jsx(
|
|
54
|
+
ProgressBar,
|
|
55
|
+
{
|
|
56
|
+
value: error ? 100 : percentage,
|
|
57
|
+
variant: error ? "danger" : "info",
|
|
58
|
+
striped: true,
|
|
59
|
+
animated: true,
|
|
60
|
+
labelPosition: "overlay",
|
|
61
|
+
label: error || inProcess
|
|
62
|
+
}
|
|
63
|
+
),
|
|
64
|
+
!processing && success && /* @__PURE__ */ jsx(Alert, { variant: "info", children: successMessage }),
|
|
65
|
+
!processing && error && /* @__PURE__ */ jsx(Alert, { variant: "warning", children: errorMessage }),
|
|
66
|
+
showProcessList && processList && processList.length > 0 && /* @__PURE__ */ jsx("ul", { children: processList.map((item) => /* @__PURE__ */ jsx("li", { className: item.status === "ng" ? "acms-admin-text-danger" : void 0, children: item.status === "ng" ? `[Error] ${item.message}` : item.message }, item.message)) })
|
|
67
|
+
] });
|
|
68
|
+
}
|
|
69
|
+
var background_process_default = BackgroundProcess;
|
|
70
|
+
export {
|
|
71
|
+
background_process_default as BackgroundProcess
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/background-process.tsx"],"sourcesContent":["import { useState, useEffect, useCallback } from 'react';\nimport Alert from '@ablogcms/components/alert';\nimport ProgressBar from '@ablogcms/components/progress-bar';\nimport { fetchClient } from '@ablogcms/fetch-client';\n\nexport interface ProcessItem {\n status: string;\n message: string;\n}\n\nexport interface ProgressResponse {\n processing: boolean;\n success: boolean;\n error: string;\n percentage: number;\n inProcess: string;\n updatedAt: string;\n processList: ProcessItem[];\n}\n\nexport interface BackgroundProcessProps {\n type: string;\n successMessage: string;\n errorMessage: string;\n interval?: number;\n timeout?: number;\n showProcessList?: boolean;\n}\n\nfunction BackgroundProcess({\n type,\n successMessage,\n errorMessage,\n interval = 1_000,\n timeout = 180_000,\n showProcessList = true,\n}: BackgroundProcessProps) {\n const [json, setJson] = useState<ProgressResponse | null>(null);\n const [stopped, setStopped] = useState(false);\n\n const poll = useCallback(async () => {\n try {\n const data = new FormData();\n data.append('ACMS_POST_Logger_ProgressJson', 'exec');\n data.append('type', type);\n data.append('formToken', window.csrfToken);\n const response = await fetchClient.post<ProgressResponse>(ACMS.Config.root, data);\n const result: ProgressResponse = response.data;\n const updatedAt = new Date(result.updatedAt).getTime();\n const now = Date.now();\n\n if (now - updatedAt > timeout) {\n result.error = 'タイムアウトしました。リロードして処理が完了しているか確認してください。';\n setStopped(true);\n }\n\n setJson(result);\n\n if (!result.processing) {\n setStopped(true);\n }\n } catch {\n setStopped(true);\n }\n }, [type, timeout]);\n\n useEffect(() => {\n const id = setInterval(() => {\n poll();\n }, interval);\n\n if (stopped) {\n clearInterval(id);\n }\n return () => clearInterval(id);\n }, [poll, interval, stopped]);\n\n if (!json) {\n return null;\n }\n\n const { processing, success, error, percentage, inProcess, processList } = json;\n\n return (\n <>\n {processing && (\n <ProgressBar\n value={error ? 100 : percentage}\n variant={error ? 'danger' : 'info'}\n striped\n animated\n labelPosition=\"overlay\"\n label={error || inProcess}\n />\n )}\n\n {!processing && success && <Alert variant=\"info\">{successMessage}</Alert>}\n\n {!processing && error && <Alert variant=\"warning\">{errorMessage}</Alert>}\n\n {showProcessList && processList && processList.length > 0 && (\n <ul>\n {processList.map((item) => (\n <li key={item.message} className={item.status === 'ng' ? 'acms-admin-text-danger' : undefined}>\n {item.status === 'ng' ? `[Error] ${item.message}` : item.message}\n </li>\n ))}\n </ul>\n )}\n </>\n );\n}\n\nexport default BackgroundProcess;\n"],"mappings":";AAAA,SAAS,UAAU,WAAW,mBAAmB;AACjD,OAAO,WAAW;AAClB,OAAO,iBAAiB;AACxB,SAAS,mBAAmB;AAiFxB,mBAEI,KAFJ;AAvDJ,SAAS,kBAAkB;AAAA,EACzB;AAAA,EACA;AAAA,EACA;AAAA,EACA,WAAW;AAAA,EACX,UAAU;AAAA,EACV,kBAAkB;AACpB,GAA2B;AACzB,QAAM,CAAC,MAAM,OAAO,IAAI,SAAkC,IAAI;AAC9D,QAAM,CAAC,SAAS,UAAU,IAAI,SAAS,KAAK;AAE5C,QAAM,OAAO,YAAY,YAAY;AACnC,QAAI;AACF,YAAM,OAAO,IAAI,SAAS;AAC1B,WAAK,OAAO,iCAAiC,MAAM;AACnD,WAAK,OAAO,QAAQ,IAAI;AACxB,WAAK,OAAO,aAAa,OAAO,SAAS;AACzC,YAAM,WAAW,MAAM,YAAY,KAAuB,KAAK,OAAO,MAAM,IAAI;AAChF,YAAM,SAA2B,SAAS;AAC1C,YAAM,YAAY,IAAI,KAAK,OAAO,SAAS,EAAE,QAAQ;AACrD,YAAM,MAAM,KAAK,IAAI;AAErB,UAAI,MAAM,YAAY,SAAS;AAC7B,eAAO,QAAQ;AACf,mBAAW,IAAI;AAAA,MACjB;AAEA,cAAQ,MAAM;AAEd,UAAI,CAAC,OAAO,YAAY;AACtB,mBAAW,IAAI;AAAA,MACjB;AAAA,IACF,QAAQ;AACN,iBAAW,IAAI;AAAA,IACjB;AAAA,EACF,GAAG,CAAC,MAAM,OAAO,CAAC;AAElB,YAAU,MAAM;AACd,UAAM,KAAK,YAAY,MAAM;AAC3B,WAAK;AAAA,IACP,GAAG,QAAQ;AAEX,QAAI,SAAS;AACX,oBAAc,EAAE;AAAA,IAClB;AACA,WAAO,MAAM,cAAc,EAAE;AAAA,EAC/B,GAAG,CAAC,MAAM,UAAU,OAAO,CAAC;AAE5B,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAEA,QAAM,EAAE,YAAY,SAAS,OAAO,YAAY,WAAW,YAAY,IAAI;AAE3E,SACE,iCACG;AAAA,kBACC;AAAA,MAAC;AAAA;AAAA,QACC,OAAO,QAAQ,MAAM;AAAA,QACrB,SAAS,QAAQ,WAAW;AAAA,QAC5B,SAAO;AAAA,QACP,UAAQ;AAAA,QACR,eAAc;AAAA,QACd,OAAO,SAAS;AAAA;AAAA,IAClB;AAAA,IAGD,CAAC,cAAc,WAAW,oBAAC,SAAM,SAAQ,QAAQ,0BAAe;AAAA,IAEhE,CAAC,cAAc,SAAS,oBAAC,SAAM,SAAQ,WAAW,wBAAa;AAAA,IAE/D,mBAAmB,eAAe,YAAY,SAAS,KACtD,oBAAC,QACE,sBAAY,IAAI,CAAC,SAChB,oBAAC,QAAsB,WAAW,KAAK,WAAW,OAAO,2BAA2B,QACjF,eAAK,WAAW,OAAO,WAAW,KAAK,OAAO,KAAK,KAAK,WADlD,KAAK,OAEd,CACD,GACH;AAAA,KAEJ;AAEJ;AAEA,IAAO,6BAAQ;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ablogcms/background-process",
|
|
3
|
+
"version": "3.2.28-beta.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "バックグラウンド処理(インポート/エクスポート等)の進捗ポーリング表示コンポーネント",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://www.a-blogcms.jp",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+ssh://git@bitbucket.org:appleple/ablogcms.git",
|
|
11
|
+
"directory": "packages/frontend/background-process"
|
|
12
|
+
},
|
|
13
|
+
"sideEffects": false,
|
|
14
|
+
"dependencies": {
|
|
15
|
+
"@ablogcms/components": "3.2.28-beta.0",
|
|
16
|
+
"@ablogcms/fetch-client": "3.2.28-beta.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@testing-library/react": "^16.3.2",
|
|
20
|
+
"vitest": "^4.1.9"
|
|
21
|
+
},
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"react": "^19",
|
|
24
|
+
"@types/react": "^19.2.17"
|
|
25
|
+
},
|
|
26
|
+
"peerDependenciesMeta": {
|
|
27
|
+
"@types/react": {
|
|
28
|
+
"optional": true
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"exports": {
|
|
32
|
+
".": {
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"import": "./dist/index.mjs",
|
|
35
|
+
"default": "./dist/index.mjs"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"dist"
|
|
43
|
+
],
|
|
44
|
+
"scripts": {
|
|
45
|
+
"build": "node ../../../tools/build-package.mjs"
|
|
46
|
+
}
|
|
47
|
+
}
|