Skip to content

Commit

Permalink
UISACQCOMP-164 Sort the list of countries based on the current locale (
Browse files Browse the repository at this point in the history
…#721)

* UISACQCOMP-164 Sort the list of countries based on the current locale

* Fix test
  • Loading branch information
usavkov-epam authored Oct 20, 2023
1 parent bf62600 commit 4a25f88
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## (5.1.0 IN PROGRESS)

* Sort the list of countries based on the current locale. Refs UISACQCOMP-164.

## [5.0.0](https://github.com/folio-org/stripes-acq-components/tree/v5.0.0) (2023-10-12)
[Full Changelog](https://github.com/folio-org/stripes-acq-components/compare/v4.0.2...v5.0.0)

Expand Down
12 changes: 8 additions & 4 deletions lib/CountryFilter/CountryFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@ import { SelectionFilter } from '../SelectionFilter';

const CountryFilter = (props) => {
const intl = useIntl();
const countriesOptions = useMemo(() => countries.map(c => ({
label: intl.formatMessage({ id: `stripes-components.countries.${c.alpha2}` }),
value: c.alpha3,
})), [intl]);
const countriesOptions = useMemo(() => (
countries
.map(c => ({
label: intl.formatDisplayName(c.alpha2, { type: 'region' }),
value: c.alpha3,
}))
.sort((a, b) => a.label.localeCompare(b.label))
), [intl]);

return (
<SelectionFilter
Expand Down
2 changes: 1 addition & 1 deletion lib/CountryFilter/CountryFilter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ describe('CountryFilter component', () => {
it('should invoke onChange callback when something is selected', async () => {
const onChangeFilter = jest.fn();
const { container, getByText } = renderFilter(false, onChangeFilter);
const afgOption = getByText('stripes-components.countries.AF');
const afgOption = getByText('AF');
const button = container.querySelector('[id="org-filter-country-selection"]');

expect(button).toBeEnabled();
Expand Down

0 comments on commit 4a25f88

Please sign in to comment.