Skip to content

Feature - Add GeoJSON preview support in ObjectsDiff #8996

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 4, 2025

Conversation

Ben-El
Copy link
Contributor

@Ben-El Ben-El commented Apr 28, 2025

Closes #9012

Change Description

This PR introduces support for previewing .geojson files directly within the diff view.

When the file path ends with .geojson, the system now detects it and renders an interactive map using Leaflet and react-leaflet.

The GeoJSON data is parsed and displayed using MapContainer and GeoJSON components.
If the data includes valid geometry, the map automatically fits its bounds. Otherwise, it defaults to a world view centered at [0, 0].

If the GeoJSON data is invalid or missing, a relevant fallback message is shown instead of the map.

Dependencies updated: leaflet, react-leaflet, and @types/leaflet were added to support this functionality.

This feature enhances the diffing experience for spatial datasets, making changes in geographic files visually accessible.

image

Why this solution?

I used a simple inline conditional inside JSX because there are only two rendering cases to handle: a GeoJSON map preview or a plain text diff. Introducing a generic wrapper component (something like <ContentDiffViewer/>) would add unnecessary abstraction for this small, self-contained logic.

This approach keeps the code simple, readable, and localized. If more preview types are added in the future, we can then refactor into a shared component.

Technical note

This feature is powered by Leaflet and React-Leaflet, both open-source libraries for interactive map rendering in the browser.
Leaflet provides the core mapping engine, while React-Leaflet offers declarative React components that integrate seamlessly with our UI.
While it was initially released over a decade ago, it remains a modern, reliable, and widely adopted solution for rendering interactive maps - especially when 3D rendering or heavy GIS capabilities aren't required. It is lightweight, easy to integrate with React via react-leaflet, and perfectly suited for displaying GeoJSON data within web applications.

Enhances ObjectsDiff with a GeoJSON preview feature using Leaflet. Updates dependencies to include Leaflet and React-Leaflet libraries, along with their TypeScript types. Integrates GeoJSON-specific handling to render a map preview when GeoJSON files are detected.
Copy link

github-actions bot commented Apr 28, 2025

E2E Test Results - Quickstart

12 passed

Copy link

E2E Test Results - DynamoDB Local - Local Block Adapter

13 passed, 1 skipped

@Ben-El Ben-El added the include-changelog PR description should be included in next release changelog label Apr 29, 2025
Simplified the conditional rendering logic for GeoJSON previews and ReactDiffViewer. Moved GeoJSON-specific handling into the main return block, reducing redundancy and improving readability. This change ensures cleaner and more maintainable code.
@Ben-El Ben-El requested a review from itaigilo April 29, 2025 12:01
@Ben-El Ben-El changed the title Add GeoJSON preview support in ObjectsDiff Feature - add GeoJSON preview support in ObjectsDiff Apr 29, 2025
@Ben-El Ben-El changed the title Feature - add GeoJSON preview support in ObjectsDiff Feature - Add GeoJSON preview support in ObjectsDiff Apr 29, 2025
@Ben-El Ben-El added the area/UI Improvements or additions to UI label Apr 29, 2025
Copy link
Contributor

@itaigilo itaigilo left a comment

Choose a reason for hiding this comment

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

Nice stuff, and a very helpful PR description.

Looking good, but some comments.

Ben-El added 2 commits April 30, 2025 17:35
Replaced `readableObject` function with a more extensible `getViewer` method to manage file format handling. Simplified GeoJSON detection and applied a shared CSS class for consistent map styling.
@Ben-El Ben-El requested a review from itaigilo April 30, 2025 14:37
Ben-El added 2 commits April 30, 2025 17:43
Replaced inline styles on the MapContainer with a dedicated CSS class `.geojson-map-container`. This improves consistency and simplifies maintenance of the map's styling.
Removed redundant span wrapper in ObjectsDiff component for cleaner code. Moved Leaflet CSS import to GeoJSONPreview to ensure proper scoping and avoid unused imports in main.tsx.
@Ben-El Ben-El requested a review from a team May 4, 2025 08:29
@Ben-El Ben-El merged commit f558785 into master May 4, 2025
44 of 46 checks passed
@Ben-El Ben-El deleted the add-geojson-preview-support branch May 4, 2025 08:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/UI Improvements or additions to UI include-changelog PR description should be included in next release changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add GeoJSON viewer support to lakeFS UI
2 participants