Skip to content

Commit

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

`history` and `react-router-update` - Part 3
  • Loading branch information
erinesullivan authored Mar 8, 2024
2 parents 39dd5c3 + 316b910 commit 3a7be8e
Show file tree
Hide file tree
Showing 16 changed files with 271 additions and 382 deletions.
12 changes: 0 additions & 12 deletions src/modules/core/components/Icon/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,18 +286,6 @@ const Icon = ({ name }) => {
</g>
</svg>
);
case 'multi-result':
return (
<svg viewBox='0 0 16 16' version='1.1' className='icon' focusable='false' role='presentation'>
<g stroke='none' strokeWidth='1' fill='none' fillRule='evenodd'>
<g transform='translate(-372.000000, -16.000000)'>
<g transform='translate(372.000000, 12.000000)'>
<path d='M9,4 L9,9 L16,9 L16,4 L9,4 Z M9,20 L16,20 L16,11 L9,11 L9,20 Z M0,20 L7,20 L7,15 L0,15 L0,20 Z M0,13 L7,13 L7,4 L0,4 L0,13 L0,13 Z' />
</g>
</g>
</g>
</svg>
);
case 'search':
return (
<svg viewBox='0 0 16 16' version='1.1' className='icon' focusable='false' role='presentation'>
Expand Down
98 changes: 32 additions & 66 deletions src/modules/datastores/components/DatastoreNavigation/index.js
Original file line number Diff line number Diff line change
@@ -1,77 +1,43 @@
import React from 'react';
import { getDatastoreUidBySlug, stringifySearchQueryForURL } from '../../../pride';
import { changeActiveDatastore } from '../../actions';
import { Icon } from '../../../core';
import './styles.css';
import { stringifySearchQueryForURL } from '../../../pride';
import { Anchor, Icon } from '../../../reusable';
import PropTypes from 'prop-types';
import { withRouter } from 'react-router-dom';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';

function DatastoreNavigation (props) {
const { match, datastores, search, activeFilters, history, institution } = props;
const routeDatastoreUid = getDatastoreUidBySlug(match.params.datastoreSlug);
const activeDatastoreUid = datastores.active;

if (routeDatastoreUid !== activeDatastoreUid) {
changeActiveDatastore(routeDatastoreUid);
}

function DatastoreNavigation ({ activeFilters, datastores, institution, search }) {
return (
<div className='datastore-list-container datastore-scroll-container'>
<nav className='datastore-scroll-x' aria-label='Datastores'>
<ol className='datastore-list'>
{datastores.datastores.map((datastore) => {
const queryString = stringifySearchQueryForURL({
query: search.query,
filter: activeFilters[datastore.uid],
page: search.page[datastore.uid] === 1 ? undefined : search.page[datastore.uid],
sort: search.sort[datastore.uid],
library: datastore.uid === 'mirlyn' ? institution.active : undefined
});
const active = datastore.uid === activeDatastoreUid;

return (
<li className='datastore-item' key={datastore.uid}>
<button
onClick={() => {
return history.push(`/${datastore.slug}${queryString.length > 0 ? `?${queryString}` : ''}`);
}}
aria-pressed={active}
className={`datastore-button ${active ? 'datastore-button--active' : ''}`}
>
{datastore.isMultisearch && <Icon name='multi-result' />}
{datastore.name}
</button>
</li>
);
})}
</ol>
</nav>
</div>
<nav className='datastore-nav' aria-label='Datastores'>
<ol>
{datastores.datastores.map((datastore) => {
const queryString = stringifySearchQueryForURL({
query: search.query,
filter: activeFilters[datastore.uid],
page: search.page[datastore.uid] === 1 ? undefined : search.page[datastore.uid],
sort: search.sort[datastore.uid],
library: datastore.uid === 'mirlyn' ? institution.active : undefined
});
return (
<li key={datastore.uid}>
<Anchor
to={`/${datastore.slug}${queryString ? `?${queryString}` : ''}`}
aria-current={datastores.active === datastore.uid && 'page'}
>
{datastore.isMultisearch && <Icon icon='multi_result' />}
{datastore.name}
</Anchor>
</li>
);
})}
</ol>
</nav>
);
};

DatastoreNavigation.propTypes = {
match: PropTypes.object,
datastores: PropTypes.object,
search: PropTypes.object,
activeFilters: PropTypes.object,
history: PropTypes.object,
institution: PropTypes.object
datastores: PropTypes.object,
institution: PropTypes.object,
search: PropTypes.object
};

export default withRouter(connect(
(state) => {
return {
datastores: state.datastores,
search: state.search,
activeFilters: state.filters.active,
institution: state.institution
};
},
(dispatch) => {
return bindActionCreators({
changeActiveDatastore
}, dispatch);
}
)(DatastoreNavigation));
export default DatastoreNavigation;
69 changes: 69 additions & 0 deletions src/modules/datastores/components/DatastoreNavigation/styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
.datastore-nav {
background: var(--search-color-grey-100);
border-bottom: solid 2px var(--search-color-grey-300);
overflow-x: auto;
}

.datastore-nav ol {
display: flex;
flex-direction: column;
list-style: none;
margin: 0;
justify-content: center;
}

@media (min-width: 600px) {
.datastore-nav ol {
flex-direction: row;
}
}

.datastore-nav li + li {
border-top: 1px solid var(--search-color-grey-300);
}

@media (min-width: 600px) {
.datastore-nav li + li {
border: 0;
}
}

.datastore-nav a {
align-items: center;
border-color: transparent;
border-style: solid;
border-left-width: 3px;
display: flex;
height: 100%;
padding: 0.5rem 1rem;
text-decoration: none;
white-space: nowrap;
}

@media (min-width: 600px) {
.datastore-nav a {
border-bottom-width: 2px;
border-left-width: 0;
}
}

.datastore-nav a:hover {
text-decoration: underline;
}

.datastore-nav a svg {
height: auto;
width: 1.5em;
}

.datastore-nav a[aria-current="page"] {
border-color: inherit;
}

.datastore-nav a:not([aria-current="page"]) {
color: var(--search-color-grey-700);
}

.datastore-nav a:not([aria-current="page"]) svg {
color: var(--search-color-grey-400);
}
28 changes: 16 additions & 12 deletions src/modules/datastores/components/FlintAlerts/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React, { useState } from 'react';
import { Alert, Anchor } from '../../../reusable';
import { connect } from 'react-redux';
import PropTypes from 'prop-types';

function FlintAlerts ({ datastore, profile }) {
Expand All @@ -23,13 +22,22 @@ function FlintAlerts ({ datastore, profile }) {

return (
<Alert type='warning'>
<span>{messages[datastore]}</span>
<button
className='btn btn--small btn--secondary no-background'
onClick={handleDismissClick}
<div
style={{
alignItems: 'center',
display: 'flex',
gap: '1rem',
justifyContent: 'center'
}}
>
Dismiss
</button>
<span>{messages[datastore]}</span>
<button
className='btn btn--small btn--secondary no-background'
onClick={handleDismissClick}
>
Dismiss
</button>
</div>
</Alert>
);
}
Expand All @@ -39,8 +47,4 @@ FlintAlerts.propTypes = {
datastore: PropTypes.string
};

export default connect((state) => {
return {
profile: state.profile
};
})(FlintAlerts);
export default FlintAlerts;
18 changes: 8 additions & 10 deletions src/modules/getthis/components/GetThisForm/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { Anchor } from '../../../reusable';
import { Alert, Anchor } from '../../../reusable';
import { connect } from 'react-redux';
import { getField, getFieldValue } from '../../../records/utilities';
import { placeHold } from '../../../pride';
Expand Down Expand Up @@ -141,22 +141,22 @@ class GetThisForm extends React.Component {
if (response) {
if (response.status === 'Action Succeeded') {
return (
<article className='alert alert-success'>
<Alert type='success'>
<h4>You have successfully requested this item</h4>
<ul className='u-margin-bottom-1 margin-left-2'>
<li>We will email you when it is available for pickup.</li>
<li>When it is available, we'll hold it for you for 7 days.</li>
</ul>
<Anchor href='https://account.lib.umich.edu/pending-requests/u-m-library'>View all your holds</Anchor>
</article>
</Alert>
);
} else {
return (
<article className='alert alert-warning'>
<Alert type='warning'>
<h4>The hold/request could not be placed</h4>
<p><span className='strong'>Status:</span> {response.status}</p>
<p className='u-margin-bottom-none'>Please contact the Graduate Library Circulation Desk at <Anchor href='mailto:[email protected]'>[email protected]</Anchor> or <Anchor href='tel:7347640401'>(734) 764-0401</Anchor> for assistance.</p>
</article>
</Alert>
);
}
}
Expand All @@ -171,17 +171,15 @@ class GetThisForm extends React.Component {

if (!form) {
return (
<div className='alert alert-warning' role='alert'>
<Alert type='warning'>
<p><span className='strong'>Error:</span> Unable to fetch details.</p>
</div>
</Alert>
);
}

return (
<>
<div role='alert'>
{this.renderResponse()}
</div>
{this.renderResponse()}
{showForm && (
<form action={form.action} method={form.method} onSubmit={this.handleSubmit}>
{fields.map((field, key) => {
Expand Down
13 changes: 7 additions & 6 deletions src/modules/getthis/components/GetThisOptionList/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React from 'react';
import { Alert } from '../../../reusable';
import { connect } from 'react-redux';
import { DetailsList } from '../../../core';
import GetThisOption from '../GetThisOption';
Expand All @@ -7,26 +8,26 @@ import PropTypes from 'prop-types';

function GetThisOptions (props) {
let section = (
<div className='alert'>
<Alert>
<p>Loading holding options...</p>
</div>
</Alert>
);

if (props.record?.getthis) {
const { status, options } = props.record.getthis;

section = (
<div className='alert'>
<Alert>
<p>Sorry, something unexpected happened.</p>
<p><span className='strong'>Status:</span> {status}</p>
</div>
</Alert>
);

if (status === 'Success') {
section = (
<div className='alert alert--error'>
<Alert type='error'>
No options available.
</div>
</Alert>
);

if (options.length) {
Expand Down
14 changes: 7 additions & 7 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, H1 } from '../../../reusable';
import { Alert, Breadcrumb, H1 } from '../../../reusable';
import PropTypes from 'prop-types';

class GetThisPage extends React.Component {
Expand Down Expand Up @@ -38,15 +38,15 @@ class GetThisPage extends React.Component {
]}
/>
</div>
<section>
<H1 className='heading-xlarge'>Get This</H1>
</section>
<H1 className='heading-xlarge'>Get This</H1>
{(() => {
if (record?.fields?.length === 0 && record?.names?.length === 0) {
return (
<div className='alert'>
<p><span className='strong'>Error:</span> Unable to find this record.</p>
</div>
<section className='container__rounded page'>
<Alert type='error'>
<span className='strong'>Error:</span> Unable to find this record.
</Alert>
</section>
);
}

Expand Down
Loading

0 comments on commit 3a7be8e

Please sign in to comment.