: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(endpoints): add tags UI (#60085)
Jovan Sakovic9cf25ededf3f
diff --git a/frontend/src/types.ts b/frontend/src/types.tsindex db419e598465..5559399c5f23 100644--- a/frontend/src/types.ts+++ b/frontend/src/types.ts@@ -2421,6 +2421,7 @@ export interface EndpointType extends WithAccessControl {materialization?: EndpointVersionMaterializationTypecolumns?: { name: string; type: string }[]bucket_overrides?: Record<string, string> | null+ tags?: string[]}/** Extends EndpointType with version-specific fields when fetching a specific version */diff --git a/products/endpoints/frontend/EndpointScene.tsx b/products/endpoints/frontend/EndpointScene.tsxindex c259cb731d27..82e33f4c89f7 100644--- a/products/endpoints/frontend/EndpointScene.tsx+++ b/products/endpoints/frontend/EndpointScene.tsx@@ -6,6 +6,8 @@ import { LemonBanner, LemonDialog, LemonDivider } from '@posthog/lemon-ui'import { ActivityLog } from 'lib/components/ActivityLog/ActivityLog'import { SceneMenuBarFileItems } from 'lib/components/Scenes/SceneMenuBarFileItems'+import { SceneTags } from 'lib/components/Scenes/SceneTags'+import { SceneTagsCombobox } from 'lib/components/Scenes/SceneTagsCombobox'import { FEATURE_FLAGS } from 'lib/constants'import 'lib/lemon-ui/LemonModal/LemonModal'import { LemonTab, LemonTabs } from 'lib/lemon-ui/LemonTabs'@@ -20,9 +22,11 @@ import {SceneMenuBarCheckboxItem,SceneMenuBarItem,SceneMenuBarMenu,+ SceneMenuBarPopover,SceneMenuBarSeparator,} from '~/layout/scenes/components/SceneMenuBar'-import { ScenePanel, ScenePanelActionsSection } from '~/layout/scenes/SceneLayout'+import { ScenePanel, ScenePanelActionsSection, ScenePanelInfoSection } from '~/layout/scenes/SceneLayout'+import { tagsModel } from '~/models/tagsModel'import { ProductKey } from '~/queries/schema/schema-general'import { ActivityScope } from '~/types'@@ -52,7 +56,8 @@ export function EndpointScene({ tabId }: EndpointProps = {}): JSX.Element {}const { endpoint, endpointLoading, activeTab, viewingVersion } = useValues(endpointSceneLogic({ tabId }))const { setViewingVersion } = useActions(endpointSceneLogic({ tabId }))- const { deleteEndpoint, confirmToggleActive } = useActions(endpointLogic({ tabId }))+ const { deleteEndpoint, confirmToggleActive, saveTagsInline } = useActions(endpointLogic({ tabId }))+ const { tags: tagsAvailable } = useValues(tagsModel)const { searchParams } = useValues(router)const { featureFlags } = useValues(featureFlagLogic)const sceneMenuBarEnabled = !!featureFlags[FEATURE_FLAGS.SCENE_MENU_BAR]@@ -148,6 +153,42 @@ export function EndpointScene({ tabId }: EndpointProps = {}): JSX.Element {return (<BindLogic logic={endpointSceneLogic} props={{ tabId }}><SceneContent className="Endpoint">+ {sceneMenuBarEnabled && endpoint && (+ <SceneMenuBar>+ <SceneMenuBarMenu label="File" dataAttr="endpoint-menubar-file">+ <SceneMenuBarFileItems dataAttrKey="endpoint" />+ <SceneMenuBarSeparator />+ <SceneMenuBarItem+ variant="destructive"+ opensFloatingUi+ onClick={handleDelete}+ data-attr="endpoint-menubar-delete"+ >+ <IconTrash />+ Delete endpoint+ </SceneMenuBarItem>+ </SceneMenuBarMenu>+ <SceneMenuBarMenu label="Edit" dataAttr="endpoint-menubar-edit">+ <SceneMenuBarSeparator />+ <SceneMenuBarCheckboxItem+ checked={endpoint.is_active}+ onCheckedChange={handleToggleActive}+ data-attr="endpoint-menubar-active"+ >+ Active+ </SceneMenuBarCheckboxItem>+ </SceneMenuBarMenu>+ <SceneMenuBarPopover label="Metadata" dataAttr="endpoint-menubar-metadata">+ <SceneTagsCombobox+ onSave={(tags) => saveTagsInline(tags)}+ canEdit+ tags={endpoint.tags}+ tagsAvailable={tagsAvailable.filter((t: string) => !endpoint.tags?.includes(t))}+ dataAttrKey="endpoint"+ />+ </SceneMenuBarPopover>+ </SceneMenuBar>+ )}<EndpointSceneHeader tabId={tabId} />{endpoint && !endpoint.is_active && (<LemonBanner type="error">@@ -165,35 +206,17 @@ export function EndpointScene({ tabId }: EndpointProps = {}): JSX.Element {{!endpointLoading && <EndpointOverview tabId={tabId} />}<LemonTabs activeKey={activeTab} tabs={tabs} /></SceneContent>- {sceneMenuBarEnabled && endpoint && (- <SceneMenuBar>- <SceneMenuBarMenu label="File" dataAttr="endpoint-menubar-file">- <SceneMenuBarFileItems dataAttrKey="endpoint" />- <SceneMenuBarSeparator />- <SceneMenuBarItem- variant="destructive"- opensFloatingUi- onClick={handleDelete}- data-attr="endpoint-menubar-delete"- >- <IconTrash />- Delete endpoint- </SceneMenuBarItem>- </SceneMenuBarMenu>- <SceneMenuBarMenu label="Edit" dataAttr="endpoint-menubar-edit">- <SceneMenuBarSeparator />- <SceneMenuBarCheckboxItem- checked={endpoint.is_active}- onCheckedChange={handleToggleActive}- data-attr="endpoint-menubar-active"- >- Active- </SceneMenuBarCheckboxItem>- </SceneMenuBarMenu>- </SceneMenuBar>- )}{endpoint && (<ScenePanel>+ <ScenePanelInfoSection>+ <SceneTags+ tags={endpoint.tags}+ tagsAvailable={tagsAvailable.filter((t: string) => !endpoint.tags?.includes(t))}+ onSave={(tags) => saveTagsInline(tags)}+ canEdit+ dataAttrKey="endpoint"+ />+ </ScenePanelInfoSection><ScenePanelActionsSection><ButtonPrimitive menuItem onClick={handleToggleActive}>{endpoint.is_active ? <IconPause /> : <IconPlay />}diff --git a/products/endpoints/frontend/Endpoints.tsx b/products/endpoints/frontend/Endpoints.tsxindex 8500d9a0b9a9..149125da7666 100644--- a/products/endpoints/frontend/Endpoints.tsx+++ b/products/endpoints/frontend/Endpoints.tsx@@ -4,6 +4,8 @@ import { router } from 'kea-router'import { IconRefresh } from '@posthog/icons'import { LemonButton, LemonDialog } from '@posthog/lemon-ui'+import { ObjectTags } from 'lib/components/ObjectTags/ObjectTags'+import { TagSelect } from 'lib/components/TagSelect'import { More } from 'lib/lemon-ui/LemonButton/More'import { LemonDivider } from 'lib/lemon-ui/LemonDivider'import { LemonInput } from 'lib/lemon-ui/LemonInput'@@ -107,6 +109,14 @@ export const EndpointsTable = ({ tabId }: EndpointsTableProps): JSX.Element => {},sorter: (a: EndpointType, b: EndpointType) => a.name.localeCompare(b.name),},+ {+ title: 'Tags',+ key: 'tags',+ dataIndex: 'tags',+ render: function RenderTags(tags: EndpointType['tags']) {+ return tags && tags.length > 0 ? <ObjectTags tags={[...tags].sort()} staticOnly /> : null+ },+ } as LemonTableColumn<EndpointType, keyof EndpointType | undefined>,createdAtColumn<EndpointType>() as LemonTableColumn<EndpointType, keyof EndpointType | undefined>,createdByColumn<EndpointType>() as LemonTableColumn<EndpointType, keyof EndpointType | undefined>,atColumn<EndpointType>('last_executed_at', 'Last executed at') as LemonTableColumn<@@ -200,23 +210,33 @@ export const EndpointsTable = ({ tabId }: EndpointsTableProps): JSX.Element => {return (<SceneContent>- <div className="flex justify-between gap-2 flex-wrap">+ <div className="flex justify-between gap-2 flex-wrap items-center"><LemonInputtype="search"- className="w-1/3"placeholder="Search for endpoints"onChange={(x) => setFilters({ search: x })}value={filters.search}/>- <LemonButton- type="secondary"- icon={<IconRefresh />}- onClick={() => loadEndpoints()}- loading={allEndpointsLoading}- size="small"- >- Reload- </LemonButton>+ <div className="flex items-center gap-2 flex-wrap">+ <span className="ml-1">+ <b>Tags</b>+ </span>+ <TagSelect+ defaultLabel="Any tags"+ value={filters.tags}+ onChange={(tags) => setFilters({ tags })}+ data-attr="endpoints-tag-filter"+ />+ <LemonButton+ type="secondary"+ icon={<IconRefresh />}+ onClick={() => loadEndpoints()}+ loading={allEndpointsLoading}+ size="small"+ >+ Reload+ </LemonButton>+ </div></div><LemonTabledata-attr="endpoints-table"diff --git a/products/endpoints/frontend/endpointLogic.tsx b/products/endpoints/frontend/endpointLogic.tsxindex 02569c2f324b..e9cce17ea359 100644--- a/products/endpoints/frontend/endpointLogic.tsx+++ b/products/endpoints/frontend/endpointLogic.tsx@@ -76,6 +76,7 @@ export const endpointLogic = kea<endpointLogicType>([clearMaterializationStatus: true,deleteEndpointFailure: () => ({}),confirmToggleActive: (endpoint: EndpointType) => ({ endpoint }),+ saveTagsInline: (tags: string[]) => ({ tags }),}),reducers({endpointName: [null as string | null, { setEndpointName: (_, { endpointName }) => endpointName }],@@ -187,7 +188,7 @@ export const endpointLogic = kea<endpointLogicType>([},],})),- listeners(({ actions }) => {+ listeners(({ actions, values }) => {const reloadMaterializationStatus = debounce((name: string, version?: number): void => {actions.loadMaterializationStatus({ name, version })}, 2000)@@ -291,6 +292,29 @@ export const endpointLogic = kea<endpointLogicType>([lemonToast.error('Failed to update endpoint')}},+ saveTagsInline: async ({ tags }, breakpoint) => {+ const endpoint = values.endpoint+ if (!endpoint) {+ return+ }+ actions.loadEndpointSuccess({ ...endpoint, tags } as EndpointVersionType)++ await breakpoint(250)++ try {+ const saved = await api.endpoint.update(endpoint.name, { tags } as Partial<EndpointRequest>)+ breakpoint()++ actions.loadEndpointSuccess(saved as EndpointVersionType)+ actions.loadEndpoints()+ } catch (error: any) {+ if (error.isBreakpoint) {+ throw error+ }+ actions.loadEndpointSuccess(endpoint)+ lemonToast.error('Failed to save tags')+ }+ },deleteEndpoint: async ({ name }) => {try {await api.endpoint.delete(name)diff --git a/products/endpoints/frontend/endpointsLogic.tsx b/products/endpoints/frontend/endpointsLogic.tsxindex e2d0922ed38c..ecbb4d4cd1b2 100644--- a/products/endpoints/frontend/endpointsLogic.tsx+++ b/products/endpoints/frontend/endpointsLogic.tsx@@ -14,10 +14,12 @@ export type EndpointsTab = 'endpoints' | 'usage'export interface EndpointsFilters {search: string+ tags: string[]}export const DEFAULT_FILTERS: EndpointsFilters = {search: '',+ tags: [],}export interface EndpointsLogicProps {@@ -61,15 +63,22 @@ export const endpointsLogic = kea<endpointsLogicType>([endpoints: [(s) => [s.allEndpoints, s.filters],(allEndpoints, filters) => {- if (!filters.search) {- return allEndpoints+ let results = allEndpoints++ if (filters.tags.length > 0) {+ const required = new Set(filters.tags)+ results = results.filter((endpoint) => endpoint.tags?.some((tag) => required.has(tag)))+ }++ if (filters.search) {+ const fuse = createFuse<EndpointType>(results, {+ keys: ['name', 'description', 'query.query'],+ threshold: 0.3,+ })+ results = fuse.search(filters.search).map((result) => result.item)}- const fuse = createFuse<EndpointType>(allEndpoints, {- keys: ['name', 'description', 'query.query'],- threshold: 0.3,- })- return fuse.search(filters.search).map((result) => result.item)+ return results},],}),