Skip to content

Commit a7d966c

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

7 files changed

Lines changed: 21 additions & 21 deletions

File tree

apps/mobile/src/app/automation/[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 { TaskAutomationValidationError } from "@posthog/api-client/posthog-client";
3-
import { parseSkillTemplateId } from "@posthog/core/automations/automationTemplatePresentation";
43
import { Stack, useLocalSearchParams, useRouter } from "expo-router";
54
import { useState } from "react";
65
import {
@@ -21,6 +20,7 @@ import {
2120
useUpdateTaskAutomation,
2221
} from "@/features/tasks/hooks/useAutomations";
2322
import { useTask } from "@/features/tasks/hooks/useTasks";
23+
import { parseSkillTemplateId } from "@/features/tasks/skills/skillTemplateIds";
2424
import { useThemeColors } from "@/lib/theme";
2525

2626
export default function AutomationDetailScreen() {

apps/mobile/src/app/automation/create.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { TaskAutomationValidationError } from "@posthog/api-client/posthog-client";
2-
import { formatSkillTemplateId } from "@posthog/core/automations/automationTemplatePresentation";
32
import { getCalendars } from "expo-localization";
43
import { Stack, useLocalSearchParams, useRouter } from "expo-router";
54
import { useMemo, useRef, useState } from "react";
@@ -15,6 +14,7 @@ import { Text } from "@/components/text";
1514
import { AutomationForm } from "@/features/tasks/components/AutomationForm";
1615
import { useCreateTaskAutomation } from "@/features/tasks/hooks/useAutomations";
1716
import { useSkillStoreSkill } from "@/features/tasks/skills/hooks";
17+
import { formatSkillTemplateId } from "@/features/tasks/skills/skillTemplateIds";
1818
import { useScreenInsets } from "@/hooks/useScreenInsets";
1919
import { useThemeColors } from "@/lib/theme";
2020

apps/mobile/src/features/tasks/components/AutomationDetail.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { Text } from "@components/text";
22
import type { TaskAutomation } from "@posthog/api-client/posthog-client";
33
import { formatAutomationScheduleSummary } from "@posthog/core/automations/automationSchedule";
4-
import { getAutomationTemplatePresentation } from "@posthog/core/automations/automationTemplatePresentation";
54
import type { TaskRun } from "@posthog/shared";
65
import { ActivityIndicator, Pressable, View } from "react-native";
6+
import { getAutomationTemplatePresentation } from "../utils/automationTemplatePresentation";
77
import { AutomationStatusBadge } from "./AutomationStatusBadge";
88

99
interface AutomationDetailProps {

apps/mobile/src/features/tasks/components/AutomationItem.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { Text } from "@components/text";
22
import type { TaskAutomation } from "@posthog/api-client/posthog-client";
33
import { formatAutomationScheduleSummary } from "@posthog/core/automations/automationSchedule";
4-
import { getAutomationTemplatePresentation } from "@posthog/core/automations/automationTemplatePresentation";
54
import type { TaskRun } from "@posthog/shared";
65
import { format, formatDistanceToNow } from "date-fns";
76
import { memo } from "react";
87
import { Pressable, View } from "react-native";
8+
import { getAutomationTemplatePresentation } from "../utils/automationTemplatePresentation";
99
import { AutomationStatusBadge } from "./AutomationStatusBadge";
1010

1111
interface AutomationItemProps {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export const SKILL_TEMPLATE_ID_PREFIX = "llm-skill:";
2+
3+
export function formatSkillTemplateId(skillName: string): string {
4+
return `${SKILL_TEMPLATE_ID_PREFIX}${skillName.trim()}`;
5+
}
6+
7+
export function parseSkillTemplateId(
8+
templateId: string | null | undefined,
9+
): string | null {
10+
if (!templateId?.startsWith(SKILL_TEMPLATE_ID_PREFIX)) return null;
11+
const skillName = templateId.slice(SKILL_TEMPLATE_ID_PREFIX.length).trim();
12+
return skillName || null;
13+
}

apps/mobile/src/features/tasks/utils/automationTemplatePresentation.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { getAutomationTemplatePresentation } from "@posthog/core/automations/automationTemplatePresentation";
21
import { describe, expect, it } from "vitest";
2+
import { getAutomationTemplatePresentation } from "./automationTemplatePresentation";
33

44
describe("automationTemplatePresentation", () => {
55
it("prefers repository context when one exists for skill-backed automations", () => {

packages/core/src/automations/automationTemplatePresentation.ts renamed to apps/mobile/src/features/tasks/utils/automationTemplatePresentation.ts

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,10 @@
11
import type { TaskAutomation } from "@posthog/api-client/posthog-client";
2-
3-
export const SKILL_TEMPLATE_ID_PREFIX = "llm-skill:";
4-
5-
export function formatSkillTemplateId(skillName: string): string {
6-
return `${SKILL_TEMPLATE_ID_PREFIX}${skillName.trim()}`;
7-
}
8-
9-
export function parseSkillTemplateId(
10-
templateId: string | null | undefined,
11-
): string | null {
12-
if (!templateId?.startsWith(SKILL_TEMPLATE_ID_PREFIX)) return null;
13-
const skillName = templateId.slice(SKILL_TEMPLATE_ID_PREFIX.length).trim();
14-
return skillName || null;
15-
}
2+
import { parseSkillTemplateId } from "../skills/skillTemplateIds";
163

174
export interface AutomationTemplatePresentation {
185
templateName: string | null;
19-
repositoryLabel: string | null;
206
contextLabel: string | null;
7+
repositoryLabel: string | null;
218
secondaryLabel: string;
229
}
2310

@@ -30,8 +17,8 @@ export function getAutomationTemplatePresentation(
3017
return {
3118
templateName:
3219
skillName ?? (automation.template_id ? "Template automation" : null),
33-
repositoryLabel,
3420
contextLabel,
21+
repositoryLabel,
3522
secondaryLabel: repositoryLabel ?? contextLabel ?? "No repository context",
3623
};
3724
}

0 commit comments

Comments
 (0)