Skip to content

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

Merged
merged 1 commit into from
May 26, 2025

Conversation

lordrip
Copy link
Member

@lordrip lordrip commented May 26, 2025

Context

While handling #1653, the update caused the StringField to keep stale values because of how the value was handled in the useFieldValue hook.

Fix

The fix is to keep the value updated by the StringField in case of adding RAW() or cleaning the property altogether. This allows React to rerender the StringField component, avoiding stale data.

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: #2295
fix: #2296

**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
@lordrip lordrip requested review from Copilot and a team May 26, 2025 11:43
Copy link
Contributor

@Copilot Copilot AI left a 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));
Copy link
Preview

Copilot AI May 26, 2025

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.

Copy link

sonarqubecloud bot commented May 26, 2025

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

Copy link
Contributor

@lhein lhein left a 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.

Copy link

codecov bot commented May 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.55%. Comparing base (c32457b) to head (dfeaa16).
Report is 2 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@lordrip lordrip merged commit bf0b08e into KaotoIO:main May 26, 2025
13 checks passed
@lordrip lordrip deleted the fix/clear-field branch May 26, 2025 12:23
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.

Raw action is not applied to the field directly Clear action on field is not clearing the field itself
2 participants