Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

feat: improve grid validation #508

Merged
merged 32 commits into from
Oct 24, 2024
Merged

Conversation

dzbo
Copy link
Collaborator

@dzbo dzbo commented Oct 24, 2024

Ticket ID

DEV-11849
DEV-11908
DEV-11916

Description

  • integrate zod for building validation schemas
  • refactor validation and forms when adding new widgets
  • improve validation and add purification to LSP28 config data

@Hugoo
Copy link
Contributor

Hugoo commented Oct 24, 2024

@dzbo dzbo requested a review from nastita October 24, 2024 04:36
@dzbo dzbo requested a review from JeneaVranceanu October 24, 2024 04:36
Copy link
Contributor

github-actions bot commented Oct 24, 2024

Deployed with Cloudflare Pages ☁️ 🚀 🆗

@Hugoo
Copy link
Contributor

Hugoo commented Oct 24, 2024

@Hugoo
Copy link
Contributor

Hugoo commented Oct 24, 2024

Comment on lines +22 to +29
} catch (error: unknown) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: formatMessage('errors_invalid_input', {
name: capitalize(type),
}),
path: ['src'],
})
Copy link
Member

Choose a reason for hiding this comment

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

Why don't we use error object in the addIssue? It should have the information about which field is invalid.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

By error object you mean ctx instance? I've checked but it's empty in this case:

Copy link
Member

Choose a reason for hiding this comment

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

No, the error: unknown.
It should return the information about the invalid field if such error is thrown.

Copy link
Collaborator Author

@dzbo dzbo Oct 24, 2024

Choose a reason for hiding this comment

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

The error we catch here comes from parsePlatformInput, it doesn't have anything to do with zod unfortunatelly :/ I guess zod has a problem here to provide exact path because we run transform over whole object, it's not single field transform where path is easy to read.

CleanShot 2024-10-24 at 16 24 04
CleanShot 2024-10-24 at 16 24 41
CleanShot 2024-10-24 at 16 25 11@2x

import { computedAsync } from '@vueuse/core'
import { ZodEffects, ZodError, type ZodObject } from 'zod'

export const useForm = (
Copy link
Contributor

Choose a reason for hiding this comment

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

I actually once saw you using a form somewhere and was going to suggest something like useForm for vue but it seems you are implementing your own here

@dzbo dzbo merged commit eb6cda5 into feat/the-grid Oct 24, 2024
2 checks passed
@dzbo dzbo deleted the feat/improve-validation-DEV-11849 branch October 24, 2024 14:28
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants