From 4c02805b2d668c0f492d41326b24da6d2ccba1d2 Mon Sep 17 00:00:00 2001 From: Michael Shilman Date: Sun, 3 Mar 2024 20:58:35 +0800 Subject: [PATCH] Merge pull request #26283 from storybookjs/shilman/fix-controls-type-summary Controls: Fix type summary when table.type unset (cherry picked from commit f0beb18e5460a8243ac27949804befa26bf932b3) --- code/ui/blocks/src/components/ArgsTable/ArgRow.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/code/ui/blocks/src/components/ArgsTable/ArgRow.tsx b/code/ui/blocks/src/components/ArgsTable/ArgRow.tsx index d6e2c73ad905..8f6b6f2c5f99 100644 --- a/code/ui/blocks/src/components/ArgsTable/ArgRow.tsx +++ b/code/ui/blocks/src/components/ArgsTable/ArgRow.tsx @@ -76,12 +76,18 @@ const StyledTd = styled.td<{ expandable: boolean }>(({ theme, expandable }) => ( paddingLeft: expandable ? '40px !important' : '20px !important', })); +const toSummary = (value: any) => { + if (!value) return value; + const val = typeof value === 'string' ? value : value.name; + return { summary: val }; +}; + export const ArgRow: FC = (props) => { const [isHovered, setIsHovered] = useState(false); const { row, updateArgs, compact, expandable, initialExpandedArgs } = props; const { name, description } = row; const table = (row.table || {}) as TableAnnotation; - const type = table.type || row.type; + const type = table.type || toSummary(row.type); const defaultValue = table.defaultValue || row.defaultValue; const required = row.type?.required; const hasDescription = description != null && description !== '';