Skip to content

Commit 791afb0

Browse files
author
Leshe4ka
committed
validation improvements
1 parent 7e4335c commit 791afb0

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

frontend/src/widgets/ClusterConfigForm/Sections/Masking.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ const Masking = () => {
176176
name={`masking.${index}.fieldsNamePattern`}
177177
placeholder="Pattern"
178178
type="text"
179+
withError
179180
/>
180181
<MaskingCharReplacement nestedIdx={index} />
181182
<Input

frontend/src/widgets/ClusterConfigForm/schema.ts

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,54 @@ const maskingSchema = object({
184184
type: mixed<ApplicationConfigPropertiesKafkaMaskingTypeEnum>()
185185
.oneOf(Object.values(ApplicationConfigPropertiesKafkaMaskingTypeEnum))
186186
.required('required field'),
187-
fields: array().of(object().shape({ value: string() })),
188-
fieldsNamePattern: string(),
187+
fields: array().of(
188+
object().shape({
189+
value: string().test(
190+
'fieldsOrPattern',
191+
'Either fields or fieldsNamePattern is required',
192+
function (value, { path, parent, ...ctx }) {
193+
const maskingItem = ctx.from?.[1].value;
194+
195+
if (value && value.trim() !== '') {
196+
return true;
197+
}
198+
199+
const otherFieldHasValue =
200+
maskingItem.fields &&
201+
maskingItem.fields.some(
202+
(field: { value: string }) =>
203+
field.value && field.value.trim() !== ''
204+
);
205+
206+
if (otherFieldHasValue) {
207+
return true;
208+
}
209+
210+
const hasPattern =
211+
maskingItem.fieldsNamePattern &&
212+
maskingItem.fieldsNamePattern.trim() !== '';
213+
214+
return hasPattern;
215+
}
216+
),
217+
})
218+
),
219+
fieldsNamePattern: string().test(
220+
'fieldsOrPattern',
221+
'Either fields or fieldsNamePattern is required',
222+
(value, { parent }) => {
223+
const hasValidFields =
224+
parent.fields &&
225+
parent.fields.length > 0 &&
226+
parent.fields.some(
227+
(field: { value: string }) => field.value && field.value.trim() !== ''
228+
);
229+
230+
const hasPattern = value && value.trim() !== '';
231+
232+
return hasValidFields || hasPattern;
233+
}
234+
),
189235
maskingCharsReplacement: array().of(object().shape({ value: string() })),
190236
replacement: string(),
191237
topicKeysPattern: string(),

0 commit comments

Comments
 (0)