Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRXN23-529] add info to solutions report #1604

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/hooks/scenarios/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -574,6 +574,7 @@ export function useScenarioPU(
excluded: ScenarioPlanningUnit['id'][];
included: ScenarioPlanningUnit['id'][];
available: ScenarioPlanningUnit['id'][];
total: number;
}
>
) {
Expand Down Expand Up @@ -613,11 +614,13 @@ export function useScenarioPU(
const available = data
.filter((p) => p.inclusionStatus === 'available' && p.setByUser)
.map((p) => p.id);
const total = data.length;

return {
included,
excluded,
available,
total,
};
},
...queryOptions,
Expand Down
4 changes: 3 additions & 1 deletion app/layout/scenarios/edit/map/legend/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { useAllGapAnalysis } from 'hooks/gap-analysis';
import { LEGEND_LAYERS } from 'hooks/map/constants';
import { useProject } from 'hooks/projects';
import { useScenario } from 'hooks/scenarios';
import { useSolutions } from 'hooks/solutions';
import { useWDPACategories } from 'hooks/wdpa';

import { CostSurface } from 'types/api/cost-surface';
Expand Down Expand Up @@ -417,6 +418,7 @@ export const useFrequencyLegend = () => {
const { query } = useRouter();
const { sid } = query as { sid: string };
const scenarioQuery = useScenario(sid);
const solutionsQuery = useSolutions(sid);

const dispatch = useAppDispatch();
const scenarioSlice = getScenarioEditSlice(sid);
Expand All @@ -426,7 +428,7 @@ export const useFrequencyLegend = () => {
if (!scenarioQuery.data?.ranAtLeastOnce) return null;

return LEGEND_LAYERS['frequency']({
numberOfRuns: scenarioQuery.data?.numberOfRuns,
numberOfRuns: solutionsQuery.data.length,
onChangeVisibility: () => {
dispatch(
setLayerSettings({
Expand Down
13 changes: 10 additions & 3 deletions app/layout/scenarios/reports/solutions/frequency/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useRouter } from 'next/router';

import { LEGEND_LAYERS } from 'hooks/map/constants';
import { useScenario } from 'hooks/scenarios';
import { useSolutions } from 'hooks/solutions';

import LegendItem from 'components/map/legend/item';
import LegendTypeGradient from 'components/map/legend/types/gradient';
Expand All @@ -15,12 +16,13 @@ export const FrequencyPage = (): JSX.Element => {

const scenarioQuery = useScenario(sid);

const solutionsQuery = useSolutions(sid);

const LEGEND = useMemo(() => {
return {
...LEGEND_LAYERS.frequency({
numberOfRuns: scenarioQuery.data?.numberOfRuns,
numberOfRuns: solutionsQuery.data.length,
}),
name: `Frequency (${scenarioQuery.data?.numberOfRuns})`,
settingsManager: null,
};
}, [scenarioQuery.data?.numberOfRuns]);
Expand All @@ -29,7 +31,12 @@ export const FrequencyPage = (): JSX.Element => {
<div className="flex flex-col">
<FrequencyReportMap id="report-map-2" />
<div className="flex flex-col space-y-3 py-8">
<LegendItem {...LEGEND} key="frequency" theme="light" className="text-left font-semibold" />
<LegendItem
{...LEGEND}
key="frequency"
theme="light"
className="pb-0 pl-0 text-left font-semibold"
/>
<LegendTypeGradient className={{ box: 'w-1/2 text-sm', bar: 'h-3' }} items={LEGEND.items} />
</div>
</div>
Expand Down
35 changes: 26 additions & 9 deletions app/layout/scenarios/reports/solutions/resume/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,35 @@ import React from 'react';

import { useRouter } from 'next/router';

import { useProjectCostSurfaces } from 'hooks/cost-surface';
import { useProjectUsers } from 'hooks/project-users';
import { useProject } from 'hooks/projects';
import { useScenario, useScenarioPU } from 'hooks/scenarios';
import { useProjectWDPAs } from 'hooks/wdpa';

export const ResumePage = (): JSX.Element => {
const { query } = useRouter();
const { pid, sid } = query as { pid: string; sid: string };
const projectQuery = useProject(pid);
const scenarioQuery = useScenario(sid);

const costSurfaceQuery = useProjectCostSurfaces(
pid,
{},
{
select: (data) =>
data.filter((cs) => cs.scenarios.filter((s) => s.id === sid).length > 0)?.[0],
}
);

const protectedAreaQuery = useProjectWDPAs(
pid,
{ sort: 'name' },
{
select: (data) => data.map(({ id, name }) => ({ id, name })),
}
);

const projectUsersQuery = useProjectUsers(pid);
const PUDataQuery = useScenarioPU(sid);

Expand Down Expand Up @@ -40,12 +59,12 @@ export const ResumePage = (): JSX.Element => {

<div className={SECTION_CLASSES}>
<h3 className={TITLE_CLASSES}>Cost surface:</h3>
<p className={TEXT_CLASSES}>Lorem Ipsum</p>
<p className={TEXT_CLASSES}>{costSurfaceQuery.data?.name}</p>
</div>

{projectQuery.data?.planningUnitAreakm2 && (
<div className={SECTION_CLASSES}>
<h3 className={TITLE_CLASSES}>Planning Area (KM2):</h3>
<h3 className={TITLE_CLASSES}>Planning Unit Grid Area (KM2):</h3>
<p className={TEXT_CLASSES}>{projectQuery.data?.planningUnitAreakm2}</p>
</div>
)}
Expand All @@ -56,24 +75,22 @@ export const ResumePage = (): JSX.Element => {
<p className={TEXT_CLASSES}>{projectQuery.data?.planningUnitGridShape}</p>
</div>
)}

<div className={SECTION_CLASSES}>
<h3 className={TITLE_CLASSES}>Planning Unit Grid Area:</h3>
<p className={TEXT_CLASSES}>Lorem Ipsum</p>
</div>
</div>
<div>
<div className={SECTION_CLASSES}>
<h3 className={TITLE_CLASSES}>Protected Areas:</h3>
<p className={TEXT_CLASSES}>Lorem Ipsum</p>
<p className={TEXT_CLASSES}>
{protectedAreaQuery.data?.map(({ name }) => name).join(', ')}
</p>
</div>

<div className={SECTION_CLASSES}>
<h3 className={TITLE_CLASSES}>No. of planning units:</h3>
<div className="flex flex-col space-y-3">
<p className={TEXT_CLASSES}>Total: {PUDataQuery.data?.available.length}</p>
<p className={TEXT_CLASSES}>Available PU: {PUDataQuery.data?.available.length}</p>
<p className={TEXT_CLASSES}>Included PU: {PUDataQuery.data?.included.length}</p>
<p className={TEXT_CLASSES}>Excluded PU: {PUDataQuery.data?.excluded.length}</p>
<p className={TEXT_CLASSES}>Total PU: {PUDataQuery.data?.total}</p>
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const SolutionsTablePage = (): JSX.Element => {
const { sid } = query as { sid: string };

const solutionsQuery = useSolutions(sid);

const bestSolutionQuery = useBestSolution(sid, {});

return (
Expand Down
Loading