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.

feat(sql-editor): allow inline edits of insight name and description (#59211)

Christiaan Hendriksene12505c31703
diff --git a/frontend/src/layout/scenes/components/SceneTitleSection.tsx b/frontend/src/layout/scenes/components/SceneTitleSection.tsx
index 3d195a5781b7..b7d07e44e215 100644
--- a/frontend/src/layout/scenes/components/SceneTitleSection.tsx
+++ b/frontend/src/layout/scenes/components/SceneTitleSection.tsx
@@ -381,7 +381,7 @@ export function SceneTitleSection({
{/* Border is handled by the outer container's border-b */}
</div>
{hasDescription && (showDescription || forceEdit) && (
- <div className="[&_svg]:size-6 -mt-4">
+ <div className={cn('[&_svg]:size-6', noPadding ? cn('pl-4 pr-2', className) : '-mt-4')}>
<SceneDescription
description={effectiveDescription}
markdown={markdown}
diff --git a/frontend/src/scenes/data-warehouse/editor/SQLEditor.tsx b/frontend/src/scenes/data-warehouse/editor/SQLEditor.tsx
index a4310768b0e2..283367e31170 100644
--- a/frontend/src/scenes/data-warehouse/editor/SQLEditor.tsx
+++ b/frontend/src/scenes/data-warehouse/editor/SQLEditor.tsx
@@ -314,6 +314,8 @@ function SQLEditorSceneTitle(): JSX.Element | null {
setSourceQuery,
setSuggestedQueryInput,
reportAIQueryPromptOpen,
+ setEditingInsightName,
+ setEditingInsightDescription,
} = useActions(sqlEditorLogic)
const { response, responseError, responseLoading } = useValues(dataNodeLogic)
const { updatingDataWarehouseSavedQuery } = useValues(dataWarehouseViewsLogic)
@@ -408,6 +410,13 @@ function SQLEditorSceneTitle(): JSX.Element | null {
noBorder
noPadding
{...titleSectionProps}
+ {...(editingInsight && {
+ onNameChange: setEditingInsightName,
+ onDescriptionChange: setEditingInsightDescription,
+ canEdit: true,
+ forceEdit: true,
+ descriptionMaxLength: 400,
+ })}
maxToolProps={{
identifier: 'execute_sql',
context: getExecuteSqlToolContext(queryInput, sourceQuery),
diff --git a/frontend/src/scenes/data-warehouse/editor/editorSceneLogic.tsx b/frontend/src/scenes/data-warehouse/editor/editorSceneLogic.tsx
index a3ba2d926797..e60b62acbe9f 100644
--- a/frontend/src/scenes/data-warehouse/editor/editorSceneLogic.tsx
+++ b/frontend/src/scenes/data-warehouse/editor/editorSceneLogic.tsx
@@ -163,7 +163,8 @@ export const editorSceneLogic = kea<editorSceneLogicType>([
return {
forceBackTo,
- name: editingInsight.name || editingInsight.derived_name || 'Untitled',
+ name: activeTab?.name || editingInsight.derived_name || '',
+ description: activeTab?.description ?? editingInsight.description ?? '',
resourceType: { type: 'insight/hog' },
}
}
@@ -284,12 +285,14 @@ export const editorSceneLogic = kea<editorSceneLogicType>([
}
const updatedName = activeTab?.name !== editingInsight.name
+ const updatedDescription = (activeTab?.description ?? '') !== (editingInsight.description ?? '')
const sourceQueryWithoutUndefinedAndNullKeys = removeUndefinedAndNull(sourceQuery)
// Normalize so DataTableNode-based insights don't look "changed" immediately after load.
const editingInsightQuery = toDataVisualizationNode(editingInsight.query) ?? editingInsight.query
return (
updatedName ||
+ updatedDescription ||
!equal(sourceQueryWithoutUndefinedAndNullKeys, removeUndefinedAndNull(editingInsightQuery))
)
},
diff --git a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts
index d8f8c436e783..8f202545d38e 100644
--- a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts
+++ b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.test.ts
@@ -743,6 +743,90 @@ describe('sqlEditorLogic', () => {
})
})
+ describe('inline insight metadata editing', () => {
+ async function loadInsight(): Promise<void> {
+ logic = sqlEditorLogic({
+ tabId: TAB_ID,
+ monaco: createMockMonaco(),
+ editor: createMockEditor(),
+ })
+ logic.mount()
+ editorRootLogic = editorSceneLogic({ tabId: TAB_ID })
+ editorRootLogic.mount()
+
+ router.actions.push(urls.sqlEditor(), { open_insight: MOCK_INSIGHT_SHORT_ID })
+ await expectLogic(logic)
+ .toDispatchActions(['editInsight', 'createTab', 'updateTab'])
+ .toMatchValues({ editingInsight: partial({ short_id: MOCK_INSIGHT_SHORT_ID }) })
+
+ // Mirror what BindLogic does in production so updateInsightButtonEnabled has the saved query
+ const visualizationLogic = dataVisualizationLogic({
+ key: logic.values.dataLogicKey,
+ query: MOCK_INSIGHT_QUERY,
+ dataNodeCollectionId: logic.values.dataLogicKey,
+ })
+ visualizationLogic.mount()
+ }
+
+ it('seeds the active tab with the insight name and description on load', async () => {
+ await loadInsight()
+
+ expect(logic.values.activeTab?.name).toEqual(MOCK_INSIGHT.name)
+ expect(logic.values.activeTab?.description).toEqual(MOCK_INSIGHT.description)
+ expect(editorRootLogic!.values.updateInsightButtonEnabled).toEqual(false)
+ })
+
+ it('preserves an empty insight name instead of falling back to NEW_QUERY', async () => {
+ logic = sqlEditorLogic({
+ tabId: TAB_ID,
+ monaco: createMockMonaco(),
+ editor: createMockEditor(),
+ })
+ logic.mount()
+ editorRootLogic = editorSceneLogic({ tabId: TAB_ID })
+ editorRootLogic.mount()
+
+ const insightWithEmptyName = { ...MOCK_INSIGHT, name: '' } as QueryBasedInsightModel
+ logic.actions.createTab(MOCK_INSIGHT_QUERY.source.query, undefined, insightWithEmptyName)
+ await expectLogic(logic).toDispatchActions(['createTab', 'updateTab'])
+
+ expect(logic.values.activeTab?.name).toEqual('')
+ })
+
+ it.each([
+ ['name', 'setEditingInsightName' as const, 'Renamed Insight'],
+ ['description', 'setEditingInsightDescription' as const, 'A new description'],
+ ])(
+ 'treats an inline %s edit as a pending change that enables Update insight',
+ async (field, action, newValue) => {
+ await loadInsight()
+
+ logic.actions[action](newValue)
+
+ expect(logic.values.activeTab?.[field as 'name' | 'description']).toEqual(newValue)
+ expect(editorRootLogic!.values.updateInsightButtonEnabled).toEqual(true)
+ expect(editorRootLogic!.values.titleSectionProps).toMatchObject({
+ [field]: newValue,
+ })
+ }
+ )
+
+ it('discards pending name and description edits when the insight is closed', async () => {
+ await loadInsight()
+
+ logic.actions.setEditingInsightName('Renamed Insight')
+ logic.actions.setEditingInsightDescription('A new description')
+ logic.actions.closeEditingObject()
+
+ await expectLogic(logic).toDispatchActions(['closeEditingObject', 'updateTab']).toMatchValues({
+ editingInsight: null,
+ })
+
+ expect(logic.values.activeTab?.name).toEqual('Untitled')
+ expect(logic.values.activeTab?.description).toEqual('')
+ })
+ })
+
describe('activeTabMatchesUrlTarget', () => {
it.each([
[
diff --git a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.tsx b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.tsx
index 96b7ea313444..c7ad51fccee6 100644
--- a/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.tsx
+++ b/frontend/src/scenes/data-warehouse/editor/sqlEditorLogic.tsx
@@ -42,6 +42,7 @@ import { urls } from 'scenes/urls'
import { userLogic } from 'scenes/userLogic'
import { dashboardsModel } from '~/models/dashboardsModel'
+import { insightsModel } from '~/models/insightsModel'
import { dataNodeLogic } from '~/queries/nodes/DataNode/dataNodeLogic'
import { dataVisualizationLogic } from '~/queries/nodes/DataVisualization/dataVisualizationLogic'
import { performQuery, queryExportContext } from '~/queries/query'
@@ -169,6 +170,7 @@ export interface QueryTab {
uri: Uri
view?: DataWarehouseSavedQuery
name: string
+ description?: string
sourceQuery?: DataVisualizationNode
insight?: QueryBasedInsightModel
response?: Record<string, any>
@@ -476,6 +478,8 @@ export const sqlEditorLogic = kea<sqlEditorLogicType>([
dagId,
}),
updateInsight: true,
+ setEditingInsightName: (name: string) => ({ name }),
+ setEditingInsightDescription: (description: string) => ({ description }),
closeEditingObject: true,
setFinishedLoading: (loading: boolean) => ({ loading }),
setError: (error: string | null) => ({ error }),
@@ -1012,7 +1016,8 @@ export const sqlEditorLogic = kea<sqlEditorLogicType>([
},
createTab: async ({ query = '', view, insight, draft }) => {
// Use tabId to ensure each browser tab has its own unique Monaco model
- const tabName = draft?.name || view?.name || insight?.name || NEW_QUERY
+ const tabName = insight ? (insight.name ?? NEW_QUERY) : draft?.name || view?.name || NEW_QUERY
+ const tabDescription = insight?.description ?? ''
const rawInsightVisualizationQuery = toDataVisualizationNode(insight?.query)
const insightVisualizationQuery = rawInsightVisualizationQuery
? sanitizeSourceQuery(rawInsightVisualizationQuery)
@@ -1041,6 +1046,7 @@ export const sqlEditorLogic = kea<sqlEditorLogicType>([
view,
insight,
name: tabName,
+ description: tabDescription,
sourceQuery: insightVisualizationQuery,
draft: draft,
})
@@ -1691,6 +1697,16 @@ export const sqlEditorLogic = kea<sqlEditorLogicType>([
lemonToast.error(error.detail || 'Failed to create endpoint')
}
},
+ setEditingInsightName: ({ name }) => {
+ if (values.activeTab) {
+ actions.updateTab({ ...values.activeTab, name })
+ }
+ },
+ setEditingInsightDescription: ({ description }) => {
+ if (values.activeTab) {
+ actions.updateTab({ ...values.activeTab, description })
+ }
+ },
updateInsight: async () => {
if (!values.editingInsight) {
return
@@ -1699,10 +1715,12 @@ export const sqlEditorLogic = kea<sqlEditorLogicType>([
actions.setInsightLoading(true)
const insightName = values.activeTab?.name
+ const insightDescription = values.activeTab?.description
const currentVisualizationQuery = getCurrentVisualizationQuery(values.dataLogicKey, values.sourceQuery)
const insightRequest: Partial<QueryBasedInsightModel> = {
name: insightName ?? values.editingInsight.name,
+ description: insightDescription ?? values.editingInsight.description ?? '',
query: currentVisualizationQuery,
}
@@ -1726,6 +1744,7 @@ export const sqlEditorLogic = kea<sqlEditorLogicType>([
insight: savedInsight,
})
}
+ insightsModel.findMounted()?.actions.renameInsightSuccess(savedInsight)
const loadedLogic = insightLogic.findMounted({
dashboardItemId: values.editingInsight.short_id,
dashboardId: undefined,
@@ -1770,6 +1789,7 @@ export const sqlEditorLogic = kea<sqlEditorLogicType>([
const nextActiveTab = {
...values.activeTab,
name: NEW_QUERY,
+ description: '',
view: undefined,
insight: undefined,
draft: undefined,
diff --git a/frontend/src/scenes/insights/InsightPageHeader.tsx b/frontend/src/scenes/insights/InsightPageHeader.tsx
index ec0449680e5f..d73429886d3c 100644
--- a/frontend/src/scenes/insights/InsightPageHeader.tsx
+++ b/frontend/src/scenes/insights/InsightPageHeader.tsx
@@ -120,7 +120,7 @@ export function InsightPageHeader({ insightLogicProps }: { insightLogicProps: In
isLoading={insightLoading && !insight?.id}
forceEdit={insightMode === ItemMode.Edit}
renameDebounceMs={0}
- saveOnBlur
+ saveOnBlur={insightMode !== ItemMode.Edit}
descriptionMaxLength={400}
maxToolProps={readDataMaxToolProps}
actions={