From 02b51577177c3be7390119ad6f7389fe9e1b37f4 Mon Sep 17 00:00:00 2001 From: robinvandermolen Date: Thu, 21 Nov 2024 16:15:31 +0100 Subject: [PATCH] :sparkles: [open-formulieren/open-forms#2173] Add background configuration to map edit --- src/components/ComponentConfiguration.tsx | 2 ++ src/context.ts | 13 ++++++++ src/registry/map/edit.tsx | 4 ++- src/registry/map/map-configuration.tsx | 38 ++++++++++++++++++++++- src/registry/map/preview.tsx | 25 +++++++++++++-- 5 files changed, 78 insertions(+), 4 deletions(-) diff --git a/src/components/ComponentConfiguration.tsx b/src/components/ComponentConfiguration.tsx index eca05a25..6dd871d8 100644 --- a/src/components/ComponentConfiguration.tsx +++ b/src/components/ComponentConfiguration.tsx @@ -33,6 +33,7 @@ const ComponentConfiguration: React.FC = ({ uniquifyKey, supportedLanguageCodes = ['nl', 'en'], richTextColors, + getLeafletMapBackgrounds, theme, getFormComponents, getValidatorPlugins, @@ -60,6 +61,7 @@ const ComponentConfiguration: React.FC = ({ uniquifyKey, supportedLanguageCodes, richTextColors, + getLeafletMapBackgrounds, theme, getFormComponents, getValidatorPlugins, diff --git a/src/context.ts b/src/context.ts index 1401c9c4..a13572b7 100644 --- a/src/context.ts +++ b/src/context.ts @@ -29,6 +29,17 @@ export interface DocumentTypeOption { omschrijving: string; } +/* + Leaflet map background options + + This datastructure is created by the Open Forms backend. + */ +export interface LeafletMapOption { + identifier: string; + url: string; + label: string; +} + /* Builder */ @@ -48,6 +59,7 @@ export interface BuilderContextType { getDocumentTypes: () => Promise>; getConfidentialityLevels: () => Promise; getAuthPlugins: () => Promise; + getLeafletMapBackgrounds: () => Promise; } const BuilderContext = React.createContext({ @@ -65,6 +77,7 @@ const BuilderContext = React.createContext({ getDocumentTypes: async () => [], getConfidentialityLevels: async () => [], getAuthPlugins: async () => [], + getLeafletMapBackgrounds: async () => [], }); BuilderContext.displayName = 'BuilderContext'; diff --git a/src/registry/map/edit.tsx b/src/registry/map/edit.tsx index f4613db4..c4c493a3 100644 --- a/src/registry/map/edit.tsx +++ b/src/registry/map/edit.tsx @@ -62,7 +62,8 @@ const EditForm: EditFormDefinition = () => { 'isSensitiveData', 'useConfigDefaultMapSettings', 'defaultZoom', - 'initialCenter' + 'initialCenter', + 'backgroundIdentifier' )} /> @@ -134,6 +135,7 @@ EditForm.defaultValues = { lat: undefined, lng: undefined, }, + backgroundIdentifier: undefined, defaultValue: null, // Advanced tab conditional: { diff --git a/src/registry/map/map-configuration.tsx b/src/registry/map/map-configuration.tsx index 9db9f2c8..43d5be98 100644 --- a/src/registry/map/map-configuration.tsx +++ b/src/registry/map/map-configuration.tsx @@ -1,7 +1,10 @@ import {TILE_LAYER_RD} from '@open-formulieren/leaflet-tools'; +import {useContext} from 'react'; import {FormattedMessage, useIntl} from 'react-intl'; +import useAsync from 'react-use/esm/useAsync'; -import {NumberField, Panel} from '@/components/formio'; +import {NumberField, Panel, Select} from '@/components/formio'; +import {BuilderContext} from '@/context'; const DefaultZoom: React.FC = () => { const intl = useIntl(); @@ -80,6 +83,38 @@ const Longitude: React.FC = () => { ); }; +const Background: React.FC = () => { + const {getLeafletMapBackgrounds} = useContext(BuilderContext); + const { + value: options, + loading, + error, + } = useAsync(async () => await getLeafletMapBackgrounds(), []); + if (error) { + throw error; + } + + const intl = useIntl(); + const tooltip = intl.formatMessage({ + description: "Tooltip for 'backgroundIdentifier' builder field", + defaultMessage: 'The background to use as the map.', + }); + return ( +