Merge pull request #9165 from tchak/chore-refactor-geo-areas-to-use-components

refactor(carto): geo area as component
This commit is contained in:
Paul Chavard 2023-06-12 10:36:05 +00:00 committed by GitHub
commit e2d7be215e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 21 additions and 6 deletions

View file

@ -2,7 +2,7 @@
- if editing - if editing
= link_to '#', data: { action: 'geo-area#onClick' } do = link_to '#', data: { action: 'geo-area#onClick' } do
= geo_area.label = geo_area.label
= text_field_tag :description, geo_area.description, data: { action: 'focus->geo-area#onFocus input->geo-area#onInput', geo_area_target: 'description' }, placeholder: 'Description', class: 'no-margin' = text_field_tag :description, geo_area.description, data: { action: 'focus->geo-area#onFocus input->geo-area#onInput', geo_area_target: 'description' }, placeholder: 'Description', class: 'no-margin', id: "geo_area_#{geo_area.id}_description"
- else - else
= link_to '#', data: { action: 'geo-area#onClick' } do = link_to '#', data: { action: 'geo-area#onClick' } do
= geo_area.label = geo_area.label

View file

@ -0,0 +1,7 @@
class Dossiers::GeoAreaComponent < ApplicationComponent
attr_reader :geo_area, :editing
def initialize(geo_area:, editing:)
@geo_area, @editing = geo_area, editing
end
end

View file

@ -3,7 +3,7 @@
.areas .areas
%ul %ul
- champ.selections_utilisateur.slice(0, 20).each do |geo_area| - champ.selections_utilisateur.slice(0, 20).each do |geo_area|
= render partial: 'shared/champs/carte/geo_area', locals: { geo_area: geo_area, editing: editing } = render Dossiers::GeoAreaComponent.new(geo_area:, editing:)
- if champ.selections_utilisateur.size > 20 - if champ.selections_utilisateur.size > 20
%li %li
%span %span
@ -14,4 +14,4 @@
.areas .areas
%ul %ul
- champ.cadastres.each do |geo_area| - champ.cadastres.each do |geo_area|
= render partial: 'shared/champs/carte/geo_area', locals: { geo_area: geo_area, editing: editing } = render Dossiers::GeoAreaComponent.new(geo_area:, editing:)

View file

@ -0,0 +1,7 @@
class Dossiers::GeoAreasComponent < ApplicationComponent
attr_reader :champ, :editing
def initialize(champ:, editing:)
@champ, @editing = champ, editing
end
end

View file

@ -8,4 +8,4 @@
autocompleteScreenReaderInstructions: t("combo_search_component.screen_reader_instructions")) autocompleteScreenReaderInstructions: t("combo_search_component.screen_reader_instructions"))
.geo-areas{ id: dom_id(@champ, :geo_areas) } .geo-areas{ id: dom_id(@champ, :geo_areas) }
= render partial: 'shared/champs/carte/geo_areas', locals: { champ: @champ, editing: true } = render Dossiers::GeoAreasComponent.new(champ: @champ, editing: true)

View file

@ -1,4 +1,5 @@
= turbo_stream.update dom_id(@champ, :geo_areas), partial: 'shared/champs/carte/geo_areas', locals: { champ: @champ, editing: true } = turbo_stream.update dom_id(@champ, :geo_areas) do
= render Dossiers::GeoAreasComponent.new(champ: @champ, editing: true)
- if @focus - if @focus
= turbo_stream.dispatch 'map:feature:focus', bbox: @champ.bounding_box = turbo_stream.dispatch 'map:feature:focus', bbox: @champ.bounding_box

View file

@ -1,4 +1,4 @@
- if champ.geometry? - if champ.geometry?
= react_component("MapReader", { featureCollection: champ.to_feature_collection, options: champ.render_options } ) = react_component("MapReader", { featureCollection: champ.to_feature_collection, options: champ.render_options } )
.geo-areas .geo-areas
= render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ, editing: false } = render Dossiers::GeoAreasComponent.new(champ:, editing: false)