Skip to content

Commit

Permalink
UIIN-2634: Set tenant from stripes.okapi.tenant if location.state
Browse files Browse the repository at this point in the history
… is empty (follow-up) (#2323)

* UIIN-2634: Remove error when search for an item

* UIIN-2634: Fix tests

* UIIN-2634: set tenant from stripes.okapi.tenant if location.state is empty

* Set !{tenantTo} instead of !{location.state.tenantTo} in holdings/items manifest

* UIIN-2634: Remove unused methods in ItemRoute component

* UIIN-2634: Fix code smell

* UIIN-2634: get rid of getRequestsPath variable

(cherry picked from commit 3d7c603)
  • Loading branch information
OleksandrHladchenko1 authored and mariia-aloshyna committed Nov 7, 2023
1 parent 104702b commit aa913ef
Show file tree
Hide file tree
Showing 5 changed files with 196 additions and 176 deletions.
4 changes: 2 additions & 2 deletions src/ViewHoldingsRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class ViewHoldingsRecord extends React.Component {
path: 'holdings-storage/holdings/:{holdingsrecordid}',
resourceShouldRefresh: false,
accumulate: true,
tenant: '!{location.state.tenantTo}'
tenant: '!{tenantTo}',
},
items: {
type: 'okapi',
Expand All @@ -97,7 +97,7 @@ class ViewHoldingsRecord extends React.Component {
type: 'okapi',
path: 'inventory/instances/:{id}',
accumulate: true,
tenant: '!{location.state.tenantTo}'
tenant: '!{tenantTo}',
},
tagSettings: {
type: 'okapi',
Expand Down
174 changes: 5 additions & 169 deletions src/routes/ItemRoute.js
Original file line number Diff line number Diff line change
@@ -1,190 +1,26 @@
import React from 'react';
import PropTypes from 'prop-types';
import {
flowRight,
get,
} from 'lodash';
import { flowRight } from 'lodash';

import { stripesConnect } from '@folio/stripes/core';

import { requestsStatusString } from '../Instance/ViewRequests/utils';

import withLocation from '../withLocation';
import { ItemView } from '../views';
import { PaneLoading } from '../components';
import { DataContext } from '../contexts';

const getRequestsPath = `circulation/requests?query=(itemId==:{itemid}) and status==(${requestsStatusString}) sortby requestDate desc&limit=1`;

class ItemRoute extends React.Component {
static manifest = Object.freeze({
query: {},
itemsResource: {
type: 'okapi',
path: 'inventory/items/:{itemid}',
POST: { path: 'inventory/items' },
resourceShouldRefresh: true,
tenant: '!{location.state.tenantTo}',
},
markItemAsWithdrawn: {
type: 'okapi',
POST: {
path: 'inventory/items/:{itemid}/mark-withdrawn',
},
clientGeneratePk: false,
fetch: false,
},
markItemAsMissing: {
type: 'okapi',
POST: {
path: 'inventory/items/:{itemid}/mark-missing',
},
clientGeneratePk: false,
fetch: false,
},
markAsInProcess: {
type: 'okapi',
POST: {
path: 'inventory/items/:{itemid}/mark-in-process',
},
clientGeneratePk: false,
fetch: false,
},
markAsInProcessNonRequestable: {
type: 'okapi',
POST: {
path: 'inventory/items/:{itemid}/mark-in-process-non-requestable',
},
clientGeneratePk: false,
fetch: false,
},
markAsIntellectualItem: {
type: 'okapi',
POST: {
path: 'inventory/items/:{itemid}/mark-intellectual-item',
},
clientGeneratePk: false,
fetch: false,
},
markAsLongMissing: {
type: 'okapi',
POST: {
path: 'inventory/items/:{itemid}/mark-long-missing',
},
clientGeneratePk: false,
fetch: false,
},
markAsRestricted: {
type: 'okapi',
POST: {
path: 'inventory/items/:{itemid}/mark-restricted',
},
clientGeneratePk: false,
fetch: false,
},
markAsUnavailable: {
type: 'okapi',
POST: {
path: 'inventory/items/:{itemid}/mark-unavailable',
},
clientGeneratePk: false,
fetch: false,
},
markAsUnknown: {
type: 'okapi',
POST: {
path: 'inventory/items/:{itemid}/mark-unknown',
},
clientGeneratePk: false,
fetch: false,
},
holdingsRecords: {
type: 'okapi',
path: 'holdings-storage/holdings/:{holdingsrecordid}',
tenant: '!{location.state.tenantTo}',
},
instanceRecords: {
type: 'okapi',
path: 'inventory/instances/:{id}',
resourceShouldRefresh: true,
},
servicePoints: {
type: 'okapi',
path: 'service-points',
records: 'servicepoints',
params: (_q, _p, _r, _l, props) => {
// Only one service point is of interest here: the SP used for the item's last check-in
// (if the item has a check-in). Iff that service point ID is found, add a query param
// to filter down to that one service point in the records returned.
const servicePointId = get(props.resources, 'itemsResource.records[0].lastCheckIn.servicePointId', '');
const query = servicePointId && `id==${servicePointId}`;
return query ? { query } : {};
},
resourceShouldRefresh: true,
},
staffMembers: {
type: 'okapi',
path: 'users',
records: 'users',
params: (_q, _p, _r, _l, props) => {
const staffMemberId = get(props.resources, 'itemsResource.records[0].lastCheckIn.staffMemberId', '');
const query = staffMemberId && `id==${staffMemberId}`;

return query ? { query } : null;
},
resourceShouldRefresh: true,
},
// return a count of the requests matching the given item and status
requests: {
type: 'okapi',
path: getRequestsPath,
records: 'requests',
PUT: { path: 'circulation/requests/%{requestOnItem.id}' },
},
openLoans: {
type: 'okapi',
path: 'circulation/loans',
params: {
query: 'status.name=="Open" and itemId==:{itemid}',
},
records: 'loans',
},
requestOnItem: {},
tagSettings: {
type: 'okapi',
records: 'configs',
path: 'configurations/entries?query=(module==TAGS and configName==tags_enabled)',
},
});

isLoading = () => {
render() {
const {
resources: {
itemsResource,
holdingsRecords,
instanceRecords,
},
stripes: { okapi },
location: { state },
} = this.props;

if (!itemsResource?.hasLoaded ||
!instanceRecords?.hasLoaded ||
!holdingsRecords?.hasLoaded) {
return true;
}

return false;
}

render() {
if (this.isLoading()) {
return <PaneLoading defaultWidth="100%" />;
}

return (
<DataContext.Consumer>
{data => (
<ItemView
{...this.props}
tenantTo={state?.tenantTo || okapi.tenant}
referenceTables={data}
/>
)}
Expand Down
10 changes: 9 additions & 1 deletion src/routes/ViewHoldingRoute.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { useContext } from 'react';
import { useParams } from 'react-router-dom';
import {
useParams,
useLocation,
} from 'react-router-dom';

import { useStripes } from '@folio/stripes/core';

import { DataContext } from '../contexts';
import ViewHoldingsRecord from '../ViewHoldingsRecord';

const ViewHoldingRoute = () => {
const { id: instanceId, holdingsrecordid } = useParams();
const referenceTables = useContext(DataContext);
const { okapi } = useStripes();
const { state } = useLocation();

return (
<ViewHoldingsRecord
id={instanceId}
tenantTo={state?.tenantTo || okapi.tenant}
referenceTables={referenceTables}
holdingsrecordid={holdingsrecordid}
/>
Expand Down
Loading

0 comments on commit aa913ef

Please sign in to comment.