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

chore: threshold schema, slice and migration #425

Merged
merged 2 commits into from
Jan 23, 2025

Conversation

cristianoventura
Copy link
Collaborator

Description

This PR is part of the Thresholds feature #369. It contains the initial setup including the Schema, Slice, and Migration.

How to Test

Checklist

  • I have performed a self-review of my code.
  • I have added tests for my changes.
  • I have run linter locally (npm run lint) and all checks pass.
  • I have run tests locally (npm test) and all tests pass.
  • I have commented on my code, particularly in hard-to-understand areas.

Screenshots (if appropriate):

Related PR(s)/Issue(s)

@cristianoventura cristianoventura self-assigned this Jan 21, 2025
allowlist: z.string().array(),
includeStaticAssets: z.boolean(),
scriptName: z.string().default('my-script.js'),
thresholds: z.array(ThresholdSchema),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The thresholds array is the only addition here.

src/schemas/generator/v2/rules.ts Outdated Show resolved Hide resolved
src/schemas/generator/v2/testData.ts Outdated Show resolved Hide resolved
src/schemas/generator/v2/testOptions.ts Outdated Show resolved Hide resolved
@@ -0,0 +1,42 @@
import { z } from 'zod'
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This Schema may evolve to include validation and potentially some conditional transform operations.

It is based on the Thresholds feature available in the Test Builder.

image

Comment on lines +4 to +12
interface State {
thresholds: Array<Threshold>
}

interface Actions {
addThreshold: (threshold: Threshold) => void
updateThreshold: (threshold: Threshold) => void
deleteThreshold: (id: string) => void
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Initial state and actions to get some UI and validation working in the upcoming branch.

@cristianoventura cristianoventura marked this pull request as ready for review January 21, 2025 19:23
@cristianoventura cristianoventura requested a review from a team as a code owner January 21, 2025 19:23
allowlist: z.string().array(),
includeStaticAssets: z.boolean(),
scriptName: z.string().default('my-script.js'),
thresholds: z.array(ThresholdSchema),
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you might be able to avoid adding a new schema version if you default thresholds to an empty array:

  thresholds: z.array(ThresholdSchema).default([])

Since it's a new property added to schema, all what migrate does is initiate an empty array, which can be done using zod's default method.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This worked perfectly, thanks for the suggestion! 🙏

Copy link
Collaborator

@e-fisher e-fisher left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@cristianoventura cristianoventura merged commit 411aa79 into main Jan 23, 2025
3 checks passed
@cristianoventura cristianoventura deleted the chore/thresholds-schema branch January 23, 2025 15:30
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.

2 participants