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: min max chars for long text #15592

Closed

Conversation

mhetreayush
Copy link
Contributor

@mhetreayush mhetreayush commented Jun 27, 2024

/claim #15577

What does this PR do?

This PR adds an optional minimum and maximum character limit to long text question in booking form.

Loom Video: https://www.loom.com/share/735a6768a92847cabefd1fe2187c499d?sid=2d606562-c6e6-4bd3-92c0-b1fcdab14218

Mandatory Tasks (DO NOT REMOVE)

  • I have self-reviewed the code (A decent size PR without self-review might be rejected).
  • N/A I have added a Docs issue here if this PR makes changes that would require a documentation change. If N/A, write N/A here and check the checkbox.
  • I confirm automated tests are in place that prove my fix is effective or that my feature works.

How should this be tested?

  • Are there environment variables that should be set?
    No

  • What are the minimal test data to have?
    N.A.

  • What is expected (happy path) to have (input and output)?

  1. Click on Event Types in the sidebar.
  2. Click on an event.
  3. Inside the event, click on the Advanced tab on the left sidebar.
  4. Add / edit a question.
  5. Set type to Long text
  6. Set the min &/or max characters.
  7. Save the question.
  8. Save the form.
  9. Click on the Preview button in the event header.
  10. Select a date on the calendar.
  11. While filling out the form, click save button with:
    a. Min &/or max character limit unsatisfied -> should show red text with error.
    b. All the conditions satisfied -> Should save successfully.

Checklist

Copy link

vercel bot commented Jun 27, 2024

@mhetreayush is attempting to deploy a commit to the cal Team on Vercel.

A member of the Team first needs to authorize it.

@graphite-app graphite-app bot requested a review from a team June 27, 2024 07:27
@graphite-app graphite-app bot added the community Created by Linear-GitHub Sync label Jun 27, 2024
@github-actions github-actions bot added booking-page area: booking page, public booking page, booker Low priority Created by Linear-GitHub Sync ui area: UI, frontend, button, form, input ⚡ Quick Wins A collection of quick wins/quick fixes that are less than 30 minutes of work ✨ feature New feature or request 💎 Bounty A bounty on Algora.io labels Jun 27, 2024
@dosubot dosubot bot added this to the Community Only milestone Jun 27, 2024
Copy link

graphite-app bot commented Jun 27, 2024

Graphite Automations

"Add consumer team as reviewer" took an action on this PR • (06/27/24)

1 reviewer was added to this PR based on Keith Williams's automation.

"Add community label" took an action on this PR • (06/27/24)

1 label was added to this PR based on Keith Williams's automation.

@mhetreayush mhetreayush force-pushed the features/long-text-min-max-chars branch from ae7b296 to 044a324 Compare June 27, 2024 07:31
Copy link
Member

@sean-brydon sean-brydon 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!
This works pretty damn well - however you can break it pretty easy. Maybe we should add a check to ensure these logically work min < max

CleanShot 2024-06-27 at 08 55 24

CleanShot 2024-06-27 at 08 54 53

Copy link
Member

Choose a reason for hiding this comment

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

@calcom/platform this looks fine for me but would like your eyes before approvals/merging as i'm not 100% sure if you are dating these upon every change

@mhetreayush
Copy link
Contributor Author

@sean-brydon thank you for a quick reply.
The min < max check you are talking about can only be applied when both min and max are filled, as both are optional, will add the check and request a review.

Comment on lines +152 to +153
minLength: z.number().optional(),
maxLength: z.number().optional(),
Copy link
Member

Choose a reason for hiding this comment

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

@calcom/platform Is it possible to reuse packages/features/form-builder/schema.ts somehow here?

Copy link
Member

@hariombalhara hariombalhara left a comment

Choose a reason for hiding this comment

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

@mhetreayush Thanks for the PR 🙏

Left a few suggestions

@mhetreayush
Copy link
Contributor Author

@sean-brydon @hariombalhara
Fixed the validation:
https://www.loom.com/share/b103eb32e0074a5e8a5397bf0312081b

Also took care of the reviews

@@ -0,0 +1 @@
export const HARD_LIMIT_MAX_LENGTH = 4000;
Copy link
Member

Choose a reason for hiding this comment

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

This is a limit for textarea only. How about we keep it in form-builder/fieldTypes as textarea.hardLimitOnMaxLength.

In this way it is better organized.

Copy link
Member

Choose a reason for hiding this comment

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

I am taking care of it. I will play around and see what is best, as it's been a long time I worked on form builder

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fair enough, can do.

Comment on lines 107 to 109
supportsLengthCheck: {
maxLength: 4000,
},
Copy link
Member

Choose a reason for hiding this comment

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

