refactor(carto): remove preview special case
This commit is contained in:
parent
68ca9efba0
commit
5c77bc139a
3 changed files with 9 additions and 22 deletions
|
@ -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<UpdateFatures>(
|
||||
|
@ -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<DeleteFeatures>(
|
||||
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 {
|
||||
|
|
|
@ -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({
|
|||
<DrawLayer
|
||||
featureCollection={featureCollection}
|
||||
{...actions}
|
||||
enabled={!preview && !cadastreEnabled}
|
||||
enabled={!cadastreEnabled}
|
||||
/>
|
||||
{options.layers.includes('cadastres') ? (
|
||||
<>
|
||||
<CadastreLayer
|
||||
featureCollection={featureCollection}
|
||||
{...actions}
|
||||
enabled={!preview && cadastreEnabled}
|
||||
enabled={cadastreEnabled}
|
||||
/>
|
||||
<div className="cadastres-selection-control mapboxgl-ctrl-group">
|
||||
<button
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
- preview = !champ.persisted?
|
||||
- url = champs_carte_features_path(preview ? 'preview' : champ)
|
||||
= react_component("MapEditor", { featureCollection: champ.to_feature_collection, url: url, preview: preview, options: champ.render_options }, class: "carte-#{champ.id}")
|
||||
= react_component("MapEditor", { featureCollection: champ.to_feature_collection, url: champs_carte_features_path(champ), options: champ.render_options }, class: "carte-#{champ.id}")
|
||||
|
||||
.geo-areas
|
||||
= render partial: 'shared/champs/carte/geo_areas', locals: { champ: champ, editing: true }
|
||||
|
|
Loading…
Reference in a new issue