Skip to content

Commit

Permalink
Resolving `Selector unknown returned the root state when called. This…
Browse files Browse the repository at this point in the history
… can lead to unnecessary rerenders.` issues, and updating/removing styles.
  • Loading branch information
erinesullivan committed Oct 17, 2024
1 parent bc38f87 commit ecb15d6
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 35 deletions.
42 changes: 18 additions & 24 deletions src/modules/advanced/components/AdvancedSearchForm/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import './styles.css';
import {
addFieldedSearch,
removeFieldedSearch,
setFieldedSearch
} from '../../../advanced';
import { addFieldedSearch, removeFieldedSearch, setFieldedSearch } from '../../../advanced';
import { Alert, Icon } from '../../../reusable';
import React, { useCallback, useState } from 'react';
import { useDispatch, useSelector } from 'react-redux';
Expand All @@ -13,32 +8,31 @@ import PropTypes from 'prop-types';
import { stringifySearch } from '../../../search';
import { useNavigate } from 'react-router-dom';

const removeUndefinedFilters = (object) => {
const filters = object || {};
Object.keys(filters).forEach((filter) => {
if (!filters[filter]) {
delete filters[filter];
}
});
return filters;
};

const AdvancedSearchForm = ({ datastore }) => {
const navigate = useNavigate();
const [errors, setErrors] = useState([]);
const dispatch = useDispatch();

const fields = useSelector((state) => {
return state.advanced[datastore.uid].fields;
const { activeFilters: currentActiveFilters, fieldedSearches, fields } = useSelector((state) => {
return state.advanced[datastore.uid];
});
const booleanTypes = useSelector((state) => {
return state.advanced.booleanTypes;
});
const fieldedSearches = useSelector((state) => {
return state.advanced[datastore.uid].fieldedSearches;
const { booleanTypes } = useSelector((state) => {
return state.advanced;
});
const institution = useSelector((state) => {
return state.institution;
});
const activeFilters = useSelector((state) => {
const currentFilters = state.advanced[datastore.uid].activeFilters || {};
Object.keys(currentFilters).forEach((filter) => {
if (!currentFilters[filter]) {
delete currentFilters[filter];
}
});
return currentFilters;
});
const activeFilters = removeUndefinedFilters(currentActiveFilters);

// Functions wrapped with useCallback to prevent unnecessary re-creation
const changeFieldedSearch = useCallback(({ booleanType, fieldedSearchIndex, query, selectedFieldUid }) => {
Expand Down Expand Up @@ -113,7 +107,7 @@ const AdvancedSearchForm = ({ datastore }) => {
}, [navigate, institution, booleanTypes, fieldedSearches, activeFilters, datastore]);

return (
<form className='y-spacing' onSubmit={handleSubmit}>
<form className='y-spacing container__rounded page margin-top__none' onSubmit={handleSubmit}>
<h2 className='h1'>{datastore.name} Search</h2>
{errors.map((error, index) => {
return (
Expand Down Expand Up @@ -144,7 +138,7 @@ const AdvancedSearchForm = ({ datastore }) => {
);
})}
<button
className='btn btn--small btn--secondary add-another-field'
className='btn btn--small btn--secondary margin-x__auto flex'
onClick={handleAddAnotherFieldedSearch}
type='button'
>
Expand Down
5 changes: 0 additions & 5 deletions src/modules/advanced/components/AdvancedSearchForm/styles.css

This file was deleted.

4 changes: 0 additions & 4 deletions src/stylesheets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -1781,10 +1781,6 @@ body {
max-width: 32rem;
}

.advanced-search-form {
margin-bottom: 2rem;
}

.advanced-input {
border: solid 1px rgba(0, 0, 0, 0.3);
}
Expand Down
5 changes: 5 additions & 0 deletions src/stylesheets/spacing.css
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@
margin-left: var(--search-spacing-m);
}

.margin-x__auto {
margin-left: auto;
margin-right: auto;
}

.margin-x__none {
margin-left: 0;
margin-right: 0;
Expand Down
4 changes: 2 additions & 2 deletions src/stylesheets/utilities.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
background-color: white;
border-radius: 4px;
box-shadow:
0 2px 2px 0 rgba(0, 0, 0, 0.12),
0 2px 4px 0 rgba(0, 0, 0, 0.24);
0 2px 2px 0 var(--search-color-grey-400),
0 2px 4px 0 var(--search-color-grey-400);
}

.flex,
Expand Down

0 comments on commit ecb15d6

Please sign in to comment.