-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UIEH-1440: Package Record - Title List Accordion - Improve Visibility…
… of Search Within/Filter/Sort options. (#1757)
- Loading branch information
1 parent
fc842b3
commit 68a7c1c
Showing
30 changed files
with
1,148 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.headline { | ||
display: flex; | ||
align-items: baseline; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { useRef } from 'react'; | ||
import { useIntl } from 'react-intl'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { Icon } from '@folio/stripes/components'; | ||
import { MultiSelectionFilter } from '@folio/stripes/smart-components'; | ||
|
||
import { SearchByCheckbox } from '../search-by-checkbox'; | ||
import { ClearButton } from '../clear-button'; | ||
import { accessTypesReduxStateShape } from '../../constants'; | ||
|
||
import styles from './access-type-filter.css'; | ||
|
||
const propTypes = { | ||
accessTypesStoreData: accessTypesReduxStateShape.isRequired, | ||
dataOptions: PropTypes.arrayOf(PropTypes.shape({ | ||
label: PropTypes.string, | ||
value: PropTypes.string, | ||
})).isRequired, | ||
handleStandaloneFilterChange: PropTypes.func.isRequired, | ||
onStandaloneFilterChange: PropTypes.func.isRequired, | ||
onStandaloneFilterToggle: PropTypes.func.isRequired, | ||
searchByAccessTypesEnabled: PropTypes.bool.isRequired, | ||
selectedValues: PropTypes.array.isRequired, | ||
showClearButton: PropTypes.bool, | ||
}; | ||
|
||
const AccessTypesFilter = ({ | ||
accessTypesStoreData, | ||
searchByAccessTypesEnabled, | ||
selectedValues, | ||
onStandaloneFilterChange, | ||
onStandaloneFilterToggle, | ||
dataOptions, | ||
handleStandaloneFilterChange, | ||
showClearButton = false, | ||
}) => { | ||
const intl = useIntl(); | ||
const labelRef = useRef(null); | ||
|
||
const accessStatusTypesExist = !!accessTypesStoreData?.items?.data?.length; | ||
const accessTypeFilterLabel = intl.formatMessage({ id: 'ui-eholdings.accessTypes.filter' }); | ||
|
||
const handleClearButtonClick = () => { | ||
onStandaloneFilterChange({ 'access-type': undefined }); | ||
labelRef.current?.focus(); | ||
}; | ||
|
||
if (accessTypesStoreData?.isLoading) { | ||
return <Icon icon="spinner-ellipsis" />; | ||
} | ||
|
||
if (!accessStatusTypesExist) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<div className={styles.headline}> | ||
<span | ||
className="sr-only" | ||
id="accessTypesFilter-label" | ||
> | ||
{intl.formatMessage({ id: 'ui-eholdings.settings.accessStatusTypes' })} | ||
</span> | ||
<SearchByCheckbox | ||
ref={labelRef} | ||
filterType="access-type" | ||
isEnabled={searchByAccessTypesEnabled} | ||
onStandaloneFilterToggle={onStandaloneFilterToggle} | ||
/> | ||
{showClearButton && ( | ||
<ClearButton | ||
show={selectedValues.length > 0} | ||
label={accessTypeFilterLabel} | ||
onClick={handleClearButtonClick} | ||
/> | ||
)} | ||
</div> | ||
<div data-testid="search-form-access-type-filter"> | ||
<MultiSelectionFilter | ||
id="accessTypeFilterSelect" | ||
ariaLabel={accessTypeFilterLabel} | ||
dataOptions={dataOptions} | ||
name="access-type" | ||
onChange={handleStandaloneFilterChange} | ||
selectedValues={selectedValues} | ||
disabled={!searchByAccessTypesEnabled} | ||
aria-labelledby="accessTypesFilter-label" | ||
/> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
AccessTypesFilter.propTypes = propTypes; | ||
|
||
export { AccessTypesFilter }; |
100 changes: 100 additions & 0 deletions
100
src/components/access-type-filter/access-type-filter.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { act } from 'react'; | ||
|
||
import { render } from '@folio/jest-config-stripes/testing-library/react'; | ||
import userEvent from '@folio/jest-config-stripes/testing-library/user-event'; | ||
|
||
import { AccessTypesFilter } from './access-type-filter'; | ||
|
||
const mockOnStandaloneFilterChange = jest.fn(); | ||
const mockOnStandaloneFilterToggle = jest.fn(); | ||
const mockHandleStandaloneFilterChange = jest.fn(); | ||
|
||
const accessTypesStoreData = { | ||
items: { | ||
data: [ | ||
{ | ||
id: '1', | ||
attributes: { name: 'Open Access' }, | ||
}, | ||
{ | ||
id: '2', | ||
attributes: { name: 'Restricted Access' }, | ||
}, | ||
], | ||
}, | ||
isLoading: false, | ||
isDeleted: false, | ||
}; | ||
|
||
const dataOptions = [ | ||
{ label: 'Open Access', value: 'open-access' }, | ||
{ label: 'Restricted Access', value: 'restricted-access' }, | ||
]; | ||
|
||
const renderAccessTypeFilter = (props = {}) => render( | ||
<AccessTypesFilter | ||
accessTypesStoreData={accessTypesStoreData} | ||
searchByAccessTypesEnabled={false} | ||
selectedValues={[]} | ||
onStandaloneFilterChange={mockOnStandaloneFilterChange} | ||
onStandaloneFilterToggle={mockOnStandaloneFilterToggle} | ||
dataOptions={dataOptions} | ||
handleStandaloneFilterChange={mockHandleStandaloneFilterChange} | ||
{...props} | ||
/> | ||
); | ||
|
||
describe('AccessTypesFilter', () => { | ||
it('should render loading', () => { | ||
const { getByTestId } = renderAccessTypeFilter({ | ||
accessTypesStoreData: { | ||
...accessTypesStoreData, | ||
isLoading: true, | ||
}, | ||
}); | ||
|
||
expect(getByTestId('spinner-ellipsis')).toBeInTheDocument(); | ||
}); | ||
|
||
describe('when there are no access types', () => { | ||
it('should render nothing', () => { | ||
const { container } = renderAccessTypeFilter({ | ||
accessTypesStoreData: { | ||
...accessTypesStoreData, | ||
items: { data: [] }, | ||
}, | ||
}); | ||
|
||
expect(container).toBeEmptyDOMElement(); | ||
}); | ||
}); | ||
|
||
it('should render access types filter', () => { | ||
const { getByText } = renderAccessTypeFilter(); | ||
|
||
expect(getByText('ui-eholdings.accessTypes.filter')).toBeInTheDocument(); | ||
}); | ||
|
||
describe('when hitting the clear icon', () => { | ||
it('should call onStandaloneFilterChange', async () => { | ||
const { getByRole } = renderAccessTypeFilter({ | ||
selectedValues: ['open-access'], | ||
showClearButton: true, | ||
}); | ||
|
||
await act(() => userEvent.click(getByRole('button', { name: /clear/i }))); | ||
|
||
expect(mockOnStandaloneFilterChange).toHaveBeenCalledWith({ 'access-type': undefined }); | ||
}); | ||
}); | ||
|
||
describe('when searchByAccessTypesEnabled is false', () => { | ||
it('should disable filter', () => { | ||
const { getByRole } = renderAccessTypeFilter({ | ||
searchByAccessTypesEnabled: false, | ||
}); | ||
|
||
expect(getByRole('combobox')).toBeDisabled(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './access-type-filter'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { useIntl } from 'react-intl'; | ||
import PropTypes from 'prop-types'; | ||
|
||
import { IconButton } from '@folio/stripes/components'; | ||
|
||
const propTypes = { | ||
className: PropTypes.string, | ||
label: PropTypes.string.isRequired, | ||
onClick: PropTypes.func.isRequired, | ||
show: PropTypes.bool.isRequired, | ||
}; | ||
|
||
const ClearButton = ({ | ||
show, | ||
label, | ||
className, | ||
onClick, | ||
}) => { | ||
const intl = useIntl(); | ||
|
||
if (!show) { | ||
return null; | ||
} | ||
return ( | ||
<IconButton | ||
className={className} | ||
size="small" | ||
iconSize="small" | ||
icon="times-circle-solid" | ||
aria-label={intl.formatMessage({ id: 'stripes-components.filterGroups.clearFilterSetLabel' }, { | ||
labelText: label, | ||
})} | ||
onClick={onClick} | ||
/> | ||
); | ||
}; | ||
|
||
ClearButton.propTypes = propTypes; | ||
|
||
export { ClearButton }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './clear-button'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './search-by-checkbox'; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
src/components/search-form/components/search-by-checkbox/index.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.