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

[RELEASE] Horrible Hackberry #224

Merged
merged 43 commits into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
c1b8ae0
Merge pull request #183 from wri/unnecessary-code-removal
roguenet May 15, 2024
c59e3e6
TM-755 add total fields to trees planted and seedlings
LimberHope May 17, 2024
5864a1b
Merge pull request #191 from wri/main
roguenet May 17, 2024
3f53462
change title to totals
LimberHope May 21, 2024
464d7c2
feat: TM-936 add hbf option
LimberHope May 22, 2024
6c4b892
Merge pull request #199 from wri/TM-936_ensure_hbf_landing_pages
LimberHope May 22, 2024
96021c5
Merge pull request #197 from wri/TM-755_add_total_fields_to_site_repo…
LimberHope May 22, 2024
16164dc
feat: TM-936 change logic to useFramework
LimberHope May 22, 2024
9576517
Merge pull request #200 from wri/TM-936_ensure_hbf_landing_pages
LimberHope May 22, 2024
4aa1b11
Merge pull request #204 from wri/main
roguenet May 23, 2024
d0498ce
feat: TM-936 addhbf option to site and nursery landing pages
LimberHope May 23, 2024
cfc3059
Merge pull request #205 from wri/TM-936_add_option_hbf_to_site_and_nu…
LimberHope May 23, 2024
ac0316f
[TM-786] Clear up some warnings in modal tests.
roguenet May 23, 2024
4cd861f
[TM-786] Test against staging
roguenet May 23, 2024
5061236
[TM-786] Regenerate out of date snapshots
roguenet May 23, 2024
4e40da0
[TM-786] Update hook tests to match old code changes.
roguenet May 23, 2024
5c3c02d
[TM-786] Add storyshots for the workday collapse grid storybook
roguenet May 23, 2024
12a3e4a
[TM-786] Regenerate storyshots
roguenet May 23, 2024
9e4d93e
[TM-929] Turn it into a real hook and reduce duplicated code.
roguenet May 24, 2024
ba3363e
[TM-929] Reduce code duplication in managing the framework selection …
roguenet May 24, 2024
891b4f8
[TM-929] This can be further optimized because they all use the same …
roguenet May 24, 2024
40cff6c
[TM-929] Support framework key on nursery and nursery report.
roguenet May 24, 2024
3c61cc1
Merge pull request #210 from wri/feat/TM-929-filter-nurseries-framework
roguenet May 24, 2024
65a9861
Merge pull request #213 from wri/feat/TM-929-filter-nurseries-framework
roguenet May 27, 2024
ef9afee
Merge remote-tracking branch 'refs/remotes/origin/staging' into feat/…
roguenet May 27, 2024
e71ad72
[TM-786] Handle some warnings in the codebase to help clean up jest o…
roguenet May 27, 2024
3e9dd67
[TM-786] Set up test of github actions
roguenet May 27, 2024
cb1a2a0
[TM-786] Add .nvmrc to match our node version on prod
roguenet May 27, 2024
4f54959
[TM-786] Run test action on pull requests.
roguenet May 27, 2024
4ba0d87
[TM-786] Fix some generic typing.
roguenet May 28, 2024
82af918
[TM-786] Fix a hook dependency warning.
roguenet May 28, 2024
8af11c8
Merge pull request #215 from wri/feat/TM-786-unit-test-linting
roguenet May 28, 2024
9c09232
chore(deps): bump pug from 3.0.2 to 3.0.3
dependabot[bot] May 28, 2024
7b0687c
Merge pull request #217 from wri/dependabot/npm_and_yarn/pug-3.0.3
roguenet May 28, 2024
d18ae24
[TM-938] Include the self-reported numbers in the project/site high l…
roguenet May 29, 2024
883d999
Merge pull request #220 from wri/fit/TM-938-site-project-workdays
roguenet May 29, 2024
561bed4
[TM-938] Update labels after product review.
roguenet May 29, 2024
3f42cfb
Merge pull request #221 from wri/fit/TM-938-site-project-workdays
roguenet May 29, 2024
0384387
feat: TM-936 change HBF -> Harit Bharat Fund
LimberHope May 29, 2024
a7f0bb1
Merge pull request #222 from wri/TM-936_ensure_harit_bharat_fund_land…
LimberHope May 29, 2024
610c8e1
feat: TM-936 change hbf -> Harit Bharat Fund to my projects page
LimberHope May 30, 2024
9da6aa6
[TM-938] revert: change workdays_count to self_reported_workdays_coun…
pachonjcl May 30, 2024
fd83d87
Merge pull request #225 from wri/TM-936_hbf_landing_pages
LimberHope May 30, 2024
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
16 changes: 16 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: pull-request
on:
pull_request:
branches: [main, staging, release/**]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Install modules
run: yarn
- name: Test
run: yarn run jest --ci
2 changes: 1 addition & 1 deletion .jest/setEnvVars.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
process.env.NODE_ENV = "test";
process.env.NEXT_PUBLIC_API_BASE_URL = "https://test.wrirestorationmarketplace.cubeapis.com";
process.env.NEXT_PUBLIC_API_BASE_URL = "https://new-wri-staging.wri-restoration-marketplace-api.com";
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
18.17.0
42 changes: 39 additions & 3 deletions src/admin/components/Dialogs/FrameworkSelectionDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { CheckCircle, InfoOutlined } from "@mui/icons-material";
import { Button, Dialog, DialogActions, DialogContent, DialogProps, DialogTitle } from "@mui/material";
import { FC, useMemo } from "react";
import { capitalize, split } from "lodash";
import { FC, useCallback, useMemo, useState } from "react";
import { AutocompleteInput, Form } from "react-admin";
import { FieldValues } from "react-hook-form";
import * as yup from "yup";

import { validateForm } from "@/admin/utils/forms";
import { useGetV2AdminReportingFrameworks } from "@/generated/apiComponents";
import { Option } from "@/types/common";
import { fetchGetV2AdminENTITYExportFRAMEWORK, useGetV2AdminReportingFrameworks } from "@/generated/apiComponents";
import { EntityName, Option } from "@/types/common";
import { downloadFileBlob } from "@/utils/network";
import { optionToChoices } from "@/utils/options";

interface FrameworkSelectionDialogContentProps {
Expand Down Expand Up @@ -57,6 +59,40 @@ const FrameworkSelectionDialogContent: FC<FrameworkSelectionDialogContentProps>
);
};

export function useFrameworkExport(entity: EntityName) {
const [exporting, setExporting] = useState(false);
const [modalOpen, setModalOpen] = useState(false);

const onExport = useCallback(
(framework: string) => {
setExporting(true);

const exportPrefix = split(entity, "-").map(capitalize).join(" ");

fetchGetV2AdminENTITYExportFRAMEWORK({
pathParams: { entity, framework }
})
.then((response: any) => {
downloadFileBlob(response, `${exportPrefix} - ${framework}.csv`);
})
.finally(() => setExporting(false));

setModalOpen(false);
},
[entity]
);

return {
exporting,
openExportDialog: useCallback(() => setModalOpen(true), []),
frameworkDialogProps: {
open: modalOpen,
onCancel: useCallback(() => setModalOpen(false), []),
onExport
}
};
}

interface FrameworkSelectionDialogProps extends DialogProps {
onExport: (framework: string) => void;
onCancel: () => void;
Expand Down
15 changes: 2 additions & 13 deletions src/admin/components/Fields/FrameworkField.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
import { FC, useEffect, useState } from "react";
import { FC } from "react";
import { FunctionField } from "react-admin";

import { useFrameworkChoices } from "@/constants/options/frameworks";

const FrameworkField: FC = () => {
const [frameworkChoices, setFrameworkChoices] = useState<any>([]);
const fetchData = async () => {
try {
const choices = await useFrameworkChoices();
setFrameworkChoices(choices);
} catch (error) {
console.error("Error fetching framework choices:", error);
}
};
const frameworkChoices = useFrameworkChoices();

useEffect(() => {
fetchData();
}, []);
return (
<FunctionField
source="framework_key"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ const HighLevelMetics: FC = () => {
</Labeled>
</When>
<When condition={record?.framework_key === "ppc"}>
<Labeled label="Workdays Created" sx={inlineLabelSx}>
<Labeled label="Workdays Created (Old Calculation)" sx={inlineLabelSx}>
<NumberField source="self_reported_workday_count" emptyText="0" />
</Labeled>
<Labeled label="Workdays Created (New Calculation)" sx={inlineLabelSx}>
<NumberField source="workday_count" emptyText="0" />
</Labeled>
</When>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ const HighLevelMetics: FC = () => {
<Box paddingX={3.75} paddingY={2}>
<Stack gap={3}>
<When condition={isPPC}>
<Labeled label="Total Number Of Workdays Created" sx={inlineLabelSx}>
<Labeled label="Workdays Created (Old Calculation)" sx={inlineLabelSx}>
<NumberField source="self_reported_workday_count" emptyText="0" />
</Labeled>
<Labeled label="Workdays Created (New Calculation)" sx={inlineLabelSx}>
<NumberField source="workday_count" emptyText="0" />
</Labeled>
</When>
Expand Down
34 changes: 33 additions & 1 deletion src/admin/components/ResourceTabs/InformationTab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import { MonitoringPartnersTable } from "@/admin/components/ResourceTabs/Informa
import SeedingsTable from "@/admin/components/Tables/SeedingsTable";
import { setDefaultConditionalFieldsAnswers } from "@/admin/utils/forms";
import List from "@/components/extensive/List/List";
import { GetV2FormsENTITYUUIDResponse, useGetV2FormsENTITYUUID } from "@/generated/apiComponents";
import {
GetV2FormsENTITYUUIDResponse,
useGetV2FormsENTITYUUID,
useGetV2SeedingsENTITYUUID
} from "@/generated/apiComponents";
import { getCustomFormSteps, normalizedFormDefaultValue } from "@/helpers/customForms";
import { pluralEntityNameToSingular } from "@/helpers/entity";
import { EntityName } from "@/types/common";
Expand Down Expand Up @@ -53,6 +57,14 @@ const InformationTab: FC<IProps> = props => {
}
});

const { data: seedlings } = useGetV2SeedingsENTITYUUID({
pathParams: {
uuid: record?.uuid,
entity: resource.replace("Report", "-report")
}
});

const totalSeedlings = seedlings?.data?.reduce((acc, curr) => acc + (curr?.amount ?? 0), 0);
const t = useT();

const isLoading = ctxLoading || queryLoading;
Expand Down Expand Up @@ -114,10 +126,30 @@ const InformationTab: FC<IProps> = props => {
</Card>

<When condition={record}>
<When
condition={
record.framework_key === "ppc" && (props.type === "sites" || props.type === "site-reports")
}
>
<Card sx={{ padding: 3 }}>
<Typography variant="h6" component="h3" className="capitalize">
Total Trees Planted
</Typography>
{record?.total_trees_planted_count}
</Card>
</When>
<TreeSpeciesTable uuid={record.uuid} entity={resource} />
</When>

<When condition={props.type === "sites" || props.type === "site-reports"}>
<When condition={record.framework_key === "ppc"}>
<Card sx={{ padding: 3 }}>
<Typography variant="h6" component="h3" className="capitalize">
Total Seeds Planted
</Typography>
{totalSeedlings}
</Card>
</When>
<SeedingsTable uuid={record.uuid} entity={resource} />
</When>

Expand Down
40 changes: 21 additions & 19 deletions src/admin/modules/nurseries/components/NurseriesList.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Divider, Stack, Typography } from "@mui/material";
import { FC, useState } from "react";
import { FC } from "react";
import {
AutocompleteInput,
Datagrid,
DateField,
EditButton,
FunctionField,
List,
ReferenceInput,
SearchInput,
Expand All @@ -19,15 +20,17 @@ import ListActions from "@/admin/components/Actions/ListActions";
import ExportProcessingAlert from "@/admin/components/Alerts/ExportProcessingAlert";
import CustomBulkDeleteWithConfirmButton from "@/admin/components/Buttons/CustomBulkDeleteWithConfirmButton";
import CustomDeleteWithConfirmButton from "@/admin/components/Buttons/CustomDeleteWithConfirmButton";
import FrameworkSelectionDialog, { useFrameworkExport } from "@/admin/components/Dialogs/FrameworkSelectionDialog";
import { getCountriesOptions } from "@/constants/options/countries";
import { useFrameworkChoices } from "@/constants/options/frameworks";
import { getChangeRequestStatusOptions, getStatusOptions } from "@/constants/options/status";
import { fetchGetV2AdminENTITYExportFRAMEWORK } from "@/generated/apiComponents";
import { downloadFileBlob } from "@/utils/network";
import { optionToChoices } from "@/utils/options";

import modules from "../..";

const NurseryDataGrid: FC = () => {
const frameworkChoices = useFrameworkChoices();

return (
<Datagrid bulkActionButtons={<CustomBulkDeleteWithConfirmButton source="name" />}>
<TextField source="name" label="Nursery Name" />
Expand All @@ -41,6 +44,15 @@ const NurseryDataGrid: FC = () => {
<TextField source="project.name" label="Project Name" />
<TextField source="organisation.name" label="Organization" />
<DateField source="start_date" label="Establishment" locales="en-GB" />
<FunctionField
source="framework_key"
label="Framework"
render={(record: any) =>
frameworkChoices.find((framework: any) => framework.id === record?.framework_key)?.name ??
record?.framework_key
}
sortable={false}
/>
<ShowButton />
<EditButton />
<WrapperField>
Expand All @@ -51,7 +63,7 @@ const NurseryDataGrid: FC = () => {
};

export const NurseriesList: FC = () => {
const [exporting, setExporting] = useState<boolean>(false);
const frameworkChoices = useFrameworkChoices();

const filters = [
<SearchInput key="search" source="search" alwaysOn />,
Expand All @@ -68,6 +80,7 @@ export const NurseriesList: FC = () => {
>
<AutocompleteInput optionText="name" label="Organization" />
</ReferenceInput>,
<SelectInput key="framework_key" label="Framework" source="framework_key" choices={frameworkChoices} />,
<SelectInput key="status" label="Status" source="status" choices={optionToChoices(getStatusOptions())} />,
<SelectInput
key="update_request_status"
Expand All @@ -89,20 +102,7 @@ export const NurseriesList: FC = () => {
</ReferenceInput>
];

const handleExport = () => {
setExporting(true);

fetchGetV2AdminENTITYExportFRAMEWORK({
pathParams: {
entity: "nurseries",
framework: "terrafund"
}
})
.then((response: any) => {
downloadFileBlob(response, "Nurseries - terrafund.csv");
})
.finally(() => setExporting(false));
};
const { exporting, openExportDialog, frameworkDialogProps } = useFrameworkExport("nurseries");

return (
<>
Expand All @@ -112,10 +112,12 @@ export const NurseriesList: FC = () => {
<Divider />
</Stack>

<List actions={<ListActions onExport={handleExport} />} filters={filters}>
<List actions={<ListActions onExport={openExportDialog} />} filters={filters}>
<NurseryDataGrid />
</List>

<FrameworkSelectionDialog {...frameworkDialogProps} />

<ExportProcessingAlert show={exporting} />
</>
);
Expand Down
40 changes: 21 additions & 19 deletions src/admin/modules/nurseryReports/components/NurseryReportsList.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { Divider, Stack, Typography } from "@mui/material";
import { FC, useState } from "react";
import { FC } from "react";
import {
AutocompleteInput,
Datagrid,
DateField,
EditButton,
FunctionField,
List,
ReferenceInput,
SearchInput,
Expand All @@ -17,15 +18,17 @@ import {
import ListActions from "@/admin/components/Actions/ListActions";
import ExportProcessingAlert from "@/admin/components/Alerts/ExportProcessingAlert";
import CustomBulkDeleteWithConfirmButton from "@/admin/components/Buttons/CustomBulkDeleteWithConfirmButton";
import FrameworkSelectionDialog, { useFrameworkExport } from "@/admin/components/Dialogs/FrameworkSelectionDialog";
import { getCountriesOptions } from "@/constants/options/countries";
import { useFrameworkChoices } from "@/constants/options/frameworks";
import { getChangeRequestStatusOptions, getReportStatusOptions } from "@/constants/options/status";
import { fetchGetV2AdminENTITYExportFRAMEWORK } from "@/generated/apiComponents";
import { downloadFileBlob } from "@/utils/network";
import { optionToChoices } from "@/utils/options";

import modules from "../..";

const NurseryReportDataGrid: FC = () => {
const frameworkChoices = useFrameworkChoices();

return (
<Datagrid bulkActionButtons={<CustomBulkDeleteWithConfirmButton source="title" />}>
<TextField source="nursery.name" label="Nursery Name" sortable={false} />
Expand All @@ -41,14 +44,23 @@ const NurseryReportDataGrid: FC = () => {
<DateField source="due_at" label="Due Date" locales="en-GB" />
<DateField source="updated_at" label="Last Updated" locales="en-GB" />
<DateField source="submitted_at" label="Date Submitted" locales="en-GB" />
<FunctionField
source="framework_key"
label="Framework"
render={(record: any) =>
frameworkChoices.find((framework: any) => framework.id === record?.framework_key)?.name ??
record?.framework_key
}
sortable={false}
/>
<ShowButton />
<EditButton />
</Datagrid>
);
};

export const NurseryReportsList: FC = () => {
const [exporting, setExporting] = useState<boolean>(false);
const frameworkChoices = useFrameworkChoices();

const filters = [
<SearchInput key="search" source="search" alwaysOn />,
Expand Down Expand Up @@ -77,6 +89,7 @@ export const NurseryReportsList: FC = () => {
<AutocompleteInput optionText="name" label="Nursery" />
</ReferenceInput>,
<SelectInput key="country" label="Country" source="country" choices={optionToChoices(getCountriesOptions())} />,
<SelectInput key="framework_key" label="Framework" source="framework_key" choices={frameworkChoices} />,
<SelectInput key="status" label="Status" source="status" choices={optionToChoices(getReportStatusOptions())} />,
<SelectInput
key="update_request_status"
Expand All @@ -86,20 +99,7 @@ export const NurseryReportsList: FC = () => {
/>
];

const handleExport = () => {
setExporting(true);

fetchGetV2AdminENTITYExportFRAMEWORK({
pathParams: {
entity: "nursery-reports",
framework: "terrafund"
}
})
.then((response: any) => {
downloadFileBlob(response, "Nursery Reports - terrafund.csv");
})
.finally(() => setExporting(false));
};
const { exporting, openExportDialog, frameworkDialogProps } = useFrameworkExport("nursery-reports");

return (
<>
Expand All @@ -109,10 +109,12 @@ export const NurseryReportsList: FC = () => {
<Divider />
</Stack>

<List actions={<ListActions onExport={handleExport} />} filters={filters}>
<List actions={<ListActions onExport={openExportDialog} />} filters={filters}>
<NurseryReportDataGrid />
</List>

<FrameworkSelectionDialog {...frameworkDialogProps} />

<ExportProcessingAlert show={exporting} />
</>
);
Expand Down
Loading