-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
overridden: backoffice: DocumentItems: Override columnFormat parameter
- Loading branch information
1 parent
f0d4bc9
commit c628b99
Showing
2 changed files
with
65 additions
and
116 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
177 changes: 63 additions & 114 deletions
177
ui/src/overridden/backoffice/Document/DocumentDetails/DocumentItems.js
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 |
---|---|---|
@@ -1,127 +1,76 @@ | ||
import React, { Component } from "react"; | ||
import PropTypes from "prop-types"; | ||
import React from "react"; | ||
import { Link } from "react-router-dom"; | ||
import { | ||
BackOfficeRoutes, | ||
itemApi, | ||
ResultsTable, | ||
Loader, | ||
Error, | ||
SeeAllButton, | ||
DocumentItems, | ||
} from "@inveniosoftware/react-invenio-app-ils"; | ||
import _get from "lodash/get"; | ||
import _isEmpty from "lodash/isEmpty"; | ||
import { parametrize } from "react-overridable"; | ||
|
||
export class DocumentItems extends Component { | ||
componentDidMount() { | ||
const { fetchDocumentItems, documentDetails } = this.props; | ||
fetchDocumentItems(documentDetails.pid); | ||
} | ||
|
||
seeAllButton = () => { | ||
const { documentDetails } = this.props; | ||
|
||
const path = BackOfficeRoutes.itemsListWithQuery( | ||
itemApi.query().withDocPid(documentDetails.pid).qs() | ||
); | ||
return <SeeAllButton to={path} />; | ||
}; | ||
|
||
viewDetails = ({ row }) => { | ||
return ( | ||
<Link | ||
to={BackOfficeRoutes.itemDetailsFor(row.metadata.pid)} | ||
data-test={row.metadata.pid} | ||
> | ||
{row.metadata.barcode} | ||
</Link> | ||
); | ||
}; | ||
|
||
locationFormatter = ({ row }) => { | ||
return `${row.metadata.internal_location.name} (${row.metadata.internal_location.location.name})`; | ||
}; | ||
|
||
callNumberFormatter = ({ row }) => { | ||
if (!_isEmpty(row.metadata.identifiers)) { | ||
return row.metadata.identifiers.find( | ||
(identifier) => identifier.scheme === "CALL_NUMBER" | ||
).value; | ||
} | ||
return "-"; | ||
}; | ||
const viewDetails = ({ row }) => { | ||
return ( | ||
<Link | ||
to={BackOfficeRoutes.itemDetailsFor(row.metadata.pid)} | ||
data-test={row.metadata.pid} | ||
> | ||
{row.metadata.barcode} | ||
</Link> | ||
); | ||
}; | ||
|
||
renderTable(data) { | ||
const { showMaxItems } = this.props; | ||
const columns = [ | ||
{ | ||
title: "Barcode", | ||
field: "metadata.barcode", | ||
formatter: this.viewDetails, | ||
}, | ||
{ title: "Status", field: "metadata.status" }, | ||
{ title: "Medium", field: "metadata.medium" }, | ||
{ | ||
title: "Location", | ||
field: "metadata.internal_location.name", | ||
formatter: this.locationFormatter, | ||
}, | ||
{ | ||
title: "Call number", | ||
field: "metadata.identifiers", | ||
formatter: this.callNumberFormatter, | ||
}, | ||
{ title: "Restrictions", field: "metadata.circulation_restriction" }, | ||
{ | ||
title: "Loan Status", | ||
field: "metadata.circulation.state", | ||
formatter: ({ row, col }) => { | ||
if (_get(row, col.field) === "ITEM_ON_LOAN") { | ||
return ( | ||
<Link | ||
to={BackOfficeRoutes.loanDetailsFor(row.metadata.circulation.loan_pid)} | ||
> | ||
on loan | ||
</Link> | ||
); | ||
} | ||
return _get(row, col.field) || "-"; | ||
}, | ||
}, | ||
]; | ||
return ( | ||
<ResultsTable | ||
data={data.hits} | ||
columns={columns} | ||
totalHitsCount={data.total} | ||
name="attached items" | ||
seeAllComponent={this.seeAllButton()} | ||
showMaxRows={showMaxItems} | ||
/> | ||
); | ||
} | ||
const locationFormatter = ({ row }) => { | ||
return `${row.metadata.internal_location.name} (${row.metadata.internal_location.location.name})`; | ||
}; | ||
|
||
render() { | ||
const { documentItems, isLoading, error } = this.props; | ||
return ( | ||
<Loader isLoading={isLoading}> | ||
<Error error={error}>{this.renderTable(documentItems)}</Error> | ||
</Loader> | ||
); | ||
const callNumberFormatter = ({ row }) => { | ||
if (!_isEmpty(row.metadata.identifiers)) { | ||
return row.metadata.identifiers.find( | ||
(identifier) => identifier.scheme === "CALL_NUMBER" | ||
).value; | ||
} | ||
} | ||
|
||
DocumentItems.propTypes = { | ||
documentItems: PropTypes.object.isRequired, | ||
documentDetails: PropTypes.object.isRequired, | ||
fetchDocumentItems: PropTypes.func.isRequired, | ||
showMaxItems: PropTypes.number, | ||
isLoading: PropTypes.bool, | ||
error: PropTypes.object, | ||
return "-"; | ||
}; | ||
|
||
DocumentItems.defaultProps = { | ||
showMaxItems: 5, | ||
isLoading: false, | ||
error: null, | ||
const columnFormat = () => { | ||
return [ | ||
{ | ||
title: "Barcode", | ||
field: "metadata.barcode", | ||
formatter: viewDetails, | ||
}, | ||
{ title: "Status", field: "metadata.status" }, | ||
{ title: "Medium", field: "metadata.medium" }, | ||
{ | ||
title: "Location", | ||
field: "metadata.internal_location.name", | ||
formatter: locationFormatter, | ||
}, | ||
{ | ||
title: "Call number", | ||
field: "metadata.identifiers", | ||
formatter: callNumberFormatter, | ||
}, | ||
{ title: "Restrictions", field: "metadata.circulation_restriction" }, | ||
{ | ||
title: "Loan Status", | ||
field: "metadata.circulation.state", | ||
formatter: ({ row, col }) => { | ||
if (_get(row, col.field) === "ITEM_ON_LOAN") { | ||
return ( | ||
<Link | ||
to={BackOfficeRoutes.loanDetailsFor(row.metadata.circulation.loan_pid)} | ||
> | ||
on loan | ||
</Link> | ||
); | ||
} | ||
return _get(row, col.field) || "-"; | ||
}, | ||
}, | ||
]; | ||
}; | ||
|
||
export const DocumentItemsLayout = parametrize(DocumentItems, { | ||
columnFormat: columnFormat, | ||
}); |