Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
ea5be91
feat: added images to markers
raven-wing Oct 17, 2026
3b71e38
added missing file
raven-wing Oct 19, 2026
5b2b582
fix linting
raven-wing Oct 21, 2026
c457915
added photo to e2e test
raven-wing Oct 21, 2026
4ec18c3
fixes after review
raven-wing Oct 21, 2026
1378fee
better examples
raven-wing Oct 21, 2026
b4f6309
fixes after review
raven-wing Oct 21, 2026
643964e
simplify
raven-wing Oct 21, 2026
7a94dd9
loader introduced
raven-wing Oct 21, 2026
3fc64a7
alt used
raven-wing Oct 21, 2026
d6a8e47
little simplier
raven-wing Oct 21, 2026
cf5419e
fix linitng
raven-wing Oct 21, 2026
ef28cc5
sonar fix
raven-wing Oct 21, 2026
fbe8ced
simplify
raven-wing Oct 22, 2026
55b01d3
cleanup
raven-wing Oct 22, 2026
147564c
fixes aftre review
raven-wing Oct 22, 2026
336c31b
fixes after reveiw
raven-wing Oct 22, 2026
1beea0d
raname
raven-wing Oct 22, 2026
a29cda8
test added
raven-wing Oct 22, 2026
0a0b87a
simpler
raven-wing Oct 22, 2026
d0b6aea
drop separator
raven-wing Oct 22, 2026
9b14294
formatter simplified
raven-wing Oct 22, 2026
038aab4
faster formatter
raven-wing Oct 22, 2026
fc23243
remove some db extensions
raven-wing Oct 22, 2026
ac1ee63
simplify
raven-wing Oct 22, 2026
a472442
simplify
raven-wing Oct 22, 2026
448c49e
renames
raven-wing Oct 22, 2026
b63c76e
rename
raven-wing Oct 22, 2026
94c7b62
fix for translated metadata
raven-wing Oct 22, 2026
827e076
fix rendeing nones
raven-wing Oct 22, 2026
52a4e70
simplify
raven-wing Oct 23, 2026
bfb9d07
docs
raven-wing Oct 23, 2026
6503eb3
removed empty code
raven-wing Oct 23, 2026
d9b39f6
simplify
raven-wing Oct 23, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/api-reference.rst
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ Formatting
Turning a point into what its popup shows: translation of category keys, option values and
field names on the way out (:ref:`config-translations`), and the rendering of a field's value
into HTML — by a plugin's shortcode, or by one of the field types goodmap builds in
(:ref:`plugins-builtin-field-types`).
(:ref:`built-in field types <plugins-builtin-field-types>`).

.. automodule:: goodmap.formatter
:members:
Expand Down
4 changes: 2 additions & 2 deletions docs/data-source.rst
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,8 @@ JSON file

The whole structure above in one file on disk. Read per request, so edits to ``data``
show up on the next refresh — though the schema keys (``categories``,
``location_obligatory_fields``, ``visible_data``) are read once at startup and need a
restart. Writes — new suggestions and reports — are written back atomically via a
``location_obligatory_fields``, ``visible_data``, ``meta_data``) are read once at startup
and need a restart. Writes — new suggestions and reports — are written back atomically via a
temporary file and a rename, so a crash mid-write cannot truncate your data.

Best for: development, and small-to-medium read-mostly maps served by a single process.
Expand Down
5 changes: 3 additions & 2 deletions docs/deployment.rst
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,9 @@ incoming reports change it while the app runs.
- **google_json** — the blob is your source of truth and the app never writes
to it. Bucket object versioning gives you history.

Schema keys (``categories``, ``visible_data``, ``location_obligatory_fields``) are read
at startup, so changing them means restarting the app. Point data is re-read per request.
Schema keys (``categories``, ``visible_data``, ``meta_data``,
``location_obligatory_fields``) are read at startup, so changing them means restarting the
app. Point data is re-read per request.

Upgrading
---------
Expand Down
25 changes: 20 additions & 5 deletions docs/http-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ list of ``[label, value]`` pairs — the fields listed in ``visible_data``, in t
with both label and value translated. ``metadata`` holds the ``meta_data`` fields. Fields
in neither list are not returned at all.

A field GoodMap renders — one naming a built-in ``type`` such as ``hyperlink`` or ``CTA``,
A field GoodMap renders — one naming a built-in ``type`` such as ``hyperlink``, ``CTA`` or ``image``,
or one a plugin's shortcode is bound to — comes back as an object rather than a bare value:

.. code-block:: json
Expand All @@ -195,10 +195,25 @@ or one a plugin's shortcode is bound to — comes back as an object rather than
"html": "<a href=\"https://example.com\" target=\"_blank\" rel=\"noopener noreferrer\">Example</a>"
}]

