From 2f2edfdfc77a2d47dcd75ec26799615357a4ee61 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Mon, 6 May 2024 18:10:30 +0200 Subject: [PATCH] refactor(champ): update champ carte --- .../editable_champ/carte_component.rb | 12 +++-- .../carte_component/carte_component.html.haml | 12 +---- .../MapEditor/components/AddressInput.tsx | 48 +++++++++---------- app/javascript/components/MapEditor/index.tsx | 16 ++----- app/views/shared/champs/carte/_show.html.haml | 3 +- 5 files changed, 40 insertions(+), 51 deletions(-) diff --git a/app/components/editable_champ/carte_component.rb b/app/components/editable_champ/carte_component.rb index 189fcb76a..b7ecb9a8c 100644 --- a/app/components/editable_champ/carte_component.rb +++ b/app/components/editable_champ/carte_component.rb @@ -4,10 +4,14 @@ class EditableChamp::CarteComponent < EditableChamp::EditableChampBaseComponent :fieldset end - def initialize(**args) - super(**args) - - @autocomplete_component = EditableChamp::ComboSearchComponent.new(**args) + def react_props + { + feature_collection: @champ.to_feature_collection, + champ_id: @champ.input_id, + url: update_path, + adresse_source: data_sources_data_source_adresse_path, + options: @champ.render_options + } end def update_path diff --git a/app/components/editable_champ/carte_component/carte_component.html.haml b/app/components/editable_champ/carte_component/carte_component.html.haml index db14600f9..052e979a9 100644 --- a/app/components/editable_champ/carte_component/carte_component.html.haml +++ b/app/components/editable_champ/carte_component/carte_component.html.haml @@ -1,14 +1,6 @@ .fr-fieldset__element - = render @autocomplete_component - - = react_component("MapEditor", - { featureCollection: @champ.to_feature_collection, - champId: @champ.input_id, - url: update_path, - options: @champ.render_options, - autocompleteAnnounceTemplateId: @autocomplete_component.announce_template_id, - autocompleteScreenReaderInstructions: t("combo_search_component.screen_reader_instructions") }, - {class: 'width-100'}) + %react-fragment.width-100 + = render ReactComponent.new "MapEditor", **react_props .geo-areas{ id: dom_id(@champ, :geo_areas) } = render Dossiers::GeoAreasComponent.new(champ: @champ, editing: true) diff --git a/app/javascript/components/MapEditor/components/AddressInput.tsx b/app/javascript/components/MapEditor/components/AddressInput.tsx index 0e2d2d2a5..0e7c22a22 100644 --- a/app/javascript/components/MapEditor/components/AddressInput.tsx +++ b/app/javascript/components/MapEditor/components/AddressInput.tsx @@ -1,33 +1,33 @@ -import React from 'react'; import { fire } from '@utils'; import type { FeatureCollection } from 'geojson'; -import ComboAdresseSearch from '../../ComboAdresseSearch'; -import { ComboSearchProps } from '~/components/ComboSearch'; +import { RemoteComboBox } from '../../ComboBox'; -export function AddressInput( - comboProps: Pick< - ComboSearchProps, - 'screenReaderInstructions' | 'announceTemplateId' - > & { featureCollection: FeatureCollection; champId: string } -) { +export function AddressInput({ + source, + featureCollection, + champId +}: { + source: string; + featureCollection: FeatureCollection; + champId: string; +}) { return ( -
- { - fire(document, 'map:zoom', { - featureCollection: comboProps.featureCollection, - feature - }); +
+ { + if (item && item.data) { + fire(document, 'map:zoom', { + featureCollection, + feature: item.data + }); + } }} - {...comboProps} />
); diff --git a/app/javascript/components/MapEditor/index.tsx b/app/javascript/components/MapEditor/index.tsx index 0a918c981..5bea4796c 100644 --- a/app/javascript/components/MapEditor/index.tsx +++ b/app/javascript/components/MapEditor/index.tsx @@ -1,4 +1,4 @@ -import React, { useState } from 'react'; +import { useState } from 'react'; import { CursorClickIcon } from '@heroicons/react/outline'; import 'maplibre-gl/dist/maplibre-gl.css'; import '@mapbox/mapbox-gl-draw/dist/mapbox-gl-draw.css'; @@ -12,21 +12,18 @@ import { AddressInput } from './components/AddressInput'; import { PointInput } from './components/PointInput'; import { ImportFileInput } from './components/ImportFileInput'; import { FlashMessage } from '../shared/FlashMessage'; -import { ComboSearchProps } from '../ComboSearch'; export default function MapEditor({ featureCollection: initialFeatureCollection, url, + adresseSource, options, - autocompleteAnnounceTemplateId, - autocompleteScreenReaderInstructions, champId }: { featureCollection: FeatureCollection; url: string; + adresseSource: string; options: { layers: string[] }; - autocompleteAnnounceTemplateId: ComboSearchProps['announceTemplateId']; - autocompleteScreenReaderInstructions: ComboSearchProps['screenReaderInstructions']; champId: string; }) { const [cadastreEnabled, setCadastreEnabled] = useState(false); @@ -41,15 +38,10 @@ export default function MapEditor({ {error && } - diff --git a/app/views/shared/champs/carte/_show.html.haml b/app/views/shared/champs/carte/_show.html.haml index 4b957d132..98534e434 100644 --- a/app/views/shared/champs/carte/_show.html.haml +++ b/app/views/shared/champs/carte/_show.html.haml @@ -1,4 +1,5 @@ - if champ.geometry? - = react_component("MapReader", { featureCollection: champ.to_feature_collection, options: champ.render_options } ) + %react-fragment.width-100 + = render ReactComponent.new "MapReader", feature_collection: champ.to_feature_collection, options: champ.render_options .geo-areas = render Dossiers::GeoAreasComponent.new(champ:, editing: false)