diff --git a/app/docs/roadmap.md b/app/docs/roadmap.md index 101311c839..4c090bc046 100644 --- a/app/docs/roadmap.md +++ b/app/docs/roadmap.md @@ -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 diff --git a/app/hooks/scenarios/index.ts b/app/hooks/scenarios/index.ts index 12862126d1..5db2fe58d9 100644 --- a/app/hooks/scenarios/index.ts +++ b/app/hooks/scenarios/index.ts @@ -31,8 +31,6 @@ import { UploadScenarioPUProps, UseSaveScenarioPUProps, SaveScenarioPUProps, - UploadPAProps, - UseUploadPAProps, UseDuplicateScenarioProps, DuplicateScenarioProps, UseCancelRunScenarioProps, @@ -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, diff --git a/app/hooks/scenarios/types.ts b/app/hooks/scenarios/types.ts index 6ae5791803..c466c16d18 100644 --- a/app/hooks/scenarios/types.ts +++ b/app/hooks/scenarios/types.ts @@ -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; diff --git a/app/hooks/wdpa/index.ts b/app/hooks/wdpa/index.ts index 6e6697d6c4..58135c5cff 100644 --- a/app/hooks/wdpa/index.ts +++ b/app/hooks/wdpa/index.ts @@ -139,13 +139,7 @@ export function useEditWDPA({ return useMutation(saveProjectWDPA); } -export function useUploadWDPAsShapefile({ - requestConfig = { - method: 'POST', - }, -}: { - requestConfig?: AxiosRequestConfig; -}) { +export function useUploadWDPAsShapefile() { const queryClient = useQueryClient(); const { data: session } = useSession(); @@ -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, { diff --git a/app/layout/project/sidebar/project/inventory-panel/wdpas/modals/upload/index.tsx b/app/layout/project/sidebar/project/inventory-panel/wdpas/modals/upload/index.tsx index 560dc68e2c..40f026ed27 100644 --- a/app/layout/project/sidebar/project/inventory-panel/wdpas/modals/upload/index.tsx +++ b/app/layout/project/sidebar/project/inventory-panel/wdpas/modals/upload/index.tsx @@ -50,7 +50,7 @@ export const WDPAUploadModal = ({ const { addToast } = useToasts(); - const uploadWDPAsShapefileMutation = useUploadWDPAsShapefile({}); + const uploadPAMutation = useUploadWDPAsShapefile(); useEffect(() => { return () => { @@ -112,7 +112,7 @@ export const WDPAUploadModal = ({ data.append('file', file); data.append('name', name); - uploadWDPAsShapefileMutation.mutate( + uploadPAMutation.mutate( { data, id: pid }, { onSuccess: () => { @@ -163,7 +163,7 @@ export const WDPAUploadModal = ({ } ); }, - [pid, addToast, onClose, uploadWDPAsShapefileMutation, successFile] + [pid, addToast, onClose, uploadPAMutation, successFile] ); const { getRootProps, getInputProps, isDragActive, isDragAccept, isDragReject } = useDropzone({ diff --git a/app/layout/project/sidebar/scenario/grid-setup/protected-areas/categories/pa-uploader/index.tsx b/app/layout/project/sidebar/scenario/grid-setup/protected-areas/categories/pa-uploader/index.tsx index 39412ecabc..2d45258227 100644 --- a/app/layout/project/sidebar/scenario/grid-setup/protected-areas/categories/pa-uploader/index.tsx +++ b/app/layout/project/sidebar/scenario/grid-setup/protected-areas/categories/pa-uploader/index.tsx @@ -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'; @@ -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 = ({ - input, -}: ProtectedAreaUploaderProps) => { +export const ProtectedAreaUploader = ({ input }): JSX.Element => { const queryClient = useQueryClient(); const { query } = useRouter(); const { pid, sid } = query as { pid: string; sid: string }; @@ -56,11 +50,7 @@ export const ProtectedAreaUploader: React.FC = ({ const editable = useCanEditScenario(pid, sid); - const uploadPAMutation = useUploadPA({ - requestConfig: { - method: 'POST', - }, - }); + const uploadPAMutation = useUploadWDPAsShapefile(); useEffect(() => { return () => { diff --git a/app/layout/projects/show/status/constants.ts b/app/layout/projects/show/status/constants.ts index 150623d25f..0baf6ebbbd 100644 --- a/app/layout/projects/show/status/constants.ts +++ b/app/layout/projects/show/status/constants.ts @@ -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...', }; @@ -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', }; diff --git a/app/layout/scenarios/edit/status/constants.ts b/app/layout/scenarios/edit/status/constants.ts index 5c506b0357..4b2e62a177 100644 --- a/app/layout/scenarios/edit/status/constants.ts +++ b/app/layout/scenarios/edit/status/constants.ts @@ -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...', @@ -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',