Skip to content

Commit 0244ee8

Browse files
committed
convert company to nested filter
move limit to top 50 from the matched company filters delete company filter, passing title to props update nested filter test remove show less logic, update icon, update unit tests adding plus icon remove typo
1 parent e05a335 commit 0244ee8

11 files changed

Lines changed: 52 additions & 170 deletions

File tree

src/components/Common/Icon/iconMap.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { ReactComponent as LineChart } from '../../../icons/line-chart-custom.sv
1414
import { ReactComponent as List } from '../../../icons/list.svg';
1515
import { ReactComponent as Map } from '../../../icons/map.svg';
1616
import { ReactComponent as MinusRound } from '../../../icons/minus-round.svg';
17+
import { ReactComponent as Plus } from '../../../icons/plus.svg';
1718
import { ReactComponent as PlusRound } from '../../../icons/plus-round.svg';
1819
import { ReactComponent as Printer } from '../../../icons/print.svg';
1920
import { ReactComponent as Right } from '../../../icons/right.svg';
@@ -52,6 +53,7 @@ const iconMap = {
5253
map: <Map />,
5354
// cf-icon-svg--minus-round
5455
'minus-round': <MinusRound />,
56+
plus: <Plus />,
5557
// cf-icon-svg--plus-round
5658
'plus-round': <PlusRound />,
5759
// cf-icon-svg--print

src/components/Filters/Company/Company.js

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

src/components/Filters/Company/Company.spec.js

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

src/components/Filters/Company/fixture.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/components/Filters/FilterPanel/FilterPanel.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import './FilterPanel.scss';
2-
import { Company } from '../Company/Company';
32
import { CompanyReceivedFilter } from '../Date/CompanyReceivedFilter';
43
import { useDispatch, useSelector } from 'react-redux';
54
import { DateFilter } from '../Date/DateFilter';
@@ -55,6 +54,7 @@ export const FilterPanel = () => {
5554
'in the complaint'
5655
}
5756
fieldName="product"
57+
filterTitle="Product / Sub-product"
5858
/>
5959
<hr />
6060
<NestedFilter
@@ -63,13 +63,21 @@ export const FilterPanel = () => {
6363
'in the complaint'
6464
}
6565
fieldName="issue"
66+
filterTitle="Issue / Sub-issue"
6667
/>
6768
<hr />
6869
<FederalState />
6970
<hr />
7071
<ZipCode />
7172
<hr />
72-
<Company />
73+
<NestedFilter
74+
desc={
75+
'The type of issue and sub-issue the consumer identified ' +
76+
'in the complaint'
77+
}
78+
fieldName="company"
79+
filterTitle="Company"
80+
/>
7381
<hr />
7482
<SimpleFilter
7583
title="Did company provide a timely response?"
Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
import PropTypes from 'prop-types';
22
import { createElement, useState } from 'react';
3+
import getIcon from '../../Common/Icon/iconMap';
34

4-
//TODO: will make much less complex in implementation
55
export const MoreOrLess = ({
66
listComponent,
77
listComponentProps = {},
88
options,
99
perBucketProps = (bucket, props) => props,
10-
hasMore = false,
1110
}) => {
12-
const [currentlyHasMore, setCurrentlyHasMore] = useState(hasMore);
13-
14-
const all = options;
15-
const some = all.length > 5 ? all.slice(0, 5) : all;
16-
const remain = all.length - 5;
17-
11+
const [limit, setLimit] = useState(5);
12+
const step = 50;
13+
const some = options.slice(0, limit);
14+
// either 50, or remaining count
15+
const nextStep = step < options.length ? step : options.length - limit;
1816
const buildListComponent = (bucket) => {
1917
const itemProps = perBucketProps(bucket, {
2018
...listComponentProps,
@@ -28,25 +26,20 @@ export const MoreOrLess = ({
2826
};
2927

3028
const toggleShowMore = () => {
31-
setCurrentlyHasMore(!currentlyHasMore);
29+
setLimit(limit + nextStep);
3230
};
3331

3432
return (
3533
<>
36-
<ul>
37-
{currentlyHasMore
38-
? all.map((bucket) => buildListComponent(bucket))
39-
: some.map((bucket) => buildListComponent(bucket))}
40-
</ul>
41-
{remain > 0 ? (
34+
<ul>{some.map((bucket) => buildListComponent(bucket))}</ul>
35+
{some.length < options.length && (
4236
<div>
4337
<button className="a-btn a-btn--link more" onClick={toggleShowMore}>
44-
{currentlyHasMore
45-
? `- Show ${remain} less`
46-
: `+ Show ${remain} more`}
38+
{getIcon('plus')}
39+
<span>{`Show ${nextStep} more`}</span>
4740
</button>
4841
</div>
49-
) : null}
42+
)}
5043
</>
5144
);
5245
};
@@ -60,5 +53,4 @@ MoreOrLess.propTypes = {
6053
listComponentProps: PropTypes.object,
6154
options: PropTypes.array.isRequired,
6255
perBucketProps: PropTypes.func,
63-
hasMore: PropTypes.bool,
6456
};

src/components/Filters/MoreOrLess/MoreOrLess.spec.js

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,28 @@ describe('component:MoreOrLess', () => {
2424

2525
beforeEach(() => {
2626
props = {
27-
hasMore: true,
2827
listComponent: AggregationItem,
29-
listComponentProps: { fieldName: 'myfield' },
28+
listComponentProps: { fieldName: 'product' },
3029
options: fixture,
3130
};
3231
});
3332

3433
it('displays and toggles properly when more results are available', async () => {
3534
renderComponent(props);
36-
37-
const lessButton = screen.getByRole('button', { name: /Show 3 less/ });
38-
expect(lessButton).toBeInTheDocument();
39-
40-
await user.click(lessButton);
4135
expect(
4236
screen.getByRole('button', { name: /Show 3 more/ }),
4337
).toBeInTheDocument();
4438
});
4539

4640
it('displays and toggles properly when no more results are available', async () => {
47-
props.hasMore = false;
4841
renderComponent(props);
49-
50-
const moreButton = screen.getByRole('button', { name: /Show 3 more/ });
51-
expect(moreButton).toBeInTheDocument();
52-
53-
await user.click(moreButton);
5442
expect(
55-
screen.getByRole('button', { name: /Show 3 less/ }),
43+
screen.getByRole('button', { name: /Show 3 more/ }),
5644
).toBeInTheDocument();
45+
46+
await user.click(screen.getByRole('button', { name: /Show 3 more/ }));
47+
expect(
48+
screen.queryByRole('button', { name: /Show 3 more/ }),
49+
).not.toBeInTheDocument();
5750
});
5851
});

src/components/Filters/NestedFilter/NestedFilter.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { MODE_TRENDS } from '../../../constants';
22
import { AggregationBranch } from '../Aggregation/AggregationBranch/AggregationBranch';
33
import { CollapsibleFilter } from '../CollapsibleFilter/CollapsibleFilter';
44
import { useSelector } from 'react-redux';
5-
import { capitalize, sortSelThenCount } from '../../../utils';
5+
import { sortSelThenCount } from '../../../utils';
66
import { MoreOrLess } from '../MoreOrLess/MoreOrLess';
77
import {
88
selectTrendsFocus,
@@ -51,16 +51,18 @@ export const generateOptions = (
5151
}
5252
});
5353
}
54+
5455
return options;
5556
};
5657

5758
/**
5859
* @param {object} params - Params needed to initialize the filter
5960
* @param {string} params.desc - Description of the filter, used in mouseover tooltips
6061
* @param {string} params.fieldName - Name of the filter field, used to pick out aggregations
62+
* @param {string} params.filterTitle - Name of the filter group, Zip Code, Product / Sub-product
6163
* @returns {JSX.Element} Element containing a collapsible filter with a list of options
6264
*/
63-
export const NestedFilter = ({ desc, fieldName }) => {
65+
export const NestedFilter = ({ desc, fieldName, filterTitle }) => {
6466
const { data, error } = useGetAggregations();
6567
// See if there are any active product filters
6668
const filtersState = useSelector(selectFiltersRoot);
@@ -92,7 +94,7 @@ export const NestedFilter = ({ desc, fieldName }) => {
9294

9395
return (
9496
<CollapsibleFilter
95-
title={capitalize(fieldName) + ' / sub-' + fieldName}
97+
title={filterTitle}
9698
desc={desc}
9799
className={'aggregation ' + fieldName}
98100
>
@@ -112,4 +114,5 @@ export const NestedFilter = ({ desc, fieldName }) => {
112114
NestedFilter.propTypes = {
113115
desc: PropTypes.string.isRequired,
114116
fieldName: PropTypes.string.isRequired,
117+
filterTitle: PropTypes.string.isRequired,
115118
};

src/components/Filters/NestedFilter/NestedFilter.spec.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,16 @@ const renderComponent = (newFiltersState, newTrendsState, newViewState) => {
2323
view: newViewState,
2424
};
2525

26-
render(<NestedFilter desc="Product filter" fieldName="product" />, {
27-
preloadedState: data,
28-
});
26+
render(
27+
<NestedFilter
28+
desc="Product filter"
29+
fieldName="product"
30+
filterTitle="Product / Sub-product"
31+
/>,
32+
{
33+
preloadedState: data,
34+
},
35+
);
2936
};
3037

3138
fetchMock.enableMocks();
@@ -59,7 +66,7 @@ describe('component:NestedFilter', () => {
5966
expect(screen.getAllByRole('checkbox').length).toBe(5);
6067
// show only 5 items
6168
expect(
62-
screen.getByRole('button', { name: '+ Show 1 more' }),
69+
screen.getByRole('button', { name: /Show 1 more/ }),
6370
).toBeInTheDocument();
6471
});
6572

src/components/Search/SearchPanel.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { SearchPanel } from './SearchPanel';
22
import { screen, testRender as render } from '../../testUtils/test-utils';
33
import fetchMock from 'jest-fetch-mock';
4-
import { aggResponse } from '../Filters/Company/fixture';
4+
import { aggResponse } from '../../api/fixture';
55

66
const renderComponent = () => {
77
const data = {

0 commit comments

Comments
 (0)