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

fix: create errors orders and fix translations #4202

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Nortsova
Copy link
Contributor

@Nortsova Nortsova commented Jan 28, 2025

Description

  • Validation warnings should appear in the same order as the fields on the form (e.g., Title, From, Recipient, Amount, Decision Method) to ensure consistency and clarity.
  • Each warning message should begin with a capital letter for consistency and readability.
  • The pointer cursor should appear when hovering over elements.

cursor-pointer

Testing

Step 1. Install voting reputation
Step 2. Install staged payments
Step 3. Open all action forms one by one and submit it to trigger validation
Step 4. Ensure that all form errors are consistent and shows in the same order as inputs

image image image image image image image

Step 5. Test that cursor pointer appears over the input labels:

cursor-pointer

Diffs

New stuff

  • InputsOrderContext to track in what order input was rendered

Changes 🏗

  • Decision method field changed from defined() to required() to implement custom translations

Resolves #3737
Resolves #3743

@Nortsova Nortsova self-assigned this Jan 28, 2025
@Nortsova Nortsova requested a review from a team as a code owner January 28, 2025 21:51
@Nortsova Nortsova marked this pull request as draft January 28, 2025 21:51
@Nortsova Nortsova force-pushed the fix/3737-update-form-order-and-translations branch from 0a51101 to 63cbde7 Compare January 29, 2025 10:17
@Nortsova Nortsova marked this pull request as ready for review January 29, 2025 10:31
@Nortsova Nortsova changed the title [WIP]: fix: create errors orders and fix translations fix: create errors orders and fix translations Jan 29, 2025
mmioana
mmioana previously approved these changes Jan 30, 2025
Copy link
Contributor

@mmioana mmioana left a comment

Choose a reason for hiding this comment

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

Really nice work @Nortsova 🥇 Thanks for fixing up the missing translations, it was something that was bugging me too for some time 😅

From what I've tested all error messages are now showing up in the right order thanks to your solution of using the context for registering the inputs order 🌟

Spam of screenshots on the way
Screenshot 2025-01-30 at 10 01 50
Screenshot 2025-01-30 at 10 05 10
Screenshot 2025-01-30 at 10 06 01
Screenshot 2025-01-30 at 10 06 18
Screenshot 2025-01-30 at 10 07 06
Screenshot 2025-01-30 at 10 07 21
Screenshot 2025-01-30 at 10 07 28
Screenshot 2025-01-30 at 10 07 35
Screenshot 2025-01-30 at 10 07 54
Screenshot 2025-01-30 at 10 08 12
Screenshot 2025-01-30 at 10 08 35
Screenshot 2025-01-30 at 10 08 47
Screenshot 2025-01-30 at 10 08 55
Screenshot 2025-01-30 at 10 09 09
Screenshot 2025-01-30 at 10 09 17
Screenshot 2025-01-30 at 10 09 59
Screenshot 2025-01-30 at 10 11 06

And the input field descriptions also had a tooltip

Screen.Recording.2025-01-30.at.10.10.34.mov

Left a few refactoring comments, but nothing to block the merging of this PR, amazing work! 💯

src/i18n/en.json Outdated
"errors.reputation.smite.notEnoughPoints": "Amount of reputation to remove is greater than the current reputation.",
"errors.recipient.required": "Recipient is required",
"errors.recipient.requiredIn": "Recipient is required in {paymentIndex, selectordinal, one {#st} two {#nd} few {#rd} other {#th}} payment.",
"errors.percent.required": "Percent is required in {paymentIndex, selectordinal, one {#st} two {#nd} few {#rd} other {#th}} payment.",
"errors.recipient.requiredIn": "Recipient is required in {paymentIndex, selectordinal, one {#st} two {#nd} few {#rd} other {#th}} payment",
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rename this to errors.recipient.requiredInPayment for more clarity?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is a really nice solution! 🌟

Comment on lines 20 to 31
const { inputsOrder } = useInputsOrderContext();

const sortedFlatFormErrors = flatFormErrors.sort((a, b) => {
const aIndex = inputsOrder.findIndex((fieldName) => a.key === fieldName);
const bIndex = inputsOrder.findIndex((fieldName) => b.key === fieldName);

if (aIndex === -1 && bIndex === -1) return 0;
if (aIndex === -1) return 1;
if (bIndex === -1) return -1;

return aIndex - bIndex;
});
Copy link
Contributor

Choose a reason for hiding this comment

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

