: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
feat(mobilehog): filter reports by status (#109529)
Dylan Martin8c409d41eb19
diff --git a/products/desktop/apps/mobilehog/src/app/(drawer)/self-driving.tsx b/products/desktop/apps/mobilehog/src/app/(drawer)/self-driving.tsxindex 687d6deabeac..798cdb46ca74 100644--- a/products/desktop/apps/mobilehog/src/app/(drawer)/self-driving.tsx+++ b/products/desktop/apps/mobilehog/src/app/(drawer)/self-driving.tsx@@ -1,3 +1,5 @@+import { Host, Picker, Text as SwiftText } from "@expo/ui/swift-ui";+import { pickerStyle, tag } from "@expo/ui/swift-ui/modifiers";import { formatRelativeAge } from "@posthog/shared";import type { SignalReport } from "@posthog/shared/domain-types";import * as Haptics from "expo-haptics";@@ -17,6 +19,7 @@ import { GlassCircleButton } from "@/components/Glass";import { MenuIcon } from "@/components/Icons";import { PriorityChip } from "@/components/ReportCard";import { TriageDeck } from "@/components/TriageDeck";+import { REPORT_FILTERS, type ReportFilter } from "@/lib/reportFilters";import {useDismissReport,useReports,@@ -25,11 +28,20 @@ import {} from "@/lib/reports";import { colors, fonts, radius } from "@/lib/theme";+const EMPTY: Record<ReportFilter, string> = {+ attention: "All clear",+ "pull-requests": "No pull requests ready",+ dismissed: "Nothing dismissed",+};+export default function SelfDrivingScreen() {const navigation = useNavigation<{ openDrawer: () => void }>();const router = useRouter();const insets = useSafeAreaInsets();+ const [filter, setFilter] = useState<ReportFilter>("attention");+ // The deck always works on the reports that need attention.const reports = useReports();+ const listed = useReports("", filter);const seen = useSeenReports((s) => s.seen);const seenHydrated = useSeenReports((s) => s.hydrated);const markSeen = useSeenReports((s) => s.markSeen);@@ -49,6 +61,8 @@ export default function SelfDrivingScreen() {() => (reports.data ?? []).filter((report) => !handled.has(report.id)),[reports.data, handled],);+ const rows = filter === "attention" ? all : (listed.data ?? []);+ const listFailed = listed.isError && !listed.data;const unseen = useMemo(() => all.filter((report) => !seen.has(report.id)),[all, seen],@@ -56,10 +70,16 @@ export default function SelfDrivingScreen() {// New reports since the last visit open the deck on their own.useEffect(() => {- if (deck === null && seenHydrated && reports.data && unseen.length > 0) {+ if (+ deck === null &&+ filter === "attention" &&+ seenHydrated &&+ reports.data &&+ unseen.length > 0+ ) {setDeck(unseen.map((report) => report.id));}- }, [deck, seenHydrated, reports.data, unseen]);+ }, [deck, filter, seenHydrated, reports.data, unseen]);const deckReports = useMemo(() =>@@ -158,11 +178,31 @@ export default function SelfDrivingScreen() {{ paddingBottom: insets.bottom + 100 },]}>- <Text style={styles.sectionTitle}>- {all.length === 0 && !reports.isLoading ? "All clear" : "Reports"}- </Text>- {reports.isLoading ? <Text style={styles.muted}>Loading</Text> : null}- {all.map((report) => (+ <Host matchContents={{ vertical: true }}>+ <Picker+ selection={filter}+ onSelectionChange={setFilter}+ modifiers={[pickerStyle("segmented")]}+ >+ {REPORT_FILTERS.map((option) => (+ <SwiftText key={option.value} modifiers={[tag(option.value)]}>+ {option.label}+ </SwiftText>+ ))}+ </Picker>+ </Host>+ {listed.isLoading ? <Text style={styles.muted}>Loading</Text> : null}+ {listFailed ? (+ <Pressable onPress={() => listed.refetch()}>+ <Text style={styles.muted}>+ Could not load reports. Tap to try again.+ </Text>+ </Pressable>+ ) : null}+ {rows.length === 0 && !listed.isLoading && !listFailed ? (+ <Text style={styles.sectionTitle}>{EMPTY[filter]}</Text>+ ) : null}+ {rows.map((report) => (<Pressablekey={report.id}onPress={() => openReport(report)}@@ -181,7 +221,9 @@ export default function SelfDrivingScreen() {{formatRelativeAge(report.updated_at)}</Text></View>- {!seen.has(report.id) ? <View style={styles.newDot} /> : null}+ {filter === "attention" && !seen.has(report.id) ? (+ <View style={styles.newDot} />+ ) : null}</Pressable>))}</Animated.ScrollView>@@ -197,7 +239,7 @@ export default function SelfDrivingScreen() {<Text style={styles.notice}>{notice}</Text></Animated.View>) : null}- {!showDeck && all.length > 0 ? (+ {!showDeck && filter === "attention" && all.length > 0 ? (<Animated.Viewentering={FadeInDown.duration(260)}exiting={FadeOutDown.duration(180)}@@ -205,18 +247,14 @@ export default function SelfDrivingScreen() {><FadeScrim style={styles.floatingScrim} /><Pressable- onPress={() =>- setDeck((unseen.length > 0 ? unseen : all).map((r) => r.id))- }+ onPress={() => setDeck(all.map((report) => report.id))}style={({ pressed }) => [styles.triage,pressed && { opacity: 0.8 },]}><Text style={styles.triageText}>- {unseen.length > 0- ? `Triage ${unseen.length} new report${unseen.length === 1 ? "" : "s"}`- : `Triage ${all.length} report${all.length === 1 ? "" : "s"}`}+ Triage {all.length} report{all.length === 1 ? "" : "s"}</Text></Pressable></Animated.View>diff --git a/products/desktop/apps/mobilehog/src/app/report/[id].tsx b/products/desktop/apps/mobilehog/src/app/report/[id].tsxindex 62cd91a77a56..93170c117882 100644--- a/products/desktop/apps/mobilehog/src/app/report/[id].tsx+++ b/products/desktop/apps/mobilehog/src/app/report/[id].tsx@@ -3,10 +3,21 @@ import { isDismissedReport } from "@posthog/core/inbox/reportMembership";import * as Haptics from "expo-haptics";import { router, useLocalSearchParams } from "expo-router";import { useEffect } from "react";-import { Pressable, StyleSheet, Text, View } from "react-native";+import {+ Alert,+ Linking,+ Pressable,+ StyleSheet,+ Text,+ View,+} from "react-native";import { useSafeAreaInsets } from "react-native-safe-area-context";import { Glass } from "@/components/Glass";import { CardButton, ReportDetail } from "@/components/ReportCard";+import {+ hasOpenImplementationPr,+ openPullRequestUrl,+} from "@/lib/reportFilters";import {useDismissReport,useHasLiveImplementationTask,@@ -51,12 +62,31 @@ export default function ReportScreen() {isTaskLookupPending: liveTask.isPending || liveTask.isError,});const taskCheckFailed = liveTask.isError && canCreateImplementationPr(report);+ // A report with an open PR cannot start another task, so the PR takes that+ // slot.+ const prUrl = canStart ? null : openPullRequestUrl(report);- const onDismiss = (): void => {+ const runDismiss = (): void => {Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Rigid).catch(() => {});dismiss.mutate(report.id, { onSuccess: () => router.back() });};+ // Dismissing a report also closes its open PR on GitHub.+ const onDismiss = (): void => {+ if (!hasOpenImplementationPr(report)) {+ runDismiss();+ return;+ }+ Alert.alert(+ "Dismiss and close the PR?",+ "The open pull request for this report will be closed.",+ [+ { text: "Cancel", style: "cancel" },+ { text: "Dismiss", style: "destructive", onPress: runDismiss },+ ],+ );+ };+// Pop back to the drawer and open the task there, so the report does not// stay under the chat.const onStart = (): void => {@@ -69,7 +99,7 @@ export default function ReportScreen() {return (<View style={styles.root}><ReportDetail report={report} />- {canDismiss || canStart || taskCheckFailed ? (+ {canDismiss || canStart || taskCheckFailed || prUrl ? (<View style={[styles.actions, { paddingBottom: insets.bottom + 12 }]}>{dismiss.isError ? (<Text style={styles.error}>Could not dismiss. Try again.</Text>@@ -92,6 +122,13 @@ export default function ReportScreen() {onPress={onDismiss}/>) : null}+ {prUrl ? (+ <CardButton+ label="Open pull request"+ primary+ onPress={() => Linking.openURL(prUrl).catch(() => {})}+ />+ ) : null}{canStart ? (<CardButtonlabel="Start task"diff --git a/products/desktop/apps/mobilehog/src/lib/reportFilters.test.ts b/products/desktop/apps/mobilehog/src/lib/reportFilters.test.tsnew file mode 100644index 000000000000..b1094a7b990c--- /dev/null+++ b/products/desktop/apps/mobilehog/src/lib/reportFilters.test.ts@@ -0,0 +1,95 @@+import type { SignalReport } from "@posthog/shared/domain-types";+import { describe, expect, it } from "vitest";+import {+ hasOpenImplementationPr,+ openPullRequestUrl,+ reportFilterParams,+} from "./reportFilters";++const PR = "https://github.com/acme/app/pull/12";++function report(fields: Partial<SignalReport>): SignalReport {+ return { id: "r", ...fields } as SignalReport;+}++describe("reportFilters", () => {+ it.each([+ [+ "attention",+ {+ status: "ready,pending_input",+ actionability: "immediately_actionable,requires_human_input",+ ordering: "status,-priority,-created_at",+ },+ ],+ [+ "pull-requests",+ {+ status: "ready",+ has_implementation_pr: true,+ ordering: "status,-priority,-created_at",+ },+ ],+ ["dismissed", { status: "suppressed,resolved", ordering: "-updated_at" }],+ ] as const)("maps %s to its list params", (filter, params) => {+ expect(reportFilterParams(filter)).toEqual(params);+ });++ it.each([+ ["no PR", {}, false],+ [+ "an open PR",+ { implementation_pr_url: PR, implementation_pr_state: "open" },+ true,+ ],+ [+ "a draft PR",+ { implementation_pr_url: PR, implementation_pr_state: "draft" },+ true,+ ],+ ["a PR with no known state", { implementation_pr_url: PR }, true],+ [+ "a merged PR",+ { implementation_pr_url: PR, implementation_pr_state: "merged" },+ false,+ ],+ [+ "a closed PR",+ { implementation_pr_url: PR, implementation_pr_state: "closed" },+ false,+ ],+ [+ "a PR flagged merged",+ { implementation_pr_url: PR, implementation_pr_merged: true },+ false,+ ],+ ] as const)("treats a report with %s as open: %s", (_label, fields, open) => {+ expect(hasOpenImplementationPr(report(fields))).toBe(open);+ });++ it.each([+ [PR, PR],+ ["http://github.com/acme/app/pull/12", null],+ ["https://evil.example.com/acme/app/pull/12", null],+ ["mailto://github.com/acme/app/pull/1", null],+ ["javascript:alert(1)", null],+ ["myapp://github.com/acme/app/pull/1", null],+ ])("only opens %s as a GitHub PR link", (url, expected) => {+ expect(+ openPullRequestUrl(+ report({ implementation_pr_url: url, implementation_pr_state: "open" }),+ ),+ ).toBe(expected);+ });++ it("does not link a merged PR", () => {+ expect(+ openPullRequestUrl(+ report({+ implementation_pr_url: PR,+ implementation_pr_state: "merged",+ }),+ ),+ ).toBeNull();+ });+});diff --git a/products/desktop/apps/mobilehog/src/lib/reportFilters.ts b/products/desktop/apps/mobilehog/src/lib/reportFilters.tsnew file mode 100644index 000000000000..8d563137ac00--- /dev/null+++ b/products/desktop/apps/mobilehog/src/lib/reportFilters.ts@@ -0,0 +1,66 @@+import {+ buildArchiveListOrdering,+ buildSignalReportListOrdering,+ INBOX_ACTIONABLE_ACTIONABILITY_FILTER,+ INBOX_ACTIONABLE_REPORT_STATUS_FILTER,+ INBOX_DISMISSED_STATUS_FILTER,+ INBOX_PULL_REQUEST_STATUS_FILTER,+} from "@posthog/core/inbox/reportFiltering";+import { isSafeGitHubPullRequestUrl } from "@posthog/shared";+import type {+ SignalReport,+ SignalReportsQueryParams,+} from "@posthog/shared/domain-types";++export type ReportFilter = "attention" | "pull-requests" | "dismissed";++export const REPORT_FILTERS: { value: ReportFilter; label: string }[] = [+ { value: "attention", label: "Needs attention" },+ { value: "pull-requests", label: "PR ready" },+ { value: "dismissed", label: "Dismissed" },+];++export function reportFilterParams(+ filter: ReportFilter,+): SignalReportsQueryParams {+ switch (filter) {+ case "attention":+ return {+ status: INBOX_ACTIONABLE_REPORT_STATUS_FILTER,+ actionability: INBOX_ACTIONABLE_ACTIONABILITY_FILTER,+ ordering: buildSignalReportListOrdering("priority", "desc"),+ };+ case "pull-requests":+ return {+ status: INBOX_PULL_REQUEST_STATUS_FILTER,+ has_implementation_pr: true,+ ordering: buildSignalReportListOrdering("priority", "desc"),+ };+ case "dismissed":+ return {+ status: INBOX_DISMISSED_STATUS_FILTER,+ ordering: buildArchiveListOrdering("updated_at", "desc"),+ };+ }+}++// The list API matches merged and closed PRs too, so the PR tab keeps only the+// ones still open.+export function hasOpenImplementationPr(report: SignalReport): boolean {+ if (!report.implementation_pr_url || report.implementation_pr_merged) {+ return false;+ }+ const state = report.implementation_pr_state;+ return state !== "merged" && state !== "closed";+}++// The URL comes from task output, so only a real GitHub PR link may reach the+// OS link handler.+export function openPullRequestUrl(report: SignalReport): string | null {+ const url = report.implementation_pr_url;+ return url &&+ hasOpenImplementationPr(report) &&+ isSafeGitHubPullRequestUrl(url)+ ? url+ : null;+}diff --git a/products/desktop/apps/mobilehog/src/lib/reports.ts b/products/desktop/apps/mobilehog/src/lib/reports.tsindex de7d3969cd11..bd5e93c01c59 100644--- a/products/desktop/apps/mobilehog/src/lib/reports.ts+++ b/products/desktop/apps/mobilehog/src/lib/reports.ts@@ -2,10 +2,6 @@ import {buildCreatePrReportPrompt,canCreateImplementationPr,} from "@posthog/core/inbox/reportActions";-import {- INBOX_ACTIONABLE_ACTIONABILITY_FILTER,- INBOX_ACTIONABLE_REPORT_STATUS_FILTER,-} from "@posthog/core/inbox/reportFiltering";import type {SignalReport,SignalReportArtefactsResponse,@@ -24,6 +20,11 @@ import { create } from "zustand";import { accountStorageKey, sessionIdentity, useAuth } from "@/lib/auth";import { getClient } from "@/lib/client";import { currentRunConfig } from "@/lib/composer";+import {+ hasOpenImplementationPr,+ type ReportFilter,+ reportFilterParams,+} from "@/lib/reportFilters";import { fetchHasLiveImplementationTask } from "@/lib/reportTasks";import { useSessions } from "@/lib/session";@@ -36,23 +37,31 @@ export const reportKeys = {liveTask: (id: string) => ["reports", id, "live-task"] as const,};-// Reports a person can act on right now, highest priority first.-export function useReports(search = "") {+// Defaults to the reports a person can act on right now.+export function useReports(search = "", filter: ReportFilter = "attention") {const session = useAuth((s) => s.session);+ const key = [...reportKeys.list, filter];return useQuery({- queryKey: search ? [...reportKeys.list, "search", search] : reportKeys.list,+ queryKey: search ? [...key, "search", search] : key,queryFn: () =>getClient().getSignalReports({- status: INBOX_ACTIONABLE_REPORT_STATUS_FILTER,- actionability: INBOX_ACTIONABLE_ACTIONABILITY_FILTER,- ordering: "status,-priority,-created_at",+ ...reportFilterParams(filter),limit: 100,search: search || undefined,}),enabled: !!session,refetchInterval: 60_000,- select: (page) =>- page.results.filter((report) => canCreateImplementationPr(report)),+ select: (page) => {+ if (filter === "attention") {+ return page.results.filter((report) =>+ canCreateImplementationPr(report),+ );+ }+ if (filter === "pull-requests") {+ return page.results.filter(hasOpenImplementationPr);+ }+ return page.results;+ },});}