Skip to content

Commit

Permalink
Merge pull request #708 from wri/release/tacky-teak
Browse files Browse the repository at this point in the history
[RELEASE] Tacky Teak
  • Loading branch information
roguenet authored Dec 2, 2024
2 parents ced7725 + 2df8bc5 commit bcb0891
Show file tree
Hide file tree
Showing 77 changed files with 4,256 additions and 1,126 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'
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
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"
});
15 changes: 15 additions & 0 deletions src/admin/apiProvider/dataProviders/userDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import {
fetchGetV2AdminUsersExport,
fetchGetV2AdminUsersMulti,
fetchGetV2AdminUsersUUID,
fetchPostV2AdminUsersCreate,
fetchPutV2AdminUsersUUID,
GetV2AdminUsersError,
GetV2AdminUsersExportError,
GetV2AdminUsersMultiError,
GetV2AdminUsersUUIDError,
PostV2AdminUsersCreateError,
PutV2AdminUsersUUIDError
} from "@/generated/apiComponents";
import { V2AdminUserRead } from "@/generated/apiSchemas";
Expand All @@ -34,6 +36,19 @@ const normalizeUserObject = (item: V2AdminUserRead) => ({
});

export const userDataProvider: UserDataProvider = {
//@ts-ignore
async create(__, params) {
try {
const response = await fetchPostV2AdminUsersCreate({
body: params.data
});

// @ts-expect-error
return { data: { ...response.data, id: response.id } };
} catch (err) {
throw getFormattedErrorForRA(err as PostV2AdminUsersCreateError);
}
},
//@ts-ignore
async getList(_, params) {
try {
Expand Down
22 changes: 22 additions & 0 deletions src/admin/components/Actions/ListActionsCreateFilter.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import DownloadIcon from "@mui/icons-material/GetApp";
import { Button, CreateButton, FilterButton, TopToolbar } from "react-admin";
import { When } from "react-if";

interface ListActionsCreateFilterProps {
isSuperAdmin?: boolean;
onExport?: () => void;
}

const ListActionsCreateFilter = ({ isSuperAdmin, onExport }: ListActionsCreateFilterProps) => (
<TopToolbar>
<When condition={isSuperAdmin}>
<CreateButton className="filter-button-page-admin" />
</When>
<FilterButton className="filter-button-page-admin" />
<When condition={!!onExport}>
<Button className="button-page-admin" label="Export" startIcon={<DownloadIcon />} onClick={onExport} />
</When>
</TopToolbar>
);

export default ListActionsCreateFilter;
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
1 change: 1 addition & 0 deletions src/admin/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const App = () => {
list={modules.user.List}
show={modules.user.Show}
edit={modules.user.Edit}
create={modules.user.Create}
icon={() => <Icon className="h-8 w-8" name={IconNames.USERS} />}
/>
<Resource
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 @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import {
fetchPostV2TerrafundValidationPolygon,
fetchPutV2ENTITYUUIDStatus,
useGetV2SitePolygonUuidVersions,
useGetV2TerrafundValidationCriteriaData,
usePostV2TerrafundClipPolygonsPolygonUuid,
usePostV2TerrafundValidationPolygon
} from "@/generated/apiComponents";
Expand Down Expand Up @@ -88,14 +87,18 @@ const PolygonDrawer = ({
const sitePolygonRefresh = context?.reloadSiteData;
const openEditNewPolygon = contextMapArea?.isUserDrawingEnabled;
const selectedPolygon = sitePolygonData?.find((item: SitePolygon) => item?.poly_id === polygonSelected);
const { statusSelectedPolygon, setStatusSelectedPolygon, setShouldRefetchValidation } = contextMapArea;
const {
statusSelectedPolygon,
setStatusSelectedPolygon,
setShouldRefetchValidation,
polygonCriteriaMap: polygonMap
} = contextMapArea;
const { showLoader, hideLoader } = useLoading();
const { openNotification } = useNotificationContext();
const wrapperRef = useRef(null);

const { mutate: getValidations } = usePostV2TerrafundValidationPolygon({
onSuccess: () => {
reloadCriteriaValidation();
setCheckPolygonValidation(false);
openNotification(
"success",
Expand All @@ -111,16 +114,6 @@ const PolygonDrawer = ({
}
});
const mutateSitePolygons = fetchPutV2ENTITYUUIDStatus;
const { data: criteriaData, refetch: reloadCriteriaValidation } = useGetV2TerrafundValidationCriteriaData(
{
queryParams: {
uuid: polygonSelected
}
},
{
enabled: !!polygonSelected
}
);

const { mutate: clipPolygons } = usePostV2TerrafundClipPolygonsPolygonUuid({
onSuccess: async (data: ClippedPolygonResponse) => {
Expand All @@ -138,6 +131,9 @@ const PolygonDrawer = ({
await refetchPolygonVersions();
await sitePolygonRefresh?.();
await refresh?.();
if (!selectedPolygon?.primary_uuid) {
return;
}
const response = (await fetchGetV2SitePolygonUuidVersions({
pathParams: { uuid: selectedPolygon?.primary_uuid as string }
})) as SitePolygonsDataResponse;
Expand All @@ -164,7 +160,6 @@ const PolygonDrawer = ({
if (checkPolygonValidation) {
showLoader();
getValidations({ queryParams: { uuid: polygonSelected } });
reloadCriteriaValidation();
}
}, [checkPolygonValidation]);

Expand All @@ -173,13 +168,14 @@ const PolygonDrawer = ({
}, [isPolygonStatusOpen]);

useEffect(() => {
const criteriaData = polygonMap[polygonSelected];
if (criteriaData?.criteria_list && criteriaData?.criteria_list.length > 0) {
setPolygonValidationData(parseValidationData(criteriaData));
setValidationStatus(true);
} else {
setValidationStatus(false);
}
}, [criteriaData]);
}, [polygonMap, polygonSelected]);

useEffect(() => {
if (Array.isArray(sitePolygonData)) {
Expand Down Expand Up @@ -263,7 +259,6 @@ const PolygonDrawer = ({
openNotification("error", t("Error"), t("Cannot fix polygons: Polygon UUID is missing."));
}
};

return (
<div className="flex flex-1 flex-col gap-6 overflow-visible">
<div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ const AttributeInformation = ({
setIsLoadingDropdown(true);
const refreshEntity = async () => {
if (selectedPolygon?.uuid) {
await sitePolygonRefresh?.();
setIsLoadingDropdown(false);
}
};
Expand Down
Loading

0 comments on commit bcb0891

Please sign in to comment.