Skip to content

feat: min max chars for long text #15691

Merged
hariombalhara merged 44 commits intocalcom:mainfrom
varshith257:features/long-text-min-max-chars
Jul 30, 2024
Merged

feat: min max chars for long text #15691
hariombalhara merged 44 commits intocalcom:mainfrom
varshith257:features/long-text-min-max-chars

Conversation

@varshith257
Copy link
Contributor

@varshith257 varshith257 commented Jul 8, 2024

What does this PR do?

Part of #15577

This PR adds an optional minimum and maximum character limit to long text question in the 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).
  • 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?
    NA

  • What is expected (happy path) to have (input and output)?
    Click on Event Types in the sidebar.
    Click on an event.
    Inside the event, click on the Advanced tab on the left sidebar.
    Add / edit a question.
    Set type to Long text
    Set the min &/or max characters.
    Save the question.
    Save the form.
    Click on the Preview button in the event header.
    Select a date on the calendar.
    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.

  • Any other important info that could help to test that PR

/claim #15577

@vercel
Copy link

vercel bot commented Jul 8, 2024

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

A member of the Team first needs to authorize it.

@varshith257
Copy link
Contributor Author

varshith257 commented Jul 9, 2024

I feel this is better and cleaner with passing e2e tests too @anikdhabal is also following up with his reviews and am following it.

To work together then let us split the bounty as of efforts taken

WDYT? @hariombalhara . Collaboration is cool in Open Source :)

@rajesh-jonnalagadda
Copy link
Contributor

I feel this is better and cleaner with passing e2e tests too @anikdhabal is also following up with his reviews and am following it.

To work together then let us split the bounty as of efforts taken

WDYT? @hariombalhara . Collaboration is cool in Open Source :)

I have closed my pr. please handle the edge case. I have handled it in my pr. if needed take reference.
when user manually clears the max/min inputs and save the question. it gets saved in local only. It is not getting updated in db. that needs to be handled.

packages/features/form-builder/FormBuilder.tsx

            const fieldType = fieldTypesConfigMap[type];
            //handling edge-case. when user manually cleared the maxLength and minLength, making sure default values were set
            if (fieldType?.supportsLengthCheck) {
              if (!data.maxLength) {
                data.maxLength = fieldType.supportsLengthCheck.maxLength || 1000;
              }
              //if NaN, set it to 0
              if (!data.minLength) {
                data.minLength = 0;
              }
            }

@varshith257
Copy link
Contributor Author

I have closed my pr. please handle the edge case. I have handled it in my pr. if needed take reference.

I think it's not needed IMO

@varshith257
Copy link
Contributor Author

@hariombalhara @anikdhabal Can have a look into it and merge it?

Comment on lines +354 to +359
if (hasExceededMaxLength) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: m(`Max. ${field.maxLength} characters allowed`),
});
}
Copy link
Member

@hariombalhara hariombalhara Jul 12, 2024

Choose a reason for hiding this comment

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

image
Getting wrong error message(undefined in it) for a field that existed before these changes. Such a field doesn't have field.maxLength set

Comment on lines +563 to +567
function FieldWithLengthCheckSupport({
fieldForm,
containerClassName = "",
className,
...rest
Copy link
Member

Choose a reason for hiding this comment

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

Refactored the new component changes out from the parent component.

Comment on lines +348 to +349
const maxLength = field.maxLength ?? fieldTypeConfig.supportsLengthCheck?.maxLength;
const minLength = field.minLength ?? 0;
Copy link
Member

Choose a reason for hiding this comment

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

Ensured that maxLength and minLength are initialized correctly and use them only and not field props.

hariombalhara
hariombalhara previously approved these changes Jul 12, 2024
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.

@varshith257 Made some changes to cleanup the code a bit more and fixed a bug.
Please review the changes made by me. It is good to go from my side.

@ThyMinimalDev Please review the v2 API related changes.

@varshith257
Copy link
Contributor Author

varshith257 commented Jul 12, 2024

@hariombalhara Thanks for fixing the bug and cleanup. I have semester exams ongoing so hadn't looked at it.

@hariombalhara
Copy link
Member

@hariombalhara Thanks for fixing the bug and cleanup. I have semester exams ongoing so hadn't looked at it.

No Problem. Good luck with your exams !!

@Amit91848 Amit91848 requested a review from a team July 18, 2024 09:01
Copy link
Contributor

@supalarry supalarry left a comment

Choose a reason for hiding this comment

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

Great PR and well done on adding e2e test!

However, the API part needs:

  1. To specifiy min and max length on the individual booking field input and output, not the whole event-type object.
  2. To add this functionality also to the latest event-types release.

Let me know if I can provide more details / explain anything : )

@ValidateNested({ each: true })
@Type(() => Source)
sources?: Source[];

Copy link
Contributor

Choose a reason for hiding this comment

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

I see that inputs and outputs of event-types in folder event-types_2024_04_15 are updated, but we also need to update inputs and outputs used by next release in the folder event-types_2024_06_14

The controller apps/api/v2/src/ee/event-types/event-types_2024_06_14/controllers/event-types.controller.ts takes inputs from packages/platform/types/event-types/event-types_2024_06_14/inputs and outputs from apps/api/v2/src/ee/event-types/event-types_2024_06_14/outputs that share underlying event-type output defined in packages/platform/types/event-types/event-types_2024_06_14/outputs/event-type.output.ts.

As you see, the inputs and outputs are in the platform-types package , which means that after changing them you have to re-build them by running rm -rf dist && npx tsc --build --force in the packages/platform/types folder.


@IsOptional()
@IsNumber()
maxLength?: number;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that maxLength and minLength should not be defined on the input object, but on the level of individual booking field, be it class BookingField_2024_04_15 or TextField_2024_06_14 within packages/platform/types/event-types/event-types_2024_06_14/inputs/booking-fields.input.ts.

Same logic applies as comment above - we need to also handle the 2024_06_14 release of event-types.


@IsOptional()
@IsNumber()
maxLength?: number;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as with inputs above - I think min and max length should be part of the individual booking field, because right now we are defining min and max length of an event type.

@keithwillcode
Copy link
Contributor

@supalarry mind making these changes? Sounds like @varshith257 is busy and might not be able to get them in.

@supalarry
Copy link
Contributor

Now that I think, it's better to do API updates seperately, so I will just

Now that I think it's better to have web app only update in this PR and then API update in separate one - I will remove API stuff from this PR so we can ship this already and add to-do for this API task.

Copy link
Contributor

@supalarry supalarry left a comment

Choose a reason for hiding this comment

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

Great job Vamshi! Tested locally and works!

@hariombalhara hariombalhara enabled auto-merge (squash) July 30, 2024 12:02
@hariombalhara hariombalhara merged commit b8ba95d into calcom:main Jul 30, 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)

8 participants