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

feat: single-line-editor add an optional prop to hide all validation messages [LUMOS-312] #1805

Conversation

ethan-ozelius-contentful
Copy link
Contributor

@ethan-ozelius-contentful ethan-ozelius-contentful commented Nov 26, 2024

Description

Add an optional prop to render all validation messages. This prop defaults to true, to ensure backward compatibility.

Necessary use case

In studio, users need to be able to bind component properties to entry/asset fields.

  • example 1: binding a heading to an entry title
  • example 2: binding a background image to an asset file.
    However, we do not allow users to make changes to the underlying entry/asset while they are in the process of binding (if they need to edit the underlying entry/asset, there is a separate form). Therefore, it doesn't make sense for studio to render the validation messages when binding.
Screenshot 2024-11-26 at 2 42 07 PM

with validation messages enabled

Screenshot 2024-11-26 at 2 14 09 PM

with withCharValidation = false

Screenshot 2024-11-26 at 2 13 46 PM

with validation messages disabled

Screenshot 2024-11-26 at 2 14 39 PM

@ethan-ozelius-contentful ethan-ozelius-contentful force-pushed the single-line-editor/add-prop-to-hide-all-validations branch from 465bcf3 to 97ca4f6 Compare November 26, 2024 21:23
@ethan-ozelius-contentful ethan-ozelius-contentful changed the title feat(single-line-editor): add an optional prop to hide all validation messages [LUMOS-312] feat(single-line-editor): add an optional prop to hide all validation messages Nov 26, 2024
@ethan-ozelius-contentful ethan-ozelius-contentful changed the title [LUMOS-312] feat(single-line-editor): add an optional prop to hide all validation messages [LUMOS-312] feat single-line-editor: add an optional prop to hide all validation messages Nov 26, 2024
@ethan-ozelius-contentful ethan-ozelius-contentful force-pushed the single-line-editor/add-prop-to-hide-all-validations branch from 97ca4f6 to 05bdb75 Compare November 26, 2024 21:32
@ethan-ozelius-contentful ethan-ozelius-contentful changed the title [LUMOS-312] feat single-line-editor: add an optional prop to hide all validation messages feat: single-line-editor add an optional prop to hide all validation messages [LUMOS-312] Nov 26, 2024
@ethan-ozelius-contentful ethan-ozelius-contentful marked this pull request as ready for review November 26, 2024 21:44
@ethan-ozelius-contentful ethan-ozelius-contentful requested a review from a team as a code owner November 26, 2024 21:44
/**
* whether validations should be rendered or not.
*/
validationsAreVisable?: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

should we name it withValidations? to stay consistent in the naming

or withCharInformation? as the char counter would be no validation 🙈

Choose a reason for hiding this comment

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

+1 to renaming to withCharInformation to match naming conventions of this component and it matches the purpose of the boolean a bit better since to Chris' point it's not just for validations but also the character counter.

/**
* whether validations should be rendered or not.
*/
validationsAreVisable?: boolean;

Choose a reason for hiding this comment

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

+1 to renaming to withCharInformation to match naming conventions of this component and it matches the purpose of the boolean a bit better since to Chris' point it's not just for validations but also the character counter.

<CharCounter value={value || ''} checkConstraint={() => true} />
</div>
)}
</>

Choose a reason for hiding this comment

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

I think we can clean up these conditionals a bit to something like:

// new const for checkConstraint above the return of the component
const handleCheckConstraint = withCharValidation ? checkConstraint : () => true

// updated return
{withCharInformation && (
    <div className={styles.validationRow}>
      <CharCounter value={value || ''} checkConstraint={handleCheckConstraint} />
      {withCharValidation && <CharValidation constraints={constraints} />}
    </div>
)}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice, yeah this change definitely cleans the code up.

  • clean up conditionals.

@ethan-ozelius-contentful ethan-ozelius-contentful force-pushed the single-line-editor/add-prop-to-hide-all-validations branch from 05bdb75 to 7861fbb Compare December 2, 2024 19:29
Copy link

@chasepoirier chasepoirier left a comment

Choose a reason for hiding this comment

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

Awesome, looks good!

@@ -229,4 +229,35 @@ describe('SingleLineEditor', () => {
expect(getByText('0 characters')).toBeInTheDocument();
expect(queryByText('Requires between 100 and 1000 characters')).not.toBeInTheDocument();
});

it('renders no validation message or counter if validationsAreVisable is false', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

NIT the test case is no longer correct after renaming the props 😅

@ethan-ozelius-contentful ethan-ozelius-contentful force-pushed the single-line-editor/add-prop-to-hide-all-validations branch from 7861fbb to f1c319a Compare December 3, 2024 16:04
@ethan-ozelius-contentful ethan-ozelius-contentful merged commit 4590482 into master Dec 3, 2024
12 checks passed
@ethan-ozelius-contentful ethan-ozelius-contentful deleted the single-line-editor/add-prop-to-hide-all-validations branch December 3, 2024 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants