feat(editor): prevent double-save and handle version conflicts#815
Conversation
WalkthroughThis PR introduces ETag-based optimistic concurrency control to the record editor while simultaneously configuring the ng-core-tester application to run in zoneless mode. The RecordService gains two new methods: Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@projects/rero/ng-core/src/lib/record/service/record/record.service.ts`:
- Around line 169-172: The mapping step currently casts response.body as T
without handling null; update the pipe map so it guards against
HttpResponse<T>.body being null by checking response.body and either (a)
returning a safe default (e.g., an empty object cast to T) for the "data" field
or (b) throwing a clear error that will be handled by _handleError; modify the
map that produces ({ data: response.body as T, etag: ... }) to first test
response.body and act accordingly so downstream code using the resulting data
cannot receive null unexpectedly.
- Around line 218-221: The If-Match header is only set when etag is truthy, so
empty-string ETag values are skipped; update the logic in RecordService.update
(the block that builds HttpHeaders where headers is set and checked with if
(etag)) to check for null/undefined instead (e.g., if (etag != null) or explicit
!== null/!== undefined) so an empty-string ETag is sent to the server and
optimistic concurrency works per RFC 9110.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: d7ecd4b3-ce29-4854-ac63-5ab275947033
📒 Files selected for processing (8)
angular.jsonprojects/ng-core-tester/src/environments/environment.tsprojects/ng-core-tester/src/polyfills.tsprojects/ng-core-tester/tsconfig.app.jsonprojects/rero/ng-core/src/lib/record/editor/component/editor/editor.component.htmlprojects/rero/ng-core/src/lib/record/editor/component/editor/editor.component.tsprojects/rero/ng-core/src/lib/record/service/record-handle-error/record-handle-error.service.tsprojects/rero/ng-core/src/lib/record/service/record/record.service.ts
💤 Files with no reviewable changes (3)
- projects/ng-core-tester/src/polyfills.ts
- angular.json
- projects/ng-core-tester/src/environments/environment.ts
fca60ad to
d264d63
Compare
- Guard submit() against re-entry while save is in progress - Disable save button visually during save - Add getRecordWithEtag() to retrieve ETag header; getRecord() delegates to it - Send If-Match header on PUT for optimistic concurrency control - Show specific warning flash message on 409/412 (record modified, reload needed) - Preserve 409/412 status codes in RecordHandleErrorService - Remove polyfills.ts (no longer needed without Zone.js) Co-Authored-By: Johnny Mariéthoz <johnny.mariethoz@rero.ch>
Co-Authored-By: Bertrand Zuchuat bertrand.zuchuat@rero.ch
Co-Authored-By: Johnny Mariéthoz johnny.mariethoz@rero.ch