``html`` is the rendering to display and ``type`` says what produced it; the entry's own
keys travel alongside for a client that would rather render from the data. See
:ref:`plugins-builtin-field-types` for which types GoodMap ships and
:ref:`plugins-shortcode-rendered-fields` for how a plugin adds one.
An image field holds one image, and comes back the same way:

.. code-block:: json

["photo", {
"type": "image",
"url": "https://example.com/deck.jpg",
"alt": "The deck at night",
"html": "<img src=\"https://example.com/deck.jpg\" alt=\"The deck at night\">"
}]

A built-in field left with nothing to show - an image whose URL is refused, say - is left
out of ``data``.

``html`` is always the server's rendering, never a value taken from the data: it is what to
display, and ``type`` says what produced it. The entry's own keys travel alongside for a
client that would rather render from the data; such a client must escape them itself. See
:ref:`built-in field types <plugins-builtin-field-types>` for which types GoodMap ships and
:ref:`shortcode-rendered fields <plugins-shortcode-rendered-fields>` for how a plugin adds one.

The path segment must be a valid UUID; anything else fails routing with ``404``. A
well-formed UUID that does not exist also gives ``404 {"message": "Location not found"}``.
Expand Down
52 changes: 49 additions & 3 deletions docs/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,47 @@ That lookup is safe only because the catalogue is closed: an entry may name a ty
and nothing else, so it can never point its own field at a plugin's renderer. ``prepare_pin``
consults it only where no plugin shortcode claimed the field by name.

A plugin cannot take over ``hyperlink`` or ``CTA`` either. The server always emits ``html``
Alongside its own, goodmap offers **one** of platzky's built-in shortcodes — ``image`` — so
a point can carry photos. Not the whole set, because the entries
naming these types are data nobody vouched for: a suggested point or an imported dataset
naming platzky's ``html`` would put raw markup into the popup. Offering another, ``figure``
say, means adding it to ``BUILTIN_FIELD_TYPES``.

Each built-in field holds one value; a field the shortcode refuses, leaving nothing to
show, is left out of the popup altogether. A place with several photos gives each its own
field. A gallery wanting a layout of its own does not reach into ``image``: it brings its
own type, either a shortcode bound to the field by name or a field ``type`` of its own that
the data names instead. A field a plugin's shortcode is bound to keeps exactly the
rendering that shortcode gives it.

An image URL must be ``https`` or a path on the site itself (``/static/…``) — platzky's
image policy, since an image is fetched by every visitor who opens the point;
``http:``, ``javascript:`` and ``data:`` are refused:

.. code-block:: json

{"photo": {"type": "image", "url": "https://example.com/front.jpg",
"alt": "The shop front, with its green door"}}

Give every photo an ``alt`` saying what it shows, so a screen reader can describe it; an
image without one gets ``alt=""``, which marks it as decorative. Image fields are shown
full-width under the popup's title, without a label.

.. note::

Unlike a link, an image is fetched as soon as its popup opens. Whoever hosts an image
URL in your data therefore learns the IP address of everyone who opens that point, and
when — which is why a suggested point's images deserve the same scrutiny as its text
before it is approved, and why an imported dataset's should come from hosts you trust.

A plugin cannot take over ``hyperlink``, ``CTA`` or ``image`` either. The server always emits ``html``
for a type it renders, so that HTML is always the innermost stage — a field plugin attached
to one of these types wraps it and cannot replace it.

The two share a rendering, because they only ever differed in presentation: both are a URL
and the text to show for it. Which one a field is decides where the popup puts it — a line
among the details, or a button below them — which ``LocationDetails`` decides from the field
name.
among the details, or a button below them — which ``LocationDetails`` decides from the
value's ``type`` in its ``SECTION_BY_TYPE`` table.

