Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIIN-2634: Set tenant from stripes.okapi.tenant if location.state is empty (follow-up) #2323

Merged
merged 10 commits into from
Oct 31, 2023
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
Loading