@godv61/dsh-task-engine 0.5.0 → 0.5.1
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/lib/client.js +57 -7
- package/lib/client.js.map +2 -2
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -4232,6 +4232,8 @@ function TaskEngineSection(props) {
|
|
|
4232
4232
|
const [config, setConfig] = (0, import_react.useState)(null);
|
|
4233
4233
|
const [source, setSource] = (0, import_react.useState)("default");
|
|
4234
4234
|
const [savedAt, setSavedAt] = (0, import_react.useState)("");
|
|
4235
|
+
const [loadError, setLoadError] = (0, import_react.useState)("");
|
|
4236
|
+
const [loadedProblems, setLoadedProblems] = (0, import_react.useState)([]);
|
|
4235
4237
|
(0, import_react.useEffect)(() => {
|
|
4236
4238
|
if (workspaces.length > 0 && workspace === "") {
|
|
4237
4239
|
setWorkspace(workspaces[0].path);
|
|
@@ -4240,20 +4242,50 @@ function TaskEngineSection(props) {
|
|
|
4240
4242
|
(0, import_react.useEffect)(() => {
|
|
4241
4243
|
if (workspace === "") return;
|
|
4242
4244
|
let alive = true;
|
|
4245
|
+
setLoadError("");
|
|
4243
4246
|
void remote.read(workspace).then((result) => {
|
|
4244
4247
|
if (!alive) return;
|
|
4245
4248
|
if (result.ok) {
|
|
4246
4249
|
setConfig(result.value.config);
|
|
4247
4250
|
setSource(result.value.source);
|
|
4251
|
+
setLoadedProblems(result.value.source === "invalid" ? result.value.problems : []);
|
|
4248
4252
|
setSavedAt("");
|
|
4253
|
+
} else {
|
|
4254
|
+
setLoadError("\u8BFB\u53D6\u914D\u7F6E\u5931\u8D25\uFF1A" + describeError(result.error));
|
|
4249
4255
|
}
|
|
4256
|
+
}, (error) => {
|
|
4257
|
+
if (alive) setLoadError("\u8BFB\u53D6\u914D\u7F6E\u5931\u8D25\uFF1A" + describeError(error));
|
|
4250
4258
|
});
|
|
4251
4259
|
return () => {
|
|
4252
4260
|
alive = false;
|
|
4253
4261
|
};
|
|
4254
4262
|
}, [remote, workspace]);
|
|
4255
4263
|
const problems = (0, import_react.useMemo)(() => config === null ? [] : validateWorkflow(config), [config]);
|
|
4256
|
-
|
|
4264
|
+
const notice = problems.length === 0 && loadedProblems.length > 0 ? loadedProblems : [];
|
|
4265
|
+
if (workspaces.length === 0) {
|
|
4266
|
+
return e(
|
|
4267
|
+
"div",
|
|
4268
|
+
{ style: styles.wrap },
|
|
4269
|
+
e("h2", { style: styles.title }, "\u5DE5\u7A0B\u6D41\u7A0B\u914D\u7F6E"),
|
|
4270
|
+
e("p", { style: styles.problems }, "\u5F53\u524D\u6CA1\u6709\u4EFB\u4F55\u5DE5\u4F5C\u533A\uFF1A\u8BF7\u5148\u5728\u4FA7\u680F\u521B\u5EFA\u4E00\u4E2A\u5DE5\u4F5C\u533A\u3002")
|
|
4271
|
+
);
|
|
4272
|
+
}
|
|
4273
|
+
if (loadError !== "") {
|
|
4274
|
+
return e(
|
|
4275
|
+
"div",
|
|
4276
|
+
{ style: styles.wrap },
|
|
4277
|
+
e("h2", { style: styles.title }, "\u5DE5\u7A0B\u6D41\u7A0B\u914D\u7F6E"),
|
|
4278
|
+
e("p", { style: styles.problems }, loadError)
|
|
4279
|
+
);
|
|
4280
|
+
}
|
|
4281
|
+
if (config === null) {
|
|
4282
|
+
return e(
|
|
4283
|
+
"div",
|
|
4284
|
+
{ style: styles.wrap },
|
|
4285
|
+
e("h2", { style: styles.title }, "\u5DE5\u7A0B\u6D41\u7A0B\u914D\u7F6E"),
|
|
4286
|
+
e("p", null, "\u52A0\u8F7D\u4E2D\u2026")
|
|
4287
|
+
);
|
|
4288
|
+
}
|
|
4257
4289
|
return e(
|
|
4258
4290
|
"div",
|
|
4259
4291
|
{ style: styles.wrap },
|
|
@@ -4283,11 +4315,17 @@ function TaskEngineSection(props) {
|
|
|
4283
4315
|
{ style: styles.problems },
|
|
4284
4316
|
e("strong", null, `\u6709 ${problems.length} \u4E2A\u95EE\u9898\uFF08\u4FDD\u5B58\u4F1A\u88AB\u62D2\u7EDD\uFF09\uFF1A`),
|
|
4285
4317
|
e("ul", null, ...problems.map((p) => e("li", { key: p }, p)))
|
|
4318
|
+
) : notice.length > 0 ? e(
|
|
4319
|
+
"div",
|
|
4320
|
+
{ style: styles.problems },
|
|
4321
|
+
e("strong", null, "\u539F .dsh/eng.json \u65E0\u6CD5\u89E3\u6790\uFF1A"),
|
|
4322
|
+
e("ul", null, ...notice.map((p) => e("li", { key: p }, p))),
|
|
4323
|
+
e("p", { style: styles.muted }, "\u5F53\u524D\u663E\u793A\u5185\u7F6E\u9ED8\u8BA4\u914D\u7F6E\uFF1B\u70B9\u51FB\u4FDD\u5B58\u4F1A\u8986\u76D6\u539F\u6587\u4EF6\u3002")
|
|
4286
4324
|
) : e("p", { style: styles.ok }, source === "default" ? "\u5F53\u524D\u4F7F\u7528\u5185\u7F6E\u9ED8\u8BA4\u914D\u7F6E\u3002" : "\u914D\u7F6E\u6709\u6548\u3002"),
|
|
4287
4325
|
e(
|
|
4288
4326
|
"div",
|
|
4289
4327
|
{ style: styles.actions },
|
|
4290
|
-
e("button", { onClick: () => save(props, config, workspace, setSavedAt, setSource), disabled: problems.length > 0 }, "\u4FDD\u5B58\u5230 .dsh/eng.json"),
|
|
4328
|
+
e("button", { onClick: () => save(props, config, workspace, setSavedAt, setSource, setLoadedProblems), disabled: problems.length > 0 }, "\u4FDD\u5B58\u5230 .dsh/eng.json"),
|
|
4291
4329
|
savedAt !== "" ? e("span", { style: styles.ok }, savedAt) : null
|
|
4292
4330
|
)
|
|
4293
4331
|
);
|
|
@@ -4435,12 +4473,15 @@ function selectOf(config, value, onChange) {
|
|
|
4435
4473
|
function update(config, setConfig, fn) {
|
|
4436
4474
|
setConfig(fn(config));
|
|
4437
4475
|
}
|
|
4438
|
-
async function save(props, config, workspace, setSavedAt, setSource) {
|
|
4476
|
+
async function save(props, config, workspace, setSavedAt, setSource, setLoadedProblems) {
|
|
4439
4477
|
const result = await props.remote.write({ path: workspace, config });
|
|
4440
|
-
if (result.ok) {
|
|
4441
|
-
|
|
4442
|
-
|
|
4478
|
+
if (!result.ok) {
|
|
4479
|
+
setSavedAt("\u4FDD\u5B58\u5931\u8D25\uFF1A" + describeError(result.error));
|
|
4480
|
+
return;
|
|
4443
4481
|
}
|
|
4482
|
+
setSource(result.value.source);
|
|
4483
|
+
setLoadedProblems(result.value.source === "invalid" ? result.value.problems : []);
|
|
4484
|
+
setSavedAt(result.value.ok ? "\u5DF2\u4FDD\u5B58" : "");
|
|
4444
4485
|
}
|
|
4445
4486
|
function splitList(text) {
|
|
4446
4487
|
return text.split(",").map((s) => s.trim()).filter((s) => s.length > 0);
|
|
@@ -4448,6 +4489,11 @@ function splitList(text) {
|
|
|
4448
4489
|
function toggle(list, value, on) {
|
|
4449
4490
|
return on ? list.includes(value) ? list : [...list, value] : list.filter((v) => v !== value);
|
|
4450
4491
|
}
|
|
4492
|
+
function describeError(error) {
|
|
4493
|
+
if (error instanceof Error) return error.message;
|
|
4494
|
+
if (typeof error === "string") return error;
|
|
4495
|
+
return "\u672A\u77E5\u9519\u8BEF";
|
|
4496
|
+
}
|
|
4451
4497
|
var styles = {
|
|
4452
4498
|
wrap: { padding: "16px", maxWidth: "760px", display: "flex", flexDirection: "column", gap: "8px" },
|
|
4453
4499
|
title: { margin: "0 0 4px" },
|
|
@@ -4467,7 +4513,11 @@ var styles = {
|
|
|
4467
4513
|
var inject = ["remote", "slots"];
|
|
4468
4514
|
async function apply(ctx) {
|
|
4469
4515
|
const disposeRemote = await ctx.remote.$mount(remote_default);
|
|
4470
|
-
const taskEngine = ctx.remote
|
|
4516
|
+
const taskEngine = ctx.get("remote.task-engine");
|
|
4517
|
+
if (taskEngine === void 0) {
|
|
4518
|
+
await disposeRemote();
|
|
4519
|
+
throw new Error("task-engine: remote.task-engine namespace failed to mount");
|
|
4520
|
+
}
|
|
4471
4521
|
ctx.slots.inject("settings.section", () => ctx.slots.register({
|
|
4472
4522
|
name: "settings.section",
|
|
4473
4523
|
id: "task-engine",
|