Skip to content

Commit 1123bcd

Browse files
committed
update filters:
consolidate filter consolidate filter save work update options delete company typeahead component since we genericized it with asynctypeaheadwrapper remove wrapper and use typeahead directly remove handleFetchSearch fixing unit test fixing nested fixing test fix test, lint fixing tests update tests update dist adding MSA and Cong Dist filters to frontend remove zipcode filter update dist
1 parent cddab0f commit 1123bcd

6 files changed

Lines changed: 134 additions & 102 deletions

File tree

dist/ccdb5.js

Lines changed: 58 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/ccdb5.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/Filters/FilterPanel/FilterPanel.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { FederalState } from '../FederalState/FederalState';
77
import { HasNarrative } from '../HasNarrative/HasNarrative';
88
import getIcon from '../../Common/Icon/iconMap';
99
import { SimpleFilter } from '../SimpleFilter/SimpleFilter';
10-
import { ZipCode } from '../ZipCode/ZipCode';
10+
import { RemoteTypeaheadFilter } from '../RemoteTypeaheadFilter/RemoteTypeaheadFilter';
1111
import { updateFilterVisibility } from '../../../reducers/view/viewSlice';
1212
import {
1313
selectViewHasFilters,
@@ -67,7 +67,29 @@ export const FilterPanel = () => {
6767
<hr />
6868
<FederalState />
6969
<hr />
70-
<ZipCode />
70+
<RemoteTypeaheadFilter
71+
desc="The metropolitan statistical area (MSA) of the mailing address provided by the consumer"
72+
fieldName="msa"
73+
labelText="Start typing to begin listing MSA names"
74+
placeholderText="Enter city or metro area name"
75+
title="Metropolitan statistical area (MSA)"
76+
/>
77+
<hr />
78+
<RemoteTypeaheadFilter
79+
desc="The mailing ZIP code provided by the consumer"
80+
fieldName="zip_code"
81+
labelText="Start typing to begin listing zip codes"
82+
placeholderText="Enter ZIP code"
83+
title="ZIP code"
84+
/>
85+
<hr />
86+
<RemoteTypeaheadFilter
87+
desc="The congressional district of the mailing address provided by the consumer, for example, `Maryland Congressional District 4`"
88+
fieldName="cong_district"
89+
labelText="Start typing to begin listing MSA names"
90+
placeholderText="Enter state name"
91+
title="Congressional District"
92+
/>
7193
<hr />
7294
<Company />
7395
<hr />
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { useSelector } from 'react-redux';
2+
import { CollapsibleFilter } from '../CollapsibleFilter/CollapsibleFilter';
3+
import { selectFiltersRoot } from '../../../reducers/filters/selectors';
4+
import { StickyOptions } from '../StickyOptions/StickyOptions';
5+
import { useGetAggregations } from '../../../api/hooks/useGetAggregations';
6+
import { AsyncTypeahead } from '../../Typeahead/AsyncTypeahead/AsyncTypeahead';
7+
import PropTypes from 'prop-types';
8+
9+
export const RemoteTypeaheadFilter = ({
10+
desc,
11+
fieldName,
12+
labelText,
13+
placeholderText,
14+
title,
15+
}) => {
16+
const { data: aggsData, error } = useGetAggregations();
17+
const filtersRoot = useSelector(selectFiltersRoot);
18+
const filters = filtersRoot?.[fieldName] || [];
19+
const aggs = error ? [] : aggsData?.[fieldName] || [];
20+
// Zip code, CD, MSA aggregations coming from API
21+
const stickyOptions = structuredClone(aggs);
22+
23+
return (
24+
<CollapsibleFilter title={title} desc={desc} className="aggregation">
25+
<AsyncTypeahead
26+
fieldName={fieldName}
27+
label={labelText}
28+
placeholder={placeholderText}
29+
ariaLabel={labelText}
30+
htmlId={fieldName + 'typeahead'}
31+
hasClearButton={true}
32+
/>
33+
<StickyOptions
34+
fieldName={fieldName}
35+
options={stickyOptions}
36+
selections={filters}
37+
/>
38+
</CollapsibleFilter>
39+
);
40+
};
41+
42+
RemoteTypeaheadFilter.propTypes = {
43+
desc: PropTypes.string.isRequired,
44+
fieldName: PropTypes.string.isRequired,
45+
labelText: PropTypes.string.isRequired,
46+
placeholderText: PropTypes.string.isRequired,
47+
title: PropTypes.string.isRequired,
48+
};

src/components/Filters/ZipCode/ZipCode.spec.js renamed to src/components/Filters/RemoteTypeaheadFilter/RemoteTypeaheadFilter.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import userEvent from '@testing-library/user-event';
77
import fetchMock from 'jest-fetch-mock';
88
import * as filterActions from '../../../reducers/filters/filtersSlice';
99
import { filtersState } from '../../../reducers/filters/filtersSlice';
10-
import { ZipCode } from './ZipCode';
10+
import { RemoteTypeaheadFilter } from './RemoteTypeaheadFilter';
1111
import { cloneDeep, merge } from 'lodash';
1212
import { aggResponse } from '../../List/ListPanel/fixture';
1313

@@ -21,12 +21,12 @@ const renderComponent = (newFiltersState) => {
2121
routes: { queryString: '?foo=bar' },
2222
};
2323

24-
render(<ZipCode />, {
24+
render(<RemoteTypeaheadFilter />, {
2525
preloadedState: data,
2626
});
2727
};
2828

29-
describe('ZipCode', () => {
29+
describe('RemoteTypeaheadFilter', () => {
3030
let zipAggsResponse;
3131
beforeEach(() => {
3232
fetchMock.resetMocks();

src/components/Filters/ZipCode/ZipCode.js

Lines changed: 0 additions & 38 deletions
This file was deleted.

0 commit comments

Comments
 (0)