A field plugin is a ``MarkerFieldPluginBase`` whose component is a stage
``({ input, config }) => element`` — it receives the previous stage's output as ``input``.
Expand Down Expand Up @@ -262,6 +295,19 @@ optionally, ``config.order``; lower order is more innermost, higher order wraps
A wrapper must have a renderer beneath it (a type rendered server-side — one of goodmap's
own, or a plugin's shortcode — or a renderer plugin it depends on).

.. warning::

A field plugin renders data nobody vouched for — a suggested point, an imported dataset —
so it must render values as text, never as markup. ``<code>{input.code}</code>`` above is
safe because React escapes what it renders: a code stored as ``<img src=x onerror=…>``
shows as those characters. Passing a value to ``dangerouslySetInnerHTML``, or building
markup from it some other way, would run whatever it holds in every visitor's browser.

This is the frontend half of the rule a shortcode follows when it escapes the data it
interpolates. The one piece of markup the popup inserts as HTML is the field's ``html``,
which only the server writes; a wrapper receives it as an element in ``input`` and
composes around it, as ``HyperlinkBadge`` does.

.. _plugins-configuration:

Configuration
Expand Down
8 changes: 7 additions & 1 deletion e2e-tests/e2e_test_data_initial.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,12 @@
"lighting"
],
"uuid": "c8ecf476-5968-40da-ba5c-e810ad9ff203",
"remark": "very old bridge"
"remark": "very old bridge",
"photo": {
"type": "image",
"url": "https://upload.wikimedia.org/wikipedia/commons/thumb/f/f3/WroclawMostZwierzyniecki.jpg/500px-WroclawMostZwierzyniecki.jpg",
"alt": "Most Zwierzyniecki"
}
},
{
"name": "Milenijny",
Expand Down Expand Up @@ -288,6 +293,7 @@
}
},
"visible_data": [
"photo",
"remark",
"accessible_by",
"type_of_place",
Expand Down
3 changes: 3 additions & 0 deletions e2e-tests/tests/basic/test_popup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ def test_displays_popup_title_subtitle_categories_and_cta(self, page: Page, wind

verify_popup_content(page, EXPECTED_PLACE_ZWIERZYNIECKA)

# The seeded photo, described by the alt its data gives it.
expect(popup.locator('img[alt="Most Zwierzyniecki"]')).to_be_attached()

# Verify close button and click it
close_button = page.locator(".leaflet-popup-close-button")
expect(close_button).to_be_visible()
Expand Down
12 changes: 11 additions & 1 deletion frontend/src/components/Map/components/AccessibilityTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
* @param {Function} props.setIsAccessibilityTableOpen - Callback to close the table and return to map view
* @returns {React.ReactElement} Table container with location data and back button
*/
// Server-rendered images carry no size of their own; the popup bounds them in its
// ImagesContainer, and a table cell needs the same or one photo stretches its whole row.
const imageCellSx = {
'& img': { display: 'block', maxWidth: 160, height: 'auto', margin: '0 auto' },
};

const AccessibilityTable = ({ userPosition, setIsAccessibilityTableOpen }) => {
const { selectedFilters } = useFilters();
const { t } = useTranslation();
Expand Down Expand Up @@ -73,7 +79,7 @@
});
setRows(rowsLocal);
} catch (error) {
console.log('AccessibilityTable: ', error);

Check warning on line 82 in frontend/src/components/Map/components/AccessibilityTable.jsx

View workflow job for this annotation

GitHub Actions / lint

Unexpected console statement
}
}, [data, t]);

Expand Down Expand Up @@ -108,7 +114,11 @@
sx={{ '&:last-child td, &:last-child th': { border: 0 } }}
>
{row.map((cell, cellIndex) => (
<TableCell key={headers[cellIndex]} align="center">
<TableCell
key={headers[cellIndex]}
align="center"
sx={imageCellSx}
>
{cell.type ? <FieldRenderer value={cell} /> : cell}
</TableCell>
))}
Expand Down
23 changes: 21 additions & 2 deletions frontend/src/components/MarkerPopup/DesktopPopup.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useEffect } from 'react';
import React, { useCallback, useEffect, useRef } from 'react';
import PropTypes from 'prop-types';
import { Popup } from 'react-leaflet';
import { useLeafletContext } from '@react-leaflet/core';
Expand All @@ -23,14 +23,33 @@ const StyledPopup = styled(Popup)`
*/
const DesktopPopup = ({ children }) => {
const context = useLeafletContext();
const popupRef = useRef(null);

useEffect(() => {
// Popup binds itself to the overlay container in its own effect, and child effects run
// before parent ones, so the popup is already bound by the time this runs.
context.overlayContainer?.openPopup();
}, [context]);

return <StyledPopup>{children}</StyledPopup>;
// react-leaflet re-lays out and re-pans the popup only when its children change. An image
// the server rendered grows the popup when it arrives, after that - upwards, as the popup
// hangs from its marker - so without this its top, close button included, ends up above
// the map. `load` and `error` do not bubble, hence the capture phase. A callback ref,
// because react-leaflet renders the children only once Leaflet has made the popup's
// content node, after this component's own effects have run.
const contentRef = useCallback(node => {
const relayout = () => popupRef.current?.update();
if (node) {
node.addEventListener('load', relayout, true);
node.addEventListener('error', relayout, true);
}
}, []);

return (
<StyledPopup ref={popupRef}>
<div ref={contentRef}>{children}</div>
</StyledPopup>
);
};

DesktopPopup.propTypes = {
Expand Down
Loading
Loading