Skip to content

Commit

Permalink
fixes cost-surfaces revalidation on upload
Browse files Browse the repository at this point in the history
  • Loading branch information
agnlez committed Jan 16, 2024
1 parent 4205f12 commit 8194888
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/hooks/map/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ export const LEGEND_LAYERS = {
},
{
color: COLORS.cost[1],
value: `${max}`,
value: max,
},
],
onChangeVisibility: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ import React, { useCallback, useEffect, useRef, useState } from 'react';

import { useDropzone, DropzoneProps } from 'react-dropzone';
import { Form as FormRFF, Field as FieldRFF, FormProps } from 'react-final-form';
import { useQueryClient } from 'react-query';

import { useRouter } from 'next/router';

import { AxiosError, isAxiosError } from 'axios';
import { motion } from 'framer-motion';

import { useUploadProjectCostSurface } from 'hooks/cost-surface';
import { useDownloadShapefileTemplate } from 'hooks/projects';
import { useDownloadShapefileTemplate, useSaveProject } from 'hooks/projects';
import { useToasts } from 'hooks/toast';

import Button from 'components/button';
Expand Down Expand Up @@ -52,7 +51,11 @@ export const CostSurfaceUploadModal = ({

const { addToast } = useToasts();

const queryClient = useQueryClient();
const projectMutation = useSaveProject({
requestConfig: {
method: 'PATCH',
},
});

const uploadProjectCostSurfaceMutation = useUploadProjectCostSurface();

Expand Down Expand Up @@ -121,8 +124,7 @@ export const CostSurfaceUploadModal = ({
{
onSuccess: () => {
setSuccessFile({ ...successFile });
queryClient.invalidateQueries(['cost-surfaces', pid]);
onClose();

addToast(
'success-upload-cost-surface-file',
<>
Expand All @@ -133,6 +135,17 @@ export const CostSurfaceUploadModal = ({
level: 'success',
}
);

onClose();

projectMutation.mutate({
id: pid,
data: {
metadata: {
cache: new Date().getTime(),
},
},
});
},
onError: (error: AxiosError | Error) => {
let errors: { status: number; title: string }[] = [];
Expand Down Expand Up @@ -167,7 +180,7 @@ export const CostSurfaceUploadModal = ({
}
);
},
[pid, addToast, onClose, uploadProjectCostSurfaceMutation, successFile, queryClient]
[pid, addToast, onClose, uploadProjectCostSurfaceMutation, successFile, projectMutation]
);

const { getRootProps, getInputProps, isDragActive, isDragAccept, isDragReject } = useDropzone({
Expand Down
2 changes: 2 additions & 0 deletions app/layout/projects/show/status/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export const TEXTS_RUNNING = {
clone: () => 'Cloning project...',
import: () => 'Importing project...',
legacy: () => 'Importing legacy project...',
costSurface: () => 'Processing cost surface...',
};

export const TEXTS_FAILURE = {
Expand All @@ -12,4 +13,5 @@ export const TEXTS_FAILURE = {
clone: () => 'Fail cloning project',
import: () => 'Fail importing project',
legacy: () => 'Fail importing legacy project',
costSurface: () => 'Fail Processing cost surface',
};
23 changes: 12 additions & 11 deletions app/layout/scenarios/edit/status/actions/done.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { mergeScenarioStatusMetaData } from 'utils/utils-scenarios';

export const useScenarioActionsDone = () => {
const { query } = useRouter();
const { sid } = query as { sid: string };
const { pid, sid } = query as { pid: string; sid: string };

const dispatch = useDispatch();
const scenarioSlice = getScenarioEditSlice(sid);
Expand Down Expand Up @@ -45,7 +45,7 @@ export const useScenarioActionsDone = () => {

scenarioMutation.mutate(
{
id: `${sid}`,
id: sid,
data: {
metadata: mergeScenarioStatusMetaData(scenarioData?.metadata, {
tab: ScenarioSidebarTabs.PLANNING_UNIT,
Expand Down Expand Up @@ -96,7 +96,7 @@ export const useScenarioActionsDone = () => {
(JOB_REF) => {
scenarioMutation.mutate(
{
id: `${sid}`,
id: sid,
data: {
metadata: mergeScenarioStatusMetaData(scenarioData?.metadata, {
tab: ScenarioSidebarTabs.PLANNING_UNIT,
Expand Down Expand Up @@ -141,7 +141,7 @@ export const useScenarioActionsDone = () => {
(JOB_REF) => {
scenarioMutation.mutate(
{
id: `${sid}`,
id: sid,
data: {
metadata: mergeScenarioStatusMetaData(scenarioData?.metadata, {
tab: ScenarioSidebarTabs.FEATURES,
Expand Down Expand Up @@ -178,7 +178,7 @@ export const useScenarioActionsDone = () => {
(JOB_REF) => {
scenarioMutation.mutate(
{
id: `${sid}`,
id: sid,
data: {
metadata: mergeScenarioStatusMetaData(
scenarioData?.metadata,
Expand All @@ -193,10 +193,10 @@ export const useScenarioActionsDone = () => {
},
},
{
onSuccess: () => {
onSuccess: async () => {
dispatch(setJob(null));
dispatch(setCache(Date.now()));
queryClient.invalidateQueries(['scenarios-cost-surface', sid]);
await queryClient.invalidateQueries(['cost-surfaces', pid]);
JOB_REF.current = null;
},
onError: () => {
Expand All @@ -214,6 +214,7 @@ export const useScenarioActionsDone = () => {
);
},
[
pid,
sid,
scenarioMutation,
scenarioData?.metadata,
Expand All @@ -230,7 +231,7 @@ export const useScenarioActionsDone = () => {
(JOB_REF) => {
scenarioMutation.mutate(
{
id: `${sid}`,
id: sid,
data: {
metadata: mergeScenarioStatusMetaData(
scenarioData?.metadata,
Expand Down Expand Up @@ -272,7 +273,7 @@ export const useScenarioActionsDone = () => {
(JOB_REF) => {
scenarioMutation.mutate(
{
id: `${sid}`,
id: sid,
data: {
metadata: mergeScenarioStatusMetaData(
scenarioData?.metadata,
Expand Down Expand Up @@ -315,7 +316,7 @@ export const useScenarioActionsDone = () => {
(JOB_REF) => {
scenarioMutation.mutate(
{
id: `${sid}`,
id: sid,
data: {
metadata: mergeScenarioStatusMetaData(scenarioData?.metadata, {
tab: ScenarioSidebarTabs.SOLUTIONS,
Expand Down Expand Up @@ -351,7 +352,7 @@ export const useScenarioActionsDone = () => {
(JOB_REF) => {
scenarioMutation.mutate(
{
id: `${sid}`,
id: sid,
data: {
metadata: mergeScenarioStatusMetaData(
scenarioData?.metadata,
Expand Down
2 changes: 2 additions & 0 deletions app/pages/projects/[pid]/scenarios/[sid]/edit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import GridSetupPlanningUnits from 'layout/project/sidebar/scenario/grid-setup/p
import GridSetupProtectedAreas from 'layout/project/sidebar/scenario/grid-setup/protected-areas';
import SolutionsOverview from 'layout/project/sidebar/scenario/solutions/overview';
import SolutionsTargetAchievements from 'layout/project/sidebar/scenario/solutions/target-achievement';
import ProjectStatus from 'layout/projects/show/status/component';
import Protected from 'layout/protected';
import ScenarioLock from 'layout/scenarios/edit/lock';
import ScenarioEditMap from 'layout/scenarios/edit/map';
Expand Down Expand Up @@ -108,6 +109,7 @@ const EditScenarioPage = (): JSX.Element => {
</ScenariosEditSidebar>
</Sidebar>
<ScenarioEditMap />
<ProjectStatus />
<ScenarioStatus />
<ScenarioLock />
</ProjectLayout>
Expand Down

0 comments on commit 8194888

Please sign in to comment.