Skip to content

fix: 編集で任意項目を空にできるようにする - #44

Merged
hduehgw0 merged 1 commit into
mainfrom
feature/#43/edit-clear-optional
Jul 23, 2026
Merged

fix: 編集で任意項目を空にできるようにする#44
hduehgw0 merged 1 commit into
mainfrom
feature/#43/edit-clear-optional

Conversation

@hduehgw0

@hduehgw0 hduehgw0 commented Jul 23, 2026

Copy link
Copy Markdown
Owner

関連 issue

resolve #43

やったこと

概要

編集で任意項目を空にしても既存値を消せなかった問題を、「空欄を明示 null として end-to-end で運ぶ」ことで修正した。原因は「空欄→undefinedJSON.stringify でキー欠落→prisma.update は欠けたキーを更新しない」。

変更点

  • スキーマsrc/lib/schemas/bottle.ts):任意項目(regionsubRegionagecaskTypenote)を .optional().nullish()null を受理)。作成の「空→undefined→省略」挙動は不変(null を追加で許すだけ)
  • 編集フォームedit-bottle-form.tsx):
    • onSubmit で空欄の任意項目を明示 null に正規化して送信(undefined だと JSON から落ちて消せないため)
    • region に「未選択」項目を追加してクリア可能に。Radix は空文字 SelectItem を禁止するため、センチネル値("__none__")→ onValueChangenull に正規化(センチネルは送信データに出さない)。null のときは value ?? NONE で「未選択」項目を選択状態にする(レビュー指摘の UX 整合)
  • PATCH ルート:変更なし(bottleSchemanull を受理し parsed.dataupdateMany に渡すため、既存コードで null が保存される)
  • 作成フォームbottle-form.tsx):スキーマ nullish 化に伴う subRegion の value 型安全化(value={field.value ?? ""})。1 行・挙動不変

受け入れ条件(セルフチェック)

  • 全任意項目(ageregionsubRegioncaskTypenote)を空にして保存すると、その値が削除される(DB が null になる)
  • region を「未選択」に戻せる UI がある
  • PATCH が null 入りボディを受理し(400 にしない)、null を保存する
  • 回帰テスト:null を送ると updateManydatanull が渡り、対象が消える(複数の任意項目を null にした代表 1 本)

動作確認

  • pnpm lint が通る
  • pnpm test が通る(PATCH の null クリア回帰テストを追加。23 本)
  • pnpm build が通る
  • モバイル幅で表示が崩れない(要ローカル確認)
  • 手動:編集で年数・国・地域・樽・メモを空/未選択にして保存 → 消えることを確認(フォーム UI は E2E 領域のためユニット未実施)

Issue 要件外の対応(あれば)

  • 作成フォーム bottle-form.tsxsubRegion value を型安全化(1 行)。共有スキーマを nullish にした型的波及への追随で、挙動は変えていない。

備考

Summary by CodeRabbit

  • New Features

    • Added support for clearing optional bottle details by submitting empty fields.
    • Updated bottle forms to handle unselected regions and empty sub-regions consistently.
  • Bug Fixes

    • Fixed optional values such as age, region, cask type, and notes not being cleared when set to empty.
    • Improved validation for fields explicitly cleared with null.

@vercel

vercel Bot commented Jul 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
mycellar Ready Ready Preview, Comment Jul 23, 2026 8:43am

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Optional bottle fields now support clearing through explicit null values. The edit form maps empty fields and an unselected region to null, shared validation accepts those values, and API tests verify they reach the Prisma update payload.

Changes

Bottle field clearing

Layer / File(s) Summary
Nullable bottle input contract
src/lib/schemas/bottle.ts
Optional text, region, and age fields accept null or undefined, while empty text continues to normalize to undefined.
Edit-form null clearing flow
src/app/bottles/[id]/edit/edit-bottle-form.tsx, src/app/bottles/new/bottle-form.tsx, src/app/api/bottles/[id]/route.test.ts
The edit form sends empty optional fields as null, supports resetting region through a sentinel option, controls subRegion inputs, and verifies null values reach updateMany.

Estimated code review effort: 2 (Simple) | ~10 minutes

Sequence Diagram(s)

sequenceDiagram
  actor Editor
  participant EditBottleForm
  participant BottleSchema
  participant Prisma
  Editor->>EditBottleForm: Clear optional fields and submit
  EditBottleForm->>EditBottleForm: Convert empty values to null
  EditBottleForm->>BottleSchema: Send PATCH payload
  BottleSchema-->>EditBottleForm: Accept nullish optional fields
  EditBottleForm->>Prisma: Update bottle fields with null
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes satisfy #43 by sending null for optional edit fields, allowing region to be cleared, accepting null in PATCH, and adding a regression test.
Out of Scope Changes check ✅ Passed No clearly unrelated code changes stand out; the BottleForm type-safety tweak is a small supporting change tied to the schema update.
Title check ✅ Passed 編集フォームで任意項目を空にして保存できる修正を端的に表しており、変更内容と一致しています。
Description check ✅ Passed 関連issue、概要、変更点、セルフチェック、動作確認、備考までテンプレートの必須項目が概ね揃っています。
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/#43/edit-clear-optional

Comment @coderabbitai help to get the list of available commands.

@hduehgw0 hduehgw0 changed the title fix: 編集で任意項目を空にして削除できるようにする(空→null 契約) #43 fix: 編集で任意項目を空にできるようにする Jul 23, 2026
@hduehgw0

Copy link
Copy Markdown
Owner Author

Out of Scope Changes check: create-form subRegion value change

ご指摘ありがとうございます。解決策 (b)(スコープに属する理由の記載)で対応します。

bottle-form.tsxsubRegionvalue={field.value ?? ""} 追加は、共有スキーマ bottleSchemanullish() にした(本 #43 の層1)ことの必須の型的帰結です。subRegion の型が string | null | undefined に広がり、React の <Input value>null を受け付けないため、この 1 行が無いと tsc / build が失敗します。

そのため解決策 (a)(別 PR へ分離)は取れません。型エラーはその原因(スキーマ変更)と不可分で、分離すると本ブランチ単体がコンパイル不能になります。挙動は変えておらず(作成は従来どおり空→undefined→省略)、純粋な型安全化です。

この理由は PR 本文の「Issue 要件外の対応」にも記載済みです。以上より、本 PR のスコープ内の変更として維持します。

- bottleSchema の任意項目を nullish 化(null 受理。作成の空→undefined→省略は不変)
- 編集フォームは空欄を明示 null で送信し、region は「未選択」項目(センチネル→null)でクリア可能に
- 作成フォームの subRegion は nullish 化に伴う value の型安全化(挙動不変)
- PATCH で null が updateMany の data に渡り値が消える回帰テストを追加
@hduehgw0
hduehgw0 force-pushed the feature/#43/edit-clear-optional branch from 25f1090 to d9280be Compare July 23, 2026 08:42
@hduehgw0 hduehgw0 closed this Jul 23, 2026
@hduehgw0 hduehgw0 reopened this Jul 23, 2026
@hduehgw0
hduehgw0 merged commit 83ce8d5 into main Jul 23, 2026
4 of 5 checks passed
@hduehgw0
hduehgw0 deleted the feature/#43/edit-clear-optional branch July 23, 2026 08:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: 編集で任意項目を空にできるようにする

1 participant