Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(workflows): truncate long descriptions in list views (#91456)

Meikel Ratz23948da0caf0
diff --git a/frontend/src/lib/lemon-ui/LemonTable/LemonTableLink.tsx b/frontend/src/lib/lemon-ui/LemonTable/LemonTableLink.tsx
index 677aa6b408f6..28aa220987cf 100644
--- a/frontend/src/lib/lemon-ui/LemonTable/LemonTableLink.tsx
+++ b/frontend/src/lib/lemon-ui/LemonTable/LemonTableLink.tsx
@@ -1,5 +1,7 @@
import clsx from 'clsx'
-import { ReactNode } from 'react'
+import { ReactNode, useEffect, useRef, useState } from 'react'
+
+import { useResizeObserver } from 'lib/hooks/useResizeObserver'
import { LemonMarkdown } from '../LemonMarkdown'
import { Link, LinkProps } from '../Link'
@@ -12,44 +14,105 @@ interface LemonTableLinkContentProps {
* instead of overflowing. The title itself must carry a `truncate` class for the ellipsis to show.
*/
truncateTitle?: boolean
+ /** Clamp the description to two lines, with a "Show more" toggle when it overflows. */
+ truncateDescription?: boolean
}
export function LemonTableLink({
title,
description,
truncateTitle,
+ truncateDescription,
...props
}: Pick<LinkProps, 'to' | 'onClick' | 'target' | 'className' | 'targetBlankIcon'> &
LemonTableLinkContentProps): JSX.Element {
+ const titleRow = (
+ <div className={clsx('flex flex-row items-center font-semibold text-sm gap-1', truncateTitle && 'min-w-0')}>
+ {title}
+ </div>
+ )
+ const descriptionBlock = description ? (
+ // Keyed by the text so a row reused for a different record (LemonTable falls back to index
+ // keys) doesn't carry over the previous record's expanded state.
+ <LemonTableLinkDescription
+ key={typeof description === 'string' ? description : undefined}
+ description={description}
+ truncate={truncateDescription}
+ />
+ ) : null
+
if (!props.to) {
- return <LemonTableLinkContent title={title} description={description} truncateTitle={truncateTitle} />
+ return (
+ <div className={clsx('flex flex-col py-1', truncateTitle && 'min-w-0')}>
+ {titleRow}
+ {descriptionBlock}
+ </div>
+ )
+ }
+
+ if (truncateDescription) {
+ // The "Show more" toggle is a button, which can't nest inside the anchor, so a clamped
+ // description sits next to the link instead of inside it.
+ return (
+ <div className={clsx('flex flex-col py-1', truncateTitle && 'min-w-0')}>
+ <Link subtle {...props} className={clsx(props.className, truncateTitle && 'block min-w-0')}>
+ {titleRow}
+ </Link>
+ {descriptionBlock}
+ </div>
+ )
}
return (
<Link subtle {...props} className={clsx(props.className, truncateTitle && 'block min-w-0')}>
- <LemonTableLinkContent title={title} description={description} truncateTitle={truncateTitle} />
+ <div className={clsx('flex flex-col py-1', truncateTitle && 'min-w-0')}>
+ {titleRow}
+ {descriptionBlock}
+ </div>
</Link>
)
}
-function LemonTableLinkContent({ title, description, truncateTitle }: LemonTableLinkContentProps): JSX.Element {
+function LemonTableLinkDescription({
+ description,
+ truncate,
+}: {
+ description: ReactNode
+ truncate?: boolean
+}): JSX.Element {
+ const contentRef = useRef<HTMLDivElement | null>(null)
+ const [expanded, setExpanded] = useState(false)
+ const [isOverflowing, setIsOverflowing] = useState(false)
+ // The column resizes with the scene (e.g. opening a side panel), which changes the line count.
+ const { width: contentWidth } = useResizeObserver({ ref: contentRef })
+
+ useEffect(() => {
+ if (truncate && !expanded && contentRef.current) {
+ setIsOverflowing(contentRef.current.scrollHeight > contentRef.current.clientHeight)
+ }
+ }, [truncate, expanded, description, contentWidth])
+
return (
- <div className={clsx('flex flex-col py-1', truncateTitle && 'min-w-0')}>
- <div className={clsx('flex flex-row items-center font-semibold text-sm gap-1', truncateTitle && 'min-w-0')}>
- {title}
+ <div className="text-xs text-tertiary mt-1">
+ <div ref={contentRef} className={clsx(truncate && !expanded && 'line-clamp-2')}>
+ {typeof description === 'string' ? (
+ <LemonMarkdown className="max-w-[30rem]" lowKeyHeadings disableImages>
+ {description}
+ </LemonMarkdown>
+ ) : (
+ description
+ )}
</div>
-
- {description ? (
- <div className="text-xs text-tertiary mt-1">
- {typeof description === 'string' ? (
- <LemonMarkdown className="max-w-[30rem]" lowKeyHeadings>
- {description}
- </LemonMarkdown>
- ) : (
- description
- )}
- </div>
- ) : null}
+ {truncate && (isOverflowing || expanded) && (
+ <Link
+ onClick={() => setExpanded(!expanded)}
+ className="text-xs"
+ aria-expanded={expanded}
+ data-attr="lemon-table-link-description-toggle"
+ >
+ {expanded ? 'Show less' : 'Show more'}
+ </Link>
+ )}
</div>
)
}
diff --git a/frontend/src/scenes/data-pipelines/DataPipelinesHogFunctions.tsx b/frontend/src/scenes/data-pipelines/DataPipelinesHogFunctions.tsx
index 4b62f690a067..b2e7996ce43d 100644
--- a/frontend/src/scenes/data-pipelines/DataPipelinesHogFunctions.tsx
+++ b/frontend/src/scenes/data-pipelines/DataPipelinesHogFunctions.tsx
@@ -102,6 +102,7 @@ export function DataPipelinesHogFunctions({
type={kind}
additionalTypes={additionalKinds}
manualFunctions={manualFunctions}
+ truncateDescriptions
/>
</SceneSection>
<SceneDivider />
diff --git a/frontend/src/scenes/hog-functions/list/HogFunctionsList.tsx b/frontend/src/scenes/hog-functions/list/HogFunctionsList.tsx
index c35093dca807..68cea76915e3 100644
--- a/frontend/src/scenes/hog-functions/list/HogFunctionsList.tsx
+++ b/frontend/src/scenes/hog-functions/list/HogFunctionsList.tsx
@@ -116,6 +116,7 @@ export function HogFunctionList({
onDeleteHogFunction,
onEditHogFunction,
returnTo,
+ truncateDescriptions = false,
...props
}: HogFunctionListLogicProps & {
extraControls?: JSX.Element
@@ -124,6 +125,8 @@ export function HogFunctionList({
onDeleteHogFunction?: (hogFunction: HogFunctionType) => void
onEditHogFunction?: (hogFunction: HogFunctionType) => void
returnTo?: string
+ /** Clamp long descriptions to two lines with a "Show more" toggle. */
+ truncateDescriptions?: boolean
}): JSX.Element {
const { loading, filteredHogFunctions, filters, hogFunctions, hiddenHogFunctions } = useValues(
hogFunctionsListLogic(props)
@@ -176,6 +179,7 @@ export function HogFunctionList({
</>
}
description={hogFunction.description}
+ truncateDescription={truncateDescriptions}
/>
)
},
@@ -324,6 +328,7 @@ export function HogFunctionList({
onDeleteHogFunction,
onEditHogFunction,
returnTo,
+ truncateDescriptions,
]) // oxlint-disable-line react-hooks/exhaustive-deps
return (
diff --git a/products/workflows/frontend/Workflows/WorkflowsTable.tsx b/products/workflows/frontend/Workflows/WorkflowsTable.tsx
index 6561cf8b6737..dc9de3d598d9 100644
--- a/products/workflows/frontend/Workflows/WorkflowsTable.tsx
+++ b/products/workflows/frontend/Workflows/WorkflowsTable.tsx
@@ -172,6 +172,7 @@ export function WorkflowsTable(): JSX.Element {
to={urls.workflow(item.id, 'workflow')}
title={item.name}
description={item.description}
+ truncateDescription
/>
)
},