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(experiments): Humanize metric reorder in activity log (#57596)

Juraj Majerik01c660fdebfa
diff --git a/frontend/src/scenes/experiments/activity-descriptions/experimentChangeDescription.tsx b/frontend/src/scenes/experiments/activity-descriptions/experimentChangeDescription.tsx
index 71e082d90594..3b754fd87fcd 100644
--- a/frontend/src/scenes/experiments/activity-descriptions/experimentChangeDescription.tsx
+++ b/frontend/src/scenes/experiments/activity-descriptions/experimentChangeDescription.tsx
@@ -37,11 +37,32 @@ export const nameOrLinkToExperiment = (name: string | null, id?: string): JSX.El
*/
type AllowedExperimentFields = Pick<
Experiment,
- 'conclusion' | 'start_date' | 'end_date' | 'metrics' | 'metrics_secondary' | 'exposure_criteria'
+ | 'conclusion'
+ | 'start_date'
+ | 'end_date'
+ | 'metrics'
+ | 'metrics_secondary'
+ | 'exposure_criteria'
+ | 'primary_metrics_ordered_uuids'
+ | 'secondary_metrics_ordered_uuids'
> & {
deleted: boolean
}
+/**
+ * Detect a pure metric reorder. Returns the description only when the two
+ * arrays contain the same set of UUIDs in a different order — additions,
+ * removals, and swaps are described by the `metrics` field matcher instead.
+ */
+const describeMetricReorder = (before: unknown, after: unknown, description: string): string | null => {
+ const b = (before as string[] | null) ?? []
+ const a = (after as string[] | null) ?? []
+ if (equal(b, a) || !equal([...b].sort(), [...a].sort())) {
+ return null
+ }
+ return description
+}
+
export const getExperimentChangeDescription = (
experimentChange: ActivityChange
): string | JSX.Element | (string | JSX.Element)[] | null => {
@@ -115,6 +136,12 @@ export const getExperimentChangeDescription = (
.with({ field: 'metrics_secondary', action: 'changed' }, ({ before, after }) =>
getMetricChanges(before as ExperimentMetric[], after as ExperimentMetric[])
)
+ .with({ field: 'primary_metrics_ordered_uuids', action: 'changed' }, ({ before, after }) =>
+ describeMetricReorder(before, after, 'reordered the primary metrics')
+ )
+ .with({ field: 'secondary_metrics_ordered_uuids', action: 'changed' }, ({ before, after }) =>
+ describeMetricReorder(before, after, 'reordered the secondary metrics')
+ )
.with({ field: 'exposure_criteria' }, ({ before, after }) => {
/**
* exposure criteria is by default `{filter_test_accounts: true}`,