diff --git a/app/hooks/features/index.ts b/app/hooks/features/index.ts index 6f8232d9b6..782326ba01 100644 --- a/app/hooks/features/index.ts +++ b/app/hooks/features/index.ts @@ -193,11 +193,12 @@ export function useSelectedFeatures( return useQuery(['selected-features', sid], fetchFeatures, { ...queryOptions, - enabled: !!sid && featureColorQueryState?.status === 'success', + enabled: + !!sid && ((featureColorQueryState && featureColorQueryState.status === 'success') || true), select: ({ data }) => { const { features = [] } = data; - let parsedData = features.map((d, index) => { + let parsedData = features.map((d) => { const { featureId, geoprocessingOperations, metadata } = d; const { @@ -275,7 +276,9 @@ export function useSelectedFeatures( min: amountMin, max: amountMax, }, - color: featureColorQueryState.data.find(({ id }) => featureId === id)?.color, + color: featureColorQueryState + ? featureColorQueryState.data.find(({ id }) => featureId === id)?.color + : null, // SPLIT splitOptions, diff --git a/app/hooks/scenarios/index.ts b/app/hooks/scenarios/index.ts index db4140bc5c..0ce67dc4a1 100644 --- a/app/hooks/scenarios/index.ts +++ b/app/hooks/scenarios/index.ts @@ -564,44 +564,6 @@ export function useUploadPA({ return useMutation(uploadPAShapefile); } -export function useCostSurfaceRange(id: Scenario['id']) { - const { data: session } = useSession(); - - const query = useQuery( - ['scenarios-cost-surface', id], - async () => - // ! this endpoint is deprecated: https://marxan23.northeurope.cloudapp.azure.com/swagger#/Scenario/ScenariosController_getCostRange - SCENARIOS.request<{ min: number; max: number }>({ - method: 'GET', - url: `/${id}/cost-surface`, - headers: { - Authorization: `Bearer ${session.accessToken}`, - }, - transformResponse: (data) => { - try { - return JSON.parse(data); - } catch (error) { - return data; - } - }, - }).then((response) => { - return response.data; - }), - { - enabled: !!id, - } - ); - - const { data } = query; - - return useMemo(() => { - return { - ...query, - data, - }; - }, [query, data]); -} - // PLANNING UNITS export function useScenarioPU( sid: string, diff --git a/app/layout/scenarios/reports/solutions/advanced-settings/index.tsx b/app/layout/scenarios/reports/solutions/advanced-settings/index.tsx index 8368729ab3..6a27cbdf00 100644 --- a/app/layout/scenarios/reports/solutions/advanced-settings/index.tsx +++ b/app/layout/scenarios/reports/solutions/advanced-settings/index.tsx @@ -80,8 +80,8 @@ export const AdvancedSettingsPage = (): JSX.Element => {
{calibrationResultsQuery.data?.map((cr) => { return ( -
- Blm Image +
+ {cr.pngData && Blm Image}

BLM:

diff --git a/app/layout/scenarios/reports/solutions/cost-surface/index.tsx b/app/layout/scenarios/reports/solutions/cost-surface/index.tsx index 321449f5b8..6bf0302159 100644 --- a/app/layout/scenarios/reports/solutions/cost-surface/index.tsx +++ b/app/layout/scenarios/reports/solutions/cost-surface/index.tsx @@ -2,8 +2,8 @@ import React, { useMemo } from 'react'; import { useRouter } from 'next/router'; +import { useProjectCostSurfaces } from 'hooks/cost-surface'; import { COLORS } from 'hooks/map/constants'; -import { useCostSurfaceRange } from 'hooks/scenarios'; import LegendItem from 'components/map/legend/item'; import LegendTypeGradient from 'components/map/legend/types/gradient'; @@ -11,8 +11,16 @@ import CostSurfaceReportMap from 'layout/scenarios/reports/solutions/cost-surfac export const CostSurfaceReport = (): JSX.Element => { const { query } = useRouter(); - const { sid } = query as { sid: string }; - const costSurfaceQuery = useCostSurfaceRange(sid); + const { pid, sid } = query as { pid: string; sid: string }; + + const costSurfaceQuery = useProjectCostSurfaces( + pid, + {}, + { + select: (data) => + data.filter((cs) => cs.scenarios.filter((s) => s.id === sid).length > 0)?.[0], + } + ); const LEGEND = useMemo(() => { return { diff --git a/app/layout/scenarios/reports/solutions/cost-surface/map/index.tsx b/app/layout/scenarios/reports/solutions/cost-surface/map/index.tsx index e3ac68e632..c5fb0e5b50 100644 --- a/app/layout/scenarios/reports/solutions/cost-surface/map/index.tsx +++ b/app/layout/scenarios/reports/solutions/cost-surface/map/index.tsx @@ -9,14 +9,17 @@ import PluginMapboxGl from '@vizzuality/layer-manager-plugin-mapboxgl'; import { LayerManager, Layer } from '@vizzuality/layer-manager-react'; import { useAccessToken } from 'hooks/auth'; -import { useBBOX, usePUGridLayer } from 'hooks/map'; +import { useProjectCostSurfaces } from 'hooks/cost-surface'; +import { useBBOX, useCostSurfaceLayer } from 'hooks/map'; import { useProject } from 'hooks/projects'; import Map from 'components/map'; -export const ReportMap = ({ id }: { id: string }): JSX.Element => { +const minZoom = 2; +const maxZoom = 20; + +export const CostSurfaceReportMap = ({ id }: { id: string }): JSX.Element => { const accessToken = useAccessToken(); - const [cache] = useState(Date.now()); const [mapTilesLoaded, setMapTilesLoaded] = useState(false); const { query } = useRouter(); @@ -27,27 +30,31 @@ export const ReportMap = ({ id }: { id: string }): JSX.Element => { const { data } = useProject(pid); + const costSurfaceQuery = useProjectCostSurfaces( + pid, + {}, + { + select: (data) => + data.filter((cs) => cs.scenarios.filter((s) => s.id === sid).length > 0)?.[0], + } + ); + const BBOX = useBBOX({ bbox: data?.bbox, }); - const minZoom = 2; - const maxZoom = 20; const [viewport, setViewport] = useState({}); const [bounds, setBounds] = useState(null); - const PUGridLayer = usePUGridLayer({ - cache, - active: true, - sid: sid ? `${sid}` : null, - include: 'cost', - sublayers: ['cost'], - options: { - cost: { - min: 0, - max: 1, - }, - settings: {}, + const PUGridLayer = useCostSurfaceLayer({ + active: Boolean(costSurfaceQuery?.data), + pid, + costSurfaceId: costSurfaceQuery?.data?.id, + layerSettings: { + opacity: 1, + visibility: true, + min: costSurfaceQuery?.data?.min, + max: costSurfaceQuery?.data?.max, }, }); @@ -123,4 +130,4 @@ export const ReportMap = ({ id }: { id: string }): JSX.Element => { ); }; -export default ReportMap; +export default CostSurfaceReportMap; diff --git a/app/layout/scenarios/reports/solutions/webshot-status/index.tsx b/app/layout/scenarios/reports/solutions/webshot-status/index.tsx index a2829c1deb..65e4fd9781 100644 --- a/app/layout/scenarios/reports/solutions/webshot-status/index.tsx +++ b/app/layout/scenarios/reports/solutions/webshot-status/index.tsx @@ -4,10 +4,11 @@ import { useSelector } from 'react-redux'; import { useRouter } from 'next/router'; +import { useProjectCostSurfaces } from 'hooks/cost-surface'; import { useSelectedFeatures } from 'hooks/features'; import { useProjectUsers } from 'hooks/project-users'; import { useProject } from 'hooks/projects'; -import { useCostSurfaceRange, useScenario, useScenarioPU } from 'hooks/scenarios'; +import { useScenario, useScenarioPU } from 'hooks/scenarios'; import { useWDPACategories } from 'hooks/wdpa'; globalThis.MARXAN = { @@ -44,8 +45,14 @@ export const WebShotStatus = () => { const { data: featuresData, isFetched: featuresDataIsFetched } = useSelectedFeatures(sid, {}); - const { data: costSurfaceRangeData, isFetched: costSurfaceRangeDataIsFetched } = - useCostSurfaceRange(sid); + const costSurfaceQuery = useProjectCostSurfaces( + pid, + {}, + { + select: (data) => + data.filter((cs) => cs.scenarios.filter((s) => s.id === sid).length > 0)?.[0], + } + ); const reportDataIsFetched = projectData && @@ -60,8 +67,8 @@ export const WebShotStatus = () => { PUDataIsFetched && featuresData && featuresDataIsFetched && - costSurfaceRangeData && - costSurfaceRangeDataIsFetched && + costSurfaceQuery.data && + costSurfaceQuery.isFetched && mapsLoaded; useEffect(() => { diff --git a/app/types/api/cost-surface.ts b/app/types/api/cost-surface.ts index 30a5db772e..cda1f98b56 100644 --- a/app/types/api/cost-surface.ts +++ b/app/types/api/cost-surface.ts @@ -1,3 +1,5 @@ +import { Scenario } from './scenario'; + export interface CostSurface { id: string; name: string; @@ -5,4 +7,5 @@ export interface CostSurface { min: number; max: number; scenarioUsageCount: number; + scenarios?: (Pick & { type: 'scenarios' })[]; }