-
Notifications
You must be signed in to change notification settings - Fork 35
fix(Form): Avoid stale value in StringField #2300
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
Conversation
**Summary of changes:** - Introduced and updated logic for form field actions, particularly for handling "RAW" value wrapping in fields. - Refactored the PasswordField and StringField components to support toggling RAW wrapping, improved error handling, and added test coverage for these features. - Extracted isRawString function to add unit tests. - Simplified `useFieldValue` hook logic. fix: KaotoIO#2295 fix: KaotoIO#2296
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.
Pull Request Overview
This PR fixes an issue in the StringField component where stale values persisted by ensuring that field values (including their RAW wrapping) update correctly.
- Introduced a new utility (isRawString) with unit tests.
- Refactored the useFieldValue hook to simplify value and RAW state management.
- Updated the StringField and PasswordField components (and corresponding tests) to support toggling RAW wrapping and improved clear functionality.
Reviewed Changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
File | Description |
---|---|
packages/ui/src/utils/is-raw-string.ts | Added a new utility function to detect RAW-wrapped strings. |
packages/ui/src/utils/is-raw-string.test.ts | Added tests for the isRawString utility. |
packages/ui/src/utils/index.ts | Exported the new isRawString utility. |
packages/ui/src/components/Visualization/Canvas/FormV2/hooks/field-value.ts | Simplified useFieldValue hook by removing the wrapValueWithRaw method and integrating RAW state updates into onChange. |
packages/ui/src/components/Visualization/Canvas/FormV2/hooks/field-value.test.tsx | Updated tests to reflect changes in the hook implementation. |
packages/ui/src/components/Visualization/Canvas/FormV2/fields/StringField.tsx | Refactored to allow additional utility components and added support for toggling raw wrapping using the new hook behavior. |
packages/ui/src/components/Visualization/Canvas/FormV2/fields/StringField.test.tsx | Added tests for additional utility and onRemove functionality. |
packages/ui/src/components/Visualization/Canvas/FormV2/fields/PasswordField.tsx | Updated similar to StringField, ensuring proper toggle and clear behavior for RAW values. |
packages/ui/src/components/Visualization/Canvas/FormV2/fields/PasswordField.test.tsx | Added tests for onRemove and error display in PasswordField. |
packages/ui/src/components/Visualization/Canvas/FormV2/fields/FieldActions.tsx | Updated FieldActions to use the passed toggleRawValueWrap function and include appropriate aria-labels and titles. |
packages/ui/src/components/Visualization/Canvas/FormV2/fields/FieldActions.test.tsx | Added/updated tests to validate FieldActions behavior including the RAW toggle functionality. |
onPropertyChange(propertyName, value); | ||
setIsRaw(checkIfWrappedWithRaw(value)); | ||
}; | ||
const [isRaw, setIsRaw] = useState<boolean>(isRawString(value)); |
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.
Consider adding a useEffect to update the 'isRaw' state whenever the derived 'value' from the model changes, to prevent any potential state mismatch between external updates and the local hook state.
Copilot uses AI. Check for mistakes.
|
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.
reported problems seem to be gone.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #2300 +/- ##
============================================
+ Coverage 82.53% 82.55% +0.02%
Complexity 468 468
============================================
Files 530 531 +1
Lines 17150 17161 +11
Branches 3587 3567 -20
============================================
+ Hits 14155 14168 +13
+ Misses 2912 2739 -173
- Partials 83 254 +171 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Context
While handling #1653, the update caused the
StringField
to keep stale values because of how thevalue
was handled in theuseFieldValue
hook.Fix
The fix is to keep the
value
updated by theStringField
in case of addingRAW()
or cleaning the property altogether. This allows React to rerender theStringField
component, avoiding stale data.Changes
isRawString
function to add unit tests.useFieldValue
hook logic.fix: #2295
fix: #2296