Skip to content

Commit

Permalink
Merge branch 'staging' of https://github.com/wri/wri-terramatch-website
Browse files Browse the repository at this point in the history
… into monitoring
  • Loading branch information
dottyy committed Nov 26, 2024
2 parents 5379aa3 + c624244 commit e2fb3f6
Show file tree
Hide file tree
Showing 188 changed files with 7,798 additions and 2,861 deletions.
16 changes: 4 additions & 12 deletions .env.local.sample
Original file line number Diff line number Diff line change
@@ -1,17 +1,9 @@
# Local dev configuration
NEXT_PUBLIC_API_BASE_URL='http://localhost:8080'
NEXT_PUBLIC_USER_SERVICE_URL='http://localhost:4010'
NEXT_PUBLIC_JOB_SERVICE_URL='http://localhost:4020'

# Accessing staging instead of local BE
NEXT_PUBLIC_API_BASE_URL='https://api-staging.terramatch.org'

NEXT_PUBLIC_MAPBOX_ACCESS_TOKEN =
# Valid values are "local", "dev", "test", "staging", "prod"
NEXT_PUBLIC_TARGET_ENV = "local"

# Get these two values securely from another dev or from Transifex directly.
TRANSIFEX_TOKEN =
TRANSIFEX_SECRET =
TRANSIFEX_TRANSLATIONS_TTL_SEC = 10

NEXT_PUBLIC_GEOSERVER_URL =
NEXT_PUBLIC_GEOSERVER_WORKSPACE =

IMAGE_DOMAINS = 'localhost,wri.s3.us-west-2.amazonaws.com,s3-eu-west-1.amazonaws.com'
27 changes: 27 additions & 0 deletions .husky/prepare-commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh

COMMIT_MSG_FILE=$1

# get current branch
branchName=`git rev-parse --abbrev-ref HEAD`

# search jira issue id in a pattern such a "fix/TM-123-description"
# regex tries to see if TM-#### is the branch name and extract that, otherwise return empty.
jira_id=$(echo $branchName | sed -E 's~^([a-z]+/(TM\-[0-9]+).*)|(.+)$~\2~')

# Test to see if jira_id is empty
if [ -z $jira_id ]; then
exit 0
fi

# Test the commit message file to see if the Jira ID is already prepended. If so, exit.
grep -Eq "^\[$jira_id\]" $COMMIT_MSG_FILE

if [ $? -eq 0 ]; then
exit 0
fi

# only prepare commit message if pattern matched and jira_id was found
if [ ! -z $jira_id ]; then
sed -i.bak -e "1s|^|\[$jira_id\] |" $COMMIT_MSG_FILE
fi
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://new-wri-staging.wri-restoration-marketplace-api.com";
process.env.NEXT_PUBLIC_API_BASE_URL = "https://api-staging.terramatch.org";
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ yarn generate:services
```

When adding a new **service** app to the v3 API:
* In your local .env, define the service URL
* In `constants.environment.ts, define the service URL for all ENVIRONMENTS.
* In `openapi-codegen.config.ts`, add the new service name to the `SERVICES` object (e.g. `foo-service`).
* This will generate a new target, which needs to be added to `package.json`:
* Under scripts, add `"generate:fooService": "npm run generate:fooService"`
Expand Down
45 changes: 43 additions & 2 deletions openapi-codegen.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,60 @@ const f = ts.factory;

dotenv.config();

// constants/environment.ts can't be imported here, so the bits that are relevant are adopted to this file
const ENVIRONMENT_NAMES = ["local", "dev", "test", "staging", "prod"] as const;
type EnvironmentName = (typeof ENVIRONMENT_NAMES)[number];

type Environment = {
apiBaseUrl: string;
userServiceUrl: string;
};

const ENVIRONMENTS: { [Property in EnvironmentName]: Environment } = {
local: {
apiBaseUrl: "http://localhost:8080",
userServiceUrl: "http://localhost:4010"
},
dev: {
apiBaseUrl: "https://api-dev.terramatch.org",
userServiceUrl: "https://api-dev.terramatch.org"
},
test: {
apiBaseUrl: "https://api-test.terramatch.org",
userServiceUrl: "https://api-test.terramatch.org"
},
staging: {
apiBaseUrl: "https://api-staging.terramatch.org",
userServiceUrl: "https://api-staging.terramatch.org"
},
prod: {
apiBaseUrl: "https://api.terramatch.org",
userServiceUrl: "https://api.terramatch.org"
}
};

const declaredEnv = (process.env.NEXT_PUBLIC_TARGET_ENV ?? "local") as EnvironmentName;
if (!ENVIRONMENT_NAMES.includes(declaredEnv as EnvironmentName)) {
throw `Environment name is not valid! [${declaredEnv}]`;
}

