Colota - Android GPS Location tracker
Pre-fill profile editor with main settings values and show defaults as hints (#216)
Max Dietrich68a6933077d5
diff --git a/apps/docs/docs/guides/tracking-profiles.md b/apps/docs/docs/guides/tracking-profiles.mdindex bc2284c8..68e742bf 100644--- a/apps/docs/docs/guides/tracking-profiles.md+++ b/apps/docs/docs/guides/tracking-profiles.md@@ -47,6 +47,8 @@ Each profile overrides the default tracking configuration with:- **Priority** - Determines which profile wins when multiple conditions match simultaneously (higher = wins)- **Deactivation Delay** - How long to wait after the condition stops matching before reverting to default settings (seconds). Prevents rapid toggling when conditions fluctuate.+When creating a new profile, GPS interval, distance filter, and sync interval are pre-filled with your current values from main Settings. Each field also shows a hint with the default value for reference.+## How It Works- When tracking starts, all enabled profiles are evaluated against current conditionsdiff --git a/apps/mobile/src/components/features/inspector/__tests__/LocationTable.test.tsx b/apps/mobile/src/components/features/inspector/__tests__/LocationTable.test.tsxindex 6592a8f1..aeaf46c0 100644--- a/apps/mobile/src/components/features/inspector/__tests__/LocationTable.test.tsx+++ b/apps/mobile/src/components/features/inspector/__tests__/LocationTable.test.tsx@@ -130,21 +130,6 @@ describe("LocationTable", () => {expect(deltaElements.length).toBe(2)})- it("first row (newest) has no delta", () => {- const { queryAllByText } = render(<LocationTable locations={locations} colors={mockColors} />)-- // After reversing: the newest item (originally index 2) has delta=30- // The second item (originally index 1) has delta=30- // The oldest item (originally index 0) has delta=null (empty string)- // So there should be exactly two "+30s" entries- const deltaElements = queryAllByText("+30s")- expect(deltaElements.length).toBe(2)-- // The oldest (now last) row has no delta - it renders as empty string ""- // This means there is no "+0s" or similar text for the first chronological item- expect(queryAllByText(/^\+\d+s$/).length).toBe(2)- })-it("handles null optional fields (altitude, speed, bearing, battery)", () => {const { getAllByText } = render(<LocationTable locations={locations} colors={mockColors} />)diff --git a/apps/mobile/src/components/features/settings/__tests__/StatsCard.test.tsx b/apps/mobile/src/components/features/settings/__tests__/StatsCard.test.tsxindex f108ef16..1f227459 100644--- a/apps/mobile/src/components/features/settings/__tests__/StatsCard.test.tsx+++ b/apps/mobile/src/components/features/settings/__tests__/StatsCard.test.tsx@@ -119,10 +119,4 @@ describe("StatsCard", () => {expect(queryByText("Critical Queue Size")).toBeNull()})})-- it("shows interval with seconds unit", () => {- const { getByText } = render(<StatsCard {...baseProps} interval="15" />)-- expect(getByText("s")).toBeTruthy()- })})diff --git a/apps/mobile/src/screens/ProfileEditorScreen.tsx b/apps/mobile/src/screens/ProfileEditorScreen.tsxindex f496010f..a50778e0 100644--- a/apps/mobile/src/screens/ProfileEditorScreen.tsx+++ b/apps/mobile/src/screens/ProfileEditorScreen.tsx@@ -17,15 +17,10 @@ import { logger } from "../utils/logger"import { shortDistanceUnit, inputToMeters, metersToInput } from "../utils/geo"import { MS_TO_KMH, PROFILE_CONDITIONS, SYNC_INTERVAL_PRESETS, SYNC_INTERVAL_LABELS } from "../constants"-const DEFAULT_PROFILE: Omit<TrackingProfile, "id" | "createdAt"> = {- name: "",- interval: 5,- distance: 0,- syncInterval: 0,- priority: 10,- condition: { type: "charging" },- deactivationDelay: 60,- enabled: true+function formatSyncDefault(seconds: number): string {+ if (SYNC_INTERVAL_LABELS[seconds]) return SYNC_INTERVAL_LABELS[seconds]+ if (seconds < 60) return `${seconds}s`+ return `${Math.round(seconds / 60)} min`}export function ProfileEditorScreen({ navigation, route }: any) {@@ -34,16 +29,25 @@ export function ProfileEditorScreen({ navigation, route }: any) {const profileId = route?.params?.profileId as number | undefinedconst isEditing = !!profileId- const [profile, setProfile] = useState<Omit<TrackingProfile, "id" | "createdAt">>(DEFAULT_PROFILE)+ const [profile, setProfile] = useState<Omit<TrackingProfile, "id" | "createdAt">>({+ name: "",+ interval: settings.interval,+ distance: settings.distance,+ syncInterval: settings.syncInterval,+ priority: 10,+ condition: { type: "charging" },+ deactivationDelay: 60,+ enabled: true+ })const [speedKmh, setSpeedKmh] = useState("30")const [saving, setSaving] = useState(false)// String representations for numeric inputs- const [intervalStr, setIntervalStr] = useState("5")- const [distanceStr, setDistanceStr] = useState("0")+ const [intervalStr, setIntervalStr] = useState(String(settings.interval))+ const [distanceStr, setDistanceStr] = useState(String(metersToInput(settings.distance)))const [priorityStr, setPriorityStr] = useState("10")const [delayStr, setDelayStr] = useState("60")- const [syncIntervalStr, setSyncIntervalStr] = useState("0")+ const [syncIntervalStr, setSyncIntervalStr] = useState(String(settings.syncInterval))useEffect(() => {if (!profileId) return@@ -251,7 +255,7 @@ export function ProfileEditorScreen({ navigation, route }: any) {{/* Tracking Settings */}<SectionTitle style={styles.sectionGap}>Tracking Settings</SectionTitle><Card>- <SettingRow label="Tracking Interval">+ <SettingRow label="Tracking Interval" hint={`Default: ${settings.interval}s`}><View style={styles.inputWithUnit}><TextInputstyle={inputStyle}@@ -267,7 +271,10 @@ export function ProfileEditorScreen({ navigation, route }: any) {<Divider />- <SettingRow label="Movement Threshold">+ <SettingRow+ label="Movement Threshold"+ hint={`Default: ${metersToInput(settings.distance)} ${shortDistanceUnit()}`}+ ><View style={styles.inputWithUnit}><TextInputstyle={inputStyle}@@ -285,7 +292,12 @@ export function ProfileEditorScreen({ navigation, route }: any) {<><Divider />- <Text style={[styles.syncLabel, { color: colors.textSecondary }]}>Sync Interval</Text>+ <View style={styles.syncLabelRow}>+ <Text style={[styles.settingLabel, { color: colors.text }]}>Sync Interval</Text>+ <Text style={[styles.settingHint, { color: colors.textSecondary }]}>+ Default: {formatSyncDefault(settings.syncInterval)}+ </Text>+ </View><View style={styles.syncGrid}>{SYNC_INTERVAL_PRESETS.map((sec) => {const isSelected =@@ -445,7 +457,9 @@ const styles = StyleSheet.create({},conditionLabel: { fontSize: 13, ...fonts.semiBold },conditionDesc: { fontSize: 11, ...fonts.regular, textAlign: "center" },- syncLabel: { fontSize: 12, ...fonts.semiBold, marginBottom: 8, textTransform: "uppercase", letterSpacing: 0.5 },+ syncLabelRow: { marginBottom: 8 },+ settingLabel: { fontSize: 16, ...fonts.semiBold, marginBottom: 2 },+ settingHint: { fontSize: 13, ...fonts.regular, lineHeight: 18 },syncGrid: { flexDirection: "row", flexWrap: "wrap", gap: 8 },syncOption: { width: "31%", padding: 12, borderRadius: 10, borderWidth: 1.5, alignItems: "center" }, // ~3 per row with gapsyncOptionLabel: { fontSize: 13, ...fonts.semiBold },diff --git a/apps/mobile/src/screens/SettingsScreen.tsx b/apps/mobile/src/screens/SettingsScreen.tsxindex b03a851b..dd30be9d 100644--- a/apps/mobile/src/screens/SettingsScreen.tsx+++ b/apps/mobile/src/screens/SettingsScreen.tsx@@ -43,9 +43,8 @@ export function SettingsScreen({ navigation }: ScreenProps) {const [unitSystem, setUnitSystem] = useState<UnitSystem>(getUnitSystem)const [timeFormat, setTimeFormat] = useState<TimeFormat>(getTimeFormat)- const toggleUnitSystem = useCallback(- async (imperial: boolean) => {- const value: UnitSystem = imperial ? "imperial" : "metric"+ const selectUnitSystem = useCallback(+ async (value: UnitSystem) => {const prev = unitSystemsetUnitSystem(value)try {@@ -58,9 +57,8 @@ export function SettingsScreen({ navigation }: ScreenProps) {[unitSystem])- const toggleTimeFormat = useCallback(- async (use12h: boolean) => {- const value: TimeFormat = use12h ? "12h" : "24h"+ const selectTimeFormat = useCallback(+ async (value: TimeFormat) => {const prev = timeFormatsetTimeFormat(value)try {@@ -178,30 +176,56 @@ export function SettingsScreen({ navigation }: ScreenProps) {<Divider />- <SettingRow label="Imperial Units" hint="Use miles, feet, and mph">- <Switch- value={unitSystem === "imperial"}- onValueChange={toggleUnitSystem}- trackColor={{- false: colors.border,- true: colors.primary + "80"- }}- thumbColor={unitSystem === "imperial" ? colors.primary : colors.border}- />+ <SettingRow label="Units">+ <View style={styles.chipGroup}>+ {(["metric", "imperial"] as const).map((unit) => {+ const selected = unitSystem === unit+ return (+ <Pressable+ key={unit}+ style={[+ styles.chip,+ {+ backgroundColor: selected ? colors.primary + "15" : colors.background,+ borderColor: selected ? colors.primary : colors.border+ }+ ]}+ onPress={() => selectUnitSystem(unit)}+ >+ <Text style={[styles.chipLabel, { color: selected ? colors.primary : colors.text }]}>+ {unit === "metric" ? "Metric" : "Imperial"}+ </Text>+ </Pressable>+ )+ })}+ </View></SettingRow><Divider />- <SettingRow label="12-Hour Time" hint="Use AM/PM instead of 24-hour format">- <Switch- value={timeFormat === "12h"}- onValueChange={toggleTimeFormat}- trackColor={{- false: colors.border,- true: colors.primary + "80"- }}- thumbColor={timeFormat === "12h" ? colors.primary : colors.border}- />+ <SettingRow label="Time Format">+ <View style={styles.chipGroup}>+ {(["24h", "12h"] as const).map((fmt) => {+ const selected = timeFormat === fmt+ return (+ <Pressable+ key={fmt}+ style={[+ styles.chip,+ {+ backgroundColor: selected ? colors.primary + "15" : colors.background,+ borderColor: selected ? colors.primary : colors.border+ }+ ]}+ onPress={() => selectTimeFormat(fmt)}+ >+ <Text style={[styles.chipLabel, { color: selected ? colors.primary : colors.text }]}>+ {fmt === "24h" ? "24h" : "12h"}+ </Text>+ </Pressable>+ )+ })}+ </View></SettingRow></Card></View>@@ -297,5 +321,19 @@ const styles = StyleSheet.create({linkSub: {fontSize: 13,...fonts.regular+ },+ chipGroup: {+ flexDirection: "row",+ gap: 8+ },+ chip: {+ paddingHorizontal: 14,+ paddingVertical: 8,+ borderRadius: 10,+ borderWidth: 1.5+ },+ chipLabel: {+ fontSize: 13,+ ...fonts.semiBold}})diff --git a/apps/mobile/src/screens/__tests__/ProfileEditorScreen.test.tsx b/apps/mobile/src/screens/__tests__/ProfileEditorScreen.test.tsxindex 16614fbe..3aca244d 100644--- a/apps/mobile/src/screens/__tests__/ProfileEditorScreen.test.tsx+++ b/apps/mobile/src/screens/__tests__/ProfileEditorScreen.test.tsx@@ -36,9 +36,21 @@ jest.mock("../../services/modalService", () => ({showAlert: (...args: any[]) => mockShowAlert(...args)}))+jest.mock("../../utils/geo", () => ({+ ...jest.requireActual("../../utils/geo"),+ shortDistanceUnit: () => "m",+ metersToInput: (v: number) => v,+ inputToMeters: (v: number) => v+}))+jest.mock("../../contexts/TrackingProvider", () => ({useTracking: () => ({- settings: { isOfflineMode: false }+ settings: {+ isOfflineMode: false,+ interval: 5,+ distance: 0,+ syncInterval: 0+ }})}))@@ -133,6 +145,21 @@ describe("ProfileEditorScreen", () => {expect(getByText("15 min")).toBeTruthy()})+ it("pre-fills fields with main settings values", () => {+ const { getByDisplayValue } = renderNewProfile()++ expect(getByDisplayValue("5")).toBeTruthy() // interval from settings+ expect(getByDisplayValue("0")).toBeTruthy() // distance from settings+ })++ it("shows default hints from main settings", () => {+ const { getByText } = renderNewProfile()++ expect(getByText("Default: 5s")).toBeTruthy()+ expect(getByText("Default: 0 m")).toBeTruthy()+ expect(getByText("Default: Instant")).toBeTruthy()+ })+// --- Validation ---it("shows alert when saving with empty name", async () => {@@ -145,15 +172,6 @@ describe("ProfileEditorScreen", () => {})})- it("allows setting interval to valid value", () => {- const { getByDisplayValue } = renderNewProfile()-- const intervalInput = getByDisplayValue("5")- fireEvent.changeText(intervalInput, "15")-- expect(getByDisplayValue("15")).toBeTruthy()- })-it("saves with speed condition when threshold is valid", async () => {const { getByText, getByDisplayValue } = renderNewProfile()diff --git a/apps/mobile/src/services/__tests__/NativeLocationService.test.ts b/apps/mobile/src/services/__tests__/NativeLocationService.test.tsindex f076b22a..848a6d33 100644--- a/apps/mobile/src/services/__tests__/NativeLocationService.test.ts+++ b/apps/mobile/src/services/__tests__/NativeLocationService.test.ts@@ -350,11 +350,5 @@ describe("NativeLocationService", () => {})expect(nativeMock.exportToFile).toHaveBeenCalledWith("geojson")})-- it("exportToFile returns null when no data", async () => {- nativeMock.exportToFile.mockResolvedValueOnce(null)- const result = await NativeLocationService.exportToFile("csv")- expect(result).toBeNull()- })})})diff --git a/apps/mobile/src/services/__tests__/SettingsService.test.ts b/apps/mobile/src/services/__tests__/SettingsService.test.tsindex e159ed2d..efed9638 100644--- a/apps/mobile/src/services/__tests__/SettingsService.test.ts+++ b/apps/mobile/src/services/__tests__/SettingsService.test.ts@@ -72,11 +72,6 @@ describe("SettingsService", () => {expect(mockSaveSetting).toHaveBeenCalledWith("httpMethod", "POST")})- it("does not throw on success", async () => {- await SettingsService.updateSetting("endpoint", "https://test.com")- expect(mockSaveSetting).toHaveBeenCalledWith("endpoint", "https://test.com")- })-it("propagates errors to caller", async () => {mockSaveSetting.mockRejectedValueOnce(new Error("Native error"))await expect(SettingsService.updateSetting("endpoint", "test")).rejects.toThrow("Native error")