Merge pull request #9144 from tchak/fix-carto-edit-decription
fix(carte): no autosave on champ carte
This commit is contained in:
commit
c85f70c805
4 changed files with 23 additions and 7 deletions
|
@ -30,7 +30,7 @@ class EditableChamp::EditableChampComponent < ApplicationComponent
|
||||||
end
|
end
|
||||||
|
|
||||||
def stimulus_controller
|
def stimulus_controller
|
||||||
if !@champ.block? && @champ.fillable?
|
if autosave_enabled?
|
||||||
# This is an editable champ. Lets find what controllers it might need.
|
# This is an editable champ. Lets find what controllers it might need.
|
||||||
controllers = ['autosave']
|
controllers = ['autosave']
|
||||||
|
|
||||||
|
@ -45,4 +45,8 @@ class EditableChamp::EditableChampComponent < ApplicationComponent
|
||||||
{}
|
{}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def autosave_enabled?
|
||||||
|
!@champ.carte? && !@champ.block? && @champ.fillable?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,6 +29,12 @@ export function useFeatureCollection(
|
||||||
const [featureCollection, setFeatureCollection] = useState(
|
const [featureCollection, setFeatureCollection] = useState(
|
||||||
initialFeatureCollection
|
initialFeatureCollection
|
||||||
);
|
);
|
||||||
|
const refreshFeatureList = useCallback<() => void>(() => {
|
||||||
|
httpRequest(url)
|
||||||
|
.turbo()
|
||||||
|
.catch(() => null);
|
||||||
|
}, [url]);
|
||||||
|
|
||||||
const updateFeatureCollection = useCallback<
|
const updateFeatureCollection = useCallback<
|
||||||
(callback: (features: Feature[]) => Feature[]) => void
|
(callback: (features: Feature[]) => Feature[]) => void
|
||||||
>(
|
>(
|
||||||
|
@ -37,11 +43,9 @@ export function useFeatureCollection(
|
||||||
type: 'FeatureCollection',
|
type: 'FeatureCollection',
|
||||||
features: callback(features)
|
features: callback(features)
|
||||||
}));
|
}));
|
||||||
httpRequest(url)
|
refreshFeatureList();
|
||||||
.turbo()
|
|
||||||
.catch(() => null);
|
|
||||||
},
|
},
|
||||||
[url, setFeatureCollection]
|
[refreshFeatureList, setFeatureCollection]
|
||||||
);
|
);
|
||||||
|
|
||||||
const addFeatures = useCallback(
|
const addFeatures = useCallback(
|
||||||
|
@ -153,13 +157,15 @@ export function useFeatureCollection(
|
||||||
if (newFeatures.length > 0) {
|
if (newFeatures.length > 0) {
|
||||||
addFeatures(newFeatures, external);
|
addFeatures(newFeatures, external);
|
||||||
updateFeatureCollection((features) => [...features, ...newFeatures]);
|
updateFeatureCollection((features) => [...features, ...newFeatures]);
|
||||||
|
} else {
|
||||||
|
refreshFeatureList();
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
onError('Le polygone dessiné n’est pas valide.');
|
onError('Le polygone dessiné n’est pas valide.');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[url, updateFeatureCollection, addFeatures, onError]
|
[url, refreshFeatureList, updateFeatureCollection, addFeatures, onError]
|
||||||
);
|
);
|
||||||
|
|
||||||
const deleteFeatures = useCallback<DeleteFeatures>(
|
const deleteFeatures = useCallback<DeleteFeatures>(
|
||||||
|
|
|
@ -19,7 +19,7 @@ export class GeoAreaController extends ApplicationController {
|
||||||
}
|
}
|
||||||
|
|
||||||
onInput() {
|
onInput() {
|
||||||
this.debounce(this.updateDescription, 200);
|
this.debounce(this.updateDescription, 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
private updateDescription(): void {
|
private updateDescription(): void {
|
||||||
|
|
|
@ -21,6 +21,12 @@ describe EditableChamp::EditableChampComponent, type: :component do
|
||||||
it { expect(subject).to eq(nil) }
|
it { expect(subject).to eq(nil) }
|
||||||
end
|
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
|
context 'when a private champ' do
|
||||||
let(:champ) { create(:champ, dossier: dossier, private: true) }
|
let(:champ) { create(:champ, dossier: dossier, private: true) }
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue