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

PIMS-1660 BC Assessment #2397

Merged
merged 19 commits into from
Jun 25, 2024
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
42 changes: 42 additions & 0 deletions react-app/src/hooks/api/useBCAssessmentApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { ConfigContext } from '@/contexts/configContext';
import { FeatureCollection } from 'geojson';
import { useContext } from 'react';

const useBCAssessmentApi = () => {
const config = useContext(ConfigContext);
const isProd = config?.NODE_ENV === 'production';
const prodURL =
'https://apps.gov.bc.ca/ext/sgw/geo.bca?REQUEST=GetFeature&SERVICE=WFS&VERSION=2.0.0&typeName=geo.bca:WHSE_HUMAN_CULTURAL_ECONOMIC.BCA_FOLIO_GNRL_PROP_VALUES_SV&outputFormat=application/json';
const testURL =
'https://test.apps.gov.bc.ca/ext/sgw/geo.bca?REQUEST=GetFeature&SERVICE=WFS&VERSION=2.0.0&typeName=geo.bca:WHSE_HUMAN_CULTURAL_ECONOMIC.BCA_FOLIO_GNRL_PROP_VALUES_SV&outputFormat=application/json';

// https://test.apps.gov.bc.ca/ext/sgw/geo.bca?REQUEST=GetFeature&SERVICE=WFS&VERSION=2.0.0&typeName=geo.bca:WHSE_HUMAN_CULTURAL_ECONOMIC.BCA_FOLIO_GNRL_PROP_VALUES_SV&outputFormat=application/json&srsName=EPSG:4326&CQL_FILTER=CONTAINS(SHAPE,SRID=4326;POINT(-123.36905121803285 48.41397415311252))
const getBCAssessmentByLocation = async (lng: string, lat: string) => {
const finalUrl = `${isProd ? prodURL : testURL}&srsName=EPSG:4326&CQL_FILTER=CONTAINS(SHAPE,SRID=4326;POINT(${lng} ${lat}))`;
// const { parsedBody } = await absoluteFetch.get(
// finalUrl,
// {},
// {
// headers: {
// // 'Access-Control-Allow-Headers': 'Origin',
// // 'Access-Control-Allow-Origin': '*',
// Origin: 'https://pims-v2-dev.apps.silver.devops.gov.bc.ca',
// Referer: 'https://pims-v2-dev.apps.silver.devops.gov.bc.ca',
// },
// credentials: 'include',
// },
// );
const response = await fetch(finalUrl, {
credentials: 'include',
});
const body = await response.json();
console.log(body);
return body as FeatureCollection;
};

return {
getBCAssessmentByLocation,
};
};

export default useBCAssessmentApi;
3 changes: 3 additions & 0 deletions react-app/src/hooks/usePimsApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import usePropertiesApi from './api/usePropertiesApi';
import useToolsApi from './api/useToolsApi';
import useParcelLayerApi from './api/useParcelLayerApi';
import useProjectsApi from './api/useProjectsApi';
import useBCAssessmentApi from '@/hooks/api/useBCAssessmentApi';
import useLtsaApi from './api/useLtsaApi';

/**
Expand All @@ -35,6 +36,7 @@ const usePimsApi = () => {
const tools = useToolsApi(fetch);
const parcelLayer = useParcelLayerApi(fetch);
const projects = useProjectsApi(fetch);
const bcAssessment = useBCAssessmentApi();
const ltsa = useLtsaApi(fetch);

return {
Expand All @@ -50,6 +52,7 @@ const usePimsApi = () => {
tools,
parcelLayer,
projects,
bcAssessment,
ltsa,
};
};
Expand Down
21 changes: 10 additions & 11 deletions react-app/src/pages/DevZone.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
/* eslint-disable no-console */
//Simple component testing area.
import { LookupContext } from '@/contexts/lookupContext';
import React, { useContext } from 'react';
import useDataLoader from '@/hooks/useDataLoader';
import usePimsApi from '@/hooks/usePimsApi';
import React, { useEffect } from 'react';

const Dev = () => {
const { data, getLookupValueById } = useContext(LookupContext);
const api = usePimsApi();
const { data, refreshData } = useDataLoader(() =>
api.bcAssessment.getBCAssessmentByLocation('-123.36905121803285', '48.41397415311252'),
);
useEffect(() => {
refreshData();
}, []);
console.log(data);
if (getLookupValueById) {
console.log(
`Get AdministrativeArea with ID 1: ${JSON.stringify(getLookupValueById('AdministrativeAreas', 1))}`,
);
console.log(
`Get RegionalDistrict with ID 19: ${JSON.stringify(getLookupValueById('RegionalDistricts', 19))}`,
);
}
return <></>;
};

Expand Down
Loading