Skip to content
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

Wizard: Refactor hostname and blueprint name inputs (HMS-5616) #2872

Merged
merged 1 commit into from
Mar 11, 2025

Conversation

mgold1234
Copy link
Collaborator

@mgold1234 mgold1234 commented Feb 10, 2025

This commit Implement refactor of HookValidatedInput for hostname and blueprint name
fields, addressing the following bugs:

  1. Fixes a bug where the validation symbol persisted after a user deleted the value in the hostname field.
  2. Fixes a bug where the validation symbol persisted after a user deleted the value in the blueprint name field.

These changes improve code maintainability and provide a more consistent user experience.
FIX ISSUE: 2917, #2971
JIRA: HMS-5616

Copy link

codecov bot commented Feb 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.91%. Comparing base (1d39a57) to head (0296174).
Report is 1 commits behind head on main.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2872   +/-   ##
=======================================
  Coverage   81.91%   81.91%           
=======================================
  Files         209      209           
  Lines       23570    23577    +7     
  Branches     2330     2333    +3     
=======================================
+ Hits        19307    19314    +7     
  Misses       4234     4234           
  Partials       29       29           
Files with missing lines Coverage Δ
...rc/Components/CreateImageWizard/ValidatedInput.tsx 90.41% <100.00%> (+0.27%) ⬆️
...mponents/CreateImageWizard/steps/Details/index.tsx 100.00% <100.00%> (ø)
...Wizard/steps/Hostname/components/HostnameInput.tsx 100.00% <100.00%> (ø)
...ents/CreateImageWizard/utilities/useValidation.tsx 83.68% <100.00%> (+0.04%) ⬆️

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1d39a57...0296174. Read the comment docs.

🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Collaborator

@lucasgarfield lucasgarfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch, the validation should not appear when there is no hostname.

I’m not sure about the approach, though. In this PR we’re hiding the validation by returning an error object with a fieldname of ‘default’. That technically works and is supported by the HookValidatedInput but it just feels kind of surprising/counter-intuitive.

I think it feels counter-intuitive because <HookValidatedInput> does not surface validation on pristine state components. So there is already an existing pattern for not displaying validation – that’s what I intuitively would expect to use. In other words, set isPristine to true when the field’s value returns to the default state (in this case, ‘’).

This might be a good opportunity to refactor a little bit. The double nested ternary operator is hard to understand. It definitely does support this ‘feature’ where if the fieldName is ‘default’ then but let’s take a step back and ask… should it? Maybe we can get rid of the nested ternary and the concept of a ‘default’ state. Having to manage both ‘default’ and ‘isPristine’ feels duplicitous.

In all the validation hooks, it only seems to be used in one other place, and there is a comment specifically calling it out as a hacky solution…
image

Therefore, I am a little hesitant to introduce this new pattern to the code base. I’d prefer refactoring a bit. What do you think?

@mgold1234
Copy link
Collaborator Author

after some investigation, the solution that I did here https://github.com/osbuild/image-builder-frontend/pull/2844/files#diff-5206f54a601e8c56290e1a412fbf3f35172f16b892c7674852c91b4ea846bcd9R62
will fix that problem, so I can close this pr

@mgold1234 mgold1234 closed this Feb 11, 2025
@mgold1234 mgold1234 reopened this Feb 11, 2025
@mgold1234
Copy link
Collaborator Author

I saw your comment here #2844
so reopen this pr and refactor the code now

@mgold1234 mgold1234 force-pushed the hostname branch 5 times, most recently from 7f3c4c0 to 32f8bba Compare February 11, 2025 13:51
@mgold1234 mgold1234 force-pushed the hostname branch 8 times, most recently from d861369 to 61d3608 Compare February 18, 2025 09:47
@mgold1234 mgold1234 requested a review from regexowl February 19, 2025 12:49
@regexowl
Copy link
Collaborator

regexowl commented Feb 20, 2025

One small bug in FSC - the input doesn't get validated without a value
image

this is how the error for invalid value looks like:
image

There's also the same problem with Blueprint name which should be required:
image

@mgold1234 mgold1234 force-pushed the hostname branch 2 times, most recently from a5d24be to 631ddf5 Compare February 20, 2025 11:34
@mgold1234
Copy link
Collaborator Author

mgold1234 commented Feb 20, 2025

nice catch @regexowl , I am looking at stage, if user delete the value in Blueprint name we should see an error be cecause it's mandatory field, am I wrong?
I fixed the FSC respectivally

Copy link
Collaborator

@lucasgarfield lucasgarfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be rebased on top of #2922?

@mgold1234 mgold1234 force-pushed the hostname branch 3 times, most recently from 432e6a3 to 1691115 Compare March 5, 2025 20:51
@mgold1234 mgold1234 marked this pull request as draft March 5, 2025 20:52
@mgold1234 mgold1234 force-pushed the hostname branch 2 times, most recently from 72d375a to 8092a84 Compare March 6, 2025 11:40
@mgold1234
Copy link
Collaborator Author

/jira-epic HMS-5294

@schutzbot schutzbot changed the title Wizrad: add condition to useHostnameValidation in case of empty string Wizrad: add condition to useHostnameValidation in case of empty string (HMS-5616) Mar 6, 2025
@mgold1234 mgold1234 force-pushed the hostname branch 2 times, most recently from 3c1248a to a6005d8 Compare March 6, 2025 11:44
@mgold1234 mgold1234 changed the title Wizrad: add condition to useHostnameValidation in case of empty string (HMS-5616) Wizard: Refactor hostname and blueprint name inputs (HMS-5616) Mar 6, 2025
@mgold1234 mgold1234 force-pushed the hostname branch 3 times, most recently from afd4c5e to 3d83f3b Compare March 6, 2025 12:01
@mgold1234 mgold1234 marked this pull request as ready for review March 6, 2025 12:41
@mgold1234 mgold1234 force-pushed the hostname branch 3 times, most recently from db2394a to 4020dcf Compare March 9, 2025 13:52
@mgold1234 mgold1234 requested a review from lucasgarfield March 9, 2025 14:49
This commit Implement refactor of HookValidatedInput for hostname and blueprint name
fields, addressing the following bugs:

1) Fixes a bug where the validation symbol persisted after a user deleted the value in the hostname field.
2) Fixes a bug where the validation symbol persisted after a user deleted the value in the blueprint name field.

These changes improve code maintainability and provide a more consistent user experience.
Copy link
Collaborator

@regexowl regexowl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you! ✨ And the blueprint name bug is a really nice catch! 🐛

@lucasgarfield lucasgarfield dismissed their stale review March 11, 2025 19:36

Dismissed, reviewed by @regexowl.

@lucasgarfield lucasgarfield merged commit 12aa5cd into osbuild:main Mar 11, 2025
19 of 22 checks passed
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.

3 participants