From 6c1c40e7ef3b978c1a6a84aaeeddee6a13c72c8e Mon Sep 17 00:00:00 2001 From: Sarah Kehoe <161879347+sarahkeh@users.noreply.github.com> Date: Fri, 6 Sep 2024 14:50:24 -0700 Subject: [PATCH] fix/cv2-5174 add search score dropdown option (#2093) * added a label if the user is doing a keyword search * sorted propTypes --- .../app/components/cds/inputs/ListSort.json | 5 ++++ src/app/components/cds/inputs/ListSort.js | 5 ++++ .../components/search/SearchFields/index.js | 27 +++++++++++-------- 3 files changed, 26 insertions(+), 11 deletions(-) diff --git a/localization/react-intl/src/app/components/cds/inputs/ListSort.json b/localization/react-intl/src/app/components/cds/inputs/ListSort.json index 1de33f0e1d..2f3166b108 100644 --- a/localization/react-intl/src/app/components/cds/inputs/ListSort.json +++ b/localization/react-intl/src/app/components/cds/inputs/ListSort.json @@ -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", diff --git a/src/app/components/cds/inputs/ListSort.js b/src/app/components/cds/inputs/ListSort.js index 3db20a642d..7649751dc0 100644 --- a/src/app/components/cds/inputs/ListSort.js +++ b/src/app/components/cds/inputs/ListSort.js @@ -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)', diff --git a/src/app/components/search/SearchFields/index.js b/src/app/components/search/SearchFields/index.js index d33238f916..23008f4676 100644 --- a/src/app/components/search/SearchFields/index.js +++ b/src/app/components/search/SearchFields/index.js @@ -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'; @@ -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 (
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 = {