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(today): resolve and dismiss reports from the hover card and report page (#110655)

Vojta Bartošb467e3fc4b13
diff --git a/frontend/src/layout/today/todayPreviewCards.ts b/frontend/src/layout/today/todayPreviewCards.ts
index 1ad216edfac1..26596655f2df 100644
--- a/frontend/src/layout/today/todayPreviewCards.ts
+++ b/frontend/src/layout/today/todayPreviewCards.ts
@@ -63,6 +63,8 @@ export interface TodayChatPreview {
export interface TodayReportCard {
/** Stable per report and list. It keys the card's live metric queries and its analytics. */
key: string
+ /** The report the card's resolve and dismiss buttons act on, or null when the card has no report. */
+ reportId: string | null
title: string
/** Why the briefing picked the report. Null for the team's reports, which no briefing picked. */
reason: string | null
diff --git a/frontend/src/scenes/project-homepage/today/TodayBriefing.tsx b/frontend/src/scenes/project-homepage/today/TodayBriefing.tsx
index 75e2b834c8d5..63b4a5422567 100644
--- a/frontend/src/scenes/project-homepage/today/TodayBriefing.tsx
+++ b/frontend/src/scenes/project-homepage/today/TodayBriefing.tsx
@@ -33,7 +33,7 @@ function TodayMetaLine(): JSX.Element {
}
function BriefingSegment({ segment }: { segment: TodayBriefingSegment }): JSX.Element {
- const { hoveredReportId, reports, teamReportPreviews } = useValues(todayLogic)
+ const { hoveredReportId, reports, teamReportPreviews, reportStateOverrides } = useValues(todayLogic)
const { reportOpened, setHoveredReportId } = useActions(todayLogic)
const { reportId } = segment
if (!reportId) {
@@ -47,6 +47,7 @@ function BriefingSegment({ segment }: { segment: TodayBriefingSegment }): JSX.El
subtle
className="TodayReportLink"
data-active={hoveredReportId === reportId}
+ data-state={reportStateOverrides[reportId] ?? 'open'}
data-attr="today-briefing-report"
onClick={() => report && reportOpened(report, 'briefing')}
onMouseEnter={() => setHoveredReportId(reportId)}
diff --git a/frontend/src/scenes/project-homepage/today/TodayHomeSidebar.tsx b/frontend/src/scenes/project-homepage/today/TodayHomeSidebar.tsx
index 48b86d6246e4..12b7a996edd0 100644
--- a/frontend/src/scenes/project-homepage/today/TodayHomeSidebar.tsx
+++ b/frontend/src/scenes/project-homepage/today/TodayHomeSidebar.tsx
@@ -68,6 +68,7 @@ export function TodayHomeSidebar(): JSX.Element {
showPersonalBriefing,
personalBriefing,
teamReportPreviews,
+ reportStateOverrides,
} = useValues(todayLogic)
const { reportOpened, setHoveredReportId } = useActions(todayLogic)
@@ -117,12 +118,16 @@ export function TodayHomeSidebar(): JSX.Element {
<TodayPreviewTrigger key={report.id} payload={teamReportPreviews.sidebar[report.id]}>
<TodayNavItem
title={reportTitle(report)}
- meta={reportMeta(report)}
+ meta={
+ itemStateLabel({ state: reportStateOverrides[report.id] ?? 'open' }) ??
+ reportMeta(report)
+ }
color={reportSource(report).color}
icon={<TodayIcon icon={reportIcon(report)} />}
to={urls.todayReport(report.id)}
active={hoveredReportId === report.id}
current={reportId === report.id}
+ state={reportStateOverrides[report.id]}
dataAttr="today-nav-report"
onClick={() => reportOpened(report, 'sidebar')}
onHoverChange={(hovered) => setHoveredReportId(hovered ? report.id : null)}
diff --git a/frontend/src/scenes/project-homepage/today/TodayReportHoverCard.tsx b/frontend/src/scenes/project-homepage/today/TodayReportHoverCard.tsx
index 0d0398def3a3..ab898d764e91 100644
--- a/frontend/src/scenes/project-homepage/today/TodayReportHoverCard.tsx
+++ b/frontend/src/scenes/project-homepage/today/TodayReportHoverCard.tsx
@@ -1,9 +1,10 @@
-import { useActions } from 'kea'
+import { useActions, useValues } from 'kea'
import { Suspense, useEffect } from 'react'
-import { IconPullRequest } from '@posthog/icons'
+import { IconCheckCircle, IconHide, IconPullRequest } from '@posthog/icons'
import {
Badge,
+ Button,
Item,
ItemActions,
ItemContent,
@@ -31,7 +32,9 @@ import {
} from 'products/signals/frontend/inbox/utils/reportMetrics'
import { pullRequestStateMeta } from 'products/tasks/frontend/spaces/TaskPullRequestChip'
-import { todayLogic } from './todayLogic'
+import { itemStateLabel } from './todayBriefingItems'
+import { TodayReportVerdict, todayLogic } from './todayLogic'
+import { isSampleReportId } from './todaySampleReports'
// The charts load on the first hover: the card sits in the app shell, and the query and chart code
// they need must stay out of the bundle every page loads.
@@ -53,12 +56,32 @@ const LISTED_METRIC_COUNT = 2
*/
export function TodayReportHoverCard({ preview }: { preview: TodayReportPreview }): JSX.Element {
const { card } = preview
- const { reportPreviewed } = useActions(todayLogic)
+ const { reportStateOverrides } = useValues(todayLogic)
+ const { reportPreviewed, requestReportVerdict } = useActions(todayLogic)
// Keyed on the report, not the card object: a poll replaces the object while the card stays open.
useEffect(() => {
reportPreviewed(card.key, preview.surface)
}, [card.key, preview.surface, reportPreviewed])
+ // Read live, not from the card: the card stays open after a click, and keeps the payload it opened with.
+ const override = card.reportId ? reportStateOverrides[card.reportId] : undefined
+ const stateLabel = override ? itemStateLabel({ state: override }) : card.stateLabel
+ const resolved = override ? override === 'done' : card.resolved
+ const { reportId } = card
+ const giveVerdict = (verdict: TodayReportVerdict): void => {
+ if (reportId) {
+ requestReportVerdict(
+ {
+ reportId,
+ title: card.title,
+ hasOpenPullRequest: card.pullRequestState === 'open' || card.pullRequestState === 'draft',
+ },
+ verdict,
+ preview.surface
+ )
+ }
+ }
+ const isSample = !!reportId && isSampleReportId(reportId)
const pullRequestState = pullRequestStateMeta(card.pullRequestState)
const metric = selectReportCardImpactMetric(card.metrics)
const aggregateQuery = metric ? asReportMetricAggregateQuery(metric.query) : null
@@ -119,9 +142,9 @@ export function TodayReportHoverCard({ preview }: { preview: TodayReportPreview
</ItemDescription>
)}
</ItemContent>
- {card.stateLabel && (
+ {stateLabel && (
<ItemActions className="self-start">
- <Badge variant={card.resolved ? 'completed' : 'default'}>{card.stateLabel}</Badge>
+ <Badge variant={resolved ? 'completed' : 'default'}>{stateLabel}</Badge>
</ItemActions>
)}
</Item>
@@ -207,6 +230,33 @@ export function TodayReportHoverCard({ preview }: { preview: TodayReportPreview
</Text>
)}
</div>
+ {reportId && !stateLabel && (
+ <>
+ <ItemSeparator className="my-0" />
+ <div className="flex flex-wrap justify-between gap-1.5 px-3 py-2">
+ <Button
+ variant="outline"
+ size="xs"
+ disabled={isSample}
+ onClick={() => giveVerdict('resolve')}
+ data-attr="today-report-hover-card-resolve"
+ >
+ <IconCheckCircle />
+ Resolve
+ </Button>
+ <Button
+ variant="outline"
+ size="xs"
+ disabled={isSample}
+ onClick={() => giveVerdict('dismiss')}
+ data-attr="today-report-hover-card-dismiss"
+ >
+ <IconHide />
+ Dismiss
+ </Button>
+ </div>
+ </>
+ )}
</div>
)
}
diff --git a/frontend/src/scenes/project-homepage/today/TodayReportPage.tsx b/frontend/src/scenes/project-homepage/today/TodayReportPage.tsx
index b0ba03ff3295..bd6403fedd4d 100644
--- a/frontend/src/scenes/project-homepage/today/TodayReportPage.tsx
+++ b/frontend/src/scenes/project-homepage/today/TodayReportPage.tsx
@@ -1,6 +1,6 @@
import { useActions, useValues } from 'kea'
-import { IconExternal } from '@posthog/icons'
+import { IconCheckCircle, IconExternal, IconHide } from '@posthog/icons'
import { LemonButton, LemonSkeleton, LemonTag } from '@posthog/lemon-ui'
import { urls } from 'scenes/urls'
@@ -8,8 +8,11 @@ import { urls } from 'scenes/urls'
import { ReportChart } from 'products/signals/frontend/inbox/components/detail/ReportChart'
import { ReportChartsContext } from 'products/signals/frontend/inbox/components/detail/reportChartsContext'
import { ReportSummaryBody } from 'products/signals/frontend/inbox/components/detail/ReportSummaryBody'
+import { canResolveReport, hasOpenImplementationPr } from 'products/signals/frontend/inbox/utils/reportActions'
+import { itemStateLabel } from './todayBriefingItems'
import { TodayIcon } from './TodayIcon'
+import { TodayReportVerdict, todayLogic } from './todayLogic'
import { TodayReportEvidence } from './TodayReportEvidence'
import { todayReportLogic } from './todayReportLogic'
import { TodayReportPrompts } from './TodayReportPrompts'
@@ -19,9 +22,18 @@ import { reportIcon, reportMeta, reportSource, reportTitle } from './todaySignal
export function TodayReportPage({ reportId }: { reportId: string }): JSX.Element {
const logic = todayReportLogic({ reportId })
- const { currentReport, reportFailed, fullReportLoading, chartPlacements, chartsById, trailingCharts, reportUrl } =
- useValues(logic)
+ const {
+ currentReport,
+ reportFailed,
+ fullReportLoading,
+ chartPlacements,
+ chartsById,
+ trailingCharts,
+ reportUrl,
+ reportState,
+ } = useValues(logic)
const { loadFullReport } = useActions(logic)
+ const { requestReportVerdict } = useActions(todayLogic)
const sampleDisabledReason = isSampleReportId(reportId) ? 'This is a sample report.' : undefined
if (!currentReport) {
@@ -55,6 +67,18 @@ export function TodayReportPage({ reportId }: { reportId: string }): JSX.Element
)
}
+ const stateLabel = itemStateLabel({ state: reportState })
+ const giveVerdict = (verdict: TodayReportVerdict): void =>
+ requestReportVerdict(
+ {
+ reportId: currentReport.id,
+ title: reportTitle(currentReport),
+ hasOpenPullRequest: hasOpenImplementationPr(currentReport),
+ },
+ verdict,
+ 'report_page'
+ )
+
return (
<div
className="TodayReport Today__page"
@@ -69,6 +93,9 @@ export function TodayReportPage({ reportId }: { reportId: string }): JSX.Element
</span>
<span>{reportMeta(currentReport)}</span>
{currentReport.priority && <LemonTag type="muted">{currentReport.priority}</LemonTag>}
+ {stateLabel && (
+ <LemonTag type={reportState === 'done' ? 'success' : 'muted'}>{stateLabel}</LemonTag>
+ )}
</div>
<h1 className="TodayReport__heading">{reportTitle(currentReport)}</h1>
<div className="flex flex-wrap gap-2 mt-4">
@@ -94,6 +121,35 @@ export function TodayReportPage({ reportId }: { reportId: string }): JSX.Element
>
Open in Inbox
</LemonButton>
+ {!stateLabel && (
+ <>
+ <LemonButton
+ type="secondary"
+ size="small"
+ icon={<IconCheckCircle />}
+ onClick={() => giveVerdict('resolve')}
+ disabledReason={
+ sampleDisabledReason ??
+ (canResolveReport(currentReport)
+ ? undefined
+ : 'You can resolve a report only after the agent finishes its research.')
+ }
+ data-attr="today-report-resolve"
+ >
+ Resolve
+ </LemonButton>
+ <LemonButton
+ type="secondary"
+ size="small"
+ icon={<IconHide />}
+ onClick={() => giveVerdict('dismiss')}
+ disabledReason={sampleDisabledReason}
+ data-attr="today-report-dismiss"
+ >
+ Dismiss
+ </LemonButton>
+ </>
+ )}
</div>
<ReportChartsContext.Provider value={chartsById}>
<div className="TodayReport__body">
diff --git a/frontend/src/scenes/project-homepage/today/todayBriefingItems.ts b/frontend/src/scenes/project-homepage/today/todayBriefingItems.ts
index 220907170256..10c02f668c4b 100644
--- a/frontend/src/scenes/project-homepage/today/todayBriefingItems.ts
+++ b/frontend/src/scenes/project-homepage/today/todayBriefingItems.ts
@@ -51,9 +51,21 @@ export function itemStateLabel(item: Pick<BriefingItemApi, 'state'>): string | n
return STATE_LABELS[item.state]
}
+const REPORT_STATUS_STATES: Record<string, BriefingItemStateEnumApi> = {
+ resolved: 'done',
+ suppressed: 'dismissed',
+ deleted: 'dismissed',
+}
+
+/** A report's status in the briefing's terms, the way the backend gives briefing items their live state. */
+export function reportItemState(status: string): BriefingItemStateEnumApi {
+ return REPORT_STATUS_STATES[status] ?? 'open'
+}
+
export function briefingItemReportCard(item: BriefingItemApi): TodayReportCard {
return {
key: item.key,
+ reportId: itemReportId(item),
title: item.title,
reason: itemReasonLabel(item),
stateLabel: itemStateLabel(item),
diff --git a/frontend/src/scenes/project-homepage/today/todayLogic.test.ts b/frontend/src/scenes/project-homepage/today/todayLogic.test.ts
index 08ea7d925a50..a41528827301 100644
--- a/frontend/src/scenes/project-homepage/today/todayLogic.test.ts
+++ b/frontend/src/scenes/project-homepage/today/todayLogic.test.ts
@@ -49,12 +49,14 @@ describe('todayLogic', () => {
let listParams: URLSearchParams | null
let briefingResponses: [number, any][]
let briefingCalls: number
+ let stateResponse: [number, any]
beforeEach(() => {
listResponse = [200, { results: [], count: 0 }]
listParams = null
briefingResponses = [[404, { detail: 'Not found.' }]]
briefingCalls = 0
+ stateResponse = [200, {}]
useMocks({
get: {
'/api/projects/:team_id/signals/reports/for_you/': ({ request }) => {
@@ -71,6 +73,7 @@ describe('todayLogic', () => {
200,
makeBriefing({ id: 'b-next', status: 'writing' }),
],
+ '/api/projects/:team_id/signals/reports/:id/state/': () => stateResponse,
},
})
initKeaTests()
@@ -124,6 +127,27 @@ describe('todayLogic', () => {
}
})
+ it.each([
+ ['keeps a verdict the API accepts', 200, 'done'],
+ ['takes back a verdict the API refuses', 409, 'open'],
+ ])('%s', async (_, status, finalState) => {
+ briefingResponses = [[200, makeBriefing()]]
+ stateResponse = [status, { detail: 'Refused.' }]
+ const logic = todayLogic()
+ logic.mount()
+ await expectLogic(logic).toFinishAllListeners()
+
+ logic.actions.requestReportVerdict(
+ { reportId: 'a', title: 'Signup form rejects emails', hasOpenPullRequest: false },
+ 'resolve',
+ 'sidebar'
+ )
+ expect(logic.values.briefingItems[0].state).toEqual('done')
+
+ await expectLogic(logic).toFinishAllListeners()
+ expect(logic.values.briefingItems[0].state).toEqual(finalState)
+ })
+
it('keeps the last briefing on screen, polls while the next is written, and stops when it is ready', async () => {
jest.useFakeTimers()
const previous = makeBriefing({ id: 'b-previous', status: 'writing' })
diff --git a/frontend/src/scenes/project-homepage/today/todayLogic.ts b/frontend/src/scenes/project-homepage/today/todayLogic.ts
index e1932ae59bd9..bc9b7140ad12 100644
--- a/frontend/src/scenes/project-homepage/today/todayLogic.ts
+++ b/frontend/src/scenes/project-homepage/today/todayLogic.ts
@@ -5,6 +5,7 @@ import type { LocationChangedPayload } from 'kea-router/lib/types'
import posthog from 'posthog-js'
import { ApiError } from 'lib/api'
+import { LemonDialog } from 'lib/lemon-ui/LemonDialog'
import { lemonToast } from 'lib/lemon-ui/LemonToast/LemonToast'
import { removeProjectIdIfPresent } from 'lib/utils/kea-router'
import { navigateToHref } from 'lib/utils/navigateToHref'
@@ -16,10 +17,21 @@ import { userLogic } from 'scenes/userLogic'
import type { TodayReportCard, TodayReportPreview } from '~/layout/today/todayPreviewCards'
import { TeamType, UserType } from '~/types'
-import { signalsReportsForYouRetrieve } from 'products/signals/frontend/generated/api'
+import { signalsReportsForYouRetrieve, signalsReportsStateCreate } from 'products/signals/frontend/generated/api'
+import type {
+ SignalReportStateEnumApi,
+ SignalReportStateRequestApi,
+} from 'products/signals/frontend/generated/api.schemas'
+import { openDismissReportDialog } from 'products/signals/frontend/inbox/components/shell/DismissReportDialog'
+import { openResolveReportDialog } from 'products/signals/frontend/inbox/components/shell/ResolveReportDialog'
import { SignalReport } from 'products/signals/frontend/inbox/types'
+import { suppressDismissalPayload } from 'products/signals/frontend/inbox/utils/dismissalReasons'
import { todayBriefingRefreshCreate, todayBriefingRetrieve } from 'products/today/frontend/generated/api'
-import type { BriefingApi, BriefingItemApi } from 'products/today/frontend/generated/api.schemas'
+import type {
+ BriefingApi,
+ BriefingItemApi,
+ BriefingItemStateEnumApi,
+} from 'products/today/frontend/generated/api.schemas'
import type { TeamPublicType } from '../../../types'
import { TodayAskContext, todayAskPrompt } from './todayAskPrompt'
@@ -31,6 +43,7 @@ import {
isBriefingSettled,
isExternalHref,
itemHref,
+ itemReportId,
} from './todayBriefingItems'
import { SAMPLE_BRIEFING, parseSampleParam, sampleTopReports } from './todaySampleReports'
import { TodayBriefingSegment, briefingForReports, teamReportCard } from './todaySignalReports'
@@ -47,6 +60,58 @@ export type TodayReportOpenSource = 'briefing' | 'chip' | 'sidebar'
/** Where a question to PostHog AI came from, sent with the `today ai asked` event. */
export type TodayAskSource = 'ask_box' | 'walk_through'
+/** What a person decides about a report from Today. */
+export type TodayReportVerdict = 'resolve' | 'dismiss'
+
+/** Where the person gave the verdict, sent with the `today report state changed` event. */
+export type TodayReportVerdictSurface = TodayReportPreview['surface'] | 'report_page'
+
+/** The report a verdict acts on. */
+export interface TodayReportVerdictTarget {
+ reportId: string
+ title: string
+ /** The backend closes an open implementation pull request on either verdict, so the person confirms first. */
+ hasOpenPullRequest: boolean
+}
+
+interface TodayReportVerdictCopy {
+ apiState: SignalReportStateEnumApi
+ itemState: BriefingItemStateEnumApi
+ success: string
+ successClosingPullRequest: string
+ failure: string
+ confirmTitle: string
+ confirmLabel: string
+ reasonTitle: string
+ reasonDescription: string
+}
+
+const VERDICTS: Record<TodayReportVerdict, TodayReportVerdictCopy> = {
+ resolve: {
+ apiState: 'resolved',
+ itemState: 'done',
+ success: 'Report resolved',
+ successClosingPullRequest: 'Report resolved. Its pull request is closing.',
+ failure: 'Couldn’t resolve the report. Try again, or resolve it from the Inbox.',
+ confirmTitle: 'Resolve this report?',
+ confirmLabel: 'Resolve and close PR',
+ reasonTitle: 'Why did you resolve this report?',
+ reasonDescription: 'The reason is saved on the report.',
+ },
+ dismiss: {
+ apiState: 'suppressed',
+ itemState: 'dismissed',
+ success: 'Report dismissed',
+ successClosingPullRequest: 'Report dismissed. Its pull request is closing.',
+ failure: 'Couldn’t dismiss the report. Try again, or dismiss it from the Inbox.',
+ confirmTitle: 'Dismiss this report?',
+ confirmLabel: 'Dismiss and close PR',
+ reasonTitle: 'Why did you dismiss this report?',
+ reasonDescription:
+ 'The reason is saved on the report. The agent that filed it reads your note on its next run.',
+ },
+}
+
/** The count behind the Inbox link: reports for the person beyond the shown ones, or open in the project. */
export interface TodayInboxMore {
count: number
@@ -135,6 +200,7 @@ export interface todayLogicValues {
reloadingAfterRefresh: boolean
reportId: string | null
reportPreviews: Record<TodayReportPreview['surface'], Record<string, TodayReportPreview>>
+ reportStateOverrides: Record<string, BriefingItemStateEnumApi>
reportSummary: string
reports: SignalReport[]
reportsFailed: boolean
@@ -168,6 +234,13 @@ export interface todayLogicActions {
searchParams: Record<string, any>
url: string
} // router
+ addReportVerdictReason: (
+ target: TodayReportVerdictTarget,
+ verdict: TodayReportVerdict
+ ) => {
+ target: TodayReportVerdictTarget
+ verdict: TodayReportVerdict
+ }
askAi: (
prompt: string,
source: TodayAskSource
@@ -258,12 +331,33 @@ export interface todayLogicActions {
cardKey: string
surface: 'briefing' | 'sidebar'
}
+ requestReportVerdict: (
+ target: TodayReportVerdictTarget,
+ verdict: TodayReportVerdict,
+ surface: TodayReportVerdictSurface
+ ) => {
+ surface: TodayReportVerdictSurface
+ target: TodayReportVerdictTarget
+ verdict: TodayReportVerdict
+ }
setHoveredItemKey: (itemKey: string | null) => {
itemKey: string | null
}
setHoveredReportId: (reportId: string | null) => {
reportId: string | null
}
+ setReportVerdict: (
+ target: TodayReportVerdictTarget,
+ verdict: TodayReportVerdict,
+ surface: TodayReportVerdictSurface
+ ) => {
+ surface: TodayReportVerdictSurface
+ target: TodayReportVerdictTarget
+ verdict: TodayReportVerdict
+ }
+ setReportVerdictFailure: (reportId: string) => {
+ reportId: string
+ }
setUseSampleData: (useSampleData: boolean) => {
useSampleData: boolean
}
@@ -287,7 +381,11 @@ export interface todayLogicMeta {
reportSummary: (hour: number, reports: SignalReport[]) => string
showPersonalBriefing: (personalBriefing: BriefingApi | null, useSampleData: boolean) => boolean
inboxMore: (personalBriefing: BriefingApi | null) => TodayInboxMore | null
- briefingItems: (personalBriefing: BriefingApi | null, showPersonalBriefing: boolean) => BriefingItemApi[]
+ briefingItems: (
+ personalBriefing: BriefingApi | null,
+ showPersonalBriefing: boolean,
+ reportStateOverrides: Record<string, BriefingItemStateEnumApi>
+ ) => BriefingItemApi[]
reportPreviews: (
briefingItems: BriefingItemApi[]
) => Record<TodayReportPreview['surface'], Record<string, TodayReportPreview>>
@@ -334,6 +432,21 @@ export const todayLogic = kea<todayLogicType>([
reportPreviewed: (cardKey: string, surface: TodayReportPreview['surface']) => ({ cardKey, surface }),
pollBriefing: true,
stopWaitingForBriefing: (briefingId: string) => ({ briefingId }),
+ requestReportVerdict: (
+ target: TodayReportVerdictTarget,
+ verdict: TodayReportVerdict,
+ surface: TodayReportVerdictSurface
+ ) => ({ target, verdict, surface }),
+ setReportVerdict: (
+ target: TodayReportVerdictTarget,
+ verdict: TodayReportVerdict,
+ surface: TodayReportVerdictSurface
+ ) => ({ target, verdict, surface }),
+ setReportVerdictFailure: (reportId: string) => ({ reportId }),
+ addReportVerdictReason: (target: TodayReportVerdictTarget, verdict: TodayReportVerdict) => ({
+ target,
+ verdict,
+ }),
}),
loaders(({ values }) => ({
topReports: [
@@ -438,6 +551,21 @@ export const todayLogic = kea<todayLogicType>([
],
// The refresh call returns before the page reloads the briefing. Until that reload returns
// the `writing` briefing, the page still waits, so the badge does not flip back to the button.
+ // A verdict shows at once in the text, the left bar and the hover card. The next briefing load
+ // gives the same state from the server, and a failed request takes the verdict back.
+ reportStateOverrides: [
+ {} as Record<string, BriefingItemStateEnumApi>,
+ {
+ setReportVerdict: (overrides, { target, verdict }) => ({
+ ...overrides,
+ [target.reportId]: VERDICTS[verdict].itemState,
+ }),
+ setReportVerdictFailure: (overrides, { reportId }) => {
+ const { [reportId]: _, ...rest } = overrides
+ return rest
+ },
+ },
+ ],
reloadingAfterRefresh: [
false,
{
@@ -495,9 +623,21 @@ export const todayLogic = kea<todayLogicType>([
},
],
briefingItems: [
- (s) => [s.personalBriefing, s.showPersonalBriefing],
- (personalBriefing: BriefingApi | null, showPersonalBriefing: boolean): BriefingItemApi[] =>
- showPersonalBriefing && personalBriefing ? personalBriefing.items : [],
+ (s) => [s.personalBriefing, s.showPersonalBriefing, s.reportStateOverrides],
+ (
+ personalBriefing: BriefingApi | null,
+ showPersonalBriefing: boolean,
+ reportStateOverrides: Record<string, BriefingItemStateEnumApi>
+ ): BriefingItemApi[] => {
+ if (!showPersonalBriefing || !personalBriefing) {
+ return []
+ }
+ return personalBriefing.items.map((item) => {
+ const reportId = itemReportId(item)
+ const state = reportId ? reportStateOverrides[reportId] : undefined
+ return state ? { ...item, state } : item
+ })
+ },
],
// The card stores its trigger's payload, so each report keeps one object per surface across renders.
reportPreviews: [
@@ -693,6 +833,91 @@ export const todayLogic = kea<todayLogicType>([
more_report_count: values.moreReportCount,
})
},
+ requestReportVerdict: ({ target, verdict, surface }) => {
+ if (!target.hasOpenPullRequest) {
+ actions.setReportVerdict(target, verdict, surface)
+ return
+ }
+ const copy = VERDICTS[verdict]
+ LemonDialog.open({
+ title: copy.confirmTitle,
+ description: 'This also closes the open pull request for this report.',
+ primaryButton: {
+ children: copy.confirmLabel,
+ onClick: () => actions.setReportVerdict(target, verdict, surface),
+ 'data-attr': `today-report-${verdict}-confirm`,
+ },
+ secondaryButton: { children: 'Cancel' },
+ })
+ },
+ setReportVerdict: async ({ target, verdict, surface }) => {
+ const copy = VERDICTS[verdict]
+ try {
+ await signalsReportsStateCreate(String(values.currentProjectId), target.reportId, {
+ state: copy.apiState,
+ })
+ } catch (error) {
+ actions.setReportVerdictFailure(target.reportId)
+ lemonToast.error((error instanceof ApiError && error.detail) || copy.failure)
+ return
+ }
+ // pinned: analytics event name and properties. Renaming them breaks dashboards.
+ posthog.capture('today report state changed', {
+ verdict,
+ surface,
+ closed_pull_request: target.hasOpenPullRequest,
+ })
+ // A reason is optional, so the verdict is one click and the reason is one more.
+ lemonToast.success(target.hasOpenPullRequest ? copy.successClosingPullRequest : copy.success, {
+ button: { label: 'Add a reason', action: () => actions.addReportVerdictReason(target, verdict) },
+ })
+ },
+ addReportVerdictReason: ({ target, verdict }) => {
+ const copy = VERDICTS[verdict]
+ const dialogCopy = {
+ title: copy.reasonTitle,
+ description: copy.reasonDescription,
+ submitLabel: 'Save reason',
+ }
+ // The state API takes the verdict the report already has and only saves the reason with it.
+ const saveReason = async (body: SignalReportStateRequestApi): Promise<void> => {
+ try {
+ await signalsReportsStateCreate(String(values.currentProjectId), target.reportId, body)
+ } catch (error) {
+ lemonToast.error(
+ (error instanceof ApiError && error.detail) || 'Couldn’t save the reason. Try again.'
+ )
+ // The dialog stays open, so the reason and the note are kept for the next try.
+ throw error
+ }
+ // pinned: analytics event name and properties. Renaming them breaks dashboards.
+ posthog.capture('today report reason added', {
+ verdict,
+ reason: body.dismissal_reason,
+ has_note: !!body.dismissal_note,
+ })
+ lemonToast.success('Reason saved')
+ }
+ if (verdict === 'resolve') {
+ openResolveReportDialog({
+ reportTitle: target.title,
+ copy: dialogCopy,
+ onConfirm: ({ reason, note }) =>
+ saveReason({
+ state: copy.apiState,
+ dismissal_reason: reason,
+ ...(note ? { dismissal_note: note } : {}),
+ }),
+ })
+ } else {
+ openDismissReportDialog({
+ reportTitle: target.title,
+ copy: dialogCopy,
+ onConfirm: (dismissal) =>
+ saveReason({ state: copy.apiState, ...suppressDismissalPayload(dismissal) }),
+ })
+ }
+ },
reportOpened: ({ report, source }) => {
if (values.useSampleData) {
return
diff --git a/frontend/src/scenes/project-homepage/today/todayReportLogic.ts b/frontend/src/scenes/project-homepage/today/todayReportLogic.ts
index 1c5865e11990..3de55948d38a 100644
--- a/frontend/src/scenes/project-homepage/today/todayReportLogic.ts
+++ b/frontend/src/scenes/project-homepage/today/todayReportLogic.ts
@@ -10,7 +10,9 @@ import { signalsReportsSignalsRetrieve } from 'products/signals/frontend/generat
import { ReportChartApi, SignalNodeApi } from 'products/signals/frontend/generated/api.schemas'
import { SignalReport } from 'products/signals/frontend/inbox/types'
import { ChartPlacements, resolveChartPlacements } from 'products/signals/frontend/inbox/utils/chartPlacement'
+import type { BriefingItemStateEnumApi } from 'products/today/frontend/generated/api.schemas'
+import { reportItemState } from './todayBriefingItems'
import { todayLogic } from './todayLogic'
import { findSampleReport, isSampleReportId, sampleSignals } from './todaySampleReports'
@@ -20,6 +22,7 @@ export interface TodayReportLogicProps {
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface todayReportLogicValues {
+ reportStateOverrides: Record<string, BriefingItemStateEnumApi> // todayLogic
reports: SignalReport[] // todayLogic
chartPlacements: ChartPlacements
chartsById: Map<string, ReportChartApi>
@@ -29,6 +32,7 @@ export interface todayReportLogicValues {
reportFailed: boolean
reportSignals: SignalNodeApi[] | null
reportSignalsLoading: boolean
+ reportState: BriefingItemStateEnumApi
reportUrl: string
signals: SignalNodeApi[]
trailingCharts: ReportChartApi[]
@@ -81,6 +85,10 @@ export interface todayReportLogicMeta {
chartsById: (currentReport: SignalReport | null) => Map<string, ReportChartApi>
trailingCharts: (currentReport: SignalReport | null, chartPlacements: ChartPlacements) => ReportChartApi[]
signals: (reportSignals: SignalNodeApi[] | null) => SignalNodeApi[]
+ reportState: (
+ currentReport: SignalReport | null,
+ reportStateOverrides: Record<string, BriefingItemStateEnumApi>
+ ) => BriefingItemStateEnumApi
}
}
@@ -95,7 +103,7 @@ export const todayReportLogic = kea<todayReportLogicType>([
props({} as TodayReportLogicProps),
key((props) => props.reportId),
path((reportId) => ['scenes', 'project-homepage', 'today', 'todayReportLogic', reportId]),
- connect(() => ({ values: [todayLogic, ['reports']] })),
+ connect(() => ({ values: [todayLogic, ['reports', 'reportStateOverrides']] })),
loaders(({ props }) => ({
fullReport: [
null as SignalReport | null,
@@ -166,6 +174,16 @@ export const todayReportLogic = kea<todayReportLogicType>([
(first, second) => new Date(second.timestamp).getTime() - new Date(first.timestamp).getTime()
),
],
+ // A verdict given from Today shows before the report reloads.
+ reportState: [
+ (s) => [s.currentReport, s.reportStateOverrides],
+ (
+ currentReport: SignalReport | null,
+ reportStateOverrides: Record<string, BriefingItemStateEnumApi>
+ ): BriefingItemStateEnumApi =>
+ reportStateOverrides[props.reportId] ??
+ (currentReport ? reportItemState(currentReport.status) : 'open'),
+ ],
// Absolute, because the session prompt gives it to the agent so the agent can read the report.
reportUrl: [
() => [],
diff --git a/frontend/src/scenes/project-homepage/today/todaySignalReports.ts b/frontend/src/scenes/project-homepage/today/todaySignalReports.ts
index 1b35cdab69c1..7fb4391a9e4f 100644
--- a/frontend/src/scenes/project-homepage/today/todaySignalReports.ts
+++ b/frontend/src/scenes/project-homepage/today/todaySignalReports.ts
@@ -83,6 +83,7 @@ export function reportSource(report: Pick<SignalReport, 'source_products'>): Tod
export function teamReportCard(report: SignalReport): TodayReportCard {
return {
key: `team-report:${report.id}`,
+ reportId: report.id,
title: reportTitle(report),
reason: null,
stateLabel: null,
diff --git a/products/signals/frontend/inbox/components/shell/DismissReportDialog.tsx b/products/signals/frontend/inbox/components/shell/DismissReportDialog.tsx
index 0e103bb1349e..3b8ffa97f41c 100644
--- a/products/signals/frontend/inbox/components/shell/DismissReportDialog.tsx
+++ b/products/signals/frontend/inbox/components/shell/DismissReportDialog.tsx
@@ -19,6 +19,9 @@ interface OpenDismissReportDialogParams {
/** Preselect this reason. The context menu's "Something else…" opens the dialog with it set,
* so the person only has to write the note. */
initialReason?: DismissalReasonValue
+ /** Replaces the default title, description and submit label. Today uses them to ask for a reason
+ * after the report was already dismissd, so the copy must not ask to dismiss it again. */
+ copy?: { title: string; description: string; submitLabel: string }
/** Called with the chosen reason, note and optional repo correction once the user confirms. */
onConfirm: (result: DismissalFeedback) => void | Promise<void>
}
@@ -41,6 +44,7 @@ export function openDismissReportDialog({
hasOpenPr = false,
hotkeys = false,
initialReason,
+ copy,
onConfirm,
}: OpenDismissReportDialogParams): void {
// The selection bar knows the count and no titles, so its copy counts reports even when one
@@ -59,8 +63,8 @@ export function openDismissReportDialog({
}`
LemonDialog.openForm({
- title,
- description,
+ title: copy?.title ?? title,
+ description: copy?.description ?? description,
maxWidth: '36rem',
overlayClassName: '!items-center',
initialValues: {
@@ -101,7 +105,7 @@ export function openDismissReportDialog({
errors: {
reason: (reason) => (!reason ? "You haven't picked a reason" : undefined),
},
- primaryButtonProps: { children: 'Dismiss & teach the agent' },
+ primaryButtonProps: { children: copy?.submitLabel ?? 'Dismiss & teach the agent' },
shouldAwaitSubmit: true,
onSubmit: async ({ reason, note, correctedRepository }) => {
if (!reason) {
diff --git a/products/signals/frontend/inbox/components/shell/ResolveReportDialog.tsx b/products/signals/frontend/inbox/components/shell/ResolveReportDialog.tsx
index a1b9272b4668..38d69fa6e912 100644
--- a/products/signals/frontend/inbox/components/shell/ResolveReportDialog.tsx
+++ b/products/signals/frontend/inbox/components/shell/ResolveReportDialog.tsx
@@ -23,6 +23,9 @@ interface OpenResolveReportDialogParams {
/** Preselect this reason. The context menu's "Something else…" opens the dialog with it set,
* so the person only has to write the note. */
initialReason?: ResolveReasonValue
+ /** Replaces the default title, description and submit label. Today uses them to ask for a reason
+ * after the report was already resolved, so the copy must not ask to resolve it again. */
+ copy?: { title: string; description: string; submitLabel: string }
/** Called with the chosen reason + note once the user confirms. */
onConfirm: (result: ResolveReportDialogResult) => void | Promise<void>
}
@@ -45,6 +48,7 @@ export function openResolveReportDialog({
hasOpenPr = false,
hotkeys = false,
initialReason,
+ copy,
onConfirm,
}: OpenResolveReportDialogParams): void {
// The selection bar knows the count and no titles, so its copy counts reports even when one
@@ -61,8 +65,8 @@ export function openResolveReportDialog({
}`
LemonDialog.openForm({
- title,
- description,
+ title: copy?.title ?? title,
+ description: copy?.description ?? description,
maxWidth: '36rem',
overlayClassName: '!items-center',
initialValues: { reason: initialReason ?? null, note: '' },
@@ -100,7 +104,7 @@ export function openResolveReportDialog({
errors: {
reason: (reason) => (!reason ? "You haven't picked a reason" : undefined),
},
- primaryButtonProps: { children: isPlural ? 'Resolve reports' : 'Resolve report' },
+ primaryButtonProps: { children: copy?.submitLabel ?? (isPlural ? 'Resolve reports' : 'Resolve report') },
shouldAwaitSubmit: true,
onSubmit: async ({ reason, note }) => {
if (!reason) {