Skip to content

Commit

Permalink
fix/cv2-5174 add search score dropdown option (#2093)
Browse files Browse the repository at this point in the history
* added a label if the user is doing a keyword search

* sorted propTypes
  • Loading branch information
sarahkeh authored Sep 6, 2024
1 parent 89e8536 commit 6c1c40e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
"description": "Label for sort criteria option displayed in a drop-down in listing pages",
"defaultMessage": "Report (status)"
},
{
"id": "searchResults.sortScore",
"description": "Label for sort criteria option displayed in a drop-down in listing pages",
"defaultMessage": "Search: Best Match"
},
{
"id": "searchResults.sortSubmitted",
"description": "Label for sort criteria option displayed in a drop-down in listing pages",
Expand Down
5 changes: 5 additions & 0 deletions src/app/components/cds/inputs/ListSort.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ const sortLabels = defineMessages({
defaultMessage: 'Report (status)',
description: 'Label for sort criteria option displayed in a drop-down in listing pages',
},
sortScore: {
id: 'searchResults.sortScore',
defaultMessage: 'Search: Best Match',
description: 'Label for sort criteria option displayed in a drop-down in listing pages',
},
sortSubmitted: {
id: 'searchResults.sortSubmitted',
defaultMessage: 'Submitted (date)',
Expand Down
27 changes: 16 additions & 11 deletions src/app/components/search/SearchFields/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* eslint-disable relay/unused-fields, react/sort-prop-types */
/* eslint-disable relay/unused-fields */
import React from 'react';
import { createFragmentContainer, graphql } from 'react-relay/compat';
import { FormattedMessage, injectIntl, intlShape, defineMessages } from 'react-intl';
Expand Down Expand Up @@ -706,6 +706,11 @@ const SearchFields = ({
{ value: 'recent_activity', label: intl.formatMessage(sortLabels.sortUpdated) },
];

// if searching for a keyword, default sort by score but only show option when searching
if (stateQuery.keyword && stateQuery.keyword.length > 0) {
listSortOptions.unshift({ value: 'score', label: intl.formatMessage(sortLabels.sortScore) });
}

return (
<div className={styles['filters-wrapper']}>
<ListSort
Expand Down Expand Up @@ -796,31 +801,31 @@ SearchFields.defaultProps = {
};

SearchFields.propTypes = {
appliedQuery: PropTypes.object.isRequired,
defaultQuery: PropTypes.object.isRequired,
feedTeam: PropTypes.shape({
id: PropTypes.string.isRequired,
filters: PropTypes.object,
feedFilters: PropTypes.object,
}),
handleSubmit: PropTypes.func.isRequired,
page: PropTypes.oneOf(['all-items', 'tipline-inbox', 'imported-fact-checks', 'suggested-matches', 'unmatched-media', 'published', 'list', 'feed', 'spam', 'trash', 'assigned-to-me']).isRequired, // FIXME Define listing types as a global constant
readOnlyFields: PropTypes.arrayOf(PropTypes.string),
savedSearch: PropTypes.shape({
filters: PropTypes.string.isRequired,
id: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
filters: PropTypes.string.isRequired,
}),
stateQuery: PropTypes.object.isRequired,
appliedQuery: PropTypes.object.isRequired,
defaultQuery: PropTypes.object.isRequired,
setStateQuery: PropTypes.func.isRequired,
onChange: PropTypes.func.isRequired, // onChange({ ... /* query */ }) => undefined
stateQuery: PropTypes.object.isRequired,
team: PropTypes.shape({
id: PropTypes.string.isRequired,
dbid: PropTypes.number.isRequired,
slug: PropTypes.string.isRequired,
id: PropTypes.string.isRequired,
permissions: PropTypes.string.isRequired,
slug: PropTypes.string.isRequired,
verification_statuses: PropTypes.object.isRequired,
}).isRequired,
handleSubmit: PropTypes.func.isRequired,
readOnlyFields: PropTypes.arrayOf(PropTypes.string),
page: PropTypes.oneOf(['all-items', 'tipline-inbox', 'imported-fact-checks', 'suggested-matches', 'unmatched-media', 'published', 'list', 'feed', 'spam', 'trash', 'assigned-to-me']).isRequired, // FIXME Define listing types as a global constant
onChange: PropTypes.func.isRequired, // onChange({ ... /* query */ }) => undefined
};

SearchFields.contextTypes = {
Expand Down

0 comments on commit 6c1c40e

Please sign in to comment.