Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix search block input clear button doesn't reset the search #4837

Merged
merged 12 commits into from
Jul 18, 2023
Merged
1 change: 1 addition & 0 deletions news/4828.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix search block input clear button doesn't reset the search @iFlameing
11 changes: 9 additions & 2 deletions src/components/manage/Blocks/Search/components/SearchInput.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@ const messages = defineMessages({
});

const SearchInput = (props) => {
const { data, searchText, setSearchText, isLive, onTriggerSearch } = props;
const {
data,
searchText,
setSearchText,
isLive,
onTriggerSearch,
removeSearchQuery,
} = props;
const intl = useIntl();

return (
Expand Down Expand Up @@ -44,7 +51,7 @@ const SearchInput = (props) => {
className="search-input-clear-icon-button"
onClick={() => {
setSearchText('');
onTriggerSearch('');
removeSearchQuery();
}}
>
<Icon name={clearSVG} />
Expand Down
11 changes: 11 additions & 0 deletions src/components/manage/Blocks/Search/hocs/withSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,16 @@ const withSearch = (options) => (WrappedComponent) => {
],
);

const removeSearchQuery = () => {
searchData.query = searchData.query.reduce(
// Remove SearchableText from query
(acc, kvp) => (kvp.i === 'SearchableText' ? acc : [...acc, kvp]),
[],
);
setSearchData(searchData);
setLocationSearchData(getSearchFields(searchData));
};

const querystringResults = useSelector(
(state) => state.querystringsearch.subrequests,
);
Expand All @@ -343,6 +353,7 @@ const withSearch = (options) => (WrappedComponent) => {
sortOrder={sortOrder}
searchedText={urlSearchText}
searchText={searchText}
removeSearchQuery={removeSearchQuery}
setSearchText={setSearchText}
onTriggerSearch={onTriggerSearch}
totalItems={totalItems}
Expand Down