diff --git a/packages/editor/src/tinacms/form-builder/fields-builder.tsx b/packages/editor/src/tinacms/form-builder/fields-builder.tsx index 4aad828a..850c6b73 100644 --- a/packages/editor/src/tinacms/form-builder/fields-builder.tsx +++ b/packages/editor/src/tinacms/form-builder/fields-builder.tsx @@ -152,7 +152,8 @@ export interface FieldsBuilderProps { export function FieldsBuilder({ form, fields }: FieldsBuilderProps) { const editorContext = useEditorContext(); const panelContext = useContext(PanelContext); - const grouped: Record> = {}; + // const grouped: Record> = {}; + const groupedWithSubgroups: { groupName: string; subGroups: string[] }[] = []; const ungrouped: Array = []; fields.forEach((field) => { @@ -161,8 +162,24 @@ export function FieldsBuilder({ form, fields }: FieldsBuilderProps) { } if (field.group) { - grouped[field.group] = grouped[field.group] || []; - grouped[field.group].push(field); + let groupName: string; + let subGroupName: string; + if (field.group.includes("::")) { + [groupName, subGroupName] = field.group.split("::"); + } else { + groupName = field.group; + subGroupName = ""; + } + const existingGroup = groupedWithSubgroups.find( + (group) => group.groupName === groupName + ); + if (existingGroup) { + if (!existingGroup.subGroups.includes(subGroupName)) { + existingGroup.subGroups.push(subGroupName); + } + } else { + groupedWithSubgroups.push({ groupName, subGroups: [subGroupName] }); + } } else { if (field.component === "identity") { return; @@ -198,23 +215,36 @@ export function FieldsBuilder({ form, fields }: FieldsBuilderProps) { {horizontalLine} )} - {Object.keys(grouped).map((groupName) => ( + {groupedWithSubgroups.map(({ groupName, subGroups }) => (
{groupName} - {grouped[groupName].map((field, index, fields) => ( -
- -
- ))} + {subGroups.map((subGroupName) => { + const fieldsInSubGroup = + subGroupName === "" + ? fields.filter((field) => field.group === groupName) + : fields.filter( + (field) => field.group === `${groupName}::${subGroupName}` + ); + return fieldsInSubGroup.map((field, index, fields) => ( + <> + {subGroupName != "" && index === 0 && ( + {subGroupName} + )} +
+ +
+ + )); + })} {horizontalLine}
))} @@ -257,6 +287,16 @@ const FieldsGroupLabel = styled.div` color: #000; `; +const FieldsSubgroupLabel = styled.div` + display: flex; + align-items: center; + + padding: 10px 16px 8px 16px; + + ${Fonts.label2}; + color: #222222; +`; + const FieldsGroup = styled.div` position: relative; display: block;