: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(aio): Polish the playground variables panel (#110573)
Juraj Majerikdcb4b743c433
diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 8a0865fb49c0..3e3b823d6841 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -1960,6 +1960,10 @@ snapshots:hash: v1.k794b7964.a3e65d5201b873423bb6d077e88fcad12715ee293bdedcf5a2dc78efbc2d0cda.VSPF0yHLd7eCx-17S2ASvg21MoomuY6VOjuxq3oPQmIcomponents-playerinspector-itemsessionchange--session-previous--light:hash: v1.k794b7964.33ce327f146d06d1412d431080ac84ae39558411b2073fe18a2ed98d834a2681.FDbDlC4-qfrH2RR1F_KpijnZNM9Ss_4s-p19Ee8fGtY+ components-playground-variables-panel--filled-and-unfilled-variables--dark:+ hash: v1.k794b7964.d28a4b122342606c71fde8cfe726699c638c612006427700a69f4583ac90c0f7.vg3kJyg8C3Yq4hkjUqsB1V7Yzn8CH_HJQKRN-uZU3w0+ components-playground-variables-panel--filled-and-unfilled-variables--light:+ hash: v1.k794b7964.4aa2c49e33f2fb605e8250c6c6dfc5a57efe9ab48e238d8e9e67c59349da62f8.VNbcy3xbFYA93udMaRpGuGWNUtfz4_Xb7zBrBcU3Npscomponents-product-empty-state--actions-needs-setup--dark:hash: v1.k794b7964.bcb8a737d22c6d807eb524fca2acc9c36420609fa1dc3921cee64b73cfb5fdea.686y8Z8cYiKOvpy5d_0CEVwMkSP00WIznn1Cqd7lxEIcomponents-product-empty-state--actions-needs-setup--light:diff --git a/products/ai_observability/frontend/playground/PlaygroundVariablesPanel.stories.tsx b/products/ai_observability/frontend/playground/PlaygroundVariablesPanel.stories.tsxnew file mode 100644index 000000000000..6fc787781d20--- /dev/null+++ b/products/ai_observability/frontend/playground/PlaygroundVariablesPanel.stories.tsx@@ -0,0 +1,31 @@+import { Meta, StoryObj } from '@storybook/react'+import { useActions } from 'kea'+import { useEffect } from 'react'++import { llmPlaygroundPromptsLogic } from './llmPlaygroundPromptsLogic'+import { llmPlaygroundVariablesLogic } from './llmPlaygroundVariablesLogic'+import { PlaygroundVariablesPanel } from './PlaygroundVariablesPanel'++const meta: Meta<typeof PlaygroundVariablesPanel> = {+ title: 'Components/Playground Variables Panel',+ component: PlaygroundVariablesPanel,+}+export default meta+type Story = StoryObj<typeof PlaygroundVariablesPanel>++export const FilledAndUnfilledVariables: Story = {+ render: function Render() {+ const { setSystemPrompt } = useActions(llmPlaygroundPromptsLogic)+ const { setVariableValue } = useActions(llmPlaygroundVariablesLogic)+ useEffect(() => {+ setSystemPrompt('You are a helpful assistant for {{company}}. Write about {{topic}}.')+ setVariableValue('company', 'Hedgebox')+ // oxlint-disable-next-line exhaustive-deps+ }, [])+ return (+ <div className="max-w-150">+ <PlaygroundVariablesPanel />+ </div>+ )+ },+}diff --git a/products/ai_observability/frontend/playground/PlaygroundVariablesPanel.tsx b/products/ai_observability/frontend/playground/PlaygroundVariablesPanel.tsxindex 2422ed052acc..4421559b6b58 100644--- a/products/ai_observability/frontend/playground/PlaygroundVariablesPanel.tsx+++ b/products/ai_observability/frontend/playground/PlaygroundVariablesPanel.tsx@@ -1,7 +1,8 @@import { useActions, useValues } from 'kea'+import { Fragment } from 'react'import { IconChevronRight, IconWarning } from '@posthog/icons'-import { LemonButton, LemonTag, LemonTextArea, Tooltip } from '@posthog/lemon-ui'+import { LemonTag, LemonTextArea, Tooltip } from '@posthog/lemon-ui'import { AnimatedCollapsible } from 'lib/components/AnimatedCollapsible'@@ -20,18 +21,21 @@ export function PlaygroundVariablesPanel(): JSX.Element {return (<div className="border rounded p-4 py-2 shrink-0"><div className={`flex items-center gap-2 ${collapsed ? '' : 'mb-2'}`}>- <LemonButton- size="small"- noPadding- icon={- <IconChevronRight className={`transition-transform ${collapsed ? 'rotate-0' : 'rotate-90'}`} />- }+ {/* A plain button rather than a LemonButton: LemonButton paints+ [aria-expanded='true'] with its active background, which reads as a+ stuck grey state on an expanded section header */}+ <button+ type="button"onClick={() => toggleCollapsed('variables')}aria-expanded={!collapsed}data-attr="llma-playground-toggle-variables"+ className="flex items-center gap-2 cursor-pointer text-sm font-semibold">+ <IconChevronRight+ className={`h-3.5 w-3.5 transition-transform ${collapsed ? 'rotate-0' : 'rotate-90'}`}+ />Variables{detectedVariables.length > 0 ? ` (${detectedVariables.length})` : ''}- </LemonButton>+ </button>{unfilledVariables.length > 0 && (<LemonTag type="warning" size="small">{unfilledVariables.length} unfilled@@ -46,33 +50,50 @@ export function PlaygroundVariablesPanel(): JSX.Element {in a test value here. Values are applied when you run. Saved prompts keep the placeholders.</p>) : (- <div className="space-y-2 mb-2 max-h-80 overflow-y-auto pr-1">- {detectedVariables.map((name) => (- <div key={name} className="flex items-start gap-2">- <code className="text-xs pt-2 whitespace-nowrap">{`{{${name}}}`}</code>- {unfilledVariables.includes(name) && (- <Tooltip title="No value set. The placeholder is sent as written.">- <span- tabIndex={0}- role="img"- aria-label="No value set"- className="text-warning mt-2 shrink-0"- >- <IconWarning />- </span>- </Tooltip>- )}- <LemonTextArea- className="text-sm flex-1"- placeholder="Value"- value={getVariableValue(variableValues, name)}- onChange={(value) => setVariableValue(name, value)}- minRows={1}- maxRows={6}- data-attr="llma-playground-variable-value"- />- </div>- ))}+ <div className="grid grid-cols-[auto_minmax(0,1fr)] gap-2 mb-2 max-h-80 overflow-y-auto pr-1">+ {detectedVariables.map((name) => {+ const unfilled = unfilledVariables.includes(name)+ // The invisible icon keeps its slot, so filling a value never shifts the row.+ const warningIcon = (+ <span+ tabIndex={unfilled ? 0 : -1}+ role="img"+ aria-label="No value set"+ aria-hidden={!unfilled}+ className={`flex shrink-0 ${unfilled ? 'text-warning' : 'invisible'}`}+ >+ <IconWarning />+ </span>+ )+ return (+ <Fragment key={name}>+ {/* h-10 matches LemonTextArea's 2.5rem min-height, centering the+ label and icon on the textarea's first row */}+ <div className="flex h-10 items-center gap-1.5 self-start">+ <code className="text-xs max-w-40 truncate" title={`{{${name}}}`}>+ {`{{${name}}}`}+ </code>+ {unfilled ? (+ <Tooltip title="No value set. The placeholder is sent as written.">+ {warningIcon}+ </Tooltip>+ ) : (+ warningIcon+ )}+ </div>+ <LemonTextArea+ className="text-sm"+ placeholder="Enter a test value"+ aria-label={`Value for {{${name}}}`}+ value={getVariableValue(variableValues, name)}+ onChange={(value) => setVariableValue(name, value)}+ minRows={1}+ maxRows={6}+ data-attr="llma-playground-variable-value"+ />+ </Fragment>+ )+ })}</div>)}</AnimatedCollapsible>