const DEFAULTS = ENVIRONMENTS[declaredEnv];
const apiBaseUrl = process.env.NEXT_PUBLIC_API_BASE_URL ?? DEFAULTS.apiBaseUrl;
const userServiceUrl = process.env.NEXT_PUBLIC_USER_SERVICE_URL ?? DEFAULTS.userServiceUrl;

// The services defined in the v3 Node BE codebase. Although the URL path for APIs in the v3 space
// are namespaced by feature set rather than service (a service may contain multiple namespaces), we
// isolate the generated API integration by service to make it easier for a developer to find where
// the associated BE code is for a given FE API integration.
const SERVICES = {
"user-service": process.env.NEXT_PUBLIC_USER_SERVICE_URL ?? process.env.NEXT_PUBLIC_API_BASE_URL
"user-service": userServiceUrl
};

const config: Record<string, Config> = {
api: {
from: {
source: "url",
url: `${process.env.NEXT_PUBLIC_API_BASE_URL}/documentation/v2/raw`
url: `${apiBaseUrl}/documentation/v2/raw`
},
outputDir: "src/generated",
to: async context => {
Expand Down
Binary file added public/images/about-us-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/about-us-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/about-us-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/about-us-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/about-us-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/about-us-header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/learn-more-data-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/learn-more-data-2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/learn-more-data-3.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/images/usign-platform.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 4 additions & 1 deletion sentry.client.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@

import * as Sentry from "@sentry/nextjs";

import { sentryDsn } from "@/constants/environment";

Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
dsn: sentryDsn,

// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1,

Expand Down
4 changes: 3 additions & 1 deletion sentry.edge.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

import * as Sentry from "@sentry/nextjs";

import { sentryDsn } from "@/constants/environment";

Sentry.init({
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1,
dsn: process.env.SENTRY_DSN,
dsn: sentryDsn,
// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: process.env.NODE_ENV === "development"
});
4 changes: 3 additions & 1 deletion sentry.server.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@

import * as Sentry from "@sentry/nextjs";

import { sentryDsn } from "@/constants/environment";

Sentry.init({
// Adjust this value in production, or use tracesSampler for greater control
tracesSampleRate: 1,
dsn: process.env.SENTRY_DSN,
dsn: sentryDsn,
// Setting this option to true will print useful information to the console while you're setting up Sentry.
debug: process.env.NODE_ENV === "development"
});
1 change: 1 addition & 0 deletions src/admin/apiProvider/utils/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export type UserRole =
| "admin-ppc"
| "admin-terrafund"
| "admin-hbf"
| "admin-epa-ghana-pilot"
| "project-developer"
| "project-manager";

Expand Down
20 changes: 16 additions & 4 deletions src/admin/components/Actions/ShowActions.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Box, Typography } from "@mui/material";
import { get } from "lodash";
import {
Button,
DeleteWithConfirmButton,
DeleteWithConfirmButtonProps,
EditButton,
Expand All @@ -24,6 +25,7 @@ interface IProps {
hasDelete?: boolean;
deleteProps?: DeleteWithConfirmButtonProps<any>;
hasEdit?: boolean;
toggleTestStatus?: (record: any) => void;
}

const ShowActions = ({
Expand All @@ -33,6 +35,7 @@ const ShowActions = ({
moduleName,
hasDelete = true,
hasEdit = true,
toggleTestStatus,
deleteProps = {}
}: IProps) => {
const record = useRecordContext<any>();
Expand All @@ -58,20 +61,29 @@ const ShowActions = ({
</Typography>
</When>
<TopToolbar sx={{ marginBottom: 2, marginLeft: "auto" }}>
<When condition={record && hasDelete}>
{record && toggleTestStatus && (
<Button
label="Toggle Test"
className="!text-sm !font-semibold !capitalize lg:!text-base wide:!text-md"
onClick={() => toggleTestStatus(record)}
>
<Icon className="h-5 w-5" name={record?.is_test ? IconNames.SORT_DOWN : IconNames.SORT_UP} />
</Button>
)}
{record && hasDelete && (
<DeleteWithConfirmButton
{...deleteProps}
mutationMode="undoable"
className="!text-sm !font-semibold !capitalize lg:!text-base wide:!text-md"
icon={<Icon className="h-5 w-5" name={IconNames.TRASH_PA} />}
/>
</When>
<When condition={record && hasEdit}>
)}
{record && hasEdit && (
<EditButton
className="!text-sm !font-semibold !capitalize !text-blueCustom-900 lg:!text-base wide:!text-md"
icon={<Icon className="h-6 w-6" name={IconNames.EDIT} />}
/>
</When>
)}
</TopToolbar>
</Box>
);
Expand Down
10 changes: 5 additions & 5 deletions src/admin/components/Dialogs/FrameworkSelectionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import * as yup from "yup";

import { validateForm } from "@/admin/utils/forms";
import { useUserFrameworkChoices } from "@/constants/options/userFrameworksChoices";
import { fetchGetV2AdminENTITYExportFRAMEWORK } from "@/generated/apiComponents";
import { fetchGetV2AdminENTITYPresignedUrlFRAMEWORK } from "@/generated/apiComponents";
import { EntityName } from "@/types/common";
import { downloadFileBlob } from "@/utils/network";
import { downloadPresignedUrl } from "@/utils/network";

interface FrameworkSelectionDialogContentProps {
onCancel: () => void;
Expand Down Expand Up @@ -59,11 +59,11 @@ export function useFrameworkExport(entity: EntityName, choices: any[]) {

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

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

Expand Down
10 changes: 6 additions & 4 deletions src/admin/components/EntityEdit/EntityEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { useNavigate, useParams } from "react-router-dom";
import modules from "@/admin/modules";
import WizardForm from "@/components/extensive/WizardForm";
import LoadingContainer from "@/components/generic/Loading/LoadingContainer";
import FrameworkProvider from "@/context/framework.provider";
import FrameworkProvider, { Framework } from "@/context/framework.provider";
import {
GetV2FormsENTITYUUIDResponse,
useGetV2FormsENTITYUUID,
Expand Down Expand Up @@ -49,10 +49,12 @@ export const EntityEdit = () => {
// @ts-ignore
const formData = (formResponse?.data ?? {}) as GetV2FormsENTITYUUIDResponse;

const formSteps = useGetCustomFormSteps(formData.form, {
const entity = {
entityName: pluralEntityNameToSingular(entityName),
entityUUID
});
};
const framework = formData?.form?.framework_key as Framework;
const formSteps = useGetCustomFormSteps(formData.form, entity, framework);

const defaultValues = useNormalizedFormDefaultValue(
// @ts-ignore
Expand All @@ -70,7 +72,7 @@ export const EntityEdit = () => {
return (
<div className="mx-auto w-full max-w-7xl">
<LoadingContainer loading={isLoading}>
<FrameworkProvider frameworkKey={formData?.form?.framework_key}>
<FrameworkProvider frameworkKey={framework}>
<WizardForm
steps={formSteps!}
errors={error}
Expand Down
4 changes: 3 additions & 1 deletion src/admin/components/Fields/ColoredChipFieldArray.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ function groupPolygonsByStatus(polygons: any[]) {

const ColoredChipFieldArray = (props: ColoredChipFieldArrayProps) => {
const recordContext = useRecordContext();
const { data: getPolygonsToSite } = useGetV2SitesSitePolygon({ pathParams: { site: recordContext.uuid } });
const { data: getPolygonsToSite } = useGetV2SitesSitePolygon({
pathParams: { site: recordContext.uuid }
});

if (!getPolygonsToSite?.length || !Array.isArray(getPolygonsToSite)) {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { Else, If, Then, When } from "react-if";
import ChangeRow from "@/admin/components/ResourceTabs/ChangeRequestsTab/ChangeRow";
import useFormChanges from "@/admin/components/ResourceTabs/ChangeRequestsTab/useFormChanges";
import List from "@/components/extensive/List/List";
import { Framework } from "@/context/framework.provider";
import { useGetV2FormsENTITYUUID } from "@/generated/apiComponents";
import { getCustomFormSteps } from "@/helpers/customForms";
import { EntityName, SingularEntityName } from "@/types/common";
Expand Down Expand Up @@ -46,6 +47,7 @@ const ChangeRequestsTab: FC<IProps> = ({ label, entity, singularEntity, ...rest

// @ts-ignore
const changeRequest = currentValues?.data?.update_request;
const framework = changeRequest?.framework_key as Framework;
const changes = changeRequest?.content;
// @ts-ignore
const current = currentValues?.data?.answers;
Expand All @@ -54,7 +56,7 @@ const ChangeRequestsTab: FC<IProps> = ({ label, entity, singularEntity, ...rest
// @ts-ignore
const form = currentValues?.data?.form;

const formSteps = useMemo(() => (form == null ? [] : getCustomFormSteps(form, t)), [form, t]);
const formSteps = useMemo(() => (form == null ? [] : getCustomFormSteps(form, t, undefined, framework)), [form, t]);
const formChanges = useFormChanges(current, changes, formSteps ?? []);
const numFieldsAffected = useMemo(
() =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,26 @@ const HighLevelMetics: FC = () => {
</Labeled>
</When>
</ContextCondition>
<ContextCondition frameworksShow={[Framework.PPC]}>
<When
condition={
resource === "projectReport" &&
record?.direct_restoration_partners !== undefined &&
record?.indirect_restoration_partners !== undefined
}
>
<Labeled label="Total Number of Restoration Partners (allowing double-counting)" sx={inlineLabelSx}>
<NumberField
source="total_restoration_partners"
record={{
total_restoration_partners:
(record.direct_restoration_partners || 0) + (record.indirect_restoration_partners || 0)
}}
emptyText="0"
/>
</Labeled>
</When>
</ContextCondition>
</Stack>
</Box>
</Card>
Expand Down
Loading

0 comments on commit e2fb3f6

Please sign in to comment.