Skip to content

Commit c01f356

Browse files
refactor(mobile): keep native presentation local
Generated-By: PostHog Code Task-Id: c1bbe3cf-742b-4b24-bf96-d11a18b4cf22
1 parent ae3f5fb commit c01f356

11 files changed

Lines changed: 57 additions & 59 deletions

File tree

apps/mobile/src/app/mcp-servers/installation/[id].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Text } from "@components/text";
22
import type { McpApprovalState } from "@posthog/api-client/types";
3-
import { isStdioMcpServer } from "@posthog/core/mcp-servers/presentation";
43
import { router, useLocalSearchParams } from "expo-router";
54
import {
65
ArrowsClockwise,
@@ -29,6 +28,7 @@ import {
2928
useUpdateMcpToolApproval,
3029
} from "@/features/mcp/hooks";
3130
import { reauthorizeInstallation } from "@/features/mcp/oauth";
31+
import { isStdioMcpServer } from "@/features/mcp/presentation";
3232
import { getMcpConnectionManager } from "@/features/mcp/service";
3333
import { useScreenInsets } from "@/hooks/useScreenInsets";
3434
import { logger } from "@/lib/logger";

apps/mobile/src/app/mcp-servers/template/[id].tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Text } from "@components/text";
2-
import { isStdioMcpServer } from "@posthog/core/mcp-servers/presentation";
32
import { router, useLocalSearchParams } from "expo-router";
43
import { Lock, Warning } from "phosphor-react-native";
54
import { useMemo, useState } from "react";
@@ -18,6 +17,7 @@ import {
1817
useMcpMarketplace,
1918
} from "@/features/mcp/hooks";
2019
import { installTemplateWithOAuth } from "@/features/mcp/oauth";
20+
import { isStdioMcpServer } from "@/features/mcp/presentation";
2121
import { useScreenInsets } from "@/hooks/useScreenInsets";
2222
import { logger } from "@/lib/logger";
2323
import { openExternalUrl } from "@/lib/openExternalUrl";

apps/mobile/src/features/inbox/activityLog.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import {
22
attributionLabel,
3-
parseDiffLines,
4-
selectActivityArtefacts,
5-
shortSha,
63
taskRunLabel,
74
} from "@posthog/core/inbox/activityLog";
85
import type { AnySignalReportArtefact } from "@posthog/shared/domain-types";
96
import { describe, expect, it } from "vitest";
7+
import {
8+
parseDiffLines,
9+
selectActivityArtefacts,
10+
shortSha,
11+
} from "./activityLog";
1012

1113
function commit(id: string, createdAt: string): AnySignalReportArtefact {
1214
return {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import type { AnySignalReportArtefact } from "@posthog/shared/domain-types";
2+
3+
export type ActivityArtefact = Extract<
4+
AnySignalReportArtefact,
5+
{ type: "commit" | "task_run" }
6+
>;
7+
8+
export function selectActivityArtefacts(
9+
artefacts: AnySignalReportArtefact[],
10+
): ActivityArtefact[] {
11+
return artefacts
12+
.filter(
13+
(artefact): artefact is ActivityArtefact =>
14+
artefact.type === "commit" || artefact.type === "task_run",
15+
)
16+
.sort((left, right) => left.created_at.localeCompare(right.created_at));
17+
}
18+
19+
export function shortSha(sha: string): string {
20+
return sha.slice(0, 12);
21+
}
22+
23+
export type DiffLineKind = "add" | "del" | "hunk" | "context";
24+
25+
export interface DiffLine {
26+
text: string;
27+
kind: DiffLineKind;
28+
}
29+
30+
export function parseDiffLines(diff: string): DiffLine[] {
31+
return diff
32+
.replace(/\n$/, "")
33+
.split("\n")
34+
.map((text) => {
35+
if (text.startsWith("+") && !text.startsWith("+++")) {
36+
return { text, kind: "add" as const };
37+
}
38+
if (text.startsWith("-") && !text.startsWith("---")) {
39+
return { text, kind: "del" as const };
40+
}
41+
if (text.startsWith("@@")) return { text, kind: "hunk" as const };
42+
return { text, kind: "context" as const };
43+
});
44+
}

apps/mobile/src/features/inbox/components/ArtefactCommit.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Text } from "@components/text";
2-
import { shortSha } from "@posthog/core/inbox/activityLog";
32
import type { CommitContent } from "@posthog/shared/domain-types";
43
import { CaretDown, CaretRight } from "phosphor-react-native";
54
import { useState } from "react";
65
import { ActivityIndicator, Pressable, View } from "react-native";
76
import { useThemeColors } from "@/lib/theme";
7+
import { shortSha } from "../activityLog";
88
import { useCommitDiff } from "../hooks/useInboxReports";
99
import { DiffBlock } from "./DiffBlock";
1010

apps/mobile/src/features/inbox/components/DiffBlock.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Text } from "@components/text";
2-
import { parseDiffLines } from "@posthog/core/inbox/activityLog";
32
import { ScrollView, View } from "react-native";
3+
import { parseDiffLines } from "../activityLog";
44

55
const LINE_CLASS: Record<string, string> = {
66
add: "bg-status-success/15 text-status-success",

apps/mobile/src/features/inbox/components/ReportActivity.tsx

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import { Text } from "@components/text";
2-
import {
3-
type ActivityArtefact,
4-
attributionLabel,
5-
selectActivityArtefacts,
6-
} from "@posthog/core/inbox/activityLog";
2+
import { attributionLabel } from "@posthog/core/inbox/activityLog";
73
import type { AnySignalReportArtefact } from "@posthog/shared/domain-types";
84
import { ClockCounterClockwise } from "phosphor-react-native";
95
import { useMemo } from "react";
106
import { View } from "react-native";
117
import { formatRelativeTime } from "@/lib/format";
128
import { useThemeColors } from "@/lib/theme";
9+
import { type ActivityArtefact, selectActivityArtefacts } from "../activityLog";
1310
import { ArtefactCommit } from "./ArtefactCommit";
1411
import { ArtefactTaskRun } from "./ArtefactTaskRun";
1512

apps/mobile/src/features/mcp/components/McpServerRow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import type {
33
McpRecommendedServer,
44
McpServerInstallation,
55
} from "@posthog/api-client/types";
6-
import { isStdioMcpServer } from "@posthog/core/mcp-servers/presentation";
76
import { CaretRight, Lock, Warning } from "phosphor-react-native";
87
import type { ReactNode } from "react";
98
import { Pressable, View } from "react-native";
109
import { useThemeColors } from "@/lib/theme";
10+
import { isStdioMcpServer } from "../presentation";
1111
import { ServerIcon } from "./ServerIcon";
1212

1313
interface McpServerRowProps {

apps/mobile/src/features/mcp/oauth.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import type {
44
McpInstallResponse,
55
McpServerInstallation,
66
} from "@posthog/api-client/types";
7-
import { isMcpOAuthRedirect } from "@posthog/core/mcp-servers/presentation";
87
import * as Linking from "expo-linking";
98
import * as WebBrowser from "expo-web-browser";
109
import { getPostHogApiClient } from "@/lib/posthogApiClient";
10+
import { isMcpOAuthRedirect } from "./presentation";
1111

1212
/** Custom URL scheme registered via app.json (`scheme: "posthog"`). The cloud
1313
* bounces the OAuth redirect back to this URL once the provider completes
File renamed without changes.

0 commit comments

Comments
 (0)