Skip to content

Commit

Permalink
UIEH-1444 Remove shouldFocus HOC and all related code. (#1756)
Browse files Browse the repository at this point in the history
* UIEH-1444 Remove `shouldFocus` HOC and all related code.

* UIEH-1444 delete shouldFocus HOC and tests
  • Loading branch information
BogdanDenis authored Jan 6, 2025
1 parent 05ae594 commit fc842b3
Show file tree
Hide file tree
Showing 10 changed files with 5 additions and 121 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [10.1.0] (IN PROGRESS)

* Add `target="_blank"` to the `New` button of agreements accordion. (UIEH-1446)
* Remove `shouldFocus` HOC and all related code. (UIEH-1444)

## [10.0.1] (https://github.com/folio-org/ui-eholdings/tree/v10.0.1) (2024-11-12)

Expand Down
3 changes: 0 additions & 3 deletions src/components/package-search-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const PackageSearchList = ({
fetch,
notFoundMessage,
onUpdateOffset,
shouldFocusItem,
onClickItem,
}) => {
const packagesCollection = extend(Object.create(collection), {
Expand Down Expand Up @@ -48,7 +47,6 @@ const PackageSearchList = ({
pathname: `/eholdings/packages/${item.content.id}`,
}}
active={item.content && activeId && item.content.id === activeId}
shouldFocus={item.content && shouldFocusItem && item.content.id === shouldFocusItem}
onClick={() => onClickItem(`/eholdings/packages/${item.content.id}`)}
showProviderName
showTitleCount
Expand All @@ -69,7 +67,6 @@ PackageSearchList.propTypes = {
]),
onClickItem: PropTypes.func.isRequired,
onUpdateOffset: PropTypes.func.isRequired,
shouldFocusItem: PropTypes.string,
};

export default PackageSearchList;
5 changes: 1 addition & 4 deletions src/components/provider-list-item/provider-list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import classNames from 'classnames/bind';
import { FormattedNumber, FormattedMessage } from 'react-intl';
import { Headline } from '@folio/stripes/components';

import shouldFocus from '../should-focus';
import InternalLink from '../internal-link';
import SelectedLabel from '../selected-label';

Expand Down Expand Up @@ -94,6 +93,4 @@ ProviderListItem.defaultProps = {
headingLevel: 'h3',
};

// this HOC adds a prop, `shouldFocus` that will focus the component's
// rendered DOM node on mount and update (when the prop is toggled)
export default shouldFocus(ProviderListItem);
export default ProviderListItem;
3 changes: 0 additions & 3 deletions src/components/provider-search-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ const ProviderSearchList = ({
fetch,
notFoundMessage,
onUpdateOffset,
shouldFocusItem,
onClickItem,
}) => {
const packagesCollection = extend(Object.create(collection), {
Expand Down Expand Up @@ -48,7 +47,6 @@ const ProviderSearchList = ({
pathname: `/eholdings/providers/${item.content.id}`,
}}
active={item.content && activeId && item.content.id === activeId}
shouldFocus={item.content && shouldFocusItem && item.content.id === shouldFocusItem}
onClick={() => onClickItem(`/eholdings/providers/${item.content.id}`)}
/>
)}
Expand All @@ -66,7 +64,6 @@ ProviderSearchList.propTypes = {
]),
onClickItem: PropTypes.func.isRequired,
onUpdateOffset: PropTypes.func.isRequired,
shouldFocusItem: PropTypes.string,
};

export default ProviderSearchList;
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {

import { Headline } from '@folio/stripes/components';

import shouldFocus from '../should-focus';
import InternalLink from '../internal-link';
import HiddenLabel from '../hidden-label';
import SelectedLabel from '../selected-label';
Expand Down Expand Up @@ -128,6 +127,4 @@ SearchPackageListItem.defaultProps = {
showTitleCount: false,
};

// this HOC adds a prop, `shouldFocus` that will focus the component's
// rendered DOM node on mount and update (when the prop is toggled)
export default shouldFocus(SearchPackageListItem);
export default SearchPackageListItem;
41 changes: 0 additions & 41 deletions src/components/should-focus.js

This file was deleted.

52 changes: 0 additions & 52 deletions src/components/should-focus.test.js

This file was deleted.

5 changes: 1 addition & 4 deletions src/components/title-list-item/title-list-item.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import isEmpty from 'lodash/isEmpty';

import { Headline } from '@folio/stripes/components';

import shouldFocus from '../should-focus';
import InternalLink from '../internal-link';
import IdentifiersList from '../identifiers-list';
import ContributorsList from '../contributors-list';
Expand Down Expand Up @@ -152,6 +151,4 @@ TitleListItem.propTypes = {
showSelected: PropTypes.bool,
};

// this HOC adds a prop, `shouldFocus` that will focus the component's
// rendered DOM node on mount and update (when the prop is toggled)
export default shouldFocus(TitleListItem);
export default TitleListItem;
3 changes: 0 additions & 3 deletions src/components/title-search-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const TitleSearchList = ({
fetch,
notFoundMessage,
onUpdateOffset,
shouldFocusItem,
onClickItem,
}) => {
const packagesCollection = extend(Object.create(collection), {
Expand Down Expand Up @@ -53,7 +52,6 @@ const TitleSearchList = ({
pathname: `/eholdings/titles/${item.content.id}`,
}}
active={item.content && activeId && item.content.id === activeId}
shouldFocus={item.content && shouldFocusItem && item.content.id === shouldFocusItem}
onClick={() => onClickItem(`/eholdings/titles/${item.content.id}`)}
/>
)}
Expand All @@ -72,7 +70,6 @@ TitleSearchList.propTypes = {
onClickItem: PropTypes.func.isRequired,
onUpdateOffset: PropTypes.func.isRequired,
packagesFacetCollection: PropTypes.object.isRequired,
shouldFocusItem: PropTypes.string,
};

export default TitleSearchList;
8 changes: 1 addition & 7 deletions src/routes/search-route/search-route.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ class SearchRoute extends Component {
const searchTypeChanged = searchType !== prevState.searchType;
const urlContainsTagsFilter = hasIn(params, ['filter', 'tags']);
const urlContainsAccessTypesFilter = hasIn(params, ['filter', 'access-type']);
let shouldFocusItem = null;

if (hideDetails && match.params.id !== (prevState.match && prevState.match.params.id)) {
shouldFocusItem = prevState.match.params.id || null;
}
// update searchstring state only when it actually changes in the location instead of updating it each time on
// input to text field. This eliminates re-rendering of the text field on each keyboard in and solves problem
// stated in https://issues.folio.org/browse/UIEH-558
Expand All @@ -118,7 +114,6 @@ class SearchRoute extends Component {
searchType,
params,
hideDetails,
shouldFocusItem,
sort: params.sort,
submittedSearchFilters: params.filter || {},
draftSearchFilters: searchTypeChanged
Expand Down Expand Up @@ -437,13 +432,12 @@ class SearchRoute extends Component {
* Renders the search component specific to the current search type
*/
renderResults() {
const { searchType, params, shouldFocusItem } = this.state;
const { searchType, params } = this.state;
const { history, location, match: { params: { id } } } = this.props;

const props = {
params,
activeId: id,
shouldFocusItem,
location: this.props.location,
collection: this.getResults(),
packagesFacetCollection: this.getPackagesFacetCollection(),
Expand Down

0 comments on commit fc842b3

Please sign in to comment.