diff --git a/app/controllers/administrateurs/procedures_controller.rb b/app/controllers/administrateurs/procedures_controller.rb index 2388508db..96d6847fb 100644 --- a/app/controllers/administrateurs/procedures_controller.rb +++ b/app/controllers/administrateurs/procedures_controller.rb @@ -44,7 +44,7 @@ module Administrateurs end def apercu - @dossier = procedure_without_control.draft_revision.new_dossier + @dossier = procedure_without_control.draft_revision.dossier_for_preview(current_user) @tab = apercu_tab end diff --git a/app/controllers/champs/siret_controller.rb b/app/controllers/champs/siret_controller.rb index 0d790704a..aaeaeac5b 100644 --- a/app/controllers/champs/siret_controller.rb +++ b/app/controllers/champs/siret_controller.rb @@ -45,11 +45,9 @@ class Champs::SiretController < ApplicationController end def find_etablisement - if params[:champ_id].present? - @champ = policy_scope(Champ).find(params[:champ_id]) - @etablissement = @champ&.etablissement - end - @procedure_id = @champ&.dossier&.procedure&.id || 'aperçu' + @champ = policy_scope(Champ).find(params[:champ_id]) + @etablissement = @champ.etablissement + @procedure_id = @champ.dossier.procedure.id end def find_etablissement_with_siret @@ -57,7 +55,7 @@ class Champs::SiretController < ApplicationController end def clear_siret_and_etablissement - @champ&.update!(value: '') + @champ.update!(value: '') @etablissement&.destroy end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 39f04b140..6572b58bb 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -62,7 +62,7 @@ module ApplicationHelper def render_champ(champ) champ_selector = "##{champ.input_group_id}" - form_html = render 'shared/dossiers/edit', dossier: champ.dossier, apercu: false + form_html = render 'shared/dossiers/edit', dossier: champ.dossier champ_html = Nokogiri::HTML.fragment(form_html).at_css(champ_selector).to_s # rubocop:disable Rails/OutputSafety raw("document.querySelector('#{champ_selector}').outerHTML = \"#{escape_javascript(champ_html)}\";") diff --git a/app/javascript/components/MapEditor/hooks.ts b/app/javascript/components/MapEditor/hooks.ts index 8c941ac58..9380a28fc 100644 --- a/app/javascript/components/MapEditor/hooks.ts +++ b/app/javascript/components/MapEditor/hooks.ts @@ -23,7 +23,7 @@ export type DeleteFeatures = (params: { export function useFeatureCollection( initialFeatureCollection: FeatureCollection, - { url, enabled = true }: { url: string; enabled: boolean } + { url }: { url: string } ) { const [error, onError] = useError(); const [featureCollection, setFeatureCollection] = useState( @@ -96,9 +96,6 @@ export function useFeatureCollection( source = SOURCE_SELECTION_UTILISATEUR, external = false }) => { - if (!enabled) { - return; - } try { const newFeatures: Feature[] = []; for (const feature of features) { @@ -117,7 +114,7 @@ export function useFeatureCollection( onError('Le polygone dessiné n’est pas valide.'); } }, - [enabled, url, updateFeatureCollection, addFeatures, onError] + [url, updateFeatureCollection, addFeatures, onError] ); const updateFeatures = useCallback( @@ -126,9 +123,6 @@ export function useFeatureCollection( source = SOURCE_SELECTION_UTILISATEUR, external = false }) => { - if (!enabled) { - return; - } try { const newFeatures: Feature[] = []; for (const feature of features) { @@ -154,14 +148,11 @@ export function useFeatureCollection( onError('Le polygone dessiné n’est pas valide.'); } }, - [enabled, url, updateFeatureCollection, addFeatures, onError] + [url, updateFeatureCollection, addFeatures, onError] ); const deleteFeatures = useCallback( async ({ features, external = false }) => { - if (!enabled) { - return; - } try { const deletedFeatures = []; for (const feature of features) { @@ -183,7 +174,7 @@ export function useFeatureCollection( onError('Le polygone n’a pas pu être supprimé.'); } }, - [enabled, url, updateFeatureCollection, removeFeatures, onError] + [url, updateFeatureCollection, removeFeatures, onError] ); return { diff --git a/app/javascript/components/MapEditor/index.tsx b/app/javascript/components/MapEditor/index.tsx index a5d81741e..d5acd5710 100644 --- a/app/javascript/components/MapEditor/index.tsx +++ b/app/javascript/components/MapEditor/index.tsx @@ -16,19 +16,17 @@ import { FlashMessage } from '../shared/FlashMessage'; export default function MapEditor({ featureCollection: initialFeatureCollection, url, - options, - preview + options }: { featureCollection: FeatureCollection; url: string; - preview: boolean; options: { layers: string[] }; }) { const [cadastreEnabled, setCadastreEnabled] = useState(false); const { featureCollection, error, ...actions } = useFeatureCollection( initialFeatureCollection, - { url, enabled: !preview } + { url } ); return ( @@ -54,14 +52,14 @@ export default function MapEditor({ {options.layers.includes('cadastres') ? ( <>