: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
feat(metrics): remove the add variable button from dashboard variables (#127833)
Frank Hamand851e67986b58
diff --git a/frontend/src/scenes/dashboard/DashboardFilters.test.tsx b/frontend/src/scenes/dashboard/DashboardFilters.test.tsxindex f893b1d31ee3..306282f8dddb 100644--- a/frontend/src/scenes/dashboard/DashboardFilters.test.tsx+++ b/frontend/src/scenes/dashboard/DashboardFilters.test.tsx@@ -62,6 +62,5 @@ describe('DashboardFilterBar', () => {expect(screen.getByText('Service')).toBeInTheDocument()expect(!!document.querySelector('[data-attr="dashboard-metric-variables-edit"]')).toBe(editable)- expect(!!document.querySelector('[data-attr="dashboard-metric-variables-add"]')).toBe(editable)})})diff --git a/products/metrics/frontend/components/dashboardVariables/DashboardMetricVariables.tsx b/products/metrics/frontend/components/dashboardVariables/DashboardMetricVariables.tsxindex 159d2774af9d..91b19b4193c7 100644--- a/products/metrics/frontend/components/dashboardVariables/DashboardMetricVariables.tsx+++ b/products/metrics/frontend/components/dashboardVariables/DashboardMetricVariables.tsx@@ -1,7 +1,7 @@import { useActions, useValues } from 'kea'import { useMemo, useState } from 'react'-import { IconGear, IconPlusSmall } from '@posthog/icons'+import { IconGear } from '@posthog/icons'import { LemonButton } from '@posthog/lemon-ui'import { DashboardEventSource } from 'lib/utils/eventUsageLogic'@@ -16,12 +16,10 @@ import { MetricVariablesModal } from './MetricVariablesModal'const NO_VARIABLES: MetricsDashboardVariable[] = []-type EditorMode = 'edit' | 'add'-export function DashboardMetricVariables({ editable = true }: { editable?: boolean }): JSX.Element | null {const { dashboard, dashboardEditing, effectiveEditBarFilters } = useValues(dashboardLogic)const { setMetricVariables, setDashboardEditing } = useActions(dashboardLogic)- const [editorMode, setEditorMode] = useState<EditorMode | null>(null)+ const [editorOpen, setEditorOpen] = useState(false)const metricVariables = effectiveEditBarFilters.metricVariables// A name from the URL without a saved definition, such as a deleted variable, has nothing to show.@@ -64,38 +62,26 @@ export function DashboardMetricVariables({ editable = true }: { editable?: booleonChange={(current) => select(variable.name, current)}/>))}- {editable && shown.length > 0 && (+ {editable && (<LemonButtonsize="small"type="tertiary"icon={<IconGear />}tooltip="Edit variables"- onClick={() => setEditorMode('edit')}+ onClick={() => setEditorOpen(true)}data-attr="dashboard-metric-variables-edit"/>)}- {editable && (- <LemonButton- size="small"- type="tertiary"- icon={<IconPlusSmall />}- onClick={() => setEditorMode('add')}- data-attr="dashboard-metric-variables-add"- >- Add variable- </LemonButton>- )}- {editorMode && (+ {editorOpen && (<MetricVariablesModaldashboardId={dashboard.id}variables={shown}options={options}dateFrom={effectiveEditBarFilters.date_from}dateTo={effectiveEditBarFilters.date_to}- addVariableOnOpen={editorMode === 'add'}- onClose={() => setEditorMode(null)}+ onClose={() => setEditorOpen(false)}onSave={(next) => {- setEditorMode(null)+ setEditorOpen(false)stage(next, variablesToReload(shown, next))}}/>diff --git a/products/metrics/frontend/components/dashboardVariables/MetricVariablesModal.tsx b/products/metrics/frontend/components/dashboardVariables/MetricVariablesModal.tsxindex 0cb897ecbec4..da36dc657abe 100644--- a/products/metrics/frontend/components/dashboardVariables/MetricVariablesModal.tsx+++ b/products/metrics/frontend/components/dashboardVariables/MetricVariablesModal.tsx@@ -22,7 +22,6 @@ export function MetricVariablesModal({options,dateFrom,dateTo,- addVariableOnOpen = false,onClose,onSave,}: {@@ -31,20 +30,15 @@ export function MetricVariablesModal({options: Record<string, string[]>dateFrom?: string | nulldateTo?: string | null- /** Opens on a new, empty variable instead of the first saved one. */- addVariableOnOpen?: booleanonClose: () => voidonSave: (variables: MetricsDashboardVariable[]) => void}): JSX.Element {- const logic = metricVariableEditorLogic({ dashboardId, variables, options, dateFrom, dateTo, addVariableOnOpen })+ const logic = metricVariableEditorLogic({ dashboardId, variables, options, dateFrom, dateTo })const { applying, draft, selectedIndex, selectedVariable, shownErrors } = useValues(logic)const { addVariable, selectVariable, apply } = useActions(logic)return (- <BindLogic- logic={metricVariableEditorLogic}- props={{ dashboardId, variables, options, dateFrom, dateTo, addVariableOnOpen }}- >+ <BindLogic logic={metricVariableEditorLogic} props={{ dashboardId, variables, options, dateFrom, dateTo }}><LemonModalisOpenonClose={onClose}diff --git a/products/metrics/frontend/components/dashboardVariables/metricVariableEditorLogic.test.ts b/products/metrics/frontend/components/dashboardVariables/metricVariableEditorLogic.test.tsindex a7a0cb02267f..584cf7c9ce09 100644--- a/products/metrics/frontend/components/dashboardVariables/metricVariableEditorLogic.test.ts+++ b/products/metrics/frontend/components/dashboardVariables/metricVariableEditorLogic.test.ts@@ -19,21 +19,6 @@ describe('metricVariableEditorLogic', () => {initKeaTests()})- it('opens on one new variable after the saved ones when it adds a variable on open', async () => {- mockOptions.mockResolvedValue({ results: [] })- const logic = metricVariableEditorLogic({- dashboardId: 1,- variables: [{ name: 'job', source: 'custom', customValues: ['a'] }],- options: {},- addVariableOnOpen: true,- })- logic.mount()- await expectLogic(logic).toFinishAllListeners()-- expect(logic.values.draft.map((variable) => variable.name)).toEqual(['job', expect.any(String)])- expect(logic.values.selectedIndex).toBe(1)- })-it('previews a query edit after an edit to another field', async () => {mockOptions.mockResolvedValue({ results: ['a'] })const logic = metricVariableEditorLogic({diff --git a/products/metrics/frontend/components/dashboardVariables/metricVariableEditorLogic.ts b/products/metrics/frontend/components/dashboardVariables/metricVariableEditorLogic.tsindex bbef47dd95ca..2aa1065c9651 100644--- a/products/metrics/frontend/components/dashboardVariables/metricVariableEditorLogic.ts+++ b/products/metrics/frontend/components/dashboardVariables/metricVariableEditorLogic.ts@@ -31,8 +31,6 @@ export interface MetricVariableEditorLogicProps {/** The dashboard date filter, so the preview shows the values of the dashboard window. */dateFrom?: string | nulldateTo?: string | null- /** Opens on a new, empty variable instead of the first saved one. */- addVariableOnOpen?: boolean}// Generated by kea-typegen. Update if you're an agent, ignore if you're human.@@ -284,7 +282,7 @@ export const metricVariableEditorLogic = kea<metricVariableEditorLogicType>([}),reducers(({ props }) => ({draft: [- props.addVariableOnOpen ? [...props.variables, newVariable(props.variables)] : props.variables,+ props.variables,{addVariable: (state) => [...state, newVariable(state)],removeVariable: (state, { index }) => state.filter((_, other) => other !== index),@@ -304,7 +302,7 @@ export const metricVariableEditorLogic = kea<metricVariableEditorLogicType>([},],selectedIndex: [- props.addVariableOnOpen ? props.variables.length : 0,+ 0,{selectVariable: (_, { index }) => index,removeVariable: (state, { index }) => (state >= index ? Math.max(state - 1, 0) : state),