Skip to content

FlightLogging: improve location selection behaviour#219

Open
Claudio-Chies wants to merge 2 commits intodbrgn:mainfrom
Claudio-Chies:pr-flightloging_location_behaviour
Open

FlightLogging: improve location selection behaviour#219
Claudio-Chies wants to merge 2 commits intodbrgn:mainfrom
Claudio-Chies:pr-flightloging_location_behaviour

Conversation

@Claudio-Chies
Copy link
Copy Markdown
Contributor

@Claudio-Chies Claudio-Chies commented Oct 14, 2025

Issue

The dropdown list for location selection was really long and not really structured, making it cumbersome to select the right entry
image

Solution

  • switched to a html5 datalist which adds searching capability,
  • improved formatting by displaying country codes as Flags, and separating altitude with a tab

Example on mobile browser

image image

Example on desktop browser

image

Tests

  • tested on Firefox and Crome (Ubuntu 25.04)
  • tested on Firefox and Safari (IOS)
  • tested with igc import

Summary by CodeRabbit

Release Notes

  • New Features

    • Searchable text inputs with live autocomplete for flight form locations
    • Country flag emojis shown next to location names and elevations
  • Tests

    • Added unit tests covering country code → flag behavior (valid and invalid inputs)
  • Translations

    • New validation message for "no matching location" in English and German

✏️ Tip: You can customize this high-level summary in your review settings.

@Claudio-Chies
Copy link
Copy Markdown
Contributor Author

kind of fixes #70 as it solves the issue with location selection.
@dbrgn would be glad for a review

@dbrgn
Copy link
Copy Markdown
Owner

dbrgn commented Dec 23, 2025

Interesting, TIL about datalist!

@coderabbitai please review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 23, 2025

@dbrgn I'll review the changes in this PR right away. The datalist approach for improving location selection with search capability and better formatting looks interesting!

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 23, 2025

Walkthrough

Adds a new utility to convert two-letter country codes to flag emojis (with tests), refactors the flight form to use text-input autocomplete for locations (displaying flag + name + elevation), and adds a new validation message for no-matching-location in translations.

Changes

Cohort / File(s) Summary
Utility function & tests
frontend/src/lib/formatters.ts, frontend/src/lib/formatters.test.ts
Added export function countryCodeToFlag(countryCode: string): string that maps valid two-letter codes to regional indicator flag emojis; returns pirate flag for invalid input. Added tests covering uppercase/lowercase codes and invalid inputs.
Flight form autocomplete refactor
frontend/src/routes/flights/FlightForm.svelte
Replaced location select dropdowns with text inputs + datalist-driven autocomplete. Added launchAtText / landingAtText, handleLocationInput() and validateLocations() to match formatted strings (flag + name + elevation) to actual locations, update location state, and surface per-field errors. Imports and uses countryCodeToFlag().
Translations
frontend/src/translations/en/translation.json, frontend/src/translations/de/translation.json
Added new error key error--no-matching-location to English and German translation files ("Kein passender Standort gefunden.").

Sequence Diagram

sequenceDiagram
    participant User
    participant Form as FlightForm
    participant Handler as handleLocationInput()
    participant Formatter as countryCodeToFlag()
    participant Store as locations[]
    participant State as launchAt/landingAt

    User->>Form: type into location text input
    Form->>Handler: onInput(text)
    Handler->>Store: fetch all locations
    loop for each location
        Handler->>Formatter: countryCodeToFlag(location.countryCode)
        Formatter-->>Handler: flagEmoji
        Handler->>Handler: format string = flagEmoji + " " + name + " (" + elevation + "m)"
        Handler->>Handler: compare formatted string to input
    end
    alt match found
        Handler->>State: set matched location (launchAt/landingAt)
        State-->>Form: reactive update (text + bound value)
    else no match
        Handler-->>Form: set field error "error--no-matching-location"
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically describes the main change: improving location selection behavior, which aligns with the core changes across the PR (replacing dropdown with datalist, adding search, improving formatting).
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
frontend/src/routes/flights/FlightForm.svelte (1)

