: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
chore(groups): adopt generated groups_types clients in groupsModel (#115380)
Thomas Obermüller50380f90a23a
diff --git a/frontend/src/models/groupsModel.test.ts b/frontend/src/models/groupsModel.test.tsindex 1d79982875f1..b60b68d9030a 100644--- a/frontend/src/models/groupsModel.test.ts+++ b/frontend/src/models/groupsModel.test.ts@@ -61,4 +61,30 @@ describe('groupsModel', () => {expect(groupTypesRequest).toHaveBeenCalledTimes(1)})++ it('saves renamed group types and keeps the names the server returns', async () => {+ const [organization] = MOCK_DEFAULT_TEAM.group_types+ const renamed = { ...organization, name_singular: 'company', name_plural: 'companies' }+ const saved = { ...organization, name_singular: 'account', name_plural: 'accounts' }+ let requestBody: unknown+ useMocks({+ patch: {+ '/api/projects/:team_id/groups_types/update_metadata': async ({ request }) => {+ requestBody = await request.json()+ return [200, [saved]]+ },+ },+ })+ initKeaTests(true, MOCK_DEFAULT_TEAM, undefined, ORGANIZATION_WITH_GROUPS)+ groupsModel.mount()+ await expectLogic(groupsModel).toFinishAllListeners()++ groupsModel.actions.updateGroupTypesMetadata([renamed])+ await expectLogic(groupsModel).toFinishAllListeners()++ expect(requestBody).toEqual([+ expect.objectContaining({ group_type_index: 0, name_singular: 'company', name_plural: 'companies' }),+ ])+ expect(groupsModel.values.aggregationLabel(0)).toEqual({ singular: 'account', plural: 'accounts' })+ })})diff --git a/frontend/src/models/groupsModel.ts b/frontend/src/models/groupsModel.tsindex aff68485622c..123deda9b295 100644--- a/frontend/src/models/groupsModel.ts+++ b/frontend/src/models/groupsModel.ts@@ -1,7 +1,6 @@import { MakeLogicType, afterMount, connect, kea, listeners, path, selectors } from 'kea'import { loaders } from 'kea-loaders'-import api from 'lib/api'import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'import { GroupsAccessStatus, groupsAccessLogic } from 'lib/introductions/groupsAccessLogic'import { wordPluralize } from 'lib/utils/strings'@@ -10,11 +9,27 @@ import { userLogic } from 'scenes/userLogic'import { GroupType, GroupTypeIndex, UserType } from '~/types'+import {+ groupsTypesCreateDetailDashboardUpdate,+ groupsTypesDestroy,+ groupsTypesList,+ groupsTypesSetDefaultColumnsUpdate,+ groupsTypesUpdateMetadataPartialUpdate,+} from 'products/groups/frontend/generated/api'+import type { GroupTypeApi } from 'products/groups/frontend/generated/api.schemas'+export interface Noun {singular: stringplural: string}+const toGroupType = ({ group_type_index, default_columns, ...groupType }: GroupTypeApi): GroupType => ({+ ...groupType,+ // Ingestion creates at most five group types per project, so every index fits GroupTypeIndex.+ group_type_index: group_type_index as GroupTypeIndex,+ default_columns: default_columns ?? undefined,+})+// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface groupsModelValues {groupsAccessStatus: GroupsAccessStatus // groupsAccessLogic@@ -71,10 +86,10 @@ export interface groupsModelActions {errorObject?: any}createDetailDashboardSuccess: (- groupTypesRaw: any[],+ groupTypesRaw: GroupType[],payload?: number) => {- groupTypesRaw: any[]+ groupTypesRaw: GroupType[]payload?: number}deleteGroupType: (groupTypeIndex: number) => number@@ -134,13 +149,13 @@ export interface groupsModelActions {errorObject?: any}setDefaultColumnsSuccess: (- groupTypesRaw: any[],+ groupTypesRaw: GroupType[],payload?: {groupTypeIndex: numberdefaultColumns: string[]}) => {- groupTypesRaw: any[]+ groupTypesRaw: GroupType[]payload?: {groupTypeIndex: numberdefaultColumns: string[]@@ -197,31 +212,34 @@ export const groupsModel = kea<groupsModelType>([if (!values.currentProjectId) {return []}- // nosemgrep: prefer-codegen-api -- Legacy raw API call with a hand-written URL and an unchecked response type. No generated function covers this endpoint yet. Find out why the generated client skips it (no schema, no product tag, or excluded from the spec) and fix that first.- return await api.get(`api/projects/${values.currentProjectId}/groups_types`)+ const groupTypes = await groupsTypesList(String(values.currentProjectId))+ return groupTypes.map(toGroupType)},updateGroupTypesMetadata: async (payload: Array<GroupType>) => {if (values.groupsEnabled) {- // nosemgrep: prefer-codegen-api -- Legacy raw API call with a hand-written URL and an unchecked response type. No generated function covers this endpoint yet. Find out why the generated client skips it (no schema, no product tag, or excluded from the spec) and fix that first.- return await api.update(- `/api/projects/${values.currentProjectId}/groups_types/update_metadata`,- payload+ const groupTypes = await groupsTypesUpdateMetadataPartialUpdate(+ String(values.currentProjectId),+ payload.map(({ group_type_index, name_singular, name_plural }) => ({+ group_type_index,+ name_singular,+ name_plural,+ })))+ return groupTypes.map(toGroupType)}return []},deleteGroupType: async (groupTypeIndex: number) => {if (values.groupsEnabled) {- // nosemgrep: prefer-codegen-api -- Legacy raw API call with a hand-written URL and an unchecked response type. No generated function covers this endpoint yet. Find out why the generated client skips it (no schema, no product tag, or excluded from the spec) and fix that first.- await api.delete(`/api/projects/${values.currentProjectId}/groups_types/${groupTypeIndex}`)+ await groupsTypesDestroy(String(values.currentProjectId), groupTypeIndex)}return []},createDetailDashboard: async (groupTypeIndex: number) => {- // nosemgrep: prefer-codegen-api -- Legacy raw API call with a hand-written URL and an unchecked response type. No generated function covers this endpoint yet. Find out why the generated client skips it (no schema, no product tag, or excluded from the spec) and fix that first.- const groupType = await api.put(- `/api/projects/${values.currentProjectId}/groups_types/create_detail_dashboard`,- { group_type_index: groupTypeIndex }+ const groupType = toGroupType(+ await groupsTypesCreateDetailDashboardUpdate(String(values.currentProjectId), {+ group_type_index: groupTypeIndex,+ }))return values.groupTypesRaw.map((gt) => (gt.group_type_index === groupTypeIndex ? groupType : gt))},@@ -243,10 +261,11 @@ export const groupsModel = kea<groupsModelType>([groupTypeIndex: numberdefaultColumns: string[]}) => {- // nosemgrep: prefer-codegen-api -- Legacy raw API call with a hand-written URL and an unchecked response type. No generated function covers this endpoint yet. Find out why the generated client skips it (no schema, no product tag, or excluded from the spec) and fix that first.- const groupType = await api.put(- `/api/projects/${values.currentProjectId}/groups_types/set_default_columns`,- { group_type_index: groupTypeIndex, default_columns: defaultColumns }+ const groupType = toGroupType(+ await groupsTypesSetDefaultColumnsUpdate(String(values.currentProjectId), {+ group_type_index: groupTypeIndex,+ default_columns: defaultColumns,+ }))return values.groupTypesRaw.map((gt) => (gt.group_type_index === groupTypeIndex ? groupType : gt))},