diff --git a/frontend/amundsen_application/static/.betterer.results b/frontend/amundsen_application/static/.betterer.results index 6cc9160f75..332993c1fe 100644 --- a/frontend/amundsen_application/static/.betterer.results +++ b/frontend/amundsen_application/static/.betterer.results @@ -729,7 +729,7 @@ exports[`eslint`] = { "js/pages/SearchPage/SearchFilter/FilterSection/index.tsx:2051916132": [ [20, 75, -647, "Expected to return a value at the end of arrow function.", "5381"] ], - "js/pages/SearchPage/SearchFilter/InputFilter/index.tsx:1977761678": [ + "js/pages/SearchPage/SearchFilter/InputFilter/index.tsx:3333995805": [ [63, 6, 13, "Do not use setState in componentDidUpdate", "57229240"] ], "js/pages/SearchPage/SearchPanel/tests/index.spec.tsx:3928473928": [ diff --git a/frontend/amundsen_application/static/js/pages/SearchPage/SearchFilter/InputFilter/index.tsx b/frontend/amundsen_application/static/js/pages/SearchPage/SearchFilter/InputFilter/index.tsx index 7e290190ac..f04517b5a9 100644 --- a/frontend/amundsen_application/static/js/pages/SearchPage/SearchFilter/InputFilter/index.tsx +++ b/frontend/amundsen_application/static/js/pages/SearchPage/SearchFilter/InputFilter/index.tsx @@ -81,26 +81,36 @@ export class InputFilter extends React.Component< const showFilterOperationToggle = newValue.includes(','); this.setState({ value: newValue, showFilterOperationToggle }); - const currentFilter = getFilterObject( - filterState, - resourceType, - categoryId - ); - const hasFilterOperation = currentFilter && currentFilter.filterOperation; - const newFilter = hasFilterOperation - ? { - value: newValue || undefined, - filterOperation: currentFilter.filterOperation, - } - : { value: newValue || undefined }; + let newFilters; + if (newValue) { + const currentFilter = getFilterObject( + filterState, + resourceType, + categoryId + ); + const hasFilterOperation = currentFilter && currentFilter.filterOperation; + const newFilter = hasFilterOperation + ? { value: newValue, filterOperation: currentFilter.filterOperation } + : { value: newValue }; + + newFilters = { + ...filterState, + [resourceType]: { + ...filterState[resourceType], + [categoryId]: newFilter, + }, + }; + } else { + // Remove the categoryId from the filters if the new value is empty + const updatedResourceFilters = { ...filterState[resourceType] }; + delete updatedResourceFilters[categoryId]; + + newFilters = { + ...filterState, + [resourceType]: updatedResourceFilters, + }; + } - const newFilters = { - ...filterState, - [resourceType]: { - ...filterState[resourceType], - [categoryId]: newFilter, - }, - }; updateFilterState(newFilters); };