fix(custom-pois): invalidate canonical parcel-analyze + parcel-poi-score keys (#1241) #1274

Merged
bot-backend merged 1 commit from fix/use-custom-pois-correct-invalidate-key-recovered into main 2026-06-13 08:15:06 +00:00
Showing only changes of commit a1a0aaead6 - Show all commits

View file

@ -27,8 +27,20 @@ function customPoisKey(parcelCad?: string | null): unknown[] {
return ["custom-pois", parcelCad ?? null];
}
// Canonical analyze key prefix is ["parcel-analyze", cad, horizon] (see
// site-finder-api.ts `useParcelAnalyzeQuery`); invalidating with the
// prefix [parcel-analyze, cad] matches every horizon variant. Custom-POI
// add/update/delete also influences the standalone POI score endpoint
// ["parcel-poi-score", cad] (see `useParcelPoiScoreQuery`), so both must
// be invalidated to refresh score + breakdown after a mutation. The
// previous key ["analyze", cad] never matched any live useQuery — bug
// reference: issue #1241.
function analyzeKey(parcelCad: string): unknown[] {
return ["analyze", parcelCad];
return ["parcel-analyze", parcelCad];
}
function poiScoreKey(parcelCad: string): unknown[] {
return ["parcel-poi-score", parcelCad];
}
// ---------------------------------------------------------------------------
@ -56,7 +68,10 @@ export function useCustomPois(parcelCad?: string | null) {
}
/**
* Create a custom POI. Invalidates list + analyze query on success.
* Create a custom POI. On success invalidates:
* - ["custom-pois", parcelCad] (scoped list) + ["custom-pois", null] (global)
* - ["parcel-analyze", parcelCad] prefix (matches every horizon variant)
* - ["parcel-poi-score", parcelCad] (POI weighted score)
*/
export function useAddCustomPoi(parcelCad?: string | null) {
const queryClient = useQueryClient();
@ -75,6 +90,9 @@ export function useAddCustomPoi(parcelCad?: string | null) {
void queryClient.invalidateQueries({ queryKey: customPoisKey(null) });
if (parcelCad) {
void queryClient.invalidateQueries({ queryKey: analyzeKey(parcelCad) });
void queryClient.invalidateQueries({
queryKey: poiScoreKey(parcelCad),
});
}
},
});
@ -99,6 +117,9 @@ export function useUpdateCustomPoi(parcelCad?: string | null) {
void queryClient.invalidateQueries({ queryKey: customPoisKey(null) });
if (parcelCad) {
void queryClient.invalidateQueries({ queryKey: analyzeKey(parcelCad) });
void queryClient.invalidateQueries({
queryKey: poiScoreKey(parcelCad),
});
}
},
});
@ -122,6 +143,9 @@ export function useDeleteCustomPoi(parcelCad?: string | null) {
void queryClient.invalidateQueries({ queryKey: customPoisKey(null) });
if (parcelCad) {
void queryClient.invalidateQueries({ queryKey: analyzeKey(parcelCad) });
void queryClient.invalidateQueries({
queryKey: poiScoreKey(parcelCad),
});
}
},
});