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

Persist saved search sort option after a deletion; fix Nav spacing #1252

Merged
merged 2 commits into from
Nov 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/Components/SavedSearches/SavedSearches.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ const SavedSearches = props => {
const isLoading = (filtersIsLoading || savedSearchesIsLoading);

const options = [
{ title: 'All Saved Searches', value: 'all', numerator: getSearches('all').length },
{ title: 'Open Positions', value: 'open', numerator: getSearches('open').length },
{ title: 'Projected Vacancies', value: 'pv', numerator: getSearches('pv').length },
{ title: 'Tandem Open Positions', value: 'open-ts', numerator: getSearches('open-ts').length },
{ title: 'Tandem Projected Vacancies', value: 'pv-ts', numerator: getSearches('pv-ts').length },
{ title: 'All Saved Searches ', value: 'all', numerator: getSearches('all').length },
{ title: 'Open Positions ', value: 'open', numerator: getSearches('open').length },
{ title: 'Projected Vacancies ', value: 'pv', numerator: getSearches('pv').length },
{ title: 'Tandem Open Positions ', value: 'open-ts', numerator: getSearches('open-ts').length },
{ title: 'Tandem Projected Vacancies ', value: 'pv-ts', numerator: getSearches('pv-ts').length },
];

const searches = { results: getSearches() };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,27 +57,27 @@ exports[`SavedSearchesComponent matches snapshot 1`] = `
Array [
Object {
"numerator": 1,
"title": "All Saved Searches",
"title": "All Saved Searches ",
"value": "all",
},
Object {
"numerator": 1,
"title": "Open Positions",
"title": "Open Positions ",
"value": "open",
},
Object {
"numerator": 0,
"title": "Projected Vacancies",
"title": "Projected Vacancies ",
"value": "pv",
},
Object {
"numerator": 0,
"title": "Tandem Open Positions",
"title": "Tandem Open Positions ",
"value": "open-ts",
},
Object {
"numerator": 0,
"title": "Tandem Projected Vacancies",
"title": "Tandem Projected Vacancies ",
"value": "pv-ts",
},
]
Expand Down
27 changes: 22 additions & 5 deletions src/Containers/SavedSearches/SavedSearches.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,36 @@ import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { withRouter } from 'react-router';
import { push } from 'connected-react-router';
import { savedSearchesFetchData, setCurrentSavedSearch, deleteSavedSearch } from '../../actions/savedSearch';
import { SAVED_SEARCH_PARENT_OBJECT } from '../../Constants/PropTypes';
import { DEFAULT_USER_PROFILE, POSITION_RESULTS_OBJECT } from '../../Constants/DefaultProps';
import { isEqual } from 'lodash';
import { savedSearchesFetchData, setCurrentSavedSearch, deleteSavedSearch } from 'actions/savedSearch';
import { SAVED_SEARCH_PARENT_OBJECT } from 'Constants/PropTypes';
import { DEFAULT_USER_PROFILE, POSITION_RESULTS_OBJECT } from 'Constants/DefaultProps';
import { formQueryString } from 'utilities';
import SavedSearchesMap from '../SavedSearchesMap';
import { formQueryString } from '../../utilities';

// Wrapper for anything related to saved searches
// Make sure to update Components/ResultsMultiSearchHeader/bypassRoutes.js with any routes
// that use this container.
class SavedSearchesContainer extends Component {
constructor(props) {
super(props);
this.state = {
defaultSort: '',
};
}

UNSAFE_componentWillMount() {
this.getSavedSearches();
}

componentWillReceiveProps(nextProps) {
if (!isEqual(nextProps.deleteIsLoading, this.props.deleteIsLoading)) {
this.getSavedSearches();
}
}

getSavedSearches() {
this.props.savedSearchesFetchData();
this.props.savedSearchesFetchData(this.state.defaultSort);
}

getSortedSearches = type => {
Expand Down Expand Up @@ -62,6 +76,7 @@ SavedSearchesContainer.propTypes = {
savedSearchesIsLoading: PropTypes.bool.isRequired,
setCurrentSavedSearch: PropTypes.func.isRequired,
deleteSearch: PropTypes.func.isRequired,
deleteIsLoading: PropTypes.bool,
ChildElement: PropTypes.func.isRequired,
};

Expand All @@ -71,6 +86,7 @@ SavedSearchesContainer.defaultProps = {
savedSearches: POSITION_RESULTS_OBJECT,
savedSearchesIsLoading: true,
savedSearchesHasErrored: false,
deleteIsLoading: false,
};

SavedSearchesContainer.contextTypes = {
Expand All @@ -83,6 +99,7 @@ const mapStateToProps = (state, ownProps) => ({
savedSearches: state.savedSearchesSuccess,
savedSearchesIsLoading: state.savedSearchesIsLoading,
savedSearchesHasErrored: state.savedSearchesHasErrored,
deleteIsLoading: state.deleteSavedSearchIsLoading,
});

export const mapDispatchToProps = dispatch => ({
Expand Down
1 change: 0 additions & 1 deletion src/actions/savedSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ export function deleteSavedSearch(id) {
SystemMessages.DELETE_SAVED_SEARCH_SUCCESS_TITLE,
));
dispatch(currentSavedSearch(false));
dispatch(savedSearchesFetchData());
})
.catch((err) => {
dispatch(deleteSavedSearchHasErrored(JSON.stringify(propOrDefault(err, 'response.data', 'An error occurred trying to delete this search.'))));
Expand Down