fix(carte): no autosave on champ carte

This commit is contained in:
Paul Chavard 2023-06-06 15:54:03 +02:00
parent ad9f072246
commit 6945b3f438
4 changed files with 23 additions and 7 deletions

View file

@ -30,7 +30,7 @@ class EditableChamp::EditableChampComponent < ApplicationComponent
end
def stimulus_controller
if !@champ.block? && @champ.fillable?
if autosave_enabled?
# This is an editable champ. Lets find what controllers it might need.
controllers = ['autosave']
@ -45,4 +45,8 @@ class EditableChamp::EditableChampComponent < ApplicationComponent
{}
end
end
def autosave_enabled?
!@champ.carte? && !@champ.block? && @champ.fillable?
end
end

View file

@ -29,6 +29,12 @@ export function useFeatureCollection(
const [featureCollection, setFeatureCollection] = useState(
initialFeatureCollection
);
const refreshFeatureList = useCallback<() => void>(() => {
httpRequest(url)
.turbo()
.catch(() => null);
}, [url]);
const updateFeatureCollection = useCallback<
(callback: (features: Feature[]) => Feature[]) => void
>(
@ -37,11 +43,9 @@ export function useFeatureCollection(
type: 'FeatureCollection',
features: callback(features)
}));
httpRequest(url)
.turbo()
.catch(() => null);
refreshFeatureList();
},
[url, setFeatureCollection]
[refreshFeatureList, setFeatureCollection]
);
const addFeatures = useCallback(
@ -153,13 +157,15 @@ export function useFeatureCollection(
if (newFeatures.length > 0) {
addFeatures(newFeatures, external);
updateFeatureCollection((features) => [...features, ...newFeatures]);
} else {
refreshFeatureList();
}
} catch (error) {
console.error(error);
onError('Le polygone dessiné nest pas valide.');
}
},
[url, updateFeatureCollection, addFeatures, onError]
[url, refreshFeatureList, updateFeatureCollection, addFeatures, onError]
);
const deleteFeatures = useCallback<DeleteFeatures>(

View file

@ -19,7 +19,7 @@ export class GeoAreaController extends ApplicationController {
}
onInput() {
this.debounce(this.updateDescription, 200);
this.debounce(this.updateDescription, 500);
}
private updateDescription(): void {

View file

@ -21,6 +21,12 @@ describe EditableChamp::EditableChampComponent, type: :component do
it { expect(subject).to eq(nil) }
end
context 'when a carte champ' do
let(:champ) { create(:champ_carte, dossier: dossier) }
it { expect(subject).to eq(nil) }
end
context 'when a private champ' do
let(:champ) { create(:champ, dossier: dossier, private: true) }