fix: Routing Forms, Number operators were using string operands#9182
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
1 Ignored Deployment
|
📦 Next.js Bundle Analysis for @calcom/webThis analysis was generated by the Next.js Bundle Analysis action. 🤖 Ten Pages Changed SizeThe following pages changed size from the code in this PR compared to its base branch:
DetailsOnly 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 Any third party scripts you have added directly to your app using the 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. |
CAL-1806 Routing Form: number comparison operators seem to operate on strings instead of numbers
Greater than operator b/w 500 and 1000 considers 500 as bigger. https://calcominc.slack.com/archives/C050R8Z2RP0/p1685143897762489 |
| ">": { | ||
| operator: "gt", | ||
| secondaryOperand: null, | ||
| }, | ||
| ">=": { | ||
| operator: "gte", | ||
| secondaryOperand: null, | ||
| }, | ||
| "<": { | ||
| operator: "lt", | ||
| secondaryOperand: null, | ||
| }, | ||
| "<=": { | ||
| operator: "lte", | ||
| secondaryOperand: null, | ||
| }, |
There was a problem hiding this comment.
These operators were missing implementation
dbada0f to
518d125
Compare
| const fieldResponse = | ||
| field.type === "multiselect" ? rawFieldResponse.split(",").map((r) => r.trim()) : rawFieldResponse; | ||
| const fieldResponse = fieldsResponses[getFieldIdentifier(field)] || ""; | ||
| const value = |
There was a problem hiding this comment.
Renamed fieldResponse as value(that better describes what it holds). Use, fieldResponse in place of rawFieldResponse.
| z.object({ | ||
| label: z.string(), | ||
| value: z.union([z.string(), z.array(z.string())]), | ||
| value: z.union([z.string(), z.number(), z.array(z.string())]), |
There was a problem hiding this comment.
Allow number to be stored now.
518d125 to
89aba8a
Compare
89aba8a to
53ec285
Compare
| } else { | ||
| serializedValue = escapeCsvText(value); | ||
| // value can be a number as well for type Number field | ||
| serializedValue = escapeCsvText(String(value)); |
There was a problem hiding this comment.
value has type string|number here. Make it string for CSV.
| const secondaryOperandAsNumber = typeof secondaryOperand === "string" ? Number(secondaryOperand) : null; | ||
|
|
||
| let prismaWhere; | ||
| if (secondaryOperandAsNumber) { |
There was a problem hiding this comment.
I rely on jsonLogicToPrisma.test.ts here.
Have added 4 new tests for >,>=, <, <=
| return; | ||
| } | ||
| const valueAsStringOrStringArray = | ||
| typeof fieldResponse.value === "number" ? String(fieldResponse.value) : fieldResponse.value; |
There was a problem hiding this comment.
fieldResponse.value is number|string|string[] here. Make it string|string[]
| path: ["505d3c3c-aa71-4220-93a9-6fd1e1087939", "value"], | ||
| string_contains: "a", | ||
| }, | ||
| describe("Number Type", () => { |
There was a problem hiding this comment.
Added these new tests and restructured others.
53ec285 to
2df59f3
Compare
hariombalhara
left a comment
There was a problem hiding this comment.
Self review done
| @@ -1,7 +1,7 @@ | |||
| import { GetServerSidePropsContext, GetServerSidePropsResult } from "next"; | |||
| import { CalendsoSessionUser } from "next-auth"; | |||
| import type { GetServerSidePropsContext, GetServerSidePropsResult } from "next"; | |||
|
No failed tests 🎉 |
2df59f3 to
f17c068
Compare
zomars
left a comment
There was a problem hiding this comment.
Tested and it's working. Nice job @hariombalhara

What does this PR do?
Fixes #9170 Fixes CAL-1806
Demo
After the fix demo
Type of change
How should this be tested?
age.Checklist