fix(forms): 다른 저장이 진행 중이면 저장 버튼을 끄고 진행 문구를 보인다
문제
1103/08-02 수정(2d5d41f8)이 저장 버튼을 disabled 대신 pending으로 바꾸면서
버튼은 결과 불명일 때만 꺼진다. 코디네이터가 mutation-pending이어도 이 폼이
저장 중이 아닐 수 있다. 저장 중에 화면을 떠났다가 같은 세션에서 돌아온 경우
(진행 중 시도가 있는 동안 채널이 남는다)와 "변경됨으로 확인"을 처리하는
동안이다. 그때 onSubmit은 아무것도 하지 않고 돌아가고 feedback에도 아무것도
없다. 저장을 눌러도 반응이 없고, 첫 저장이 끝난 뒤에도 그 클릭은 실행되지
않는다(리뷰 08-R1 D). 참조 폼과 생성기 템플릿이 같다.
고른 방법
"코디네이터가 mutation-pending인데 이 폼은 저장 중이 아님"을 otherSaveRunning으로
두고 두 가지를 함께 한다.
- 저장 버튼을 그동안 끈다. 이 폼 자신의 저장 중에는 지금처럼 끄지 않고 busy로
둔다(포커스 유지, 1103/08-02). 그때 포커스는 저장 버튼에 있지 않다(다시
마운트한 폼이거나, 누른 버튼은 "변경됨으로 확인"이다).
- feedback에 코디네이터 상태를 AsyncSurface로 그려 "변경 사항을 저장하고
있습니다."를 보인다. 이 폼의 결과 불명을 확인하는 동안(결과가 effect-unknown)은
그리지 않는다. 확인이 끝나면 곧 결과가 바뀌고, 그 사이에 상태 문구가 하나 더
생기지 않게 한다.
참조 폼 페이지와 create:feature 쓰기 슬라이스 템플릿을 같이 고쳤다.
버린 대안
문구만 보이고 버튼은 켜 둔다(리뷰 문서가 포커스 때문에 권한 쪽): 확인 중에는
문구를 그릴 수 없어(위) 그때 버튼이 다시 무반응이 된다. 끄는 버튼에 포커스가
없으므로 포커스를 잃지 않는다.
위험·한계
- 생성기 쪽은 생성 결과 문자열만 단위 테스트가 본다. 다시 마운트하는 동작은
참조 폼 테스트로만 확인한다. 생성 기능의 기존 테스트는 test:feature-scaffold
(FE-GATE-020)와 test:sample-removal에서 돈다.
- 다른 탭이나 새로고침은 해당 없다(코디네이터는 앱 메모리 안이다).
검증
desktop batch에서 확인:
node scripts/run-vitest.ts run tests/features/reference-feature/reference-page.test.tsx
tests/unit/create-feature.test.ts
Refs: 1105/08-04
This commit is contained in:
@@ -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")}
|
||||
</Button>
|
||||
@@ -718,6 +722,8 @@ export default function ${pascal}CreatePage() {
|
||||
void form.resendUnknown(async () => openSaved(await mutation.resendUnknownEffect()));
|
||||
}}
|
||||
/>
|
||||
) : otherSaveRunning && form.result !== "effect-unknown" ? (
|
||||
<AsyncSurface state={mutation.state} />
|
||||
) : null
|
||||
}
|
||||
guard={<DirtyNavigationDialog guard={guard} />}
|
||||
|
||||
@@ -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")}
|
||||
</Button>
|
||||
@@ -179,6 +185,10 @@ export default function ReferenceResourceFormPage() {
|
||||
<p role="status">{message("reference.form.saved")}</p>
|
||||
) : form.result === "conflict" ? (
|
||||
<p role="status">{message("reference.form.conflict")}</p>
|
||||
) : 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.
|
||||
<AsyncSurface state={mutation.state} />
|
||||
) : null
|
||||
}
|
||||
aside={
|
||||
|
||||
@@ -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<ReferenceResourceView>) => void)
|
||||
| undefined;
|
||||
const createResource = vi
|
||||
.fn<ReferenceFeatureInput["createResource"]>()
|
||||
.mockImplementationOnce(
|
||||
() =>
|
||||
new Promise<ReferenceResult<ReferenceResourceView>>((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 () => {
|
||||
|
||||
@@ -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("<AsyncSurface state={mutation.state} />");
|
||||
});
|
||||
|
||||
// 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" });
|
||||
|
||||
Reference in New Issue
Block a user