diff --git a/apps/docs/app/lib/getComponentProps.ts b/apps/docs/app/lib/getComponentProps.ts index b1b27b95..8304f024 100644 --- a/apps/docs/app/lib/getComponentProps.ts +++ b/apps/docs/app/lib/getComponentProps.ts @@ -25,12 +25,30 @@ export const formatData = async (prop: PropItem) => { }; async function formatPropTable(data: ComponentDocWithGroups[]) { - const result = []; + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const result: any[] = []; for (const item of data) { const { groups } = item; for (const group of Object.keys(groups)) { const groupItems = await Promise.all(Object.keys(groups[group]).map(key => formatData(groups[group][key]))); - result.push({ [group]: groupItems }); + + if (groupItems.length > 0) { + const existingGroup = result.find(entry => entry[group]); + + if (existingGroup) { + // Merge new items into the existing group, without duplicates which has the same name + existingGroup[group] = [ + ...existingGroup[group], + ...groupItems.filter( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + newItem => !existingGroup[group].some((existingItem: any) => existingItem.name === newItem.name) + ) + ]; + } else { + // Add a new group to the result + result.push({ [group]: groupItems }); + } + } } } diff --git a/apps/docs/app/ui/components/propTable/PropTable.tsx b/apps/docs/app/ui/components/propTable/PropTable.tsx index 6c6006e2..bffe4890 100644 --- a/apps/docs/app/ui/components/propTable/PropTable.tsx +++ b/apps/docs/app/ui/components/propTable/PropTable.tsx @@ -109,25 +109,9 @@ export default async function PropTable({ component }: PropTableProps) { const { groups } = await getComponentProps(component); const formattedGroups = await formatGroup(groups); - const mergedObject = formattedGroups.reduce((acc, current) => { - for (const [key, value] of Object.entries(current)) { - if (acc[key]) { - acc[key] = acc[key].concat(value); - } else { - acc[key] = value; - } - } - - return acc; - }, {}); - - const mergedArray = Object.entries(mergedObject).map(([key, value]) => ({ - [key]: value - })); - return ( <> - {mergedArray.map(group => { + {formattedGroups.map(group => { const [key] = Object.keys(group); const isEmpty = group[key].length === 0;