Skip to content

Commit

Permalink
backoffice: Use ? operator instead of _get
Browse files Browse the repository at this point in the history
  • Loading branch information
sakshamarora1 authored and kpsherva committed May 28, 2024
1 parent 12f2d60 commit 76aba5e
Show file tree
Hide file tree
Showing 10 changed files with 16 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/lib/modules/Document/DocumentCard/DocumentCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DocumentCard extends Component {
metadata,
'relations.multipart_monograph[0].record_metadata.title'
);
const subtitle = renderSubtitle(_get(metadata, 'alternative_titles'));
const subtitle = renderSubtitle(metadata.alternative_titles);

return (
<Overridable id="DocumentCard.layout" {...this.props}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class DocumentListEntry extends Component {
metadata={this.metadata}
/>
<Item.Meta>
{renderSubtitle(_get(this.metadata, 'alternative_titles'))}
{renderSubtitle(this.metadata?.alternative_titles)}
<DocumentAuthors
authors={this.metadata.authors}
hasOtherAuthors={this.metadata.other_authors}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export default class DocumentListEntry extends Component {
<Grid columns={3}>
<Grid.Column computer={6} largeScreen={5}>
<Item.Meta className="document-authors">
{renderSubtitle(_get(document, 'metadata.alternative_titles'))}
{renderSubtitle(document.metadata?.alternative_titles)}
<DocumentAuthors
authors={document.metadata.authors}
hasOtherAuthors={document.metadata.other_authors}
Expand Down
8 changes: 2 additions & 6 deletions src/lib/modules/Document/utils.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import React from 'react';
import { Truncate } from '@components/Truncate';
import find from 'lodash/find';
import _isEmpty from 'lodash/isEmpty';
import _find from 'lodash/find';

export const renderSubtitle = (alternativeTitles) => {
if (_isEmpty(alternativeTitles)) {
return null;
}
const subtitle = find(alternativeTitles, { type: 'SUBTITLE' });
const subtitle = _find(alternativeTitles, { type: 'SUBTITLE' });
return subtitle ? <Truncate>{subtitle.value}</Truncate> : null;
};
4 changes: 4 additions & 0 deletions src/lib/modules/Series/SeriesCard.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Link } from 'react-router-dom';
import { Card, Label } from 'semantic-ui-react';
import { Truncate } from '@components/Truncate';
import { invenioConfig } from '@config';
import { renderSubtitle } from '@modules/Document/utils';

export class SeriesCard extends Component {
renderImage = () => {
Expand Down Expand Up @@ -40,6 +41,8 @@ export class SeriesCard extends Component {
.slice(0, invenioConfig.LITERATURE.authors.maxDisplay)
.join('; ')
: null;
const subtitle = renderSubtitle(data.metadata?.alternative_titles);

return (
<Card
centered
Expand All @@ -65,6 +68,7 @@ export class SeriesCard extends Component {
{data.metadata.edition && (
<div>Edition {data.metadata.edition}</div>
)}
{subtitle}
{data.metadata.publisher && (
<div>Publisher {data.metadata.publisher}</div>
)}
Expand Down
2 changes: 2 additions & 0 deletions src/lib/modules/Series/SeriesListEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import { Grid, Item, Label, List } from 'semantic-ui-react';
import { renderSubtitle } from '@modules/Document/utils';

export default class SeriesListEntry extends Component {
constructor(props) {
Expand Down Expand Up @@ -59,6 +60,7 @@ export default class SeriesListEntry extends Component {
<LiteratureTitle title={this.metadata.title} />
</Item.Header>
<Item.Meta>
{renderSubtitle(this.metadata?.alternative_titles)}
<SeriesAuthors authors={this.metadata.authors} prefix="by " />
</Item.Meta>
<Item.Description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import React from 'react';
import { Link } from 'react-router-dom';
import { Divider, Grid, Icon, Item, Message, Popup } from 'semantic-ui-react';
import Overridable from 'react-overridable';
import _get from 'lodash/get';
import { renderSubtitle } from '@modules/Document/utils';

const OrderLineLeftColumn = ({ line }) => {
Expand Down Expand Up @@ -113,7 +112,7 @@ export const OrderLine = ({ line, LeftColumn, MiddleColumn, RightColumn }) => {
/>
</Link>
<Item.Meta>
{renderSubtitle(_get(line, 'document.alternative_titles'))}
{renderSubtitle(line.document?.alternative_titles)}
</Item.Meta>
<Divider />
<Grid columns={3}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import { BorrowingRequestMetadata } from './BorrowingRequestMetadata';
import { BorrowingRequestPayment } from './BorrowingRequestPayment';
import { BorrowingRequestStatistics } from './BorrowingRequestStatistics';
import { BorrowingRequestSteps } from './BorrowingRequestSteps';
import _get from 'lodash/get';
import { renderSubtitle } from '@modules/Document/utils';

class BorrowingRequestHeader extends React.Component {
Expand Down Expand Up @@ -55,9 +54,7 @@ class BorrowingRequestHeader extends React.Component {
{provider.name}
</Link>
);
const subtitle = renderSubtitle(
_get(brwReq, 'document.alternative_titles')
);
const subtitle = renderSubtitle(brwReq.document?.alternative_titles);
const pid = brwReq.pid;
const recordInfo = (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import { Grid, Item, List } from 'semantic-ui-react';
import _get from 'lodash/get';
import { renderSubtitle } from '@modules/Document/utils';

export default class BorrowingRequestListEntry extends Component {
Expand Down Expand Up @@ -140,9 +139,7 @@ export default class BorrowingRequestListEntry extends Component {
{brwReqMetadata.document.title}
</Item.Header>
<Item.Meta>
{renderSubtitle(
_get(brwReqMetadata, 'document.alternative_titles')
)}
{renderSubtitle(brwReqMetadata.document?.alternative_titles)}
</Item.Meta>
<Grid highlight={3}>
<Grid.Column computer={5} largeScreen={5}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import PropTypes from 'prop-types';
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import { Grid, Header, Icon, Item, List } from 'semantic-ui-react';
import { renderSubtitle } from '@modules/Document/utils';

export class SeriesListEntry extends Component {
renderImage = (series) => (
Expand Down Expand Up @@ -117,6 +118,7 @@ export class SeriesListEntry extends Component {
<Grid columns={3}>
<Grid.Column computer={6} largeScreen={5}>
<Item.Meta className="series-authors">
{renderSubtitle(series.metadata?.alternative_titles)}
<SeriesAuthors prefix="by " authors={series.metadata.authors} />
</Item.Meta>
{identifier && (
Expand Down

0 comments on commit 76aba5e

Please sign in to comment.