Skip to content

Commit

Permalink
Extract attributes checker to utility function.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdusovic committed Aug 4, 2020
1 parent 3bf9e21 commit 80d998f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/app/components/Common/NavigationBar/Search/SearchBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { RouteComponentProps } from 'react-router';
import { withRouter } from 'react-router-dom';
import withMK from '../../../../hoc/withMK';
import translate from '../../../../utils/translations/Translations';
import { hasAttributes } from '../../../../utils/Utils';
import Loader from '../../Loader/Loader';
import AlbumResultItem from './AlbumResultItem';
import ArtistResultItem from './ArtistResultItem';
Expand Down Expand Up @@ -132,8 +133,7 @@ class SearchBar extends React.Component<SearchBarProps, SearchBarState> {

const catalogItems = catalogData && catalogData[type] ? catalogData[type].data : [];

// Filter out invalid items returned from the API.
return [...libraryItems, ...catalogItems].filter(item => item.attributes !== undefined);
return [...libraryItems, ...catalogItems].filter(hasAttributes);
};

public renderType = (
Expand Down
5 changes: 5 additions & 0 deletions src/app/utils/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,8 @@ export const getRatingUrl = (type: string, id: any) => {
export function setPseudoRoute(route: string) {
window.history.pushState('', '', route);
}

// TODO: Replace this with comprehensive validation of API responses.
export function hasAttributes(resource: any): boolean {
return !!resource.attributes;
}

0 comments on commit 80d998f

Please sign in to comment.