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 (