Skip to content

Commit

Permalink
Merge pull request #437 from mlibrary/history-react-router-dom-update…
Browse files Browse the repository at this point in the history
…-part-2

`history` and `react-router-update` - Part 2
  • Loading branch information
erinesullivan authored Mar 7, 2024
2 parents 1e6f635 + 258f566 commit 39dd5c3
Show file tree
Hide file tree
Showing 26 changed files with 390 additions and 541 deletions.
19 changes: 12 additions & 7 deletions src/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const config = {
},
sorts: {
mirlyn: {
default: 'relevance',
sorts: [
'relevance',
'date_asc',
Expand All @@ -63,7 +62,6 @@ const config = {
]
},
primo: {
default: 'relevance',
sorts: [
'relevance',
'date_asc',
Expand All @@ -73,11 +71,13 @@ const config = {
]
},
databases: {
default: 'relevance',
sorts: ['relevance', 'title_asc', 'title_desc']
sorts: [
'relevance',
'title_asc',
'title_desc'
]
},
onlinejournals: {
default: 'relevance',
sorts: [
'relevance',
'date_asc',
Expand All @@ -88,8 +88,13 @@ const config = {
]
},
website: {
default: 'relevance',
sorts: ['relevance', 'title_asc', 'title_desc', 'date_asc', 'date_desc']
sorts: [
'relevance',
'title_asc',
'title_desc',
'date_asc',
'date_desc'
]
}
},
advancedBooleanTypes: ['AND', 'OR', 'NOT'],
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import { connect, Provider } from 'react-redux';
import { Route, Switch, Redirect } from 'react-router-dom';
import { ConnectedRouter } from 'connected-react-router';
import './stylesheets/colors.css';
import './stylesheets/utilities.css';
import './stylesheets/main.css';
import './stylesheets/utilities.css';
import { Alert } from './modules/reusable';
import {
initializePride,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import _ from 'underscore';
import { MEDIA_QUERIES, SEARCH_COLORS } from '../../../reusable/umich-lib-core-temp';
import {
Breadcrumb,
H1,
Tabs,
TabList,
TabPanel,
Expand Down Expand Up @@ -50,7 +51,7 @@ class AdvancedSearchContainer extends React.Component {
]}
/>

<h1 className='heading-xlarge' id='maincontent' tabIndex='-1'>Advanced Search</h1>
<H1 className='heading-xlarge'>Advanced Search</H1>
<p className='font-lede'>Select a search category below for associated advanced search options.</p>

<Tabs defaultIndex={activeDatastoreIndex}>
Expand Down
4 changes: 2 additions & 2 deletions src/modules/affiliation/components/choose-affiliation.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function ChooseAffiliation () {
return (
<div>
<button
className='btn btn--secondary'
className='btn btn--secondary no-background'
css={{
borderColor: COLORS.blue[300],
color: 'white',
Expand Down Expand Up @@ -98,7 +98,7 @@ export default function ChooseAffiliation () {
return (
<div>
<button
className='btn btn--secondary'
className='btn btn--secondary no-background'
css={{
borderColor: COLORS.blue[300],
color: 'white',
Expand Down
4 changes: 2 additions & 2 deletions src/modules/browse/components/BrowsePage/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React from 'react';
import { connect } from 'react-redux';
import { BrowseAtoZ, BrowseByFilters } from '../../../browse';
import { Breadcrumb } from '../../../reusable';
import { Breadcrumb, H1 } from '../../../reusable';
import PropTypes from 'prop-types';

function BrowsePage (props) {
Expand All @@ -15,7 +15,7 @@ function BrowsePage (props) {
{ text: 'Browse' }
]}
/>
<h1 className='heading-xlarge' id='maincontent' tabIndex='-1'>Browse all {datastore.name}</h1>
<H1 className='heading-xlarge'>Browse all {datastore.name}</H1>
<p className='font-lede'>When you're stuck looking for specific {datastore.name.toLowerCase()} or just want to see what's out there, the browse page makes finding the right {datastore.name.toLowerCase()} easy. Browse all {datastore.name.toLowerCase()} titles alphabetically or by academic discipline.</p>
<BrowseAtoZ />
<BrowseByFilters filters={browse} />
Expand Down
2 changes: 1 addition & 1 deletion src/modules/datastores/components/FlintAlerts/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function FlintAlerts ({ datastore, profile }) {
<Alert type='warning'>
<span>{messages[datastore]}</span>
<button
className='btn btn--small btn--secondary'
className='btn btn--small btn--secondary no-background'
onClick={handleDismissClick}
>
Dismiss
Expand Down
53 changes: 39 additions & 14 deletions src/modules/datastores/components/Landing/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import { Anchor } from '../../../reusable';
import { useLocation } from 'react-router-dom';
import { Anchor, H1 } from '../../../reusable';
import { BrowseInfo } from '../../../browse';
import { InstitutionSelect } from '../../../institution';
import PropTypes from 'prop-types';

function Landing ({ activeDatastore }) {
const { uid } = activeDatastore;
function Landing ({ activeDatastore, institution }) {
const location = useLocation();
const { uid, name } = activeDatastore;
const landingContent = {
everything: {
headingText: (<>Search <span className='strong'>Everything</span> to see a broad sampling of results from across 'Library Search' and to explore specific areas and records in greater detail.</>),
Expand Down Expand Up @@ -48,36 +49,60 @@ function Landing ({ activeDatastore }) {
}
};

const queryParam = (string) => {
return string.replaceAll(' ', '+');
};

const activeLibrary = (query) => {
if (location.query.library) {
return location.query.library.includes(query);
}

return query === queryParam(institution.defaultInstitution);
};

return (
<div className='container'>
<h1 className='visually-hidden' id='maincontent' tabIndex='-1'>
{activeDatastore.name}
</h1>
<H1 className='visually-hidden'>
{name}
</H1>
<div className='landing-container'>
<p className='landing-heading-text'>{landingContent[uid].headingText}</p>
{landingContent[uid].content}
</div>
{uid === 'mirlyn' && (
<div className='container container-narrow'>
<div className='institution-select-landing-container'>
<h2 className='heading-large' style={{ textAlign: 'center' }}>
<div className='institution-select-landing-container center-text'>
<h2 className='heading-large'>
To find materials closest to you, please choose a library
</h2>
<InstitutionSelect type='switch' />
</div>
<p className='landing-extra-info'>
<p>
{institution.options.map((library, index) => {
const query = queryParam(library);
return (
<Anchor
key={index}
to={`?library=${query}`}
className={`btn btn--secondary ${activeLibrary(query) ? 'btn--secondary--active' : ''}`}
>
{library}
</Anchor>
);
})}
</p>
<Anchor href='https://lib.umich.edu/find-borrow-request/find-materials/using-other-catalogs'>
About our other Library Catalogs
</Anchor>
</p>
</div>
</div>
)}
</div>
);
};

Landing.propTypes = {
activeDatastore: PropTypes.object
activeDatastore: PropTypes.object,
institution: PropTypes.object
};

export default Landing;
4 changes: 2 additions & 2 deletions src/modules/getthis/components/GetThisPage/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { connect } from 'react-redux';
import { withRouter } from 'react-router-dom';
import { requestRecord, requestGetThis } from '../../../pride';
import { GetThisOptionList, GetThisRecord } from '../../../getthis';
import { Breadcrumb } from '../../../reusable';
import { Breadcrumb, H1 } from '../../../reusable';
import PropTypes from 'prop-types';

class GetThisPage extends React.Component {
Expand Down Expand Up @@ -39,7 +39,7 @@ class GetThisPage extends React.Component {
/>
</div>
<section>
<h1 className='heading-xlarge' id='maincontent' tabIndex='-1'>Get This</h1>
<H1 className='heading-xlarge'>Get This</H1>
</section>
{(() => {
if (record?.fields?.length === 0 && record?.names?.length === 0) {
Expand Down
151 changes: 54 additions & 97 deletions src/modules/institution/components/InstitutionSelect/index.js
Original file line number Diff line number Diff line change
@@ -1,115 +1,72 @@
import React from 'react';
import { connect } from 'react-redux';
import _ from 'underscore';
import { withRouter } from 'react-router-dom';
import { useSelector } from 'react-redux';
import { useHistory } from 'react-router-dom';
import { createSelector } from '@reduxjs/toolkit';
import { stringifySearchQueryForURL } from '../../../pride';
import PropTypes from 'prop-types';

class InstitutionSelect extends React.Component {
handleChange (event) {
const { searchQuery, activeFilters, activeDatastore, history } = this.props;
const InstitutionSelect = ({ activeDatastore, institution }) => {
const { uid, slug } = activeDatastore;
const { activeFilters, searchQuery } = useSelector(createSelector(
(state) => {
return state.filters.active[uid];
},
(state) => {
return state.search.query;
},
(activeFilters, searchQuery) => {
return { activeFilters, searchQuery };
}
));
const history = useHistory();

if (uid !== 'mirlyn') {
return null;
}

const { active, defaultInstitution, options } = institution;

const handleChange = (event) => {
const queryString = stringifySearchQueryForURL({
query: searchQuery,
filter: activeFilters,
library: event.target.value
});

history.push(`/${activeDatastore.slug}?${queryString}`);
}

render () {
const { activeDatastore, type } = this.props;
const { active, defaultInstitution, options } = this.props.institution;

// This feature is only for Mirlyn.
if (activeDatastore.uid !== 'mirlyn') {
return null;
}

if (type === 'switch') {
const selectedOption = active || defaultInstitution;
history.push(`/${slug}?${queryString}`);
};

return (
<fieldset className='radio-fieldset'>
<legend className='visually-hidden'>Institutions</legend>
{options.map((option, index) => {
return (
<span key={index}>
<input
id={`library-${index}`}
type='radio'
className='radio-input'
checked={selectedOption === option}
value={option}
onChange={(event) => {
return this.handleChange(event);
}}
/>
<label
htmlFor={`library-${index}`}
className={`radio-label ${
selectedOption === option ? 'radio-selected' : ''
}`}
>
<span className='radio-label-text'>{option}</span>
</label>
</span>
);
})}
</fieldset>
);
} else {
return (
<fieldset className='institution-select-container'>
<legend className='visually-hidden'>Institutions</legend>
<label
className='institution-select-label institution-select-label-text'
htmlFor='library-scope'
>
Library Scope
</label>
<select
className='dropdown'
value={active || defaultInstitution}
onChange={(event) => {
return this.handleChange(event);
}}
id='library-scope'
autoComplete='off'
>
{options.map((option, index) => {
return (
<option value={option} key={index}>
{option}
</option>
);
})}
</select>
</fieldset>
);
}
}
}
return (
<fieldset className='institution-select-container'>
<legend className='visually-hidden'>Institutions</legend>
<label
className='institution-select-label institution-select-label-text'
htmlFor='library-scope'
>
Library Scope
</label>
<select
className='dropdown'
value={active || defaultInstitution}
onChange={handleChange}
id='library-scope'
autoComplete='off'
>
{options.map((option, index) => {
return (
<option value={option} key={index}>
{option}
</option>
);
})}
</select>
</fieldset>
);
};

InstitutionSelect.propTypes = {
searchQuery: PropTypes.string,
activeFilters: PropTypes.object,
activeDatastore: PropTypes.object,
history: PropTypes.object,
type: PropTypes.string,
institution: PropTypes.object
};

function mapStateToProps (state) {
return {
activeDatastore: _.findWhere(state.datastores.datastores, {
uid: state.datastores.active
}),
institution: state.institution,
activeFilters: state.filters.active[state.datastores.active],
searchQuery: state.search.query
};
}

export default withRouter(connect(mapStateToProps)(InstitutionSelect));
export default InstitutionSelect;
Loading

0 comments on commit 39dd5c3

Please sign in to comment.