Frontend Validation #46
Replies: 2 comments 6 replies
-
|
Thanks for looking into this. I am already familiar with Zod a bit. I was actually thinking about implementing it into my thesis for university recently. From what I see, I believe once we implement it, we might as well benefit from it when it comes to the import feature, in case something breaks/we want to make it work better. It looks robust.
The pain points I see:
Something we might want to decide on:
With the revamp, the Some more thoughts:
And then in the same component where we call selectUsers, we'd also call selectUsersValidation: |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for bringing this up! The way we're handling validation at the moment sometimes feels overwhelming and incomplete at the same time to be honest. Just from a quick look - zod looks quite interesting, not overly complicated and its weekly downloads on npm are going up so they have to be doing something right :D I like the examples and having re-usable schemas would be lovely.
I mean yeah, but that's just part of the job 🤷 The main pain point seems to currently be inconsistency in validation between create/edit and import. We don't really allow users to input invalid values when they're creating/editing a blueprint, but they can still "force" the values in via import. Meaning there are two ways to input data and two ways we need to validate it, leaving us with possible gaps that are bubbling up to the surface and require more attention along the way. If this could be de-duplicated that would be perfect. I can see there are also valid arguments for implementing something on our side, current validation or at least what we need from it can be quite complex, with nested/multiple errors. It's probably not possible to say if we'll be perfectly fine with a "pre-made" solution or if we'll encounter issues we'd need a custom rules and schemas for (possibly missing warnings might be one of blockers). But I'd say we won't know until we give it a try 🤷 What I'd be interested in is how would new validation schemas work with components we already use. Also all for splitting validation into more manageable files! I've been already tempted to add |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been looking into typescript validation libraries like https://zod.dev/ & https://valibot.dev/.
We could possibly benefit from using something like this in our frontend repo to help us tighten up our validation.
The benefits of using a library like this is that they have a lot of builtin validation types already and so we don't have to re-implement these (e.g. URL validation).
The validation is all declarative too and we could make re-usable schemas for common items such as SSH keys and CA certs. I'm sure there are more examples of this too. We can also assert that these validation schemas match the image builder api generated types so that there isn't any drift there.
We would then have a unified way of validating user input and hopefully this could improve the dev experience.
I have a simple example of how we can do this below. I chose
timezonesince it is fairly straightforward with enough custom logic to show how we could handle this:We can assert that the inferred schema type matches our
image-builder-apitype:Here is how we can then test input against the validation schema:
With output:
What's nice about this is that it returns all the errors and not just the first one. This could & should simplify the validation logic that we have. This also should make it easy to disable the
nextbutton when needed inside the Wizard. The downside is that it is a new "framework" for devs to learn.Beta Was this translation helpful? Give feedback.
All reactions