50-56: Consider extracting the location format string to reduce duplication.

The format string for displaying locations (${countryCodeToFlag(...)} ${name} ${elevation} m) is duplicated in multiple places:

  • Line 52, 55: Initialization
  • Line 192: handleLocationInput matching
  • Line 316, 325: IGC metadata processing
  • Line 544-546, 577-579: Datalist options

This creates a maintenance burden. If the format changes, all instances must be updated consistently.

🔎 Suggested refactor to centralize formatting logic

Add a helper function in this component:

function formatLocationText(location: FlightLocation): string {
  return `${countryCodeToFlag(location.countryCode)} ${location.name} ${location.elevation} m`;
}

Then use it throughout:

-  let launchAtText: string = launchAt
-    ? `${countryCodeToFlag(launchAt.countryCode)} ${launchAt.name} ${launchAt.elevation} m`
-    : '';
+  let launchAtText: string = launchAt ? formatLocationText(launchAt) : '';

Apply similar changes to all other occurrences.

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 3f91f3c and f03a69e.

📒 Files selected for processing (3)
  • frontend/src/lib/formatters.test.ts
  • frontend/src/lib/formatters.ts
  • frontend/src/routes/flights/FlightForm.svelte
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Follow TypeScript coding conventions

Files:

  • frontend/src/lib/formatters.test.ts
  • frontend/src/lib/formatters.ts
frontend/**/*.{ts,tsx,svelte}

📄 CodeRabbit inference engine (AGENTS.md)

Apply Prettier code style using npm run format in the frontend

Files:

  • frontend/src/lib/formatters.test.ts
  • frontend/src/lib/formatters.ts
  • frontend/src/routes/flights/FlightForm.svelte
**/*.{rs,ts,tsx,svelte}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{rs,ts,tsx,svelte}: Avoid deeply nested logic by using early returns for error cases
Write clean, high-quality code with concise comments and clear variable names

Files:

  • frontend/src/lib/formatters.test.ts
  • frontend/src/lib/formatters.ts
  • frontend/src/routes/flights/FlightForm.svelte
🧬 Code graph analysis (1)
frontend/src/lib/formatters.test.ts (1)
frontend/src/lib/formatters.ts (1)
  • countryCodeToFlag (51-62)
🔇 Additional comments (5)
frontend/src/lib/formatters.test.ts (1)

40-72: LGTM! Comprehensive test coverage.

The test suite properly covers both valid country codes (uppercase and lowercase) and various invalid input cases. The test structure follows the existing patterns in the file.

frontend/src/lib/formatters.ts (1)

51-62: LGTM! Clean and correct implementation.

The function correctly converts country codes to flag emojis using Unicode regional indicator symbols. The offset calculation (127397) and case-insensitive handling are both correct.

frontend/src/routes/flights/FlightForm.svelte (3)

310-327: LGTM! Correct synchronization of location state.

The IGC metadata processing correctly updates both the location objects (launchAt, landingAt) and their text representations (launchAtText, landingAtText). This ensures the UI stays in sync when locations are auto-populated from IGC data.

Note: The format string duplication here is addressed in my earlier comment about extracting a helper function.


530-554: LGTM! Correct datalist implementation for launch site.

The transition from dropdown to text input with datalist follows HTML5 patterns correctly. The binding and event handling properly maintain synchronization between text input and location object.

Note: Validation concerns for the location selection are addressed in my earlier comment on the handleLocationInput function.


563-587: LGTM! Consistent implementation for landing site.

The landing site input follows the same pattern as the launch site, maintaining consistency. The implementation correctly handles the autocomplete functionality.

Note: Validation concerns apply here as well and are addressed in my earlier comment on the handleLocationInput function.

Comment thread frontend/src/routes/flights/FlightForm.svelte
@Claudio-Chies
Copy link
Copy Markdown
Contributor Author

@dbrgn
The AI tool gave pretty good input, added the validation. tested and works as intended
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants