From 4a010cba6f4b3164d34c933d701893d6592a5242 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 tile layer configuration to map edit --- src/components/ComponentConfiguration.tsx | 2 + src/components/builder/loader.stories.tsx | 15 ++++++++ src/components/builder/loader.tsx | 13 +++++++ src/context.ts | 13 +++++++ src/registry/map/edit.tsx | 45 +++++++++++++++++++++-- src/registry/map/preview.tsx | 26 ++++++++++++- 6 files changed, 109 insertions(+), 5 deletions(-) create mode 100644 src/components/builder/loader.stories.tsx create mode 100644 src/components/builder/loader.tsx diff --git a/src/components/ComponentConfiguration.tsx b/src/components/ComponentConfiguration.tsx index eca05a25..7fec9d2a 100644 --- a/src/components/ComponentConfiguration.tsx +++ b/src/components/ComponentConfiguration.tsx @@ -33,6 +33,7 @@ const ComponentConfiguration: React.FC = ({ uniquifyKey, supportedLanguageCodes = ['nl', 'en'], richTextColors, + getMapTileLayers, theme, getFormComponents, getValidatorPlugins, @@ -60,6 +61,7 @@ const ComponentConfiguration: React.FC = ({ uniquifyKey, supportedLanguageCodes, richTextColors, + getMapTileLayers, theme, getFormComponents, getValidatorPlugins, diff --git a/src/components/builder/loader.stories.tsx b/src/components/builder/loader.stories.tsx new file mode 100644 index 00000000..bdcefc32 --- /dev/null +++ b/src/components/builder/loader.stories.tsx @@ -0,0 +1,15 @@ +import {Meta, StoryObj} from '@storybook/react'; + +import Loader from '@/components/builder/loader'; + +type Story = StoryObj; + +export default { + title: 'Formio/Builder/Loader', + component: Loader, + parameters: { + modal: {noModal: true}, + }, +} satisfies Meta; + +export const Default: Story = {}; diff --git a/src/components/builder/loader.tsx b/src/components/builder/loader.tsx new file mode 100644 index 00000000..5d54c777 --- /dev/null +++ b/src/components/builder/loader.tsx @@ -0,0 +1,13 @@ +import {FormattedMessage} from 'react-intl'; + +const Loader: React.FC = () => { + return ( +
+ + + +
+ ); +}; + +export default Loader; diff --git a/src/context.ts b/src/context.ts index 3d42eb93..6af2f831 100644 --- a/src/context.ts +++ b/src/context.ts @@ -29,6 +29,17 @@ export interface DocumentTypeOption { description: string; } +/* + Map tile layers + + This datastructure is created by the Open Forms backend. + */ +export interface MapTileLayer { + identifier: string; + url: string; + label: string; +} + /* Builder */ @@ -48,6 +59,7 @@ export interface BuilderContextType { getDocumentTypes: () => Promise>; getConfidentialityLevels: () => Promise; getAuthPlugins: () => Promise; + getMapTileLayers: () => Promise; } const BuilderContext = React.createContext({ @@ -65,6 +77,7 @@ const BuilderContext = React.createContext({ getDocumentTypes: async () => [], getConfidentialityLevels: async () => [], getAuthPlugins: async () => [], + getMapTileLayers: async () => [], }); BuilderContext.displayName = 'BuilderContext'; diff --git a/src/registry/map/edit.tsx b/src/registry/map/edit.tsx index f4613db4..4ce73b10 100644 --- a/src/registry/map/edit.tsx +++ b/src/registry/map/edit.tsx @@ -1,7 +1,8 @@ import {MapComponentSchema} from '@open-formulieren/types'; import {useFormikContext} from 'formik'; -import {useEffect} from 'react'; +import {useContext, useEffect} from 'react'; import {FormattedMessage, useIntl} from 'react-intl'; +import useAsync from 'react-use/esm/useAsync'; import { BuilderTabs, @@ -20,7 +21,8 @@ import { useDeriveComponentKey, } from '@/components/builder'; import {LABELS} from '@/components/builder/messages'; -import {Checkbox, TabList, TabPanel, Tabs} from '@/components/formio'; +import {Checkbox, Select, TabList, TabPanel, Tabs} from '@/components/formio'; +import {BuilderContext} from '@/context'; import {useErrorChecker} from '@/utils/errors'; import {EditFormDefinition} from '../types'; @@ -62,7 +64,8 @@ const EditForm: EditFormDefinition = () => { 'isSensitiveData', 'useConfigDefaultMapSettings', 'defaultZoom', - 'initialCenter' + 'initialCenter', + 'tileLayerIdentifier' )} /> @@ -83,6 +86,7 @@ const EditForm: EditFormDefinition = () => { {!values.useConfigDefaultMapSettings && } + {/* Advanced tab */} @@ -134,6 +138,7 @@ EditForm.defaultValues = { lat: undefined, lng: undefined, }, + tileLayerIdentifier: undefined, defaultValue: null, // Advanced tab conditional: { @@ -174,4 +179,38 @@ const UseConfigDefaultMapSettings: React.FC<{}> = () => { ); }; +const TileLayer: React.FC = () => { + const {getMapTileLayers} = useContext(BuilderContext); + const intl = useIntl(); + const {value: options, loading, error} = useAsync(async () => await getMapTileLayers(), []); + if (error) { + throw error; + } + + const tooltip = intl.formatMessage({ + description: "Tooltip for 'tileLayerIdentifier' builder field", + defaultMessage: + 'The tile layer is responsible for showing the map background. ' + + 'This effects the map style at particular coordinates and zoom levels.', + }); + return ( +