Skip to content

Commit

Permalink
Merge pull request #1634 from Vizzuality/MRXN23-506-removal-of
Browse files Browse the repository at this point in the history
[MRXN23-506]: removes WDPA upload endpoint associated to scenario
  • Loading branch information
agnlez authored Jan 22, 2024
2 parents cf0a82b + ce72034 commit 37b4e20
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 63 deletions.
2 changes: 0 additions & 2 deletions app/docs/roadmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ https://www.figma.com/file/hq0BZNB9fzyFSbEUgQIHdK/Marxan-Visual_V02?node-id=2991
## Cost surface
If someone uploads a cost surface, they should be able to download the cost surface uploaded and the template. For doing this we need:

#### Get current cost surface 'GET' `​/api​/v1​/scenarios​/{id}​/cost-surface`
It should return a .zip file if the user has already uploaded one. Otherwise null.

#### Get min-max range 'GET' `​/api​/v1​/scenarios​/{id}​/cost-surface/range`
Migrate the current endpoint that is returning the min and max to this one. Just a naming change
Expand Down
25 changes: 0 additions & 25 deletions app/hooks/scenarios/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ import {
UploadScenarioPUProps,
UseSaveScenarioPUProps,
SaveScenarioPUProps,
UploadPAProps,
UseUploadPAProps,
UseDuplicateScenarioProps,
DuplicateScenarioProps,
UseCancelRunScenarioProps,
Expand Down Expand Up @@ -541,29 +539,6 @@ export function useUploadScenarioPU({
});
}

// CUSTOM PROTECTED AREAS
export function useUploadPA({
requestConfig = {
method: 'POST',
},
}: UseUploadPAProps) {
const { data: session } = useSession();

const uploadPAShapefile = ({ id, data }: UploadPAProps) => {
return UPLOADS.request({
url: `scenarios/${id}/protected-areas/shapefile`,
data,
headers: {
Authorization: `Bearer ${session.accessToken}`,
'Content-Type': 'multipart/form-data',
},
...requestConfig,
});
};

return useMutation(uploadPAShapefile);
}

// PLANNING UNITS
export function useScenarioPU(
sid: string,
Expand Down
9 changes: 0 additions & 9 deletions app/hooks/scenarios/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,6 @@ export interface SaveScenarioPUProps {
data: any;
}

// useUploadPA
export interface UseUploadPAProps {
requestConfig?: AxiosRequestConfig;
}
export interface UploadPAProps {
id?: string;
data: any;
}

// useDuplicateScenario
export interface UseDuplicateScenarioProps {
requestConfig?: AxiosRequestConfig;
Expand Down
12 changes: 3 additions & 9 deletions app/hooks/wdpa/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,7 @@ export function useEditWDPA({
return useMutation(saveProjectWDPA);
}

export function useUploadWDPAsShapefile({
requestConfig = {
method: 'POST',
},
}: {
requestConfig?: AxiosRequestConfig<FormData>;
}) {
export function useUploadWDPAsShapefile() {
const queryClient = useQueryClient();
const { data: session } = useSession();

Expand All @@ -156,13 +150,13 @@ export function useUploadWDPAsShapefile({
const uploadWDPAShapefile = ({ id, data }: { id: Project['id']; data: FormData }) => {
return UPLOADS.request<{ success: true }>({
url: `/projects/${id}/protected-areas/shapefile`,
method: 'POST',
data,
headers: {
Authorization: `Bearer ${session.accessToken}`,
'Content-Type': 'multipart/form-data',
},
...requestConfig,
} as typeof requestConfig);
});
};

return useMutation(uploadWDPAShapefile, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const WDPAUploadModal = ({

const { addToast } = useToasts();

const uploadWDPAsShapefileMutation = useUploadWDPAsShapefile({});
const uploadPAMutation = useUploadWDPAsShapefile();

useEffect(() => {
return () => {
Expand Down Expand Up @@ -112,7 +112,7 @@ export const WDPAUploadModal = ({
data.append('file', file);
data.append('name', name);

uploadWDPAsShapefileMutation.mutate(
uploadPAMutation.mutate(
{ data, id: pid },
{
onSuccess: () => {
Expand Down Expand Up @@ -163,7 +163,7 @@ export const WDPAUploadModal = ({
}
);
},
[pid, addToast, onClose, uploadWDPAsShapefileMutation, successFile]
[pid, addToast, onClose, uploadPAMutation, successFile]
);

const { getRootProps, getInputProps, isDragActive, isDragAccept, isDragReject } = useDropzone({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { getScenarioEditSlice } from 'store/slices/scenarios/edit';
import { motion } from 'framer-motion';

import { useCanEditScenario } from 'hooks/permissions';
import { useUploadPA } from 'hooks/scenarios';
import { useToasts } from 'hooks/toast';
import { useUploadWDPAsShapefile } from 'hooks/wdpa';

import Button from 'components/button';
import Field from 'components/forms/field';
Expand All @@ -30,13 +30,7 @@ import { bytesToMegabytes } from 'utils/units';

import CLOSE_SVG from 'svgs/ui/close.svg?sprite';

export interface ProtectedAreaUploaderProps {
input: any;
}

export const ProtectedAreaUploader: React.FC<ProtectedAreaUploaderProps> = ({
input,
}: ProtectedAreaUploaderProps) => {
export const ProtectedAreaUploader = ({ input }): JSX.Element => {
const queryClient = useQueryClient();
const { query } = useRouter();
const { pid, sid } = query as { pid: string; sid: string };
Expand All @@ -56,11 +50,7 @@ export const ProtectedAreaUploader: React.FC<ProtectedAreaUploaderProps> = ({

const editable = useCanEditScenario(pid, sid);

const uploadPAMutation = useUploadPA({
requestConfig: {
method: 'POST',
},
});
const uploadPAMutation = useUploadWDPAsShapefile();

useEffect(() => {
return () => {
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...',
protectedAreas: () => 'Processing protected area...',
costSurface: () => 'Processing cost surface...',
};

Expand All @@ -13,5 +14,6 @@ export const TEXTS_FAILURE = {
clone: () => 'Fail cloning project',
import: () => 'Fail importing project',
legacy: () => 'Fail importing legacy project',
protectedAreas: () => 'Fail Processing uploaded protected area',
costSurface: () => 'Fail Processing cost surface',
};
2 changes: 0 additions & 2 deletions app/layout/scenarios/edit/status/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export const TEXTS_RUNNING = {
planningAreaProtectedCalculation: () => 'Calculating the protected areas percentages...',
protectedAreas: () => 'Processing uploaded protected area...',
features: () => 'Processing the features...',
planningUnitsInclusion: () => 'Processing inclusion/exclusion of planning units...',
costSurface: () => 'Processing cost surface...',
Expand All @@ -12,7 +11,6 @@ export const TEXTS_RUNNING = {

export const TEXTS_FAILURE = {
planningAreaProtectedCalculation: () => 'Fail Calculating the protected areas percentages',
protectedAreas: () => 'Fail Processing uploaded protected area',
features: () => 'Fail Processing the features',
planningUnitsInclusion: () => 'Fail Processing inclusion/exclusion of planning units',
costSurface: () => 'Fail Processing cost surface',
Expand Down

1 comment on commit 37b4e20

@vercel
Copy link

@vercel vercel bot commented on 37b4e20 Jan 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

marxan – ./

marxan-vizzuality1.vercel.app
marxan23.vercel.app
marxan-git-develop-vizzuality1.vercel.app

Please sign in to comment.