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: Route Builder rules should be case insensitive #9040

Conversation

jemiluv8
Copy link
Contributor

@jemiluv8 jemiluv8 commented May 22, 2023

What does this PR do?

Override jsonLogic operators on string operands to allow for case insensitive comparisons

Fixes #5439

Case insensitive "equals" comparison
Case insensitive "not equals" comparison

Case insensitive "contains" comparison
Case insensitive "not contains" comparison

Type of change

  • Chore (refactoring code, technical debt, workflow improvements)

How should this be tested?

  • Install the "Routing Forms" app
  • Create a new form
  • Create form fields under the "Form" tab
  • Go to the routing tab and create a rule for any of the string operators ("contains", "not contains", "equals", "not equals")
  • Use the test preview on the left sidebar to fill out an example form
  • Use the "Test Routing" button to confirm the case insensitive comparison of the form values for relevant rules

Edit by @hariombalhara

Checklist

  • I haven't added tests that prove my fix is effective or that my feature works

/claim #5439

jemiluv8 added 2 commits May 22, 2023 14:27
…ensitive comparisons.

Affected Operators: "==", "===", "!=", "!==", "in"
@jemiluv8 jemiluv8 requested a review from hariombalhara as a code owner May 22, 2023 15:29
@jemiluv8 jemiluv8 requested a review from a team May 22, 2023 15:29
@vercel
Copy link

vercel bot commented May 22, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 23, 2023 10:22pm

@vercel
Copy link

vercel bot commented May 22, 2023

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

A member of the Team first needs to authorize it.

@github-actions
Copy link
Contributor

github-actions bot commented May 22, 2023

📦 Next.js Bundle Analysis for @calcom/web

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

One Page Changed Size

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

Page Size (compressed) First Load % of Budget (350 KB)
/auth/login 149.41 KB 300.35 KB 85.81% (🟢 -0.18%)
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.

…code there will be from jsonLogic and may not meet our coding style.

Majority of overrides require us to copy over functions and their signatures from jsonLogic and then modify their implementation.

The signature of functions implementing most operators take the operands typed as "any", which is intended, but doesn't adhere to our coding style. Hence the need to override the eslint rule
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.

Looks good so far except 1 bug where MultiSelect equals stopped working.

That was because 'in' operator got second argument as an array of string which wasn't handled in normalize. So, one operand got lowercased but not the other one causing in operator to always fail. I have fixed that case.

@jemiluv8 I would suggest you to do one more round of testing with all the operators and field types combination.

Also, there is an open comment.

Note: this deviates from the original implementation in the jsonLogic library because our current useage ensures that the second operand is always a string or string[] and will therefore always have .index function. Whenever our invariants change in the future, make sure to modify this implementation to prevent any unexpected
@jemiluv8
Copy link
Contributor Author

jemiluv8 commented May 23, 2023

@hariombalhara, I just completed another round of testing and all looks fine.
I admit I didn't pay much attention to select/multiselect field types and their
respective operations

About the redundant check in our override for the "in" operator
I decided to remove the redundant check for the typeof second.indexOf === "undefined".

Justification
Like I mentioned in the comment above I tried to copy over the exact implementation of
various jsonLogic operators from the repo. For the "in" operator, the library assumed the
second operand could be of any type and was therefore guarding against situations where
it may not be a string or an array.

Our current useage of the jsonLogic library ensures that the "in" operator will always get either a
string or string[]. That makes the extra check redundant.

@PeerRich PeerRich changed the title [CAL-336] Route Builder rules should be case insensitive fix: Route Builder rules should be case insensitive May 24, 2023
const DEFAULT_NAVIGATION_TIMEOUT = process.env.CI ? 15000 : 50000;
const DEFAULT_EXPECT_TIMEOUT = process.env.CI ? 15000 : 50000;
const DEFAULT_NAVIGATION_TIMEOUT = process.env.CI ? 15000 : 120000;
const DEFAULT_EXPECT_TIMEOUT = process.env.CI ? 15000 : 120000;
Copy link
Member

Choose a reason for hiding this comment

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

Added this change here because sometimes dev server can be too slow and it times out unncessarily.

@hariombalhara hariombalhara added this pull request to the merge queue May 26, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 26, 2023
@PeerRich PeerRich merged commit 15e50fc into calcom:main May 29, 2023
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.

[CAL-336] Route Builder rules should be case insensitive
3 participants