Skip to content

Commit c20a244

Browse files
authored
Merge pull request #85 from workfloworchestrator/1904-fix-labels
1904 fix labels
2 parents af63193 + 208afd1 commit c20a244

File tree

10 files changed

+13
-119
lines changed

10 files changed

+13
-119
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+
Fixes label fields by removing section logic

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export const ArrayField = ({ pydanticFormField }: PydanticFormElementProps) => {
3838
}}
3939
>
4040
<RenderFields
41-
components={[
41+
pydanticFormComponents={[
4242
{
4343
Element: component.Element,
4444
pydanticFormField: arrayField,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export const ObjectField = ({
2828
}}
2929
>
3030
<h1>{pydanticFormField.title}</h1>
31-
<RenderFields components={components} />
31+
<RenderFields pydanticFormComponents={components} />
3232
</div>
3333
);
3434
};
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * from './fields';
2+
export * from './zodValidationsPresets';
Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,8 @@
11
import React from 'react';
22

3-
import { RenderFields, RenderSections } from '@/components/render';
4-
import { getFieldBySection } from '@/core/helper';
3+
import { RenderFields } from '@/components/render';
54
import type { FormRenderer as Renderer } from '@/types';
65

76
export const FormRenderer: Renderer = ({ pydanticFormComponents }) => {
8-
const formSections = getFieldBySection(pydanticFormComponents);
9-
const sections = formSections.map((section) => (
10-
<RenderSections
11-
section={section}
12-
key={section.id}
13-
components={pydanticFormComponents}
14-
>
15-
{({ components }) => <RenderFields components={components} />}
16-
</RenderSections>
17-
));
18-
19-
return <div>{sections}</div>;
7+
return <RenderFields pydanticFormComponents={pydanticFormComponents} />;
208
};

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ import { WrapFieldElement } from '@/core/WrapFieldElement';
1010
import { PydanticFormComponents, PydanticFormField } from '@/types';
1111

1212
interface RenderFieldsProps {
13-
components: PydanticFormComponents;
13+
pydanticFormComponents: PydanticFormComponents;
1414
extraTriggerFields?: string[]; // The use case for this is that we want to trigger the array field aswell as the array item field
1515
}
1616

1717
export function RenderFields({
18-
components,
18+
pydanticFormComponents,
1919
extraTriggerFields,
2020
}: RenderFieldsProps) {
21-
return components.map((component) => {
21+
return pydanticFormComponents.map((component) => {
2222
const { Element, isControlledElement } = component.Element;
2323
const field: PydanticFormField = component.pydanticFormField;
2424

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

Lines changed: 0 additions & 36 deletions
This file was deleted.

frontend/packages/pydantic-forms/src/components/render/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,3 @@ export * from './FormRenderer';
33
export * from './RenderForm';
44
export * from './RenderFormErrors';
55
export * from './RenderReactHookFormErrors';
6-
export * from './Sections';

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

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@ import { ControllerRenderProps, FieldValues, useForm } from 'react-hook-form';
88
import {
99
Properties,
1010
PydanticFormApiResponse,
11-
PydanticFormComponents,
1211
PydanticFormField,
1312
PydanticFormFieldAttributes,
1413
PydanticFormFieldOption,
15-
PydanticFormFieldSection,
1614
PydanticFormFieldType,
1715
PydanticFormFieldValidations,
1816
PydanticFormPropertySchemaParsed,
@@ -243,61 +241,6 @@ export const getFieldValidation = (
243241
export const isNullableField = (field: PydanticFormField) =>
244242
!!field.validations.isNullable;
245243

246-
/**
247-
* Sort field per section for displaying
248-
*
249-
* This function will organize the fields per section
250-
* every time a field comes by that starts with label_
251-
* we start a new section
252-
*/
253-
export const getFieldBySection = (components: PydanticFormComponents) => {
254-
const sections: PydanticFormFieldSection[] = [];
255-
let curSection = 0;
256-
257-
// Ids will be nested at this point. We look at the last part of the id
258-
for (const component of components) {
259-
const id = component.pydanticFormField.id.split('.').pop();
260-
const field = component.pydanticFormField;
261-
262-
if (id && id.startsWith('label_')) {
263-
curSection++;
264-
sections.push({
265-
id,
266-
267-
// strange as it is, the backend will put the
268-
// correct label in the 'default' prop
269-
title: field.default ?? field.title,
270-
271-
components: [],
272-
});
273-
274-
continue;
275-
}
276-
277-
if (curSection === 0) {
278-
// if we are here there was no first label field,
279-
// we'll create a label / section to prevent errors
280-
281-
sections.push({
282-
id: 'auto-created-section',
283-
title: '',
284-
components: [],
285-
});
286-
287-
// Make sure new fields are pushed into this section and
288-
// prevent empty sections created
289-
curSection = 1;
290-
}
291-
292-
// since we start at 0, and the first label will add
293-
const targetSection = curSection - 1;
294-
295-
sections[targetSection].components.push(component);
296-
}
297-
298-
return sections;
299-
};
300-
301244
/**
302245
* Will return a Record map of [fieldId]: "Fieldvalue"
303246
*

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,6 @@ export interface PydanticFormField {
115115
properties?: Properties;
116116
}
117117

118-
export interface PydanticFormFieldSection {
119-
id: string;
120-
title: string;
121-
components: PydanticFormComponents;
122-
}
123-
124118
export enum PydanticFormFieldType {
125119
// Primitive types https://json-schema.org/understanding-json-schema/reference/type
126120
STRING = 'string',

0 commit comments

Comments
 (0)