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

Psp-6836 ensure address search matches properties consistently #3510

Merged
merged 3 commits into from
Oct 12, 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
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ export const MapStateMachineProvider: React.FC<React.PropsWithChildren<unknown>>

const geoFilter = getQueryParams(searchCriteria);

if (geoFilter?.latitude && geoFilter?.longitude) {
if (geoFilter?.PID || geoFilter?.PID_PADDED || geoFilter?.PIN) {
return mapSearch.searchMany(geoFilter);
} else if (geoFilter?.latitude && geoFilter?.longitude) {
const geoLat = Number(geoFilter.latitude);
const geoLng = Number(geoFilter.longitude);
return mapSearch.searchOneLocation(geoLat, geoLng);
Expand Down Expand Up @@ -319,6 +321,7 @@ const getQueryParams = (filter: IPropertyFilter): IGeoSearchParams => {
// The map will search for either identifier.
const pinOrPidValue = filter.pinOrPid ? filter.pinOrPid?.replace(/-/g, '') : undefined;
return {
PID_PADDED: pinOrPidValue,
PID: pinOrPidValue,
PIN: pinOrPidValue,
STREET_ADDRESS_1: filter.address,
Expand Down
1 change: 1 addition & 0 deletions source/frontend/src/constants/API.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export interface IPaginateProperties extends IPaginateParams {
export interface IGeoSearchParams {
STREET_ADDRESS_1?: string;
PID?: string;
PID_PADDED?: string;
PIN?: string;
SURVEY_PLAN_NUMBER?: string;
BBOX?: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useKeycloak } from '@react-keycloak/web';
import axios from 'axios';
import axios, { AxiosResponse } from 'axios';
import { createMemoryHistory } from 'history';
import configureMockStore from 'redux-mock-store';
import thunk from 'redux-thunk';

import * as API from '@/constants/API';
import { useApiGeocoder } from '@/hooks/pims-api/useApiGeocoder';
import { IPagedItems, IProperty } from '@/interfaces';
import filterSlice from '@/store/slices/filter/filterSlice';
import { ILookupCode, lookupCodesSlice } from '@/store/slices/lookupCodes';
import { act, cleanup, fireEvent, render, waitFor } from '@/utils/test-utils';
Expand All @@ -18,6 +20,12 @@ const onFilterChange = jest.fn<void, [IPropertyFilter]>();
//prevent web calls from being made during tests.
jest.mock('axios');
jest.mock('@react-keycloak/web');
jest.mock('@/hooks/pims-api/useApiGeocoder');

const mockApiGetSitePidsApi = jest.fn<Promise<AxiosResponse<IPagedItems<IProperty>>>, any>();
(useApiGeocoder as unknown as jest.Mock<Partial<typeof useApiGeocoder>>).mockReturnValue({
getSitePidsApi: mockApiGetSitePidsApi,
});

const mockedAxios = axios as jest.Mocked<typeof axios>;
const mockKeycloak = (claims: string[]) => {
Expand Down
15 changes: 11 additions & 4 deletions source/frontend/src/features/properties/filter/PropertyFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import styled from 'styled-components';
import { ResetButton, SearchButton } from '@/components/common/buttons';
import { Form, Input, Select } from '@/components/common/form';
import { TableSort } from '@/components/Table/TableSort';
import { useGeocoderRepository } from '@/hooks/useGeocoderRepository';
import { useRouterFilter } from '@/hooks/useRouterFilter';
import { FilterBarSchema } from '@/utils/YupSchema';

Expand Down Expand Up @@ -49,6 +50,8 @@ export const PropertyFilter: React.FC<React.PropsWithChildren<IPropertyFilterPro
}) => {
const [propertyFilter, setPropertyFilter] = useState<IPropertyFilter>(defaultFilter);

const { getSitePids } = useGeocoderRepository();

useRouterFilter<IPropertyFilter>({
filter: propertyFilter,
setFilter: filter => {
Expand Down Expand Up @@ -111,7 +114,6 @@ export const PropertyFilter: React.FC<React.PropsWithChildren<IPropertyFilterPro
]}
className="idir-input-group"
onChange={() => {
setFieldValue('pinOrPid', '');
setFieldValue('latitude', null);
setFieldValue('longitude', null);
}}
Expand All @@ -126,9 +128,14 @@ export const PropertyFilter: React.FC<React.PropsWithChildren<IPropertyFilterPro
data-testid="geocoder-mapview"
field="address"
placeholder="Enter an address"
onSelectionChanged={val => {
setFieldValue('latitude', val.latitude);
setFieldValue('longitude', val.longitude);
onSelectionChanged={async val => {
const geocoderPidResponse = await getSitePids(val.siteId);
if (geocoderPidResponse?.pids?.length === 1) {
setFieldValue('pinOrPid', geocoderPidResponse?.pids[0]);
} else {
setFieldValue('latitude', val.latitude);
setFieldValue('longitude', val.longitude);
}
}}
value={values.address}
autoSetting="off"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createMemoryHistory } from 'history';

import * as API from '@/constants/API';
import Claims from '@/constants/claims';
import { useApiGeocoder } from '@/hooks/pims-api/useApiGeocoder';
import { useApiProperties } from '@/hooks/pims-api/useApiProperties';
import { IPagedItems, IProperty } from '@/interfaces';
import { mockParcel } from '@/mocks/filterData.mock';
Expand All @@ -23,6 +24,11 @@ const mockApiGetPropertiesPagedApi = jest.fn<Promise<AxiosResponse<IPagedItems<I
getPropertiesPagedApi: mockApiGetPropertiesPagedApi,
});

const mockApiGetSitePidsApi = jest.fn<Promise<AxiosResponse<IPagedItems<IProperty>>>, any>();
(useApiGeocoder as unknown as jest.Mock<Partial<typeof useApiGeocoder>>).mockReturnValue({
getSitePidsApi: mockApiGetSitePidsApi,
});

const mockAxios = new MockAdapter(axios);
const history = createMemoryHistory();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const usePimsPropertyLayer = () => {
const geoserver_params = {
STREET_ADDRESS_1: params?.STREET_ADDRESS_1,
PID: params?.PID,
PID_PADDED: params?.PID_PADDED,
PIN: params?.PIN,
SURVEY_PLAN_NUMBER: params?.SURVEY_PLAN_NUMBER,
};
Expand Down