Skip to content

Commit

Permalink
Refactor the checks catalog_new view filter
Browse files Browse the repository at this point in the history
  • Loading branch information
EMaksy committed Jan 24, 2023
1 parent 39c86f5 commit 1487f5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
21 changes: 11 additions & 10 deletions assets/js/components/ChecksCatalog/ChecksCatalogNew.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ import CheckItem from './CheckItem';
import ProviderSelection from './ProviderSelection';

const ALL_FILTER = 'All';
const updatedProvider = {
default: { label: ALL_FILTER },
...providerData,
};
const providerLabels = getLabels(updatedProvider);

// eslint-disable-next-line import/prefer-default-export
export function ChecksCatalogNew() {
const dispatch = useDispatch();
const updatedProvider = providerData;
updatedProvider[''] = { label: ALL_FILTER };
const providerLabels = getLabels(providerData);

const [selectedProvider, setProviderSelected] = useState(ALL_FILTER);

const {
Expand All @@ -33,13 +34,13 @@ export function ChecksCatalogNew() {
} = useSelector(getCatalog());

useEffect(() => {
dispatch(
updateCatalog({
provider: getProviderByLabel(providerData, selectedProvider) || null,
})
);
}, [dispatch, selectedProvider]);
const apiParams =
selectedProvider === ALL_FILTER
? {}
: { provider: getProviderByLabel(updatedProvider, selectedProvider) };

dispatch(updateCatalog(apiParams));
}, [dispatch, selectedProvider]);
return (
<div>
<CatalogContainer
Expand Down
4 changes: 2 additions & 2 deletions assets/js/components/ChecksCatalog/ChecksCatalogNew.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('ChecksCatalog ChecksCatalogNew component', () => {
const expectedActions = [
{
type: 'UPDATE_CATALOG_NEW',
payload: { provider: null },
payload: {},
},
];
expect(actions).toEqual(expectedActions);
Expand Down Expand Up @@ -73,7 +73,7 @@ describe('ChecksCatalog ChecksCatalogNew component', () => {
const expectedActions = [
{
type: 'UPDATE_CATALOG_NEW',
payload: { provider: null },
payload: {},
},
{
type: 'UPDATE_CATALOG_NEW',
Expand Down

0 comments on commit 1487f5e

Please sign in to comment.