: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(customer-analytics): restore add metric button on customer profiles (#75296)
Christiaan Hendriksen3acab590390d
diff --git a/frontend/src/scenes/notebooks/Nodes/NotebookNodeUsageMetrics.tsx b/frontend/src/scenes/notebooks/Nodes/NotebookNodeUsageMetrics.tsxindex 5096e892137e..64eebb8d388e 100644--- a/frontend/src/scenes/notebooks/Nodes/NotebookNodeUsageMetrics.tsx+++ b/frontend/src/scenes/notebooks/Nodes/NotebookNodeUsageMetrics.tsx@@ -1,10 +1,14 @@import { BindLogic, useActions, useValues } from 'kea'import { IconPlusSmall, IconRefresh } from '@posthog/icons'+import { LemonButton } from '@posthog/lemon-ui'import { ProductIntroduction } from 'lib/components/ProductIntroduction/ProductIntroduction'+import { RestrictionScope, useRestrictedArea } from 'lib/components/RestrictedArea'+import { TeamMembershipLevel } from 'lib/constants'import { useOnMountEffect } from 'lib/hooks/useOnMountEffect'import { useAttachedLogic } from 'lib/logic/scenes/useAttachedLogic'+import { eventUsageLogic } from 'lib/utils/eventUsageLogic'import { UsageMetricsConfig, UsageMetricsModal } from 'scenes/settings/environment/UsageMetricsConfig'import { usageMetricsConfigLogic } from 'scenes/settings/environment/usageMetricsConfigLogic'@@ -24,7 +28,7 @@ import { notebookNodeLogic } from './notebookNodeLogic'const Component = ({ attributes }: NotebookNodeProps<NotebookNodeUsageMetricsAttributes>): JSX.Element | null => {const { expanded, notebookLogic } = useValues(notebookNodeLogic)- const { setActions, setMenuItems } = useActions(notebookNodeLogic)+ const { setMenuItems } = useActions(notebookNodeLogic)const { personId, groupKey, groupTypeIndex, tabId } = attributesconst dataNodeLogicProps = personId? {@@ -50,24 +54,11 @@ const Component = ({ attributes }: NotebookNodeProps<NotebookNodeUsageMetricsAttuseAttachedLogic(logic, notebookLogic)const { response, responseLoading, responseError } = useValues(logic)const { loadData } = useActions(logic)- const usageMetricsConfigLogicProps = { logicKey: attributes.nodeId }+ const usageMetricsConfigLogicProps = { logicKey: attributes.nodeId, onMetricsChanged: loadData }const { openModal } = useActions(usageMetricsConfigLogic(usageMetricsConfigLogicProps))useOnMountEffect(() => {const removeMenuItem = getCustomerProfileRemoveMenuItem(NotebookNodeType.UsageMetrics)- setActions([- {- text: 'Add metric',- icon: <IconPlusSmall />,- onClick: openModal,- },- {- text: 'Refresh',- icon: <IconRefresh />,- onClick: loadData,- },- ])-const addMetricMenuItem = {label: 'Add metric',sideIcon: <IconPlusSmall />,@@ -113,7 +104,10 @@ const Component = ({ attributes }: NotebookNodeProps<NotebookNodeUsageMetricsAttreturn (<BindLogic logic={usageMetricsConfigLogic} props={usageMetricsConfigLogicProps}><div className="@container">- <div className="grid grid-cols-1 @md:grid-cols-2 @xl:grid-cols-4 gap-4 p-4">+ <div className="flex justify-end px-4 pt-4">+ <AddUsageMetricButton />+ </div>+ <div className="grid grid-cols-1 @md:grid-cols-2 @xl:grid-cols-4 gap-4 px-4 pb-4 pt-2">{results.map((metric) => (<UsageMetricCard key={metric.id} metric={metric} />))}@@ -124,8 +118,37 @@ const Component = ({ attributes }: NotebookNodeProps<NotebookNodeUsageMetricsAtt)}+function AddUsageMetricButton(): JSX.Element {+ const { openModal } = useActions(usageMetricsConfigLogic)+ const { reportUsageMetricsCreateButtonClicked } = useActions(eventUsageLogic)+ const restrictedReason = useRestrictedArea({+ scope: RestrictionScope.Project,+ minimumAccessLevel: TeamMembershipLevel.Admin,+ })++ return (+ <LemonButton+ type="secondary"+ size="small"+ icon={<IconPlusSmall />}+ disabledReason={restrictedReason}+ data-attr="usage-metrics-node-add-metric"+ onClick={() => {+ reportUsageMetricsCreateButtonClicked()+ openModal()+ }}+ >+ Add metric+ </LemonButton>+ )+}+function UsageMetricsEmptyState(): JSX.Element {const { openModal } = useActions(usageMetricsConfigLogic)+ const restrictedReason = useRestrictedArea({+ scope: RestrictionScope.Project,+ minimumAccessLevel: TeamMembershipLevel.Admin,+ })return (<ProductIntroductionproductName="Customer analytics"@@ -135,6 +158,7 @@ function UsageMetricsEmptyState(): JSX.Element {productKey={ProductKey.CUSTOMER_ANALYTICS}className="border-none"action={() => openModal()}+ disabledReason={restrictedReason ?? undefined}/>)}diff --git a/frontend/src/scenes/settings/environment/usageMetricsConfigLogic.ts b/frontend/src/scenes/settings/environment/usageMetricsConfigLogic.tsindex a27cb7e32149..b6aa8451a75f 100644--- a/frontend/src/scenes/settings/environment/usageMetricsConfigLogic.ts+++ b/frontend/src/scenes/settings/environment/usageMetricsConfigLogic.ts@@ -118,6 +118,7 @@ const GROUP_TYPE_INDEX = 0export interface UsageMetricsConfigLogicProps {logicKey?: string+ onMetricsChanged?: () => void}// Generated by kea-typegen. Update if you're an agent, ignore if you're human.@@ -370,7 +371,7 @@ export const usageMetricsConfigLogic = kea<usageMetricsConfigLogicType>([},})),- listeners(({ actions }) => ({+ listeners(({ actions, props }) => ({closeModal: () => {actions.resetUsageMetric()},@@ -385,14 +386,17 @@ export const usageMetricsConfigLogic = kea<usageMetricsConfigLogicType>([product_type: ProductKey.CUSTOMER_ANALYTICS,intent_context: ProductIntentContext.CUSTOMER_ANALYTICS_USAGE_METRIC_CREATED,})+ props.onMetricsChanged?.()},updateUsageMetricSuccess: () => {actions.loadUsageMetrics()actions.reportUsageMetricUpdated()+ props.onMetricsChanged?.()},removeUsageMetricSuccess: () => {actions.loadUsageMetrics()actions.reportUsageMetricDeleted()+ props.onMetricsChanged?.()},})),])