@mhetreayush Added maxLength support here. It easily allows any field that wants to support length check feature to define maxLength. Infact it is mandatory to define maxLength if someone enables length check support.

This should also solve the problem of easily configuring it for text field type.

Copy link
Member

Choose a reason for hiding this comment

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

This is different from the maxLength that we have in baseFieldSchema as that can be changed by the user per field. This on the other hand is constant and defined by our code and applies to all fields of that type

@@ -0,0 +1,158 @@
import { expect } from "@playwright/test";
Copy link
Member

Choose a reason for hiding this comment

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

@mhetreayush We have playwright/manage-booking-questions.e2e.ts for form builder related tests.
We should move this test there.

Also, could you see if we can test textarea field along with any existing test in there? If not that's also fine. The tests there follow the same flow, it is just about adding and verifying a new field.

I wanted to ensure that we don't introduce new e2es when when we can amend any existing e2e. As an e2e test is time consuming.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do that.

Copy link
Member

@hariombalhara hariombalhara Jun 28, 2024

Choose a reason for hiding this comment

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

Also, maybe we could also add unit test for textarea schema in schema.ts.
And, supportsLengthCheck related component code can also be unit tested with react-testing-library. For that you would have to refactor supportsLengthCheck related code into a new component(which really makes sense anyway)

Copy link
Contributor

📦 Next.js Bundle Analysis for @calcom/web

This analysis was generated by the Next.js Bundle Analysis action. 🤖

Forty-two Pages Changed Size

The following pages changed size from the code in this PR compared to its base branch:

Page Size (compressed) First Load % of Budget (350 KB)
/[user]/[type] 416.97 KB 644.68 KB 184.19% (🟡 +0.24%)
/[user]/[type]/embed 416.97 KB 644.68 KB 184.20% (🟡 +0.23%)
/apps/[slug]/[...pages] 593.64 KB 821.36 KB 234.67% (🟡 +0.29%)
/apps/installation/[[...step]] 168.18 KB 395.9 KB 113.11% (🟡 +0.15%)
/auth/saml-idp 12.22 KB 239.94 KB 68.55% (🟢 -20.80%)
/booking/[uid] 236.49 KB 464.21 KB 132.63% (🟡 +0.15%)
/booking/[uid]/embed 236.5 KB 464.21 KB 132.63% (🟡 +0.15%)
/bookings/[status] 330.73 KB 558.44 KB 159.55% (🟡 +0.16%)
/d/[link]/[slug] 416.77 KB 644.48 KB 184.14% (🟡 +0.23%)
/event-types 566.67 KB 794.38 KB 226.97% (🟡 +0.37%)
/event-types/[type] 442.33 KB 670.04 KB 191.44% (🟡 +0.23%)
/org/[orgSlug] 266.88 KB 494.59 KB 141.31% (🟡 +0.15%)
/org/[orgSlug]/[user] 272.99 KB 500.71 KB 143.06% (🟡 +0.15%)
/org/[orgSlug]/[user]/[type] 417.17 KB 644.88 KB 184.25% (🟡 +0.23%)
/org/[orgSlug]/[user]/[type]/embed 417.19 KB 644.91 KB 184.26% (🟡 +0.23%)
/org/[orgSlug]/[user]/embed 273.02 KB 500.74 KB 143.07% (🟡 +0.14%)
/org/[orgSlug]/embed 266.89 KB 494.61 KB 141.32% (🟡 +0.14%)
/org/[orgSlug]/instant-meeting/team/[slug]/[type] 416.79 KB 644.5 KB 184.14% (🟡 +0.24%)
/org/[orgSlug]/team/[slug] 266.88 KB 494.6 KB 141.31% (🟡 +0.15%)
/org/[orgSlug]/team/[slug]/[type] 416.98 KB 644.7 KB 184.20% (🟡 +0.23%)
/settings/admin/lockedSMS/UsersTable 79.98 KB 307.69 KB 87.91% (🟢 -0.14%)
/settings/admin/lockedSMS/lockedSMSView 119.46 KB 347.18 KB 99.19% (🟢 -0.17%)
/settings/admin/oAuth/oAuthView 95.5 KB 323.21 KB 92.35% (🟢 -0.18%)
/settings/admin/orgMigrations/moveTeamToOrg 305.66 KB 533.38 KB 152.39% (🟡 +0.16%)
/settings/admin/orgMigrations/moveUserToOrg 325.43 KB 553.15 KB 158.04% (🟡 +0.17%)
/settings/admin/orgMigrations/removeTeamFromOrg 305.42 KB 533.14 KB 152.33% (🟡 +0.15%)
/settings/admin/orgMigrations/removeUserFromOrg 305.43 KB 533.15 KB 152.33% (🟡 +0.16%)
/settings/admin/users/[id]/edit 398.79 KB 626.5 KB 179.00% (🟡 +0.16%)
/settings/admin/users/add 398.45 KB 626.17 KB 178.91% (🟡 +0.16%)
/settings/my-account/appearance 320.22 KB 547.94 KB 156.55% (🟡 +0.16%)
/settings/organizations/[id]/about 159.67 KB 387.39 KB 110.68% (🟡 +0.48%)
/settings/organizations/[id]/add-teams 159.66 KB 387.38 KB 110.68% (🟡 +0.47%)
/settings/organizations/new 159.67 KB 387.39 KB 110.68% (🟡 +0.48%)
/settings/platform/new 120.72 KB 348.43 KB 99.55% (🟡 +0.52%)
/settings/security/password 310.55 KB 538.27 KB 153.79% (🟡 +0.16%)
/signup 179.2 KB 406.91 KB 116.26% (🟡 +0.15%)
/team/[slug] 266.81 KB 494.53 KB 141.29% (🟡 +0.15%)
/team/[slug]/[type] 416.95 KB 644.67 KB 184.19% (🟡 +0.23%)
/team/[slug]/[type]/embed 416.98 KB 644.7 KB 184.20% (🟡 +0.23%)
/team/[slug]/embed 266.88 KB 494.59 KB 141.31% (🟡 +0.15%)
/video/[uid] 291.22 KB 518.94 KB 148.27% (🟢 -0.17%)
/workflows/[workflow] 420.26 KB 647.98 KB 185.14% (🟡 +0.17%)
Details