As an improvement, we could create a Map for the inputsOrder to store the fieldName and the current index. This will help reduce repeated lookups through the inputsOrder to find the index of a given field. In the sort function, if the fieldName doesn't exist in the map, we can fallback to Infinity and should still get the expected result.

  const orderMap = new Map<string, number>(
    inputsOrder.map((fieldName, index) => [fieldName, index]),
  );

  const sortedFlatFormErrors = flatFormErrors.sort((a, b) => {
    const aIndex = orderMap.get(a.key.toString()) ?? Infinity;
    const bIndex = orderMap.get(b.key.toString()) ?? Infinity;

    return aIndex - bIndex;
  });

This is more of a suggestion, so let me know what you think about it @Nortsova 🙌

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point! thank you :)

@Nortsova Nortsova force-pushed the fix/3737-update-form-order-and-translations branch from 3b8e652 to fcc4630 Compare January 30, 2025 21:34
iamsamgibbs
iamsamgibbs previously approved these changes Jan 31, 2025
Copy link
Contributor

@iamsamgibbs iamsamgibbs left a comment

Choose a reason for hiding this comment

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

Nice job! I like this solution! Approving as it does resolve the original issue, I've got a few observations I'll leave but they're not necessarily directly related so feel free to decide if you think they are worth tackling here.

The biggest simple change that stood out to me is that all the fields have popovers now except for "Action type" and the "Token" field on the unlock token action. It would be nice to add those just for the sake of consistency.

I was able to get some wrong invalid errors showing. This only happens if you have the form open on "Staged payments" then switch to "Create agreement" and submit the form. If you directly open "Create agreement" via the sidebar, or select it after another action it isn't an issue.

Screenshot 2025-01-31 at 09 33 05

Also on the create agreement form, "description" is a required field but the placeholder does not go red when submitting.

And lastly there is a little inconsistency with the "Member" field on the "Manage reputation" form. The field is disabled so when the form is submitted, the label stays greyed out whilst the select changes to red. I think the intended behaviour here is for the select to also stayed greyed out whilst it is disabled.

Screenshot 2025-01-31 at 09 36 04

Nice job resolving the error order issue though, not a straightforward issue to solve!

Copy link
Member

@rdig rdig left a comment

Choose a reason for hiding this comment

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

Very nice work cleaning this up. I've tested all that I could, with most of them working. The only two that I had problems with are Split Payments and Manage Verified Members (details below)

Working:

  1. Simple Payment Screenshot from 2025-01-31 14-28-12
  2. Advanced Payments image
  3. Staged Payments image
  4. Transfer funds image
  5. Mint Tokens image
  6. Unlock Tokens image
  7. Manage Tokens image
  8. Create new domain image
  9. Edit an existing domain image
  10. Manage reputation image
  11. Manage permissions image
  12. Arbitrary TX image
  13. Edit Colony image
  14. Create agreement image

Not working

  1. Split payment has recepient before percent, and doesn't have the individual amount (although I'm not sure the last one is required) image
  2. Manage verified memebers has one extra entry (I think it's for the same thing -- selecting the member) image

@Nortsova Nortsova force-pushed the fix/3737-update-form-order-and-translations branch from fcc4630 to 76f133a Compare January 31, 2025 16:41
@Nortsova
Copy link
Contributor Author

Thanks, @rdig , you were right; split payments were working incorrectly; I added InputsOrderCellWrapper to solve it.

image

Regarding Manage verified members it is a bit complecated, it actually was a correct behaviour, because after user select method add or remove members table will appear, so last error was related to this hidden table.
But it is not understandable for user, so I hided this error untill Method selected 🙌

image image

Copy link
Member

@rdig rdig left a comment

Choose a reason for hiding this comment

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

All good now. Nicely done!

Copy link
Contributor

@iamsamgibbs iamsamgibbs left a comment

Choose a reason for hiding this comment

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

Nice fixes!

Recipient and percentage are in the correct order:
Screenshot 2025-02-04 at 10 55 12

No "Select a member" error when "Add"/"Remove" has not yet been selected:
Screenshot 2025-02-04 at 10 55 34

And then does show once selected and resubmitted:
Screenshot 2025-02-04 at 10 55 48

Copy link
Contributor

@mmioana mmioana left a comment

Choose a reason for hiding this comment

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

Hey @Nortsova really amazing efforts on this issue 🙌

I've retested the scenarios that were previously mentioned and it seems they behave properly 💯
Screenshot 2025-02-04 at 18 41 00
Screenshot 2025-02-04 at 18 41 22
Screenshot 2025-02-04 at 18 42 17

However @Nortsova I did encounter an issue when switching from Staged payments to Manage verified members, when the createdIn field appears as required and you can no longer submit the form 😢

Screen.Recording.2025-02-04.at.18.43.36.mov
Screen.Recording.2025-02-04.at.18.46.30.mov

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants