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(bi): edit bound parameters in metric worksheets (#124721)

Marius Andrad5c9c06cb221
diff --git a/docs/published/handbook/engineering/data-warehouse.md b/docs/published/handbook/engineering/data-warehouse.md
index 0b8e3fa7f573..6bb5bb173128 100644
--- a/docs/published/handbook/engineering/data-warehouse.md
+++ b/docs/published/handbook/engineering/data-warehouse.md
@@ -412,7 +412,7 @@ BI chart settings preserve custom scatter axes and implicit count formatting. Nu
## Catalog metrics in BI mode
-Catalog SQL metrics can open as BI query snapshots. Opening a metric shows a loading state until its definition is ready, or an error if it cannot load. Press **Run** to query the snapshot. Their dates, grouping, and bound values come from the metric definition; shelf edits, worksheet date filters, pivots, and result drilling are unavailable. Changing the chart changes the presentation of those results. Saved snapshots do not follow later catalog edits.
+Catalog SQL metrics can open as BI query snapshots. Opening a metric shows a loading state until its definition is ready, or an error if it cannot load. Press **Run** to query the snapshot. Their dates, grouping, and bound values come from the metric definition; shelf edits, worksheet date filters, pivots, and result drilling are unavailable. For snapshots with bound string, number, or boolean values, **Edit parameters** changes those values for the worksheet without changing the SQL or catalog definition. Number parameters require a finite number. Other parameter types remain unchanged. Apply follows the worksheet auto-update setting; with auto-update off, press **Run**. Changing the chart changes the presentation of those results. Saved snapshots do not follow later catalog edits.
After running a worksheet, **Propose as catalog metric** sends its resolved SQL and date window through catalog review. A pending or failed query cannot be proposed. Proposing an existing metric name updates its definition for review. Direct-connection worksheets cannot be proposed as catalog metrics.
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 6b4c48a6c46e..4ba4a952565f 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -6948,6 +6948,10 @@ snapshots:
hash: v1.k794b7964.5272d9fc095372492de4bc666a4fd7c995c2fb3de8c859a48ddbf7dae5094c8b.VCgPn7znPvjkY-Sx_PsctneSMhp8KtDuBPxFoGjYdPA
products-business-intelligence-scatter--read-only--light:
hash: v1.k794b7964.21cf4e3c6d31ac5d3653d176f876dbec5894d2569bd082e4fc5117a7dbe40af3.b-Dnoj2QTxOlUnZTMZuBqQGvSNk2lnMS0V6wnY_Aud0
+ products-business-intelligence-worksheet-exploration--catalog-metric-parameters--dark:
+ hash: v1.k794b7964.e4aba5a02b47ed60fee15aad80c85c441ace3ccb5d3b01588d3de6e400d1bc6a.vaAwhvGpZJ-YzoLfr5lXDawVlMY26mqYT9GWz58BG4g
+ products-business-intelligence-worksheet-exploration--catalog-metric-parameters--light:
+ hash: v1.k794b7964.c7f82a1b856cd680d7abcdc083c4c867aa5053e375e4ccb25bc79d4d7f7e6467.ZADdvcly-pakRpNSnbtLMw-J0ihLOb2LsLtrhwZGmDY
products-business-intelligence-worksheet-exploration--daily-1500-groups--dark:
hash: v1.k794b7964.2016a21a055e190a89fe3bb674de641d8841a050204b3646a1052ae00a201a4e.91mWPEAqeMveO3bjutJW2uDvY6aYHdP20UTJpLWZRjc
products-business-intelligence-worksheet-exploration--daily-1500-groups--light:
@@ -10797,9 +10801,9 @@ snapshots:
scenes-app-data-warehouse-sql-editor--bi-calculated-measure-editor--light:
hash: v1.k794b7964.c9e9cf295cbfb0aa5228652d2fcde7a616bdbc45406120442f61a57616b3ac1c.hxQqmOmxq6w9FrhKZBKKUhrsjTmOqmcP1p-wXdkO6Go
scenes-app-data-warehouse-sql-editor--bi-catalog-snapshot--dark:
- hash: v1.k794b7964.10181063f3827891d0805f30255cdea9016bd9719e548b1ddbfa9333c79ff677.hkULoQ4TwGAnGsc2m6CXFTzhI_6TfuF2bBpKJXEIP0E
+ hash: v1.k794b7964.3bab191ca654373affb2a2ff0e9fd186102376d247f882ad5e6e11c0a433571b.X2uMCRABz2YNnmzlS4zVq_Z7VbrFwQZ52B33Chp8CTo
scenes-app-data-warehouse-sql-editor--bi-catalog-snapshot--light:
- hash: v1.k794b7964.3370c5777a860307cb7bd0a13c902b1610f9c38065b64fadbfe185349cd9ec81.1PpQrK62SuqteGgeX4sXzL09NY-yAjHumWFFfLzpx7k
+ hash: v1.k794b7964.cee3fd95c7cdabb29d773cf26a06a7e0830e229ba5f13f1996bd981d69bffaa8._dYoW7AVF_leqUuIs_lnnWD8Aaw3VKI-Xp5mc2XhTNQ
scenes-app-data-warehouse-sql-editor--bi-catalog-source--dark:
hash: v1.k794b7964.7db47de6204c734f634f14500a32ad50c79ba78b0ed3c1f8d0204806f9ee7062.cpAWrZVLUPNbk5Vgw6j7FNZgvAzdLNKdg8HMSh-eHrw
scenes-app-data-warehouse-sql-editor--bi-catalog-source--light:
diff --git a/products/business_intelligence/frontend/BIEditor.tsx b/products/business_intelligence/frontend/BIEditor.tsx
index 5d34db78674f..b08fda6238b6 100644
--- a/products/business_intelligence/frontend/BIEditor.tsx
+++ b/products/business_intelligence/frontend/BIEditor.tsx
@@ -26,6 +26,8 @@ import { BIToolbar } from 'products/business_intelligence/frontend/components/BI
import { BIAnalysisControls } from './BIAnalysisControls'
import { BILocalFieldModal } from './BILocalFieldModal'
import { BIMeasureSettingsModal } from './BIMeasureSettingsModal'
+import { biMetricParametersLogic, metricParameterDrafts } from './biMetricParametersLogic'
+import { BIMetricParametersModal } from './BIMetricParametersModal'
export function BIEditor({
tabId,
@@ -40,6 +42,8 @@ export function BIEditor({
const { removeFieldFromShelf, setActiveDropShelf, setActivePanel, toggleFieldsPane } = useActions(
biEditorLogic({ tabId })
)
+ const { open: openMetricParameters } = useActions(biMetricParametersLogic({ tabId }))
+ const hasMetricParameters = metricParameterDrafts(config.querySnapshot).length > 0
const containerRef = useRef<HTMLDivElement>(null)
const biEditorResizerProps: ResizerLogicProps = {
logicKey: 'bi-editor-side-pane',
@@ -88,12 +92,23 @@ export function BIEditor({
<BindLogic logic={biEditorLogic} props={{ tabId }}>
<div className="@container/bi-editor flex min-h-0 flex-1 flex-col" data-attr="bi-catalog-snapshot">
<LemonBanner type="info" dismissKey="bi-query-snapshot">
- This is a fixed SQL copy. Use View SQL to edit its dates or grouping in the SQL editor. Catalog
- changes won't update this copy.{' '}
+ This is a SQL copy.{' '}
+ {hasMetricParameters
+ ? 'Edit its parameters below, or use View SQL to change the query.'
+ : 'Use View SQL to edit its dates or grouping in the SQL editor.'}{' '}
+ Catalog changes won't update this copy.{' '}
{config.catalogMetric && (
<Link to={urls.dataCatalogMetric(config.catalogMetric)}>View catalog definition</Link>
)}
</LemonBanner>
+ {hasMetricParameters && (
+ <div className="p-2">
+ <LemonButton type="secondary" onClick={openMetricParameters}>
+ Edit parameters
+ </LemonButton>
+ </div>
+ )}
+ <BIMetricParametersModal tabId={tabId} />
<BIToolbar />
<div className="relative flex min-h-0 flex-1">
<div className="flex min-h-0 min-w-0 flex-1 flex-col">{children}</div>
diff --git a/products/business_intelligence/frontend/BIMetricParametersModal.tsx b/products/business_intelligence/frontend/BIMetricParametersModal.tsx
new file mode 100644
index 000000000000..5b5eabc291e8
--- /dev/null
+++ b/products/business_intelligence/frontend/BIMetricParametersModal.tsx
@@ -0,0 +1,56 @@
+import { useActions, useValues } from 'kea'
+
+import { LemonButton, LemonCheckbox, LemonInput, LemonLabel, LemonModal } from '@posthog/lemon-ui'
+
+import { biMetricParametersLogic } from './biMetricParametersLogic'
+
+export function BIMetricParametersModal({ tabId }: { tabId: string }): JSX.Element {
+ const { source, parameters, parameterErrors, applyDisabledReason } = useValues(biMetricParametersLogic({ tabId }))
+ const { close, changeParameter, apply } = useActions(biMetricParametersLogic({ tabId }))
+
+ return (
+ <LemonModal
+ title="Edit metric parameters"
+ isOpen={!!source}
+ onClose={close}
+ footer={
+ <>
+ <LemonButton onClick={close}>Cancel</LemonButton>
+ <LemonButton type="primary" onClick={apply} disabledReason={applyDisabledReason}>
+ Apply
+ </LemonButton>
+ </>
+ }
+ >
+ <div className="space-y-4 ph-no-capture">
+ <p>Changes apply to this worksheet. The catalog definition stays the same.</p>
+ {parameters.map(({ name, type, value }) => (
+ <div key={name} className="space-y-1">
+ {type === 'boolean' ? (
+ <LemonCheckbox
+ label={name}
+ checked={value === true}
+ onChange={(value) => changeParameter(name, value)}
+ />
+ ) : (
+ <>
+ <LemonLabel htmlFor={`bi-parameter-${name}`}>{name}</LemonLabel>
+ <LemonInput
+ id={`bi-parameter-${name}`}
+ value={String(value)}
+ onChange={(value) => changeParameter(name, value)}
+ status={parameterErrors[name] ? 'danger' : undefined}
+ />
+ {parameterErrors[name] && (
+ <div className="text-danger" role="alert">
+ {parameterErrors[name]}
+ </div>
+ )}
+ </>
+ )}
+ </div>
+ ))}
+ </div>
+ </LemonModal>
+ )
+}
diff --git a/products/business_intelligence/frontend/BusinessIntelligenceScene.stories.tsx b/products/business_intelligence/frontend/BusinessIntelligenceScene.stories.tsx
index 76a750c28a6b..56ad8ac983cc 100644
--- a/products/business_intelligence/frontend/BusinessIntelligenceScene.stories.tsx
+++ b/products/business_intelligence/frontend/BusinessIntelligenceScene.stories.tsx
@@ -355,3 +355,33 @@ export const NestedPanes: StoryObj = {
export const NestedPanesNarrow: StoryObj = {
render: () => <WorksheetStage config={paneConfig} chartSettings={paneSettings} width={520} />,
}
+
+export const CatalogMetricParameters: StoryObj = {
+ parameters: { testOptions: { waitForSelector: '[role="dialog"]' } },
+ render: () => (
+ <WorksheetStage
+ config={{
+ ...config,
+ source: null,
+ catalogMetric: 'regional_revenue',
+ querySnapshot: {
+ kind: NodeKind.HogQLQuery,
+ query: 'SELECT region, sum(revenue) AS revenue FROM example_orders WHERE channel = {channel} AND revenue >= {minimum_revenue} GROUP BY region',
+ values: { channel: 'direct', minimum_revenue: 100 },
+ },
+ }}
+ />
+ ),
+ play: async (context) => {
+ await meta.play?.(context)
+ await userEvent.click(
+ await waitFor(() => {
+ const button = Array.from(document.querySelectorAll('button')).find(
+ (button) => button.textContent === 'Edit parameters'
+ )
+ expect(button).toBeTruthy()
+ return button!
+ })
+ )
+ },
+}
diff --git a/products/business_intelligence/frontend/biEditorLogic.test.ts b/products/business_intelligence/frontend/biEditorLogic.test.ts
index d0e5d781e6b7..78c0a953dad4 100644
--- a/products/business_intelligence/frontend/biEditorLogic.test.ts
+++ b/products/business_intelligence/frontend/biEditorLogic.test.ts
@@ -14,6 +14,7 @@ import { ChartDisplayType } from '~/types'
import { biConnectionsLogic } from './biConnectionsLogic'
import { biEditorLogic } from './biEditorLogic'
import { BIEditorView, buildBIQuery, getBIFieldPillLabel, parseBIEditorState } from './biEditorTypes'
+import { biMetricParametersLogic } from './biMetricParametersLogic'
describe('biEditorLogic', () => {
const TAB_ID = 'bi-test'
@@ -62,6 +63,68 @@ describe('biEditorLogic', () => {
limit: 1000,
sort: null,
}
+ it('edits snapshot parameters as typed bound values, with cancellation and stale-draft protection', async () => {
+ const logic = biEditorLogic({ tabId: TAB_ID })
+ const parameters = biMetricParametersLogic({ tabId: TAB_ID })
+ logic.mount()
+ parameters.mount()
+ logic.actions.setAutoUpdate(false)
+ const querySnapshot = {
+ kind: NodeKind.HogQLQuery as const,
+ query: 'SELECT {cohort} AS cohort, {minimum} AS minimum, {include_trial} AS include_trial',
+ values: {
+ cohort: 'paid',
+ minimum: 10,
+ include_trial: true,
+ ids: [1, 2],
+ missing: null,
+ ['__proto__']: 'paid',
+ constructor: 5,
+ },
+ }
+ logic.actions.restoreState({ editorView: BIEditorView.BI, config: { ...config, querySnapshot } })
+ parameters.actions.open()
+ expect(parameters.values.parameters.map(({ name }) => name)).toEqual([
+ 'cohort',
+ 'minimum',
+ 'include_trial',
+ '__proto__',
+ 'constructor',
+ ])
+ expect(parameters.values.parameterErrors['__proto__']).toBeUndefined()
+ expect(parameters.values.parameterErrors['constructor']).toBeUndefined()
+ parameters.actions.changeParameter('constructor', '')
+ expect(parameters.values.parameterErrors['constructor']).toBe('Enter a valid number')
+ parameters.actions.changeParameter('constructor', '5')
+ expect(parameters.values.parameterErrors['constructor']).toBeUndefined()
+ parameters.actions.changeParameter('minimum', '')
+ expect(parameters.values.parameterErrors).toEqual({ minimum: 'Enter a valid number' })
+ parameters.actions.apply()
+ expect(logic.values.config.querySnapshot).toEqual(querySnapshot)
+ parameters.actions.close()
+ parameters.actions.open()
+ expect(parameters.values.parameters.find(({ name }) => name === 'minimum')?.value).toBe('10')
+ const literal = "paid' OR 1=1 --"
+ parameters.actions.changeParameter('cohort', literal)
+ parameters.actions.changeParameter('minimum', '25.5')
+ parameters.actions.changeParameter('include_trial', false)
+ await expectLogic(logic, () => parameters.actions.apply()).toDispatchActions([
+ 'setSnapshotParameters',
+ 'runAfterChange',
+ ])
+ expect(buildBIQuery(logic.values.config)?.node.source).toMatchObject({
+ query: querySnapshot.query,
+ values: { ...querySnapshot.values, cohort: literal, minimum: 25.5, include_trial: false },
+ })
+ expect(parameters.values.source).toBeNull()
+ parameters.actions.open()
+ logic.actions.restoreState({ editorView: BIEditorView.BI, config: { ...config, querySnapshot } })
+ expect(parameters.values.applyDisabledReason).toContain('worksheet changed')
+ parameters.actions.apply()
+ expect(logic.values.config.querySnapshot).toEqual(querySnapshot)
+ parameters.unmount()
+ logic.unmount()
+ })
it.each(['sum(properties.amount)', 'sum(properties.amount) / nullIf(count(), 0)'])(
'saves a custom measure expression without the previous count wrapper: %s',
(expression) => {
diff --git a/products/business_intelligence/frontend/biEditorLogic.ts b/products/business_intelligence/frontend/biEditorLogic.ts
index 0988111af2af..432df45295d3 100644
--- a/products/business_intelligence/frontend/biEditorLogic.ts
+++ b/products/business_intelligence/frontend/biEditorLogic.ts
@@ -29,6 +29,7 @@ import {
DatabaseSchemaTable,
DateRange,
HogQLMetadata,
+ HogQLQuery,
HogQLMetadataResponse,
HogLanguage,
NodeKind,
@@ -694,6 +695,13 @@ export interface biEditorLogicActions {
setPanes: (panes: BIConfig['panes']) => {
panes: BIPaneSettings | undefined
}
+ setSnapshotParameters: (
+ source: HogQLQuery,
+ parameters: Record<string, boolean | number | string>
+ ) => {
+ parameters: Record<string, boolean | number | string>
+ source: HogQLQuery
+ }
setSort: (sort: BISort | null) => {
sort: BISort | null
}
@@ -895,6 +903,10 @@ export const biEditorLogic = kea<biEditorLogicType>([
target,
}),
setChartType: (chartType: ChartDisplayType) => ({ chartType }),
+ setSnapshotParameters: (source: HogQLQuery, parameters: Record<string, string | number | boolean>) => ({
+ source,
+ parameters,
+ }),
setDateRange: (dateRange: DateRange) => ({ dateRange }),
setCompareFilter: (compareFilter: CompareFilter) => ({ compareFilter }),
setMissingDates: (missingDates: BIConfig['missingDates']) => ({ missingDates }),
@@ -1052,6 +1064,20 @@ export const biEditorLogic = kea<biEditorLogicType>([
config: [
freshBIConfig(),
{
+ setSnapshotParameters: (config, { source, parameters }) => {
+ if (
+ config.querySnapshot !== source ||
+ Object.entries(parameters).some(
+ ([name, value]) =>
+ !Object.prototype.hasOwnProperty.call(source.values ?? {}, name) ||
+ typeof value !== typeof source.values?.[name] ||
+ (typeof value === 'number' && !Number.isFinite(value))
+ )
+ ) {
+ return config
+ }
+ return { ...config, querySnapshot: { ...source, values: { ...source.values, ...parameters } } }
+ },
renameField: (config, { shelf, index, name }) => {
if (!name.trim()) {
return config
@@ -1712,6 +1738,7 @@ export const biEditorLogic = kea<biEditorLogicType>([
removeFieldFromShelf: () => actions.runAfterChange(),
setChartType: () => actions.runAfterChange(),
setColorBy: () => actions.runAfterChange(),
+ setSnapshotParameters: () => actions.runAfterChange(),
setDateRange: () => actions.runAfterChange(),
setCompareFilter: () => actions.runAfterChange(),
setMissingDates: () => actions.runAfterChange(),
diff --git a/products/business_intelligence/frontend/biMetricParametersLogic.ts b/products/business_intelligence/frontend/biMetricParametersLogic.ts
new file mode 100644
index 000000000000..285f636431f6
--- /dev/null
+++ b/products/business_intelligence/frontend/biMetricParametersLogic.ts
@@ -0,0 +1,161 @@
+import { MakeLogicType, actions, connect, kea, key, listeners, path, props, reducers, selectors } from 'kea'
+
+import { HogQLQuery } from '~/queries/schema/schema-general'
+
+import type { BIConfig } from '../../../frontend/src/queries/schema/schema-business-intelligence'
+import { biEditorLogic } from './biEditorLogic'
+
+type ParameterDraft = { name: string; type: 'string' | 'number' | 'boolean'; value: string | boolean }
+
+export function metricParameterDrafts(query?: HogQLQuery): ParameterDraft[] {
+ return Object.entries(query?.values ?? {}).flatMap<ParameterDraft>(([name, value]) => {
+ if (typeof value === 'boolean') {
+ return [{ name, type: 'boolean' as const, value }]
+ }
+ if (typeof value === 'string' || (typeof value === 'number' && Number.isFinite(value))) {
+ return [{ name, type: typeof value as 'string' | 'number', value: String(value) }]
+ }
+ return []
+ })
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface biMetricParametersLogicValues {
+ config: BIConfig // biEditorLogic
+ applyDisabledReason: string | undefined
+ parameterErrors: Record<string, string>
+ parameters: ParameterDraft[]
+ source: HogQLQuery | null
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface biMetricParametersLogicActions {
+ setSnapshotParameters: (
+ source: HogQLQuery,
+ parameters: Record<string, boolean | number | string>
+ ) => {
+ parameters: Record<string, boolean | number | string>
+ source: HogQLQuery
+ } // biEditorLogic
+ apply: () => {
+ value: true
+ }
+ changeParameter: (
+ name: string,
+ value: boolean | string
+ ) => {
+ name: string
+ value: boolean | string
+ }
+ close: () => {
+ value: true
+ }
+ open: () => {
+ value: true
+ }
+ setDraft: (
+ source: HogQLQuery,
+ parameters: ParameterDraft[]
+ ) => {
+ parameters: ParameterDraft[]
+ source: HogQLQuery
+ }
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface biMetricParametersLogicProps {
+ tabId: string
+}
+
+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
+export interface biMetricParametersLogicMeta {
+ key: string
+ __keaTypeGenInternalSelectorTypes: {
+ parameterErrors: (parameters: ParameterDraft[]) => Record<string, string>
+ applyDisabledReason: (
+ source: HogQLQuery | null,
+ config: BIConfig,
+ parameterErrors: Record<string, string>
+ ) => string | undefined
+ }
+}
+
+export type biMetricParametersLogicType = MakeLogicType<
+ biMetricParametersLogicValues,
+ biMetricParametersLogicActions,
+ biMetricParametersLogicProps,
+ biMetricParametersLogicMeta
+>
+
+export const biMetricParametersLogic = kea<biMetricParametersLogicType>([
+ path(['products', 'business_intelligence', 'frontend', 'biMetricParametersLogic']),
+ props({} as { tabId: string }),
+ key((props) => props.tabId),
+ connect((props: { tabId: string }) => ({
+ values: [biEditorLogic(props), ['config']],
+ actions: [biEditorLogic(props), ['setSnapshotParameters']],
+ })),
+ actions({
+ open: true,
+ close: true,
+ setDraft: (source: HogQLQuery, parameters: ParameterDraft[]) => ({ source, parameters }),
+ changeParameter: (name: string, value: string | boolean) => ({ name, value }),
+ apply: true,
+ }),
+ reducers({
+ source: [null as HogQLQuery | null, { setDraft: (_, { source }) => source, close: () => null }],
+ parameters: [
+ [] as ParameterDraft[],
+ {
+ setDraft: (_, { parameters }) => parameters,
+ changeParameter: (parameters, { name, value }) =>
+ parameters.map((parameter) => (parameter.name === name ? { ...parameter, value } : parameter)),
+ close: () => [],
+ },
+ ],
+ }),
+ selectors({
+ parameterErrors: [
+ (s) => [s.parameters],
+ (parameters: ParameterDraft[]): Record<string, string> =>
+ Object.assign(
+ Object.create(null) as Record<string, string>,
+ Object.fromEntries(
+ parameters.flatMap(({ name, type, value }) =>
+ type === 'number' && (String(value).trim() === '' || !Number.isFinite(Number(value)))
+ ? [[name, 'Enter a valid number']]
+ : []
+ )
+ )
+ ),
+ ],
+ applyDisabledReason: [
+ (s) => [s.source, s.config, s.parameterErrors],
+ (source: HogQLQuery | null, config: BIConfig, errors: Record<string, string>): string | undefined =>
+ source !== config.querySnapshot
+ ? 'The worksheet changed. Close this dialog and try again.'
+ : Object.keys(errors).length
+ ? 'Fix the invalid parameters first'
+ : undefined,
+ ],
+ }),
+ listeners(({ actions, values }) => ({
+ open: () => {
+ if (values.config.querySnapshot) {
+ actions.setDraft(values.config.querySnapshot, metricParameterDrafts(values.config.querySnapshot))
+ }
+ },
+ apply: () => {
+ if (!values.source || values.applyDisabledReason) {
+ return
+ }
+ actions.setSnapshotParameters(
+ values.source,
+ Object.fromEntries(
+ values.parameters.map(({ name, type, value }) => [name, type === 'number' ? Number(value) : value])
+ )
+ )
+ actions.close()
+ },
+ })),
+])
diff --git a/products/business_intelligence/frontend/biSceneLogic.test.ts b/products/business_intelligence/frontend/biSceneLogic.test.ts
index 3d9ebf56545f..4eb909ee16e7 100644
--- a/products/business_intelligence/frontend/biSceneLogic.test.ts
+++ b/products/business_intelligence/frontend/biSceneLogic.test.ts
@@ -284,6 +284,29 @@ describe('biSceneLogic', () => {
expect(logic.values.agentUpdateState).toBeNull()
})
+ it('keeps parameter edits pending with auto-update off and restores them through undo', () => {
+ const node = catalogMetricWorksheet({
+ name: 'event_count',
+ definition: {
+ kind: NodeKind.HogQLQuery,
+ query: 'SELECT count(*) FROM events WHERE event = {event}',
+ values: { event: '$pageview' },
+ },
+ })!
+ logic.actions.restoreWorksheet(node)
+ logic.actions.recordWorksheet(true)
+ editor.actions.setAutoUpdate(false)
+ const lastRun = logic.values.lastRunQuery
+ editor.actions.setSnapshotParameters(editor.values.config.querySnapshot!, { event: 'signup' })
+ expect(logic.values.worksheet.source.values).toEqual({ event: 'signup' })
+ expect(logic.values.worksheet.config.catalogMetric).toBe('event_count')
+ expect(logic.values.lastRunQuery).toEqual(lastRun)
+ logic.actions.undo()
+ expect(logic.values.worksheet.source.values).toEqual({ event: '$pageview' })
+ logic.actions.redo()
+ expect(logic.values.worksheet.config.querySnapshot?.values).toEqual({ event: 'signup' })
+ })
+
it('opens catalog definitions as fixed snapshots and waits for Run', async () => {
const runQuery = jest.fn(() => [200, { columns: ['revenue'], results: [[42]] }])
useMocks({