Skip to content

Commit

Permalink
Ensure No search results found isn't shown without a search
Browse files Browse the repository at this point in the history
  • Loading branch information
mynameisbogdan committed Jul 20, 2023
1 parent ecda751 commit 79361d9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import PropTypes from 'prop-types';
import React from 'react';
import translate from 'Utilities/String/translate';
import styles from './NoSearchResults.css';

function NoSearchResults(props) {
interface NoSearchResultsProps {
totalItems: number;
}

function NoSearchResults(props: NoSearchResultsProps) {
const { totalItems } = props;

if (totalItems > 0) {
Expand All @@ -18,15 +21,9 @@ function NoSearchResults(props) {

return (
<div>
<div className={styles.message}>
{translate('NoSearchResultsFound')}
</div>
<div className={styles.message}>{translate('NoSearchResultsFound')}</div>
</div>
);
}

NoSearchResults.propTypes = {
totalItems: PropTypes.number.isRequired
};

export default NoSearchResults;
25 changes: 15 additions & 10 deletions frontend/src/Search/SearchIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,15 +326,17 @@ class SearchIndex extends Component {
innerClassName={styles.tableInnerContentBody}
>
{
isFetching && !isPopulated &&
<LoadingIndicator />
isFetching && !isPopulated ?
<LoadingIndicator /> :
null
}

{
!isFetching && !!error &&
!isFetching && !!error ?
<Alert kind={kinds.DANGER}>
{getErrorMessage(error, 'Failed to load search results from API')}
</Alert>
</Alert> :
null
}

{
Expand All @@ -359,16 +361,18 @@ class SearchIndex extends Component {
}

{
!error && !isFetching && !hasIndexers &&
!error && !isFetching && !hasIndexers ?
<NoIndexer
totalItems={0}
onAddIndexerPress={this.onAddIndexerPress}
/>
/> :
null
}

{
!error && !isFetching && hasIndexers && !items.length &&
<NoSearchResults totalItems={totalItems} />
!error && !isFetching && isPopulated && hasIndexers && !items.length ?
<NoSearchResults totalItems={totalItems} /> :
null
}

<AddIndexerModal
Expand All @@ -384,11 +388,12 @@ class SearchIndex extends Component {
</PageContentBody>

{
isLoaded && !!jumpBarItems.order.length &&
isLoaded && !!jumpBarItems.order.length ?
<PageJumpBar
items={jumpBarItems}
onItemPress={this.onJumpBarItemPress}
/>
/> :
null
}
</div>

Expand Down

0 comments on commit 79361d9

Please sign in to comment.