From aad03d4f09b3a5c8665bf22913d583f349a56a9a Mon Sep 17 00:00:00 2001 From: Amogh Bharadwaj Date: Tue, 30 Apr 2024 19:35:04 +0530 Subject: [PATCH] UI: Fix kafka zod (#1657) - Allows for empty partition field - Adds some error messaging for the zod schema --- ui/app/peers/create/[peerType]/schema.ts | 44 ++++++++++++++++-------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/ui/app/peers/create/[peerType]/schema.ts b/ui/app/peers/create/[peerType]/schema.ts index ab0e2e73af..498613edb4 100644 --- a/ui/app/peers/create/[peerType]/schema.ts +++ b/ui/app/peers/create/[peerType]/schema.ts @@ -288,26 +288,42 @@ export const chSchema = z.object({ export const kaSchema = z.object({ servers: z - .array(z.string({ required_error: 'Server address must not be empty' })) + .array( + z.string({ + invalid_type_error: 'Invalid server provided', + required_error: 'Server address must not be empty', + }) + ) .min(1, { message: 'At least 1 server required' }), username: z.string().optional(), password: z.string().optional(), sasl: z - .union([ - z.literal('PLAIN'), - z.literal('SCRAM-SHA-256'), - z.literal('SCRAM-SHA-512'), - ]) + .union( + [ + z.literal('PLAIN'), + z.literal('SCRAM-SHA-256'), + z.literal('SCRAM-SHA-512'), + ], + { errorMap: (issue, ctx) => ({ message: 'Invalid SASL mechanism' }) } + ) .optional(), partitioner: z - .union([ - z.literal('Default'), - z.literal('LeastBackup'), - z.literal('Manual'), - z.literal('RoundRobin'), - z.literal('StickyKey'), - z.literal('Sticky'), - ]) + .union( + [ + z.literal('Default'), + z.literal('LeastBackup'), + z.literal('Manual'), + z.literal('RoundRobin'), + z.literal('StickyKey'), + z.literal('Sticky'), + z.literal(''), + ], + { + errorMap: (issue, ctx) => ({ + message: 'Invalid partitioning mechanism', + }), + } + ) .optional(), disableTls: z.boolean().optional(), });