-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #507 from mlibrary/LIBSEARCH-1042-update-articles-…
…catalog-medium-view [LIBSEARCH-1042] Update Articles & Catalog medium view
- Loading branch information
Showing
10 changed files
with
164 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import { Anchor, Icon } from '../../../reusable'; | ||
import { BrowseLink } from '../../../browse'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import { stringifySearch } from '../../../search'; | ||
import { TrimString } from '../../../core'; | ||
|
||
const Description = ({ activeDatastore, data, datastores, institution, viewType }) => { | ||
if (Array.isArray(data)) { | ||
return ( | ||
<ol className='list__unstyled'> | ||
{data.map((datum, index) => { | ||
return ( | ||
<li key={index}> | ||
{index > 0 && <Icon icon='navigate_next' className='text-grey__light' />} | ||
<Description {...{ activeDatastore, data: datum, datastores, institution, viewType }} /> | ||
</li> | ||
); | ||
})} | ||
</ol> | ||
); | ||
} | ||
|
||
const { browse, href, icon, search, text } = data; | ||
const searchScope = search?.scope || {}; | ||
const anchorAttributes = search | ||
? ( | ||
() => { | ||
const { slug, uid } = datastores.find((datastore) => { | ||
return datastore.uid === activeDatastore; | ||
}); | ||
const { scope, type, value } = search; | ||
return { | ||
to: `/${slug}?${stringifySearch({ | ||
filter: type === 'filtered' ? { [scope]: value } : {}, | ||
library: uid === 'mirlyn' ? institution : '', | ||
query: type === 'fielded' ? `${scope}:${value}` : value | ||
})}` | ||
}; | ||
} | ||
)() | ||
: { href }; | ||
|
||
const { text: browseText, type, value } = browse || {}; | ||
|
||
const child = ( | ||
<> | ||
{icon && <Icon icon={icon} size={19} className='margin-right__2xs text-grey__light' />} | ||
{ ['Preview', 'Medium'].includes(viewType) ? <TrimString {...{ string: text, trimLength: searchScope === 'author' ? 64 : 240 }} /> : text } | ||
</> | ||
); | ||
|
||
return ( | ||
<> | ||
{(href || search) ? <Anchor {...anchorAttributes}>{child}</Anchor> : child} | ||
{browseText && ( | ||
<> | ||
<span className='text-grey font-small margin-x__2xs'>|</span> | ||
<BrowseLink | ||
className='text-grey font-small underline underline__hover-thick' | ||
{...{ type, value }} | ||
> | ||
{browseText} | ||
</BrowseLink> | ||
</> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
Description.propTypes = { | ||
activeDatastore: PropTypes.string, | ||
data: PropTypes.oneOfType([ | ||
PropTypes.array, | ||
PropTypes.object | ||
]), | ||
datastores: PropTypes.array, | ||
institution: PropTypes.string, | ||
viewType: PropTypes.string | ||
}; | ||
|
||
export default Description; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import './styles.css'; | ||
import { | ||
ContextProvider, | ||
Expandable, | ||
ExpandableButton, | ||
ExpandableChildren | ||
} from '../../../reusable'; | ||
import Description from '../Description'; | ||
import PropTypes from 'prop-types'; | ||
import React from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
|
||
const Metadata = ({ metadata = {} }) => { | ||
const { active: activeInstitution, defaultInstitution } = useSelector((state) => { | ||
return state.institution; | ||
}); | ||
const { active: activeDatastore, datastores } = useSelector((state) => { | ||
return state.datastores; | ||
}); | ||
|
||
if (!metadata || Object.keys(metadata).length === 0) { | ||
return null; | ||
} | ||
|
||
const institution = activeInstitution || defaultInstitution; | ||
|
||
const metadataView = { | ||
Full: metadata.full, | ||
Medium: metadata.medium, | ||
Preview: metadata.preview | ||
}; | ||
|
||
return ( | ||
<ContextProvider | ||
render={({ viewType }) => { | ||
return ( | ||
<dl className='flex__responsive metadata-list'> | ||
{(metadataView[viewType] || metadata.full).map(({ description, term, termPlural }, index) => { | ||
if (!description) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<div className={viewType === 'Preview' ? '' : 'metadata-list-item'} key={index}> | ||
<Expandable> | ||
<dt className={viewType === 'Preview' ? 'visually-hidden' : ''}> | ||
{term} | ||
</dt> | ||
<ExpandableChildren> | ||
{description.map((data, dataIndex) => { | ||
return ( | ||
<dd key={dataIndex}> | ||
<Description {...{ activeDatastore, data, datastores, institution, viewType }} /> | ||
</dd> | ||
); | ||
})} | ||
</ExpandableChildren> | ||
{description.length > 3 && <dd className='margin-top__2xs'><ExpandableButton name={termPlural || term} count={description.length} /></dd>} | ||
</Expandable> | ||
</div> | ||
); | ||
})} | ||
</dl> | ||
); | ||
}} | ||
/> | ||
); | ||
}; | ||
|
||
Metadata.propTypes = { | ||
metadata: PropTypes.object | ||
}; | ||
|
||
export default Metadata; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.