Repository navigation
行変更の確定結果を操作単位で通知できるようにする #11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| ## Context | ||
|
|
||
| テーブルは非制御コンポーネントとして行データを内部に保持する。 | ||
|
|
||
| 現在の`onChange`第1引数は、編集基準から変更された行を返す。この情報は保存対象全体の取得には適しているが、今回の操作でどの状態からどの状態へ変わったかは表さない。 | ||
|
|
||
| 利用側が操作単位のAPI更新を作る場合、通知された行と比較するための行データをテーブルとは別に保持する必要がある。 | ||
|
|
||
| ## Goals / Non-Goals | ||
|
|
||
| ### Goals | ||
|
|
||
| - 利用側が行データを二重管理せず、操作直前と確定後の行を取得できるようにする。 | ||
| - 補正された複数項目を含む最終行を、1操作の結果として通知する。 | ||
| - 拒否された変更候補と元の行を、行番号から引き直さず取得できるようにする。 | ||
| - 既存の`onChange`利用側との互換性を保つ。 | ||
|
|
||
| ### Non-Goals | ||
|
|
||
| - APIリクエストや業務固有の更新イベントをライブラリ内で生成すること。 | ||
| - 非同期の行検証を追加すること。 | ||
| - 外部制御コンポーネントへ変更すること。 | ||
| - 累積変更を返す`getChangedRows()`の意味を変更すること。 | ||
|
|
||
| ## Decisions | ||
|
|
||
| ### 操作単位の確定通知を独立したコールバックとして追加する | ||
|
|
||
| `onChange`は編集基準からの累積変更を通知する既存APIとして維持する。 | ||
|
|
||
| 操作単位の確定結果は、新しい`onRowChangeCommitted`で通知する。 | ||
|
|
||
| 既存コールバックへ引数を追加すると、引数を厳密に検証する利用側のテストへ影響する可能性がある。独立したコールバックにすることで、既存`onChange`の型と実行時の呼び出しを変更しない。 | ||
|
|
||
| ```ts | ||
| type CommittedRowChange<T> = { | ||
| rowIndex: number | ||
| previousRow: T | ||
| row: T | ||
| changes: ReadonlyArray<CellChange<T>> | ||
| } | ||
|
|
||
| type RowChangeCommit<T> = { | ||
| source: 'edit' | 'paste' | ||
| rows: ReadonlyArray<CommittedRowChange<T>> | ||
| } | ||
|
|
||
| type RejectedRowChange<T> = { | ||
| rowIndex: number | ||
| previousRow: T | ||
| candidateRow: T | ||
| issues: ReadonlyArray<RowChangeIssue<T>> | ||
| } | ||
|
|
||
| type RowChangeRejection<T> = { | ||
| source: 'edit' | 'paste' | ||
| errors: ReadonlyArray<CellValidationError> | ||
| rows: ReadonlyArray<RejectedRowChange<T>> | ||
| } | ||
| ``` | ||
|
|
||
| 行オブジェクトはテーブルが保持するスナップショットとして渡し、利用側は読み取り専用として扱う。 | ||
|
|
||
| ### 変更トランザクションは操作直前のStoreから作る | ||
|
|
||
| 編集確定直前に`store.getRows()`を取得し、確定後の行と比較してトランザクションを組み立てる。 | ||
|
|
||
| これにより、`markAsSaved()`や編集基準からの累積変更に依存せず、今回の操作だけを表現できる。 | ||
|
|
||
| `processRowChange`が補正した項目も、確定前後で値が異なる場合は`changes`へ含める。 | ||
|
|
||
| ### 拒否トランザクションは行変更準備中に保持する | ||
|
|
||
| `prepareCellUpdates`は変更前の行、入力候補の行、`processRowChange`が返した拒否理由をすでに参照している。 | ||
|
|
||
| 拒否時にこの情報を破棄せず、セルエラーとともに`useSpreadSheetTable`へ返す。 | ||
|
|
||
| 複数行ペーストでは拒否された行をまとめ、ペースト全体が確定されなかったことを1回のコールバックで通知する。 | ||
|
|
||
| ## Risks / Trade-offs | ||
|
|
||
| - 行オブジェクトをコールバックへ追加するため、通知データ量が増える。 | ||
| 対象は1操作で影響を受けた行だけに限定する。 | ||
| - `onChange`の累積変更と`onRowChangeCommitted`の操作変更は意味が異なる。 | ||
| コールバック名、型名、APIドキュメント、例で区別を明記する。 | ||
| - 行オブジェクトはStoreのスナップショットであり、利用側が変更すると混乱を招く。 | ||
| 公開型を`readonly`とし、ライブラリ内ではイミュータブルに扱う。 | ||
|
|
||
| ## Migration Plan | ||
|
|
||
| 1. 公開型とテストを追加する。 | ||
| 2. 行変更準備処理から拒否コンテキストを返す。 | ||
| 3. 確定前後の行から変更トランザクションを作る。 | ||
| 4. 独立した確定コールバックと拒否コールバックから通知する。 | ||
| 5. ドキュメントと利用例を更新する。 | ||
|
|
||
| 既存の`onChange`を変更しないため、利用側の一括移行は不要である。 |
22 changes: 22 additions & 0 deletions
22
openspec/changes/add-change-transaction-context/proposal.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| # Change: 変更操作の行コンテキストを通知する | ||
|
|
||
| ## Why | ||
|
|
||
| `onChange`は編集基準からの累積変更行だけを通知するため、利用側が操作直前と確定後の行を比較するには、テーブル内部と同じ行データを別途保持する必要がある。 | ||
|
|
||
| `onRowChangeRejected`も行番号とセルエラーだけを通知するため、利用側は拒否された行の識別情報を自前の行データから引き直している。 | ||
|
|
||
| テーブルがすでに保持している操作単位の行コンテキストを公開し、利用側による状態の二重管理を不要にする。 | ||
|
|
||
| ## What Changes | ||
|
|
||
| - `onRowChangeCommitted`を追加し、操作種別と確定前後の行を操作単位で通知する。 | ||
| - `onRowChangeRejected`は、操作種別、セルエラー、変更前の行、変更候補の行、拒否理由を一つのオブジェクトで通知する。 | ||
| - 単一セル編集と複数セルペーストのどちらも、1操作につき1トランザクションを通知する。 | ||
| - 既存の`onChange`の型と呼び出し方は変更せず、既存利用側との互換性を保つ。 | ||
|
|
||
| ## Impact | ||
|
|
||
| - Affected specs: `table-api` | ||
| - Affected code: public types、行変更準備、`useSpreadSheetTable`、APIドキュメント | ||
| - Consumer impact: 既存の`onChange`利用側は変更不要。操作単位の前後行が必要な利用側だけ新しいコールバックを使用する。 |
69 changes: 69 additions & 0 deletions
69
openspec/changes/add-change-transaction-context/specs/table-api/spec.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| ## ADDED Requirements | ||
|
|
||
| ### Requirement: Row Change Commit Notification | ||
|
|
||
| テーブルは、単一セル編集またはペーストによる変更を確定した際、`onRowChangeCommitted`へ今回の操作で確定した行変更を通知しなければならない(MUST)。 | ||
|
|
||
| 確定通知は操作種別、および影響を受けた各行の変更前の行、確定後の行、セル単位の変更詳細を含まなければならない(MUST)。 | ||
|
|
||
| 既存の`onChange`の型と呼び出し方を変更してはならない(MUST NOT)。 | ||
|
|
||
| ```typescript | ||
| type RowChangeCommit<T> = { | ||
| source: 'edit' | 'paste' | ||
| rows: ReadonlyArray<{ | ||
| rowIndex: number | ||
| previousRow: T | ||
| row: T | ||
| changes: ReadonlyArray<{ | ||
| key: keyof T | ||
| previousValue: T[keyof T] | ||
| newValue: T[keyof T] | ||
| }> | ||
| }> | ||
| } | ||
| ``` | ||
|
|
||
| #### Scenario: Single cell edit notification | ||
|
|
||
| - **WHEN** ユーザーが1つのセルを編集する | ||
| - **THEN** `onRowChangeCommitted`が1回だけ呼ばれる | ||
| - **AND** 操作種別`edit`と変更前後の行が渡される | ||
| - **AND** `changes`に今回変更したセルの変更前後の値が含まれる | ||
|
|
||
| #### Scenario: Normalized row notification | ||
|
|
||
| - **GIVEN** `processRowChange`が同じ行の別項目を補正する | ||
| - **WHEN** ユーザーがセル編集を確定する | ||
| - **THEN** 確定後の行に補正済みの値が含まれる | ||
| - **AND** `changes`に入力項目と補正項目が含まれる | ||
|
|
||
| #### Scenario: Bulk paste notification | ||
|
|
||
| - **WHEN** ユーザーが3行分のデータをペーストする | ||
| - **THEN** `onRowChangeCommitted`は1回だけ呼ばれる | ||
| - **AND** 操作種別は`paste`である | ||
| - **AND** 影響を受けた3行の変更前後の行が含まれる | ||
|
|
||
| #### Scenario: Existing onChange compatibility | ||
|
|
||
| - **GIVEN** 利用側が既存の`onChange`だけを指定している | ||
| - **WHEN** ユーザーがセルを編集する | ||
| - **THEN** `onChange`は従来と同じ1引数で呼ばれる | ||
|
|
||
| ### Requirement: Row Change Rejection Context | ||
|
|
||
| `processRowChange`が行変更を拒否した場合、`onRowChangeRejected`は操作種別、セルエラー、および拒否された各行の変更前の行、変更候補の行、拒否理由を一つの拒否オブジェクトとして通知しなければならない(MUST)。 | ||
|
|
||
| #### Scenario: Rejected single edit context | ||
|
|
||
| - **WHEN** `processRowChange`が単一セル編集を拒否する | ||
| - **THEN** `onRowChangeRejected`が1回だけ呼ばれる | ||
| - **AND** 操作種別`edit`、セルエラー、変更前の行、変更候補の行、拒否理由が渡される | ||
|
|
||
| #### Scenario: Rejected atomic paste context | ||
|
|
||
| - **WHEN** 複数行ペーストの一部を`processRowChange`が拒否する | ||
| - **THEN** ペースト全体は確定されない | ||
| - **AND** `onRowChangeRejected`は1回だけ呼ばれる | ||
| - **AND** 拒否された各行の変更前の行、変更候補の行、拒否理由が含まれる |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| ## 1. Implementation | ||
|
|
||
| - [x] 1.1 単一編集の変更トランザクションをテストで固定する。 | ||
| - [x] 1.2 補正された複数項目と複数行ペーストのトランザクションをテストで固定する。 | ||
| - [x] 1.3 拒否トランザクションへ変更前の行と候補行が含まれることをテストで固定する。 | ||
| - [x] 1.4 公開型へ変更トランザクションと拒否トランザクションを追加する。 | ||
| - [x] 1.5 `useSpreadSheetTable`から独立した確定コールバックと拒否コールバックを通知する。 | ||
| - [x] 1.6 APIドキュメントと利用例を更新する。 | ||
| - [x] 1.7 typecheck、lint、test、buildを実行する。 | ||
|
|
||
| ## 2. Consumer Verification | ||
|
|
||
| - [x] 2.1 利用側が行データの比較用コピーを保持せず、変更トランザクションからAPI更新を作れることを確認する。 | ||
| - [x] 2.2 利用側が拒否された行を行番号から引き直さず、検証エラーへ変換できることを確認する。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.