fix: text search rewrite text added
This commit is contained in:
@@ -14,18 +14,23 @@ function SearchInfo({
|
||||
text,
|
||||
loadingStatus,
|
||||
onClear,
|
||||
textSearchRewrite,
|
||||
}) {
|
||||
return (
|
||||
<div className="d-flex flex-row border-bottom border-light-400">
|
||||
<Icon src={Search} className="justify-content-start ml-3.5 mr-2 mb-2 mt-2.5" />
|
||||
<Button variant="" size="inline">
|
||||
{
|
||||
loadingStatus === RequestStatus.SUCCESSFUL
|
||||
? intl.formatMessage(messages.searchInfo, { count, text })
|
||||
: intl.formatMessage(messages.searchInfoSearching)
|
||||
}
|
||||
<Button variant="" size="inline" className="text-justify p-2">
|
||||
{loadingStatus === RequestStatus.SUCCESSFUL && (
|
||||
textSearchRewrite ? intl.formatMessage(messages.searchRewriteInfo, {
|
||||
searchString: text,
|
||||
count,
|
||||
textSearchRewrite,
|
||||
})
|
||||
: intl.formatMessage(messages.searchInfo, { count, text })
|
||||
)}
|
||||
{loadingStatus !== RequestStatus.SUCCESSFUL && intl.formatMessage(messages.searchInfoSearching)}
|
||||
</Button>
|
||||
<Button variant="link" size="inline" className="ml-auto mr-4" onClick={onClear}>
|
||||
<Button variant="link" size="inline" className="ml-auto mr-3" onClick={onClear} style={{ minWidth: '26%' }}>
|
||||
{intl.formatMessage(messages.clearSearch)}
|
||||
</Button>
|
||||
</div>
|
||||
@@ -37,11 +42,13 @@ SearchInfo.propTypes = {
|
||||
count: PropTypes.number.isRequired,
|
||||
text: PropTypes.string.isRequired,
|
||||
loadingStatus: PropTypes.string.isRequired,
|
||||
textSearchRewrite: PropTypes.string,
|
||||
onClear: PropTypes.func,
|
||||
};
|
||||
|
||||
SearchInfo.defaultProps = {
|
||||
onClear: () => {},
|
||||
textSearchRewrite: null,
|
||||
};
|
||||
|
||||
export default injectIntl(SearchInfo);
|
||||
|
||||
@@ -46,6 +46,7 @@ function PostsView() {
|
||||
const dispatch = useDispatch();
|
||||
const searchString = useSelector(({ threads }) => threads.filters.search);
|
||||
const resultsFound = useSelector(({ threads }) => threads.totalThreads);
|
||||
const textSearchRewrite = useSelector(({ threads }) => threads.textSearchRewrite);
|
||||
const loadingStatus = useSelector(({ threads }) => threads.status);
|
||||
|
||||
let postsListComponent;
|
||||
@@ -80,6 +81,7 @@ function PostsView() {
|
||||
text={searchString}
|
||||
loadingStatus={loadingStatus}
|
||||
onClear={() => dispatch(setSearchQuery(''))}
|
||||
textSearchRewrite={textSearchRewrite}
|
||||
/>
|
||||
)}
|
||||
<PostFilterBar />
|
||||
|
||||
@@ -40,6 +40,7 @@ const threadsSlice = createSlice({
|
||||
nextPage: null,
|
||||
totalPages: null,
|
||||
totalThreads: null,
|
||||
textSearchRewrite: null,
|
||||
postStatus: RequestStatus.SUCCESSFUL,
|
||||
filters: {
|
||||
status: PostsStatusFilter.ALL,
|
||||
@@ -80,6 +81,7 @@ const threadsSlice = createSlice({
|
||||
state.nextPage = (payload.page < payload.pagination.numPages) ? payload.page + 1 : null;
|
||||
state.totalPages = payload.pagination.numPages;
|
||||
state.totalThreads = payload.pagination.count;
|
||||
state.textSearchRewrite = payload.textSearchRewrite;
|
||||
},
|
||||
fetchThreadsFailed: (state) => {
|
||||
state.status = RequestStatus.FAILED;
|
||||
|
||||
@@ -138,7 +138,7 @@ export function fetchThreads(courseId, {
|
||||
const data = await getThreads(courseId, options);
|
||||
const normalisedData = normaliseThreads(camelCaseObject(data), topicIds);
|
||||
dispatch(fetchThreadsSuccess({
|
||||
...normalisedData, page, author,
|
||||
...normalisedData, page, author, textSearchRewrite: data.text_search_rewrite,
|
||||
}));
|
||||
} catch (error) {
|
||||
if (getHttpErrorStatus(error) === 403) {
|
||||
|
||||
@@ -26,6 +26,11 @@ const messages = defineMessages({
|
||||
defaultMessage: 'Showing {count} results for "{text}"',
|
||||
description: 'Message displayed when user performs a search',
|
||||
},
|
||||
searchRewriteInfo: {
|
||||
id: 'discussions.actionBar.searchRewriteInfo',
|
||||
defaultMessage: 'No results found for "{searchString}". Showing {count} results for "{textSearchRewrite}".',
|
||||
description: 'Message displayed when user performs a search and search query is rewritten because matching results are not found',
|
||||
},
|
||||
searchInfoSearching: {
|
||||
id: 'discussions.actionBar.searchInfoSearching',
|
||||
defaultMessage: 'Searching...',
|
||||
|
||||
Reference in New Issue
Block a user