diff --git a/scripts/create-feature-write-slice.ts b/scripts/create-feature-write-slice.ts
index 558967c5..83e147eb 100644
--- a/scripts/create-feature-write-slice.ts
+++ b/scripts/create-feature-write-slice.ts
@@ -656,6 +656,10 @@ export default function ${pascal}CreatePage() {
});
const effectUnknown = mutation.state.indicator === "mutation-effect-unknown";
const blocked = effectUnknown || mutation.state.indicator === "mutation-pending";
+ // A save this form did not start holds the coordinator (one left running
+ // when the user came back, or the check behind "confirm applied"): the save
+ // is off and the feedback says a save is running (1105/08-04).
+ const otherSaveRunning = mutation.state.indicator === "mutation-pending" && !form.pending;
const guard = useDirtyNavigationGuard(form.dirty && !form.pending);
return (
@@ -694,7 +698,7 @@ export default function ${pascal}CreatePage() {
type="submit"
pending={form.pending}
pendingLabel={message("${camel}.form.saving")}
- disabled={effectUnknown}
+ disabled={effectUnknown || otherSaveRunning}
>
{message("${camel}.form.save")}
@@ -718,6 +722,8 @@ export default function ${pascal}CreatePage() {
void form.resendUnknown(async () => openSaved(await mutation.resendUnknownEffect()));
}}
/>
+ ) : otherSaveRunning && form.result !== "effect-unknown" ? (
+
) : null
}
guard={}
diff --git a/src/features/reference-feature/presentation/reference-resource-form-page.tsx b/src/features/reference-feature/presentation/reference-resource-form-page.tsx
index 3a5e4760..f6047e45 100644
--- a/src/features/reference-feature/presentation/reference-resource-form-page.tsx
+++ b/src/features/reference-feature/presentation/reference-resource-form-page.tsx
@@ -53,6 +53,12 @@ export default function ReferenceResourceFormPage() {
mutation.state.indicator === "mutation-effect-unknown";
const mutationBlocked =
mutationEffectUnknown || mutation.state.indicator === "mutation-pending";
+ // 1105/08-04. A save this form did not start holds the coordinator: one
+ // left running when the user came back to the form, or the check behind
+ // "confirm applied". The save button is off and, for the first, the
+ // feedback says a save is running, instead of a click that does nothing.
+ const otherSaveRunning =
+ mutation.state.indicator === "mutation-pending" && !form.pending;
const guard = useDirtyNavigationGuard(form.dirty && !form.pending);
return (
@@ -125,7 +131,7 @@ export default function ReferenceResourceFormPage() {
type="submit"
pending={form.pending}
pendingLabel={message("reference.form.saving")}
- disabled={mutationEffectUnknown}
+ disabled={mutationEffectUnknown || otherSaveRunning}
>
{message("reference.form.save")}
@@ -179,6 +185,10 @@ export default function ReferenceResourceFormPage() {
{message("reference.form.saved")}
) : form.result === "conflict" ? (
{message("reference.form.conflict")}
+ ) : otherSaveRunning && form.result !== "effect-unknown" ? (
+ // 1105/08-04. While this form's own unknown result is being
+ // checked, the result that follows is shown instead.
+
) : null
}
aside={
diff --git a/tests/features/reference-feature/reference-page.test.tsx b/tests/features/reference-feature/reference-page.test.tsx
index a5017ce7..744e5ce6 100644
--- a/tests/features/reference-feature/reference-page.test.tsx
+++ b/tests/features/reference-feature/reference-page.test.tsx
@@ -586,6 +586,64 @@ describe("reference feature page states", () => {
);
});
+ // 1105/08-04. A save left running when the user leaves and comes back
+ // still holds the coordinator. The remounted form says a save is running
+ // and keeps its save off, instead of a save button that does nothing.
+ it("says a save is running and keeps the save off after coming back during a save", async () => {
+ const user = userEvent.setup();
+ let release:
+ | ((result: ReferenceResult) => void)
+ | undefined;
+ const createResource = vi
+ .fn()
+ .mockImplementationOnce(
+ () =>
+ new Promise>((resolve) => {
+ release = resolve;
+ }),
+ )
+ .mockResolvedValue({
+ ok: true,
+ value: { resourceId: "created-2", title: "Second item", createdAt: null },
+ });
+ renderReference(
+ inputWith({ createResource }),
+ "/examples/reference-resources/new",
+ );
+ await user.type(
+ await screen.findByRole("textbox", { name: /새 항목 이름/ }),
+ "First item",
+ );
+ await user.click(screen.getByRole("button", { name: "저장" }));
+ await waitFor(() => expect(createResource).toHaveBeenCalledOnce());
+ await user.click(screen.getByRole("button", { name: "목록으로 돌아가기" }));
+ await waitFor(() =>
+ expect(window.location.pathname).toBe("/examples/reference-resources"),
+ );
+ window.history.pushState({}, "", "/examples/reference-resources/new");
+ window.dispatchEvent(new PopStateEvent("popstate"));
+ await user.type(
+ await screen.findByRole("textbox", { name: /새 항목 이름/ }),
+ "Second item",
+ );
+
+ expect(await screen.findByText("변경 사항을 저장하고 있습니다.")).toBeVisible();
+ expect(screen.getByRole("button", { name: "저장" })).toBeDisabled();
+
+ release?.({
+ ok: true,
+ value: { resourceId: "created-1", title: "First item", createdAt: null },
+ });
+ await waitFor(() =>
+ expect(screen.getByRole("button", { name: "저장" })).toBeEnabled(),
+ );
+ expect(screen.queryByText("변경 사항을 저장하고 있습니다.")).not.toBeInTheDocument();
+ await user.click(screen.getByRole("button", { name: "저장" }));
+
+ expect(await screen.findByText("저장했습니다.")).toBeVisible();
+ expect(createResource).toHaveBeenCalledTimes(2);
+ });
+
// 0929/08-04. The ids a user quotes to support reach the screens that
// need them, and the sample status page shows no made-up reference.
it("shows the request id of an unknown create next to its result", async () => {
diff --git a/tests/unit/create-feature.test.ts b/tests/unit/create-feature.test.ts
index d28042fe..51e50a56 100644
--- a/tests/unit/create-feature.test.ts
+++ b/tests/unit/create-feature.test.ts
@@ -265,6 +265,23 @@ describe("create:feature --with-create", () => {
expect(contribution).toContain('refusedBeforeWrite: Object.freeze(["INVOICE_INVALID"]),');
});
+ // 1105/08-04. Like the reference form: while a save this page did not
+ // start holds the coordinator, the save is off and the feedback says a
+ // save is running, instead of a save button that does nothing.
+ it("keeps the create's save off and says so while another save of it runs", () => {
+ const page =
+ plan({ id: "invoice-feature", write: "NEVER" }).files.get(
+ "src/features/invoice-feature/presentation/invoice-create-page.tsx",
+ ) ?? "";
+
+ expect(page).toContain(
+ 'const otherSaveRunning = mutation.state.indicator === "mutation-pending" && !form.pending;',
+ );
+ expect(page).toContain("disabled={effectUnknown || otherSaveRunning}");
+ expect(page).toContain('otherSaveRunning && form.result !== "effect-unknown" ? (');
+ expect(page).toContain("");
+ });
+
// 1103/16-07. A backend create made KEYED (IdempotencyExecutor) takes these.
it("writes the KEYED values for a backend create made KEYED", () => {
const { files } = plan({ id: "invoice-feature", write: "KEYED" });