fix(carte): no autosave on champ carte
This commit is contained in:
parent
ad9f072246
commit
6945b3f438
4 changed files with 23 additions and 7 deletions
|
@ -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
|
||||
|
|
|
@ -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é n’est pas valide.');
|
||||
}
|
||||
},
|
||||
[url, updateFeatureCollection, addFeatures, onError]
|
||||
[url, refreshFeatureList, updateFeatureCollection, addFeatures, onError]
|
||||
);
|
||||
|
||||
const deleteFeatures = useCallback<DeleteFeatures>(
|
||||
|
|
|
@ -19,7 +19,7 @@ export class GeoAreaController extends ApplicationController {
|
|||
}
|
||||
|
||||
onInput() {
|
||||
this.debounce(this.updateDescription, 200);
|
||||
this.debounce(this.updateDescription, 500);
|
||||
}
|
||||
|
||||
private updateDescription(): void {
|
||||
|
|
|
@ -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) }
|
||||
|
||||
|
|
Loading…
Reference in a new issue