Skip to content

Commit

Permalink
Adding TrimString to author metadata. Replacing kind with `view…
Browse files Browse the repository at this point in the history
…Type`.
  • Loading branch information
erinesullivan committed Nov 19, 2024
1 parent 7a995a0 commit f56bb0d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
5 changes: 2 additions & 3 deletions src/modules/records/components/RecordMetadata/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ContextProvider, Metadata } from '../../../reusable';
import PropTypes from 'prop-types';
import React from 'react';

const RecordMetadata = ({ kind, record }) => {
const RecordMetadata = ({ record }) => {
const { metadata } = record;

if (!metadata) {
Expand All @@ -17,14 +17,13 @@ const RecordMetadata = ({ kind, record }) => {
Medium: metadata.medium,
Preview: metadata.preview
};
return <Metadata data={data[context.viewType] || metadata.full} kind={kind} />;
return <Metadata data={data[context.viewType] || metadata.full} viewType={context.viewType} />;
}}
/>
);
};

RecordMetadata.propTypes = {
kind: PropTypes.string,
record: PropTypes.object
};

Expand Down
2 changes: 1 addition & 1 deletion src/modules/records/components/RecordPreview/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const RecordPreview = ({ datastoreUid, record, searchQuery }) => {
return (
<article className='record-preview'>
<Header {...{ datastoreUid, record, searchQuery }} />
<RecordMetadata {...{ record }} kind='condensed' />
<RecordMetadata {...{ record }} />
<Zotero {...{ record }} />
<Footer {...{ record, searchQuery }} />
</article>
Expand Down
20 changes: 11 additions & 9 deletions src/modules/reusable/components/Metadata/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { BrowseLink } from '../../../browse';
import PropTypes from 'prop-types';
import React from 'react';
import { stringifySearch } from '../../../search';
import { TrimString } from '../../../core';
import { useSelector } from 'react-redux';

const DescriptionItem = ({ browse, children, href, search }) => {
Expand Down Expand Up @@ -63,7 +64,7 @@ DescriptionItem.propTypes = {
search: PropTypes.object
};

const Description = ({ data }) => {
const Description = ({ data, viewType }) => {
if (Array.isArray(data)) {
return (
<ol className='list__unstyled'>
Expand All @@ -79,7 +80,7 @@ const Description = ({ data }) => {
);
}

const { icon, image, text } = data;
const { icon, image, search: { scope } = {}, text } = data;

return (
<DescriptionItem {...data}>
Expand All @@ -91,7 +92,7 @@ const Description = ({ data }) => {
className='margin-right__2xs text-grey__light'
/>
)}
{text}
{scope === 'author' && viewType !== 'Full' ? <TrimString {...{ string: text, trimLength: 64 }} /> : text}
</span>
{image && (
<img
Expand All @@ -108,26 +109,27 @@ Description.propTypes = {
data: PropTypes.oneOfType([
PropTypes.array,
PropTypes.object
])
]),
viewType: PropTypes.string
};

export default function Metadata ({ data, kind }) {
export default function Metadata ({ data, viewType }) {
return (
<dl className='flex__responsive metadata-list'>
{data.map((datum, datumIndex) => {
const { description, term, termPlural } = datum;
const isExpandable = description.length > 5;
return (
<div className={kind === 'condensed' ? '' : 'metadata-list-item'} key={datumIndex}>
<div className={viewType === 'Preview' ? '' : 'metadata-list-item'} key={datumIndex}>
<Expandable>
<dt className={kind === 'condensed' ? 'visually-hidden' : ''}>
<dt className={viewType === 'Preview' ? 'visually-hidden' : ''}>
{term}
</dt>
<ExpandableChildren show={isExpandable ? 4 : description.length}>
{description.map((descriptor, index) => {
return (
<dd key={index}>
<Description data={descriptor} />
<Description data={descriptor} viewType={viewType} />
</dd>
);
})}
Expand All @@ -143,5 +145,5 @@ export default function Metadata ({ data, kind }) {

Metadata.propTypes = {
data: PropTypes.array,
kind: PropTypes.string
viewType: PropTypes.string
};

0 comments on commit f56bb0d

Please sign in to comment.