Skip to content

Commit

Permalink
Prevent errors from legend. Invalidate all-paginated-features
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarrenechea authored and andresgnlez committed Jan 15, 2024
1 parent 6c0cab8 commit 4c9e7aa
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 6 deletions.
4 changes: 4 additions & 0 deletions app/hooks/features/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,7 @@ export function useUploadFeaturesShapefile({
onSuccess: async (data, variables) => {
const { id: projectId } = variables;
await queryClient.invalidateQueries(['all-features', projectId]);
await queryClient.invalidateQueries(['all-paginated-features', projectId]);
},
});
}
Expand Down Expand Up @@ -640,6 +641,7 @@ export function useUploadFeaturesCSV({
onSuccess: async (data, variables) => {
const { id: projectId } = variables;
await queryClient.invalidateQueries(['all-features', projectId]);
await queryClient.invalidateQueries(['all-paginated-features', projectId]);
},
});
}
Expand Down Expand Up @@ -701,6 +703,7 @@ export function useEditFeatureTag() {
await queryClient.invalidateQueries(['feature', featureId]);
await queryClient.invalidateQueries(['project-tags', projectId]);
await queryClient.invalidateQueries(['all-features', projectId]);
await queryClient.invalidateQueries(['all-paginated-features', projectId]);
},
onError: (error, variables, context) => {
console.info('Error', error, variables, context);
Expand Down Expand Up @@ -734,6 +737,7 @@ export function useDeleteFeatureTag() {
const { featureId, projectId } = variables;
await queryClient.invalidateQueries(['feature', featureId]);
await queryClient.invalidateQueries(['all-features', projectId]);
await queryClient.invalidateQueries(['all-paginated-features', projectId]);
},
onError: (error, variables, context) => {
console.info('Error', error, variables, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ const DeleteModal = ({
bulkDeleteFeatureFromProject(pid, deletableFeatureIds, session)
.then(async () => {
await queryClient.invalidateQueries(['all-features', pid]);
await queryClient.invalidateQueries(['all-paginated-features', pid]);
await queryClient.invalidateQueries(['project-tags', pid]);

onDismiss();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ const EditBulkModal = ({
editFeaturesTagsBulk(pid, selectedFeaturesIds, session, data)
.then(async () => {
await queryClient.invalidateQueries(['all-features', pid]);
await queryClient.invalidateQueries(['all-paginated-features', pid]);

handleModal('edit', false);

addToast(
Expand Down Expand Up @@ -103,6 +105,8 @@ const EditBulkModal = ({
deleteFeaturesTagsBulk(pid, selectedFeaturesIds, session)
.then(async () => {
await queryClient.invalidateQueries(['all-features', pid]);
await queryClient.invalidateQueries(['all-paginated-features', pid]);

handleModal('edit', false);

addToast(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ const EditModal = ({
Promise.all([editFeaturePromise, editFeatureTagPromise()])
.then(async () => {
await queryClient.invalidateQueries(['all-features', pid]);
await queryClient.invalidateQueries(['all-paginated-features', pid]);

onDone?.();
handleModal('edit', false);

Expand Down
2 changes: 2 additions & 0 deletions app/layout/project/sidebar/project/scenarios-list/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export const ScenariosList: React.FC = () => {
);
await queryClient.invalidateQueries(['scenarios', pid]);
await queryClient.invalidateQueries(['all-features', pid]);
await queryClient.invalidateQueries(['all-paginated-features', pid]);

setDelete(null);
},
onError: () => {
Expand Down
2 changes: 1 addition & 1 deletion app/layout/scenarios/edit/map/component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ export const ScenariosEditMap = (): JSX.Element => {
}
};

console.log({ LAYERS });
// console.log({ LAYERS });

return (
<div className="relative h-full w-full overflow-hidden">
Expand Down
13 changes: 8 additions & 5 deletions app/layout/scenarios/edit/map/legend/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ export const useFeaturesLegend = () => {
const featureColors = useColorFeatures(pid, sid);

const selectedFeaturesQuery = useSelectedFeatures(sid);
const selectedFeaturesIds = selectedFeaturesQuery.data?.map(({ metadata }) => metadata?.id) || [];
const selectedFeaturesIds =
selectedFeaturesQuery.data?.filter((s) => s.metadata).map(({ metadata: { id } }) => id) || [];

const projectFeaturesQuery = useAllFeatures(
pid,
Expand Down Expand Up @@ -200,8 +201,9 @@ export const useFeaturesLegend = () => {

const targetedFeatures = useTargetedFeatures(sid);

const parsedTargetedFeatures = targetedFeatures.data?.map(
({ id, name, splitted, parentId, splitSelected }) => {
const parsedTargetedFeatures = targetedFeatures.data
?.filter(({ featureId }) => selectedFeaturesIds.includes(featureId))
?.map(({ id, name, splitted, parentId, splitSelected }) => {
const allFeatures = queryClient.getQueryData<any>(['all-features', pid], {
exact: false,
})?.data;
Expand All @@ -217,8 +219,7 @@ export const useFeaturesLegend = () => {
split: splitSelected,
color: featureColors?.find(({ id: featureId }) => featureId === id)?.color,
};
}
);
});

const targetedFeaturesByRange = parsedTargetedFeatures?.reduce(
(acc, x) => ({
Expand Down Expand Up @@ -254,6 +255,8 @@ export const useFeaturesLegend = () => {
index === self.findIndex((t) => JSON.stringify(t) === JSON.stringify(item))
);

// console.log({ uniqueBinaryFeatures, uniqueContinuousFeatures });

return [
...LEGEND_LAYERS['binary-features']({
items: uniqueBinaryFeatures,
Expand Down

0 comments on commit 4c9e7aa

Please sign in to comment.