Only the gzipped size is provided here based on an expert tip.

First Load is the size of the global bundle plus the bundle for the individual page. If a user were to show up to your website and land on a given page, the first load size represents the amount of javascript that user would need to download. If next/link is used, subsequent page loads would only need to download that page's bundle (the number in the "Size" column), since the global bundle has already been downloaded.

Any third party scripts you have added directly to your app using the <script> tag are not accounted for in this analysis

The "Budget %" column shows what percentage of your performance budget the First Load total takes up. For example, if your budget was 100kb, and a given page's first load size was 10kb, it would be 10% of your budget. You can also see how much this has increased or decreased compared to the base branch of your PR. If this percentage has increased by 20% or more, there will be a red status indicator applied, indicating that special attention should be given to this. If you see "+/- <0.01%" it means that there was a change in bundle size, but it is a trivial enough amount that it can be ignored.

@@ -105,7 +105,8 @@ const configMap: Record<FieldType, Omit<z.infer<typeof fieldTypeConfigSchema>, "
value: "textarea",
isTextType: true,
supportsLengthCheck: {
maxLength: 4000,
// Keep it as small as possible. It is easier to change to a higher value but coming back to a lower value(due to any reason) would be problematic for users who have saved higher value.
maxLength: 1000,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@hariombalhara Can we use a shared constant here instead of a direct value? Bringing this up since you mentioned it is constant to our code base.

Copy link
Member

Choose a reason for hiding this comment

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

I think we can define a local HARD_MAX_LENGTH_TEXTAREA locally in this module.

It isn't a constant to be used throughout the app now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we can define a local HARD_MAX_LENGTH_TEXTAREA locally in this module.

Yes this would be better I believe

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll take care of that @hariombalhara

@hariombalhara
Copy link
Member

The test seems to be failing, could you check
image

@mhetreayush
Copy link
Contributor Author

@hariombalhara I am actually unavailable for some time, so will be inactive on the issue, could you or someone else take this ahead?

@varshith257
Copy link
Contributor

@mhetreayush I would like to collaborate with you and make progress on this issue. I will take on this issue :)

@mhetreayush
Copy link
Contributor Author

Thanks @varshith257 , I will cancel my claim attempt then

@rajeshj11
Copy link
Contributor

@hariombalhara I am actually unavailable for some time, so will be inactive on the issue, could you or someone else take this ahead?

@mhetreayush
Hey, I have fixed the issue. please merge the below changes into your branch.
mhetreayush#1

@hariombalhara
Copy link
Member

Closing it in favour of #15693 which improves over the changes in this PR.

@dosubot dosubot bot modified the milestone: Community Only Jul 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
booking-page area: booking page, public booking page, booker 🙋 Bounty claim 💎 Bounty A bounty on Algora.io community Created by Linear-GitHub Sync ✨ feature New feature or request Low priority Created by Linear-GitHub Sync ⚡ Quick Wins A collection of quick wins/quick fixes that are less than 30 minutes of work ready-for-e2e ui area: UI, frontend, button, form, input
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[CAL-3973] booking questions for long text: add min and max characters (both optionally)
7 participants