-
Notifications
You must be signed in to change notification settings - Fork 61
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
fix(application-system): Error on removing uploaded documents #17233
base: main
Are you sure you want to change the base?
Conversation
When documents are chosen for uploading and then removed right after it was causing an error because of manipulating a read only property
Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 eslint
warning eslint@8.57.0: This version is no longer supported. Please see https://eslint.org/version-support for other options. WalkthroughThe changes in this pull request involve a modification to the Changes
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
Datadog ReportAll test runs ✅ 5 Total Test Services: 0 Failed, 5 Passed Test Services
🔻 Code Coverage Decreases vs Default Branch (1)
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (1)
libs/application/ui-fields/src/lib/FileUploadFormField/FileUploadFormField.tsx (1)
Line range hint
37-43
: LGTM! The fix addresses the read-only property mutation issue.The use of
structuredClone
effectively prevents mutation of the read-onlyapplication.answers
object.Consider adding fallback and error handling.
While the implementation is correct, consider these improvements for robustness:
- Add a fallback for browsers that don't support
structuredClone
- Add error handling for potential
structuredClone
exceptionsconst onFileRemoveWhenInAnswers = (fileToRemove: UploadFile) => { - const answers = structuredClone(application.answers) + let answers; + try { + answers = typeof structuredClone === 'function' + ? structuredClone(application.answers) + : JSON.parse(JSON.stringify(application.answers)); + } catch (error) { + console.error('Failed to clone answers:', error); + return; + } const updatedAnswers = set( answers, id, currentValue.filter((x: UploadFile) => x.key !== fileToRemove.key), ) answerQuestions?.({ ...application.answers, ...updatedAnswers, }) }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
libs/application/ui-fields/src/lib/FileUploadFormField/FileUploadFormField.tsx
(1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
libs/application/ui-fields/src/lib/FileUploadFormField/FileUploadFormField.tsx (1)
Pattern libs/**/*
: "Confirm that the code adheres to the following:
- Reusability of components and hooks across different NextJS apps.
- TypeScript usage for defining props and exporting types.
- Effective tree-shaking and bundling practices."
🔇 Additional comments (1)
libs/application/ui-fields/src/lib/FileUploadFormField/FileUploadFormField.tsx (1)
Line range hint 1-89
: Coding guidelines compliance confirmed.
The component implementation follows best practices:
- Properly typed with TypeScript
- Designed for reusability across NextJS apps
- Uses named exports for better tree-shaking
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #17233 +/- ##
==========================================
- Coverage 35.74% 35.74% -0.01%
==========================================
Files 6937 6937
Lines 148171 148172 +1
Branches 42253 42253
==========================================
Hits 52969 52969
- Misses 95202 95203 +1
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
|
When documents are chosen for uploading and then removed right after it was causing an error because of trying to manipulate a read only property
...
Attach a link to issue if relevant
What
Specify what you're trying to achieve
Why
Specify why you need to achieve this
Screenshots / Gifs
Screen.Recording.2024-12-22.at.15.04.48.mov
Checklist:
Summary by CodeRabbit
Bug Fixes
Refactor