feat(customer-analytics): add calculation selector and adopt generated API types#54347
Conversation
|
Size Change: +5.42 kB (0%) Total Size: 130 MB
ℹ️ View Unchanged
|
This comment was marked as outdated.
This comment was marked as outdated.
Prompt To Fix All With AIThis is a comment left during a code review.
Path: frontend/src/scenes/settings/environment/usageMetricsConfigLogic.ts
Line: 21
Comment:
**Superfluous re-export**
`GroupUsageMetricApi` is no longer imported from this logic file by any consumer — `UsageMetricsConfig.tsx` now imports directly from the generated schema, and `NotebookNodeUsageMetrics.tsx` only imports the logic function itself. This dead re-export violates the "no superfluous parts" simplicity rule.
```suggestion
```
(Remove the line entirely.)
How can I resolve this? If you propose a fix, please make it concise.
---
This is a comment left during a code review.
Path: frontend/src/scenes/settings/environment/usageMetricsConfigLogic.ts
Line: 83-88
Comment:
**Type assertion incorrectly adds `id` back**
`payload` is `Omit<GroupUsageMetricApi, 'id'>`, but it is cast to `GroupUsageMetricApi` whose `id: string` is required. TypeScript accepts the `as` assertion without verifying the missing field, so the generated `groupsTypesMetricsCreate` function's parameter type `NonReadonly<GroupUsageMetricApi>` is technically violated. A safer assertion that accurately reflects the runtime shape would be:
```suggestion
const newMetric = await groupsTypesMetricsCreate(
values.currentProjectId,
GROUP_TYPE_INDEX,
payload as NonReadonly<Omit<GroupUsageMetricApi, 'id'>> as NonReadonly<GroupUsageMetricApi>
)
```
Or alternatively, the generated function signature for create could be widened to accept `Omit<NonReadonly<GroupUsageMetricApi>, 'id'>` if regenerating.
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "feat(customer-analytics): add calculatio..." | Re-trigger Greptile |
9b7a48c to
3e24102
Compare
|
🎭 Playwright report · View test results →
These issues are not necessarily caused by your changes. |
6d6a4ad to
e0673f4
Compare
e0673f4 to
659b6d3
Compare
73ce462 to
bbd12a4
Compare
Prompt To Fix All With AIThis is a comment left during a code review.
Path: frontend/src/scenes/settings/environment/usageMetricsConfigLogic.ts
Line: 21
Comment:
**Superfluous `export` on `UsageMetricFormData`**
`UsageMetricFormData` is only used within this file (`NEW_USAGE_METRIC`, `addUsageMetric`, `updateUsageMetric`) and nothing imports it externally. The `export` keyword is superfluous per the "no superfluous parts" simplicity rule.
```suggestion
type UsageMetricFormData = Omit<GroupUsageMetricApi, 'id'> & { id?: string }
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (2): Last reviewed commit: "fix(customer-analytics): fix type error ..." | Re-trigger Greptile |
There was a problem hiding this comment.
The PR imports GroupUsageMetricApi and groupsTypesMetrics* API functions from products/customer_analytics/frontend/generated/api[.schemas], but those exports only exist in products/metrics/frontend/generated/. The customer_analytics generated files contain only CustomerJourneyApi and related types. Additionally, the existing GroupUsageMetricApi in the metrics schema lacks the math and math_property fields this code uses, indicating the backend serializer and OpenAPI types were never regenerated. This PR would fail TypeScript compilation.
659b6d3 to
9eef96d
Compare
bbd12a4 to
4bbfb67
Compare
…d API types Generated-By: PostHog Code Task-Id: 887010a6-d3c0-4a87-b260-bdbc5cb48df1
Generated-By: PostHog Code Task-Id: 887010a6-d3c0-4a87-b260-bdbc5cb48df1
Generated-By: PostHog Code Task-Id: 887010a6-d3c0-4a87-b260-bdbc5cb48df1
Generated-By: PostHog Code Task-Id: 887010a6-d3c0-4a87-b260-bdbc5cb48df1
185891e to
e3593d6
Compare

Problem
The usage metrics config UI has no way to select sum-based aggregation (added in #54346), and the frontend uses handwritten types and manual API calls instead of generated ones.
Changes
api.get/create/update/deletecalls to generatedgroupsTypesMetrics*functionsUsageMetricFormDatafrom the generatedGroupUsageMetricApitypeGroupUsageMetricViewSettypes tocustomer_analyticsgenerated outputHow did you test this code?
Existing test suite. Frontend changes are type-safe against the generated API types.
Publish to changelog?
No
Docs update
N/A
🤖 LLM context
Agent-authored PR. Frontend half of a stacked PR — depends on #54346 for the backend model changes.
Created with PostHog Code