This pull request adds the ability to use query parameters to pass filters into the StudyList from the url. These parameters are of the same form used by the QIDO requests to apply the filters. This solution seemed to me to be the most obvious way to manage them. There's one open question however, around what to do with the parameters after the initial load. For now, the URL parameters are overridden the moment the user tries to add another filter. Depending on review feedback it seems like it may make more sense for those query parameter filters to be "permanent" and so any further filtering would augment those parameters rather than replace them.
37 lines
901 B
JavaScript
37 lines
901 B
JavaScript
import React from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import { withRouter } from 'react-router-dom';
|
|
import queryString from 'query-string';
|
|
import ConnectedStudyList from './ConnectedStudyList';
|
|
|
|
// TODO: Move to react-viewerbase
|
|
|
|
function toLowerCaseFirstLetter(word) {
|
|
return word[0].toLowerCase() + word.slice(1);
|
|
}
|
|
|
|
function getFilters({ search }) {
|
|
const searchParameters = queryString.parse(search);
|
|
const filters = {};
|
|
|
|
Object.entries(searchParameters).forEach(([key, value]) => {
|
|
filters[toLowerCaseFirstLetter(key)] = value;
|
|
});
|
|
|
|
return filters;
|
|
}
|
|
|
|
function StudyListRouting({ location }) {
|
|
const filters = location ? getFilters(location) : undefined;
|
|
|
|
return <ConnectedStudyList filters={filters} />;
|
|
}
|
|
|
|
StudyListRouting.propTypes = {
|
|
location: PropTypes.shape({
|
|
search: PropTypes.string,
|
|
}).isRequired,
|
|
};
|
|
|
|
export default withRouter(StudyListRouting);
|