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(engineering-analytics): show friction on the teams roster and team page (#106448)

Julian Bez2f39d0298e22
diff --git a/frontend/snapshots.yml b/frontend/snapshots.yml
index 67fb6fc326aa..02af2142731d 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -8469,21 +8469,21 @@ snapshots:
scenes-app-engineering-analytics-run-activity-chart--default--light:
hash: v1.k794b7964.f63752ff3ebf3bbee3be4ddc83d1ff657d9cdd11ee71e7283c30ce5a1aefde72.yTb8kpRqcG51TbM2CqgRmC5YvgE7-6pV1Trc7y5wuto
scenes-app-engineering-analytics-team--team--dark:
- hash: v1.k794b7964.2f951d96c575ff0f885d1c81b69bdeaec6d25ee5450d207561ae1215a3bd9be3.Y7zgUsl87c8frDY84qEtWiUwKOjoypzPxNkJQdCzEug
+ hash: v1.k794b7964.9ddb8638593809903ad048fd0dc36d76f1558cbd10f65a36503f7b3c1bb7a2e8.lhhA3Dojxz5aDLfACuv7V7vDS-hAOr0VI7c6OPXmPI0
scenes-app-engineering-analytics-team--team--light:
- hash: v1.k794b7964.c8315ec4a28e42f3ce074e0b5c388eca3be0f46b3d6bbc128d469f011389bbb0.7fQ5t9nHDImfuPh2iOU-74-ymwf2wDsJpAsZPfYnjDU
+ hash: v1.k794b7964.e3e2163a7c066bc26f1b3e7f80541d5c5bf1419d8a503d35a554ed72d048ee82.Ov31vsxKog4PRQOFXFyXMS-QrY6UhgMxAqqtaJWocWM
scenes-app-engineering-analytics-team--team-narrow--dark:
- hash: v1.k794b7964.608002b57ac616fe54a60a80f7bf923b5e16038d2f06724ac372cb3bb0329458.cFoJbUiL6BZE96P9kchIJyJ0u3O2Nc571PJLGgYeXV8
+ hash: v1.k794b7964.6de8ee5eac265b4472c96f92c8e082ac9cea49406503cec0021e8dcdbe7d927d.mOg79dFV_FrNp_7sqO6ohCyZMfuWDwbOpdE5esKnjjk
scenes-app-engineering-analytics-team--team-narrow--light:
- hash: v1.k794b7964.cb4bb3728f0f568b646e2a32806502d752fff5de55cd4b5c50a23cd823b2168f.ZAeFoIqOj7QGnVDKdsBjUWwNsyKVA_LND-A-aPmVHlk
+ hash: v1.k794b7964.0150502cfbac0b95b123c0e37f806559babbd5501547b0259566f8aad52cb08a.YFoPIcTeQqzV_19qbyRbDN2tEJCviQxRF0MlSJyC0ss
scenes-app-engineering-analytics-team--team-quarantine-load-error--dark:
- hash: v1.k794b7964.541452d01837a1c1129b58ec587f3417a8aabd0dd1b92bd52229a160c1d07d6a.j1fzAkcNzZSw9KI7zOdccCx17gv-AlR5SocMTb2cOxw
+ hash: v1.k794b7964.1c6be5bb3f64f79843d2befde083faec26e3b4ad6dd7d2867a99b599d2943324.hFMUrz-ggVkoUYAZ_UL5sx4qeN-_zFWPHOXyg7GP1CU
scenes-app-engineering-analytics-team--team-quarantine-load-error--light:
- hash: v1.k794b7964.cdb1215ddbfbed34cfe0ee14a694349d294a00cf7388e9891de5f080693ae025.BdZyEbPlRvzd9YxLHP4ahd5E_Y2uzEPsF-OjLfxUkNI
+ hash: v1.k794b7964.35fc08fe30a34fafdde9dd5048a5e81e8c17ecc2979a1e3840744de6825ad3cb.4wPCav0Ylkv-DrywkGXIu-7QyXyHwZqMjOLucNIIsiw
scenes-app-engineering-analytics-team--team-without-membership--dark:
- hash: v1.k794b7964.6c597367df91af414d0ed49f8a13e687349f4c8e7952f9f05e9926acc3848dd1.9puYEgRsC--vOo4DwU3e1gWEyHfR4jZb-vY7rKrPYlk
+ hash: v1.k794b7964.2e1a6a228e691ae3ea643ebfdf22bade2ebe807a33821654bd59e3ab499e39c8.TFV-yx33ZgxZHTfeNJeXQ6TenTVR4r5myTdJM5CIROw
scenes-app-engineering-analytics-team--team-without-membership--light:
- hash: v1.k794b7964.d4e2de6cbcb878719014f8b5d038a1cc6e0ddc204de1f82b254ea99c032c57da.5Fd7ZBgUGdp6rQO7sroVkUpeDyRbxOiULjDN54bG3Wk
+ hash: v1.k794b7964.a9ab1c76bcd7aa78683e75ab34dbd4d8c0d2b87df0464138df865a43fac470c7.tL5_rdplygpDskdSRBIeYGBpXzaPZ3ZtrcJE8nNZ8Mc
scenes-app-engineering-analytics-teams--team-ci-health-load-error--dark:
hash: v1.k794b7964.2c5b47795360001e6281631b9c29b313cab79a2c10b335f018c3a9b333ba8593.aEHiND5D1aaD-yEMHu8kAQRrHw2X6AIRTQS6X9j0CNk
scenes-app-engineering-analytics-teams--team-ci-health-load-error--light:
diff --git a/products/engineering_analytics/frontend/components/AuthorFrictionTable.tsx b/products/engineering_analytics/frontend/components/AuthorFrictionTable.tsx
new file mode 100644
index 000000000000..9ea71545c01a
--- /dev/null
+++ b/products/engineering_analytics/frontend/components/AuthorFrictionTable.tsx
@@ -0,0 +1,124 @@
+import { LemonTable, LemonTableColumns, Link } from '@posthog/lemon-ui'
+
+import { Lettermark } from 'lib/lemon-ui/Lettermark'
+import { urls } from 'scenes/urls'
+
+import type { AuthorFrictionApi } from '../generated/api.schemas'
+import { timesTypical } from '../lib/format'
+import { FRICTION_GROUP_DESCRIPTIONS, FRICTION_GROUP_LABELS, FRICTION_GROUP_ORDER } from '../lib/friction'
+import { rowNavigationProps } from '../lib/rowNavigation'
+import { withCurrentScope } from '../lib/scope'
+import { CountCell } from './CountCell'
+import { FrictionGroupBar } from './FrictionGroupBar'
+
+function authorUrl(handle: string, sourceId: string | null): string {
+ return withCurrentScope(urls.engineeringAnalyticsAuthor(handle), sourceId)
+}
+
+const GROUPS_TOOLTIP = FRICTION_GROUP_ORDER.map(
+ (group) => `${FRICTION_GROUP_LABELS[group]}: ${FRICTION_GROUP_DESCRIPTIONS[group]}.`
+).join(' ')
+
+/** Authors by friction with their repository-wide ranks, whether the list shows everyone or one team. */
+export function AuthorFrictionTable({
+ authors,
+ rankedAuthorCount,
+ windowDays,
+ maxScore,
+ loading,
+ sourceId,
+ emptyState,
+ dataAttr,
+}: {
+ authors: AuthorFrictionApi[]
+ rankedAuthorCount: number
+ windowDays: number
+ /** The highest score in the repository, so bar lengths read the same on every page. */
+ maxScore: number
+ loading: boolean
+ sourceId: string | null
+ emptyState: string
+ dataAttr: string
+}): JSX.Element {
+ const windowLabel = `last ${windowDays} days`
+ const columns: LemonTableColumns<AuthorFrictionApi> = [
+ {
+ title: 'Rank',
+ key: 'rank',
+ width: 90,
+ tooltip: `Position by friction among ${rankedAuthorCount} authors. The range is where the author lands when their pull requests are resampled, so a wide range means the position is not settled.`,
+ sorter: (a, b) => a.rank - b.rank,
+ render: (_, row) => (
+ <span className="tabular-nums">
+ {row.rank}
+ {row.rank_low !== row.rank_high && (
+ <span className="text-tertiary">
+ {' '}
+ ({row.rank_low}–{row.rank_high})
+ </span>
+ )}
+ </span>
+ ),
+ },
+ {
+ title: 'Author',
+ key: 'author',
+ sorter: (a, b) => a.author.localeCompare(b.author),
+ render: (_, row) => (
+ <div className="flex items-center gap-2">
+ {row.avatar_url ? (
+ <img src={row.avatar_url} alt="" className="size-5 shrink-0 rounded-full" />
+ ) : (
+ <Lettermark name={row.author} size="small" />
+ )}
+ <Link
+ to={authorUrl(row.author, sourceId)}
+ className="whitespace-nowrap text-xs font-medium"
+ data-attr="engineering-analytics-friction-author-link"
+ >
+ {row.author}
+ </Link>
+ </div>
+ ),
+ },
+ {
+ title: 'Friction',
+ key: 'score',
+ width: 90,
+ align: 'right',
+ tooltip: `Friction over pull requests merged in the ${windowLabel}, as a multiple of the typical author: 1.0× is typical. It counts what happened to the author, never how much or how fast they ship.`,
+ sorter: (a, b) => a.score - b.score,
+ render: (_, row) => <span className="tabular-nums">{timesTypical(row.score)}</span>,
+ },
+ {
+ title: 'Where it comes from',
+ key: 'groups',
+ width: '40%',
+ tooltip: GROUPS_TOOLTIP,
+ render: (_, row) => <FrictionGroupBar groups={row.groups} max={maxScore} />,
+ },
+ {
+ title: 'Pull requests',
+ key: 'pr_count',
+ width: 110,
+ align: 'right',
+ tooltip: `Merged in the ${windowLabel}. An author needs 3 to get a score.`,
+ render: (_, row) => <CountCell value={row.pr_count} />,
+ },
+ ]
+ return (
+ <LemonTable
+ data-attr={dataAttr}
+ size="small"
+ columns={columns}
+ dataSource={authors}
+ rowKey={(row) => row.author}
+ rowClassName="cursor-pointer"
+ onRow={(row) => rowNavigationProps(authorUrl(row.author, sourceId))}
+ loading={loading}
+ useURLForSorting={false}
+ emptyState={emptyState}
+ nouns={['author', 'authors']}
+ />
+ )
+}
diff --git a/products/engineering_analytics/frontend/lib/frictionFixtures.ts b/products/engineering_analytics/frontend/lib/frictionFixtures.ts
new file mode 100644
index 000000000000..9adb4cfbf206
--- /dev/null
+++ b/products/engineering_analytics/frontend/lib/frictionFixtures.ts
@@ -0,0 +1,42 @@
+import type { AuthorFrictionApi, AuthorFrictionListApi } from '../generated/api.schemas'
+
+function author(
+ name: string,
+ rank: number,
+ [queue, review, ci, rework]: [number, number, number, number],
+ teams: string[]
+): AuthorFrictionApi {
+ return {
+ author: name,
+ avatar_url: '',
+ score: queue + review + ci + rework,
+ groups: [
+ { group: 'queue', score: queue },
+ { group: 'review', score: review },
+ { group: 'ci', score: ci },
+ { group: 'rework', score: rework },
+ ],
+ pr_count: 12,
+ rank,
+ rank_low: Math.max(1, rank - 2),
+ rank_high: rank + 4,
+ teams,
+ }
+}
+
+/** Story fixture for the friction read: invented authors, two of them on team-replay. */
+export const FRICTION_STORY_FIXTURE: AuthorFrictionListApi = {
+ available: true,
+ window_days: 30,
+ ranked_author_count: 5,
+ github_team: null,
+ has_membership_data: true,
+ items: [
+ author('jane-dev', 1, [1.4, 0.3, 0.6, 0.2], ['team-replay']),
+ author('sam-ops', 2, [0.9, 0.6, 0.3, 0.2], ['team-infra']),
+ author('li-web', 3, [0.5, 0.5, 0.2, 0.1], ['team-replay']),
+ author('max-data', 4, [0.3, 0.2, 0.2, 0.1], ['team-replay']),
+ author('ana-api', 5, [0.2, 0.2, 0.1, 0.1], ['team-infra']),
+ ],
+ teams: [{ github_team: 'team-replay', median_score: 1.3, scored_author_count: 3 }],
+}
diff --git a/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthors.tsx b/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthors.tsx
index b6acfa8810ba..aadb07d8f08a 100644
--- a/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthors.tsx
+++ b/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsAuthors.tsx
@@ -1,33 +1,16 @@
import { useActions, useValues } from 'kea'
-import { LemonSelect, LemonTable, LemonTableColumns, Link } from '@posthog/lemon-ui'
-
-import { Lettermark } from 'lib/lemon-ui/Lettermark'
-import { urls } from 'scenes/urls'
+import { LemonSelect } from '@posthog/lemon-ui'
+import { AuthorFrictionTable } from '../components/AuthorFrictionTable'
import { CIAnalyticsLoadError } from '../components/CIAnalyticsLoadError'
import { ConnectGitHubSource } from '../components/ConnectGitHubSource'
-import { CountCell } from '../components/CountCell'
-import { FrictionGroupBar } from '../components/FrictionGroupBar'
import { FrictionGroupLegend } from '../components/FrictionGroupLegend'
import { SourceScopeChip } from '../components/ScopeBar'
import { ScopePanel } from '../components/ScopePanel'
import { Section } from '../components/Section'
-import type { AuthorFrictionApi } from '../generated/api.schemas'
-import { timesTypical } from '../lib/format'
-import { FRICTION_GROUP_DESCRIPTIONS, FRICTION_GROUP_LABELS, FRICTION_GROUP_ORDER } from '../lib/friction'
-import { rowNavigationProps } from '../lib/rowNavigation'
-import { withCurrentScope } from '../lib/scope'
import { authorFrictionLogic } from './authorFrictionLogic'
-function authorUrl(handle: string, sourceId: string | null): string {
- return withCurrentScope(urls.engineeringAnalyticsAuthor(handle), sourceId)
-}
-
-const GROUPS_TOOLTIP = FRICTION_GROUP_ORDER.map(
- (group) => `${FRICTION_GROUP_LABELS[group]}: ${FRICTION_GROUP_DESCRIPTIONS[group]}.`
-).join(' ')
-
export function EngineeringAnalyticsAuthors(): JSX.Element {
const {
friction,
@@ -41,75 +24,8 @@ export function EngineeringAnalyticsAuthors(): JSX.Element {
} = useValues(authorFrictionLogic)
const { loadFriction, setGithubTeam } = useActions(authorFrictionLogic)
- const windowLabel = `last ${friction?.window_days ?? 30} days`
const maxScore = Math.max(0, ...(friction?.items ?? []).map((item) => item.score))
- const columns: LemonTableColumns<AuthorFrictionApi> = [
- {
- title: 'Rank',
- key: 'rank',
- width: 90,
- tooltip: `Position by friction among ${friction?.ranked_author_count ?? 0} authors. The range is where the author lands when their pull requests are resampled, so a wide range means the position is not settled.`,
- sorter: (a, b) => a.rank - b.rank,
- render: (_, row) => (
- <span className="tabular-nums">
- {row.rank}
- {row.rank_low !== row.rank_high && (
- <span className="text-tertiary">
- {' '}
- ({row.rank_low}–{row.rank_high})
- </span>
- )}
- </span>
- ),
- },
- {
- title: 'Author',
- key: 'author',
- sorter: (a, b) => a.author.localeCompare(b.author),
- render: (_, row) => (
- <div className="flex items-center gap-2">
- {row.avatar_url ? (
- <img src={row.avatar_url} alt="" className="size-5 shrink-0 rounded-full" />
- ) : (
- <Lettermark name={row.author} size="small" />
- )}
- <Link
- to={authorUrl(row.author, sourceId)}
- className="text-xs font-medium"
- data-attr="engineering-analytics-friction-author-link"
- >
- {row.author}
- </Link>
- </div>
- ),
- },
- {
- title: 'Friction',
- key: 'score',
- width: 90,
- align: 'right',
- tooltip: `Friction over pull requests merged in the ${windowLabel}, as a multiple of the typical author: 1.0× is typical. It counts what happened to the author, never how much or how fast they ship.`,
- sorter: (a, b) => a.score - b.score,
- render: (_, row) => <span className="tabular-nums">{timesTypical(row.score)}</span>,
- },
- {
- title: 'Where it comes from',
- key: 'groups',
- width: '40%',
- tooltip: GROUPS_TOOLTIP,
- render: (_, row) => <FrictionGroupBar groups={row.groups} max={maxScore} />,
- },
- {
- title: 'Pull requests',
- key: 'pr_count',
- width: 110,
- align: 'right',
- tooltip: `Merged in the ${windowLabel}. An author needs 3 to get a score.`,
- render: (_, row) => <CountCell value={row.pr_count} />,
- },
- ]
-
if (frictionNotConnected) {
return <ConnectGitHubSource />
}
@@ -153,22 +69,19 @@ export function EngineeringAnalyticsAuthors(): JSX.Element {
workflow jobs and pull requests synced, and it refreshes every 12 hours.
</div>
) : (
- <LemonTable
- data-attr="engineering-analytics-friction-table"
- size="small"
- columns={columns}
- dataSource={authors}
- rowKey={(row) => row.author}
- rowClassName="cursor-pointer"
- onRow={(row) => rowNavigationProps(authorUrl(row.author, sourceId))}
+ <AuthorFrictionTable
+ authors={authors}
+ rankedAuthorCount={friction?.ranked_author_count ?? 0}
+ windowDays={friction?.window_days ?? 30}
+ maxScore={maxScore}
loading={frictionLoading}
- useURLForSorting={false}
+ sourceId={sourceId}
emptyState={
githubTeam
? 'No one on this team has 3 merged pull requests in the window yet.'
: 'No author has 3 merged pull requests in the window yet.'
}
- nouns={['author', 'authors']}
+ dataAttr="engineering-analytics-friction-table"
/>
)}
</Section>
diff --git a/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsTeamScene.stories.tsx b/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsTeamScene.stories.tsx
index a1ced2b19e18..d8eb128aa39c 100644
--- a/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsTeamScene.stories.tsx
+++ b/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsTeamScene.stories.tsx
@@ -12,6 +12,7 @@ import type {
TeamCIHealthListApi,
TrunkQuarantineDebtApi,
} from '../generated/api.schemas'
+import { FRICTION_STORY_FIXTURE } from '../lib/frictionFixtures'
const HOUR = 3600
const TEAM = 'team-replay'
@@ -166,6 +167,7 @@ const meta: Meta = {
'api/projects/:team_id/engineering_analytics/team_ci_health/': TEAM_CI_HEALTH,
'api/projects/:team_id/engineering_analytics/team_ci_activity/': TEAM_CI_ACTIVITY,
'api/projects/:team_id/engineering_analytics/team_merge_trend/': TEAM_MERGE_TREND,
+ 'api/projects/:team_id/engineering_analytics/author_friction/': FRICTION_STORY_FIXTURE,
'api/projects/:team_id/engineering_analytics/sources/': [
{ id: 'src-1', repo: 'PostHog/posthog', prefix: '' },
],
diff --git a/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsTeamScene.tsx b/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsTeamScene.tsx
index 3afdb2e5df6c..f5c4aec282b1 100644
--- a/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsTeamScene.tsx
+++ b/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsTeamScene.tsx
@@ -29,6 +29,7 @@ import { withCurrentScope } from '../lib/scope'
import { engineeringAnalyticsLogic } from './engineeringAnalyticsLogic'
import { TeamDeliveryPanel } from './TeamDeliveryPanel'
import { TeamDetailLogicProps, TeamTestSignalRow, teamDetailLogic } from './teamDetailLogic'
+import { TeamFrictionSection } from './TeamFrictionSection'
import { DEFAULT_TEAMS_WINDOW, TEAMS_WINDOW_DATE_OPTIONS, TEAMS_WINDOW_LABELS, UNOWNED_TEAM } from './teamsLogic'
export const scene: SceneExport<TeamDetailLogicProps> = {
@@ -230,6 +231,10 @@ export function EngineeringAnalyticsTeamScene(): JSX.Element {
<ConnectGitHubSource />
) : (
<>
+ {/* Friction reads a fixed window, so it sits above the panel the date picker governs, as on the
+ author page. */}
+ {!isUnowned && <TeamFrictionSection githubTeam={ownerTeam} />}
+
{deliveryScope ? (
<TeamDeliveryPanel
scope={deliveryScope}
diff --git a/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsTeams.stories.tsx b/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsTeams.stories.tsx
index ac0873f42ac3..ed145a76dc48 100644
--- a/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsTeams.stories.tsx
+++ b/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsTeams.stories.tsx
@@ -7,6 +7,7 @@ import { urls } from 'scenes/urls'
import { mswDecorator } from '~/mocks/browser'
import type { GitHubSourceApi, TeamCIHealthItemApi, TeamCIHealthListApi } from '../generated/api.schemas'
+import { FRICTION_STORY_FIXTURE } from '../lib/frictionFixtures'
const SOURCES: GitHubSourceApi[] = [{ id: 'src-1', repo: 'PostHog/posthog', prefix: '' }]
@@ -82,6 +83,7 @@ const meta: Meta = {
mswDecorator({
get: {
'api/projects/:team_id/engineering_analytics/team_ci_health/': TEAM_CI_HEALTH,
+ 'api/projects/:team_id/engineering_analytics/author_friction/': FRICTION_STORY_FIXTURE,
'api/projects/:team_id/engineering_analytics/sources/': SOURCES,
// Sibling-tab loaders mount with the scene; stub them so the story renders without error toasts.
'api/projects/:team_id/engineering_analytics/ci_cards/': {
@@ -123,7 +125,11 @@ type Story = StoryObj<typeof meta>
export const TeamCIHealthRoster: Story = {
render: () => <App />,
- parameters: { pageUrl: urls.engineeringAnalyticsTeams() },
+ parameters: {
+ pageUrl: urls.engineeringAnalyticsTeams(),
+ // The friction column appears only after its own request lands, later than the roster rows.
+ testOptions: { waitForSelector: '[data-attr="engineering-analytics-teams-friction"]' },
+ },
}
export const TeamCIHealthLoadError: Story = {
diff --git a/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsTeams.tsx b/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsTeams.tsx
index 4966cfc7ecc1..41f7f2a6dc5f 100644
--- a/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsTeams.tsx
+++ b/products/engineering_analytics/frontend/scenes/EngineeringAnalyticsTeams.tsx
@@ -9,8 +9,10 @@ import { ConnectGitHubSource } from '../components/ConnectGitHubSource'
import { CountCell } from '../components/CountCell'
import { ScopeBar, SourceScopeChip } from '../components/ScopeBar'
import { Section } from '../components/Section'
+import { timesTypical } from '../lib/format'
import { rowNavigationProps } from '../lib/rowNavigation'
import { withCurrentScope } from '../lib/scope'
+import { authorFrictionLogic } from './authorFrictionLogic'
import { DEFAULT_TEAMS_WINDOW, TEAMS_WINDOW_LABELS, TeamCIHealthRow, UNOWNED_TEAM, teamsLogic } from './teamsLogic'
const FIXED_WINDOW = TEAMS_WINDOW_LABELS[DEFAULT_TEAMS_WINDOW].current.toLowerCase()
@@ -23,6 +25,31 @@ function detailUrlOf(ownerTeam: string, sourceId: string | null): string {
export function EngineeringAnalyticsTeams(): JSX.Element {
const { teams, teamsFailed, teamsLoading, teamsNotConnected, sourceId } = useValues(teamsLogic)
const { loadTeams } = useActions(teamsLogic)
+ const { friction } = useValues(authorFrictionLogic)
+ const medianFriction = new Map((friction?.teams ?? []).map((team) => [team.github_team, team.median_score]))
+
+ // A dash would read as too few scored members, so without friction data or memberships the column stays out.
+ const frictionColumns: LemonTableColumns<TeamCIHealthRow> =
+ friction?.available && friction.has_membership_data
+ ? [
+ {
+ title: 'Friction',
+ key: 'friction',
+ width: 100,
+ align: 'right',
+ tooltip: `Median friction of the team's members over the last ${friction?.window_days ?? 30} days, as a multiple of the typical author. Shown for teams with at least 3 members who have a score.`,
+ sorter: (a, b) =>
+ (medianFriction.get(a.ownerTeam) ?? -1) - (medianFriction.get(b.ownerTeam) ?? -1),
+ render: (_, row) => (
+ <span className="tabular-nums" data-attr="engineering-analytics-teams-friction">
+ {medianFriction.has(row.ownerTeam)
+ ? timesTypical(medianFriction.get(row.ownerTeam))
+ : '–'}
+ </span>
+ ),
+ },
+ ]
+ : []
const columns: LemonTableColumns<TeamCIHealthRow> = [
{
@@ -55,6 +82,7 @@ export function EngineeringAnalyticsTeams(): JSX.Element {
</Link>
),
},
+ ...frictionColumns,
{
title: 'Test files',
key: 'testFileCount',
diff --git a/products/engineering_analytics/frontend/scenes/TeamFrictionSection.tsx b/products/engineering_analytics/frontend/scenes/TeamFrictionSection.tsx
new file mode 100644
index 000000000000..d841164de3c1
--- /dev/null
+++ b/products/engineering_analytics/frontend/scenes/TeamFrictionSection.tsx
@@ -0,0 +1,63 @@
+import { useActions, useValues } from 'kea'
+
+import { AuthorFrictionTable } from '../components/AuthorFrictionTable'
+import { CIAnalyticsLoadError } from '../components/CIAnalyticsLoadError'
+import { FrictionGroupLegend } from '../components/FrictionGroupLegend'
+import { Section } from '../components/Section'
+import { timesTypical } from '../lib/format'
+import { authorFrictionLogic } from './authorFrictionLogic'
+
+/** A team's median friction and its members by friction. Members keep their repository-wide ranks. */
+export function TeamFrictionSection({ githubTeam }: { githubTeam: string }): JSX.Element {
+ const { friction, frictionLoading, frictionFailed, frictionNotConnected, sourceId } = useValues(authorFrictionLogic)
+ const { loadFriction } = useActions(authorFrictionLogic)
+
+ const members = (friction?.items ?? []).filter((item) => (item.teams ?? []).includes(githubTeam))
+ const team = (friction?.teams ?? []).find((entry) => entry.github_team === githubTeam)
+ const maxScore = Math.max(0, ...(friction?.items ?? []).map((item) => item.score))
+
+ return (
+ <Section
+ id="team-friction"
+ title="Friction"
+ note={
+ <span className="flex flex-wrap items-center gap-2">
+ <span>Last {friction?.window_days ?? 30} days</span>
+ <FrictionGroupLegend />
+ </span>
+ }
+ right={
+ // During a reload the median still belongs to the previous scope, so it waits for the answer.
+ team && !frictionLoading ? (
+ <span className="tabular-nums text-secondary">
+ {timesTypical(team.median_score)} median across {team.scored_author_count} members
+ </span>
+ ) : undefined
+ }
+ >
+ {frictionFailed ? (
+ <CIAnalyticsLoadError onRetry={loadFriction} loading={frictionLoading} />
+ ) : frictionNotConnected || (friction && !friction.available) ? (
+ <div className="text-sm text-secondary">
+ Friction is not ready for this project yet. It needs a GitHub source with workflow runs, workflow
+ jobs and pull requests synced, and it refreshes every 12 hours.
+ </div>
+ ) : (
+ <AuthorFrictionTable
+ authors={members}
+ rankedAuthorCount={friction?.ranked_author_count ?? 0}
+ windowDays={friction?.window_days ?? 30}
+ maxScore={maxScore}
+ loading={frictionLoading}
+ sourceId={sourceId}
+ emptyState={
+ friction?.has_membership_data === false
+ ? 'Team membership is not synced for this source, so the team has no members to show.'
+ : `No scored members found for this team in the last ${friction?.window_days ?? 30} days. A score needs 3 merged pull requests, and members come from the GitHub team with this name.`
+ }
+ dataAttr="engineering-analytics-team-friction-table"
+ />
+ )}
+ </Section>
+ )
+}