Skip to content

Commit bb8b415

Browse files
authored
Merge pull request #124 from workfloworchestrator/rename-component-matcher
Rename componentMatcher to componentMatcherExtender
2 parents c6feb21 + 8cf1046 commit bb8b415

File tree

9 files changed

+43
-30
lines changed

9 files changed

+43
-30
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'pydantic-forms': minor
3+
---
4+
5+
Rename componentMatcher to componentMatcherExtender

frontend/apps/example/src/app/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ export default function Home() {
9898
apiProvider: pydanticFormApiProvider,
9999
labelProvider: pydanticLabelProvider,
100100
customDataProvider: pydanticCustomDataProvider,
101-
componentMatcher: componentMatcher,
101+
componentMatcherExtender: componentMatcher,
102102
customTranslations: customTranslations,
103103
locale: locale,
104104
}}

frontend/packages/pydantic-forms/src/components/fields/ArrayField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export const ArrayField = ({ pydanticFormField }: PydanticFormElementProps) => {
4545

4646
const component = fieldToComponentMatcher(
4747
arrayItem,
48-
config?.componentMatcher,
48+
config?.componentMatcherExtender,
4949
);
5050

5151
const renderField = (field: Record<'id', string>, index: number) => {

frontend/packages/pydantic-forms/src/components/fields/ObjectField.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export const ObjectField = ({
1212
const { config } = usePydanticFormContext();
1313
const components = getPydanticFormComponents(
1414
pydanticFormField.properties || {},
15-
config?.componentMatcher,
15+
config?.componentMatcherExtender,
1616
);
1717

1818
return (

frontend/packages/pydantic-forms/src/components/render/RenderForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const RenderForm = (contextProps: PydanticFormContextProps) => {
3737
const pydanticFormComponents: PydanticFormComponents =
3838
getPydanticFormComponents(
3939
pydanticFormSchema?.properties || {},
40-
config?.componentMatcher,
40+
config?.componentMatcherExtender,
4141
);
4242

4343
const t = useTranslations('renderForm');

frontend/packages/pydantic-forms/src/core/PydanticFormContextProvider.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ function PydanticFormContextProvider({
8282
customValidationRules,
8383
allowUntouchedSubmit,
8484
skipSuccessNotice,
85-
componentMatcher,
85+
componentMatcherExtender,
8686
cancelButton,
8787
} = config;
8888

@@ -168,7 +168,7 @@ function PydanticFormContextProvider({
168168
pydanticFormSchema,
169169
rhfRef.current,
170170
customValidationRules,
171-
componentMatcher,
171+
componentMatcherExtender,
172172
);
173173

174174
const initialData = getFormValuesFromFieldOrLabels(
@@ -177,7 +177,7 @@ function PydanticFormContextProvider({
177177
...formLabels?.data,
178178
...customData,
179179
},
180-
componentMatcher,
180+
componentMatcherExtender,
181181
);
182182

183183
// initialize the react-hook-form

frontend/packages/pydantic-forms/src/core/helper.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ export const isNullableField = (field: PydanticFormField) =>
258258
export const getFormValuesFromFieldOrLabels = (
259259
pydanticFormSchema?: PydanticFormSchema,
260260
labelData?: Record<string, string>,
261-
componentMatcher?: PydanticFormsContextConfig['componentMatcher'],
261+
componentMatcherExtender?: PydanticFormsContextConfig['componentMatcherExtender'],
262262
) => {
263263
if (!pydanticFormSchema) {
264264
return {};
@@ -270,7 +270,7 @@ export const getFormValuesFromFieldOrLabels = (
270270

271271
const pydanticFormComponents = getPydanticFormComponents(
272272
pydanticFormSchema.properties,
273-
componentMatcher,
273+
componentMatcherExtender,
274274
);
275275

276276
pydanticFormComponents.forEach((component) => {
@@ -346,10 +346,10 @@ export const rhfTriggerValidationsOnChange =
346346
};
347347

348348
export const getMatcher = (
349-
customComponentMatcher: PydanticFormsContextConfig['componentMatcher'],
349+
componentMatcherExtender: PydanticFormsContextConfig['componentMatcherExtender'],
350350
) => {
351-
const componentMatchers = customComponentMatcher
352-
? customComponentMatcher(defaultComponentMatchers)
351+
const componentMatchers = componentMatcherExtender
352+
? componentMatcherExtender(defaultComponentMatchers)
353353
: defaultComponentMatchers;
354354

355355
return (field: PydanticFormField): PydanticComponentMatcher | undefined => {
@@ -362,10 +362,10 @@ export const getMatcher = (
362362
export const getClientSideValidationRule = (
363363
field: PydanticFormField | undefined,
364364
rhf?: ReturnType<typeof useForm>,
365-
customComponentMatcher?: PydanticFormsContextConfig['componentMatcher'],
365+
componentMatcherExtender?: PydanticFormsContextConfig['componentMatcherExtender'],
366366
) => {
367367
if (!field) return z.unknown();
368-
const matcher = getMatcher(customComponentMatcher);
368+
const matcher = getMatcher(componentMatcherExtender);
369369

370370
const componentMatch = matcher(field);
371371

@@ -389,9 +389,9 @@ const defaultComponent: ElementMatch = {
389389

390390
export const fieldToComponentMatcher = (
391391
pydanticFormField: PydanticFormField,
392-
customComponentMatcher: PydanticFormsContextConfig['componentMatcher'],
392+
componentMatcherExtender: PydanticFormsContextConfig['componentMatcherExtender'],
393393
) => {
394-
const matcher = getMatcher(customComponentMatcher);
394+
const matcher = getMatcher(componentMatcherExtender);
395395
const matchedComponent = matcher(pydanticFormField);
396396

397397
const ElementMatch: ElementMatch = matchedComponent
@@ -405,11 +405,14 @@ export const fieldToComponentMatcher = (
405405
};
406406
export const getPydanticFormComponents = (
407407
properties: Properties,
408-
componentMatcher: PydanticFormsContextConfig['componentMatcher'],
408+
componentMatcherExtender: PydanticFormsContextConfig['componentMatcherExtender'],
409409
): PydanticFormComponents => {
410410
const components: PydanticFormComponents = Object.values(properties).map(
411411
(pydanticFormField) => {
412-
return fieldToComponentMatcher(pydanticFormField, componentMatcher);
412+
return fieldToComponentMatcher(
413+
pydanticFormField,
414+
componentMatcherExtender,
415+
);
413416
},
414417
);
415418

frontend/packages/pydantic-forms/src/core/hooks/useGetZodValidator.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ const getZodRule = (
2929
pydanticFormField: PydanticFormField,
3030
rhf: ReturnType<typeof useForm>,
3131
customValidationRule?: CustomValidationRule,
32-
customComponentMatcher?: PydanticFormsContextConfig['componentMatcher'],
32+
componentMatcherExtender?: PydanticFormsContextConfig['componentMatcherExtender'],
3333
): ZodTypeAny => {
3434
const customRule = customValidationRule?.(pydanticFormField, rhf);
3535

@@ -42,7 +42,7 @@ const getZodRule = (
4242
pydanticFormField.properties || {},
4343
rhf,
4444
customValidationRule,
45-
customComponentMatcher,
45+
componentMatcherExtender,
4646
);
4747
return objectValidationObject;
4848
}
@@ -53,7 +53,7 @@ const getZodRule = (
5353
arrayItem,
5454
rhf,
5555
customValidationRule,
56-
customComponentMatcher,
56+
componentMatcherExtender,
5757
)
5858
: z.unknown();
5959
const arrayRule = z
@@ -81,7 +81,7 @@ const getZodRule = (
8181
return getClientSideValidationRule(
8282
pydanticFormField,
8383
rhf,
84-
customComponentMatcher,
84+
componentMatcherExtender,
8585
);
8686
};
8787

@@ -95,11 +95,11 @@ const getZodValidationObject = (
9595
properties: Properties,
9696
rhf: ReturnType<typeof useForm>,
9797
customValidationRule?: CustomValidationRule,
98-
customComponentMatcher?: PydanticFormsContextConfig['componentMatcher'],
98+
componentMatcherExtender?: PydanticFormsContextConfig['componentMatcherExtender'],
9999
) => {
100100
const pydanticFormComponents = getPydanticFormComponents(
101101
properties,
102-
customComponentMatcher,
102+
componentMatcherExtender,
103103
);
104104
if (!pydanticFormComponents) return z.unknown();
105105

@@ -116,7 +116,7 @@ const getZodValidationObject = (
116116
pydanticFormField,
117117
rhf,
118118
customValidationRule,
119-
customComponentMatcher,
119+
componentMatcherExtender,
120120
);
121121

122122
validationObject[id] = zodRules;
@@ -129,7 +129,7 @@ export const useGetZodValidator = (
129129
pydanticFormSchema?: PydanticFormSchema,
130130
rhf?: ReturnType<typeof useForm>,
131131
customValidationRule?: CustomValidationRule,
132-
customComponentMatcher?: PydanticFormsContextConfig['componentMatcher'],
132+
componentMatcherExtender?: PydanticFormsContextConfig['componentMatcherExtender'],
133133
) => {
134134
return useMemo(() => {
135135
if (!pydanticFormSchema || !rhf) {
@@ -140,9 +140,14 @@ export const useGetZodValidator = (
140140
pydanticFormSchema.properties,
141141
rhf,
142142
customValidationRule,
143-
customComponentMatcher,
143+
componentMatcherExtender,
144144
);
145145

146146
return validationObject;
147-
}, [customComponentMatcher, customValidationRule, pydanticFormSchema, rhf]);
147+
}, [
148+
componentMatcherExtender,
149+
customValidationRule,
150+
pydanticFormSchema,
151+
rhf,
152+
]);
148153
};

frontend/packages/pydantic-forms/src/types.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export interface PydanticFormZodValidationPresets {
259259
[type: string]: PydanticFormZodValidationFn;
260260
}
261261

262-
export type ComponentMatcher = (
262+
export type ComponentMatcherExtender = (
263263
currentMatchers: PydanticComponentMatcher[],
264264
) => PydanticComponentMatcher[];
265265

@@ -290,7 +290,7 @@ export interface PydanticFormsContextConfig {
290290

291291
resetButtonAlternative?: React.ReactNode;
292292

293-
componentMatcher?: ComponentMatcher;
293+
componentMatcherExtender?: ComponentMatcherExtender;
294294

295295
formRenderer?: FormRenderComponent;
296296
footerRenderer?: React.JSXElementConstructor<object>;

0 commit comments

Comments
 (0)