-
Notifications
You must be signed in to change notification settings - Fork 620
insight playground - allow array items to be single item #7373
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
insight playground - allow array items to be single item #7373
Conversation
|
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
5 Skipped Deployments
|
WalkthroughThe change updates the array type handling within the Changes
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (8)
✨ Finishing Touches
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #7373 +/- ##
=======================================
Coverage 52.35% 52.35%
=======================================
Files 939 939
Lines 63161 63161
Branches 4214 4214
=======================================
Hits 33070 33070
Misses 29984 29984
Partials 107 107
🚀 New features to boost your workflow:
|
size-limit report 📦
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
apps/playground-web/src/app/insight/[blueprint_slug]/blueprint-playground.client.tsx(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: Size
- GitHub Check: Analyze (javascript)
| const arraySchema = isRequired | ||
| ? z.array(itemSchema).min(1, { message: "Required" }) | ||
| : z.array(itemSchema).optional(); | ||
| : z.array(itemSchema); | ||
| const arrayOrSingleItemSchema = z.union([arraySchema, itemSchema]); | ||
| return isRequired | ||
| ? arrayOrSingleItemSchema | ||
| : arrayOrSingleItemSchema.optional(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix validation inconsistency for required array parameters.
The union schema approach correctly solves the issue of accepting both single values and arrays. However, there's a validation inconsistency:
- Required arrays validate with
.min(1, { message: "Required" }) - Required single items use the base
itemSchemawithout additional validation - Other required parameter types in this function apply
.min(1)validation (see lines 786-788, 795-797, 834-836)
This means a single empty string would pass validation while an empty array would fail.
Apply this fix to ensure consistent validation:
if (itemSchema) {
+ let validatedItemSchema = itemSchema;
+ if (isRequired) {
+ if (schema.items.type === "string") {
+ validatedItemSchema = itemSchema.min(1, { message: "Required" });
+ } else if (schema.items.type === "number" || schema.items.type === "integer") {
+ validatedItemSchema = itemSchema.min(1, { message: "Required" });
+ }
+ }
+
const arraySchema = isRequired
- ? z.array(itemSchema).min(1, { message: "Required" })
- : z.array(itemSchema);
- const arrayOrSingleItemSchema = z.union([arraySchema, itemSchema]);
+ ? z.array(validatedItemSchema).min(1, { message: "Required" })
+ : z.array(itemSchema);
+ const arrayOrSingleItemSchema = z.union([arraySchema, validatedItemSchema]);
return isRequired
? arrayOrSingleItemSchema
: arrayOrSingleItemSchema.optional();
}📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const arraySchema = isRequired | |
| ? z.array(itemSchema).min(1, { message: "Required" }) | |
| : z.array(itemSchema).optional(); | |
| : z.array(itemSchema); | |
| const arrayOrSingleItemSchema = z.union([arraySchema, itemSchema]); | |
| return isRequired | |
| ? arrayOrSingleItemSchema | |
| : arrayOrSingleItemSchema.optional(); | |
| if (itemSchema) { | |
| let validatedItemSchema = itemSchema; | |
| if (isRequired) { | |
| if (schema.items.type === "string") { | |
| validatedItemSchema = itemSchema.min(1, { message: "Required" }); | |
| } else if (schema.items.type === "number" || schema.items.type === "integer") { | |
| validatedItemSchema = itemSchema.min(1, { message: "Required" }); | |
| } | |
| } | |
| const arraySchema = isRequired | |
| ? z.array(validatedItemSchema).min(1, { message: "Required" }) | |
| : z.array(itemSchema); | |
| const arrayOrSingleItemSchema = z.union([arraySchema, validatedItemSchema]); | |
| return isRequired | |
| ? arrayOrSingleItemSchema | |
| : arrayOrSingleItemSchema.optional(); | |
| } |
🤖 Prompt for AI Agents
In
apps/playground-web/src/app/insight/[blueprint_slug]/blueprint-playground.client.tsx
around lines 818 to 824, the validation for required single items lacks a
minimum length check, causing inconsistency with required arrays that enforce a
minimum of one item. To fix this, apply a `.min(1, { message: "Required" })`
validation to the single item schema within the union when isRequired is true,
ensuring both single items and arrays enforce the same minimum presence
requirement.
Merge activity
|
Fixes validation for query params that can be single or multiple value.
E.g. `?contract_address=0x...&contract_address=0x..` and `?contract_address=0x..` are both valid queries. Doing just 1 value as in the second variant did not pass validation previously, but now does
<!-- start pr-codex -->
---
## PR-Codex overview
This PR modifies the schema validation logic in the `blueprint-playground.client.tsx` file to handle required and optional array or single item schemas more effectively.
### Detailed summary
- Updated the return value to use `arrayOrSingleItemSchema` for both required and optional cases.
- Introduced `arraySchema` to define the structure of required arrays.
- Created `arrayOrSingleItemSchema` to combine array and single item schemas.
> ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}`
<!-- end pr-codex -->
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit
- **New Features**
- Enhanced form input flexibility to accept either a single item or an array of items for array-typed parameters.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
7871e40 to
a1d8373
Compare

Fixes validation for query params that can be single or multiple value.
E.g.
?contract_address=0x...&contract_address=0x..and?contract_address=0x..are both valid queries. Doing just 1 value as in the second variant did not pass validation previously, but now doesPR-Codex overview
This PR refines the schema validation logic in the
blueprint-playground.client.tsxfile. It modifies how required items are handled in an array schema and introduces a union type for better flexibility.Detailed summary
isRequiredis true to usez.unionto allow either an array or a single item schema.isRequiredis true.isRequiredis false.Summary by CodeRabbit