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-2452: Fix creating/editing/duplicating holdings/items for different member tenants (follow-up) #2319

Merged
merged 56 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
e9ff698
Consortial holdings acc
mariia-aloshyna Sep 22, 2023
f5c029c
UIIN-2410: Adjustments
mariia-aloshyna Sep 25, 2023
4a08c0c
UIIN-2410: Add new hook
mariia-aloshyna Sep 27, 2023
5dfcf0d
UIIN-2410: Add tests
mariia-aloshyna Sep 27, 2023
188acc3
UIIN-2452: Disable buttons when member tenant does not have permissions
OleksandrHladchenko1 Oct 3, 2023
58f4cd4
UIIN-2410: Instance 3rd pane: Add consortial holdings/item accordion
mariia-aloshyna Sep 22, 2023
dc2e0d0
UIIN-2452: Add unit tests & switching affiliation when view holdings …
OleksandrHladchenko1 Oct 3, 2023
108f852
UIIN-2410: Fix tests
mariia-aloshyna Oct 4, 2023
3f42476
Merge branch 'master' into UIIN-2410
mariia-aloshyna Oct 4, 2023
9e1b138
UIIN-2452: Add switching affiliation when click on item barcode & Add…
OleksandrHladchenko1 Oct 5, 2023
872f7be
Merge branch 'master' into UIIN-2452
OleksandrHladchenko1 Oct 5, 2023
c8e3f29
UIIN-2452: Add behaviour for non-consortial tenant
OleksandrHladchenko1 Oct 6, 2023
f57ce13
Merge branch 'UIIN-2452' of https://github.com/folio-org/ui-inventory…
OleksandrHladchenko1 Oct 6, 2023
5726f06
UIIN-2452: Fix tests
OleksandrHladchenko1 Oct 6, 2023
d25021e
Merge branch 'master' into UIIN-2452
OleksandrHladchenko1 Oct 6, 2023
767a4a1
Update HoldingAccordion.js
OleksandrHladchenko1 Oct 6, 2023
5769fca
Update HoldingButtonsGroup.js
OleksandrHladchenko1 Oct 6, 2023
fc4b05a
UIIN-2452: Fix tests
OleksandrHladchenko1 Oct 6, 2023
1c5bcd1
Merge branch 'UIIN-2452' of https://github.com/folio-org/ui-inventory…
OleksandrHladchenko1 Oct 6, 2023
081f18b
Update HoldingsListMovement.js
OleksandrHladchenko1 Oct 8, 2023
60b4011
Update HoldingContainer.js
OleksandrHladchenko1 Oct 9, 2023
9c397c8
UIIN-2452: Add returning to the previous affiliation
OleksandrHladchenko1 Oct 10, 2023
483d77e
Merge branch 'UIIN-2452' of https://github.com/folio-org/ui-inventory…
OleksandrHladchenko1 Oct 10, 2023
7894483
UIIN-2452: Add tenantId to props validation
OleksandrHladchenko1 Oct 10, 2023
a7efac1
UIIN-2452: Add behaviour for non-consortial tenant
OleksandrHladchenko1 Oct 10, 2023
42f16f0
Fix some comments
mariia-aloshyna Oct 13, 2023
22d2dc9
Fix perms handling
mariia-aloshyna Oct 13, 2023
ae50bd4
Merge branch 'master' into UIIN-2452
mariia-aloshyna Oct 13, 2023
69396b4
Fix warnings
mariia-aloshyna Oct 13, 2023
4244578
Adjust tests
mariia-aloshyna Oct 13, 2023
39c34b5
Merge branch 'master' into UIIN-2452
mariia-aloshyna Oct 13, 2023
27fc561
Fix tests
mariia-aloshyna Oct 13, 2023
2398063
Merge remote-tracking branch 'origin/UIIN-2452' into UIIN-2452
mariia-aloshyna Oct 13, 2023
a603d03
UIIN-2452: Switch user affiliation using validateUser
OleksandrHladchenko1 Oct 17, 2023
b313553
Merge branch 'master' into UIIN-2452
OleksandrHladchenko1 Oct 17, 2023
e18e43c
Update HoldingAccordion.js
OleksandrHladchenko1 Oct 17, 2023
f72699c
Supress Add holding & Add item & View holdings buttons if user doesn'…
OleksandrHladchenko1 Oct 18, 2023
10a2e3a
Resolve conflicts
OleksandrHladchenko1 Oct 18, 2023
773e3c1
UIIN-2452: Fix comments & add unit tests
OleksandrHladchenko1 Oct 18, 2023
76a05f7
UIIN-2452: Fixes after review
OleksandrHladchenko1 Oct 18, 2023
4d4d213
Merge branch 'master' into UIIN-2452
OleksandrHladchenko1 Oct 18, 2023
355c482
UIIN-2452: Fix code smells
OleksandrHladchenko1 Oct 18, 2023
00589ea
Merge branch 'UIIN-2452' of https://github.com/folio-org/ui-inventory…
OleksandrHladchenko1 Oct 18, 2023
99a92ca
UIIN-2452: Change permissions to view/create holdings and items
OleksandrHladchenko1 Oct 24, 2023
05d6335
UIIN-2452: Change permissions to view/create holdings and items
OleksandrHladchenko1 Oct 24, 2023
527541f
Merge branch 'master' into UIIN-2452
OleksandrHladchenko1 Oct 24, 2023
730279c
UIIN-2452: Instance 3rd pane: Enable/disable consortial holdings/item…
mariia-aloshyna Oct 24, 2023
fd7e0ce
Merge origin UIIN-2452
mariia-aloshyna Oct 24, 2023
1523490
UIIN-2452: Fixes in CreateHoldings component
OleksandrHladchenko1 Oct 24, 2023
add9713
UIIN-2452: Fix test
OleksandrHladchenko1 Oct 24, 2023
d62e8d3
UIIN-2452: fix creating holdings/items for different member tenants
OleksandrHladchenko1 Oct 26, 2023
22ec665
UIIN-2452: Fix code smells
OleksandrHladchenko1 Oct 26, 2023
b5c1604
Merge branch 'master' into UIIN-2452
OleksandrHladchenko1 Oct 26, 2023
bdd7406
UIIN-2452: Fix tests
OleksandrHladchenko1 Oct 27, 2023
cd47a0d
Merge branch 'UIIN-2452' of https://github.com/folio-org/ui-inventory…
OleksandrHladchenko1 Oct 27, 2023
56ad03a
UIIN-2452: Remove excessive permission checking
OleksandrHladchenko1 Oct 27, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions src/Holding/CreateHolding/CreateHolding.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const CreateHolding = ({
const callout = useCallout();
const { instance, isLoading: isInstanceLoading } = useInstance(instanceId);
const sourceId = referenceData.holdingsSourcesByName?.FOLIO?.id;
const { location: { state: { tenantFrom } } } = history;
const tenantFrom = location?.state?.tenantFrom || stripes.okapi.tenant;

const goBack = useCallback(() => {
history.push({
Expand All @@ -39,21 +39,22 @@ const CreateHolding = ({
});
}, [location.search, instanceId]);

const onCancel = useCallback(() => {
switchAffiliation(stripes, tenantFrom, goBack);
const onCancel = useCallback(async () => {
await switchAffiliation(stripes, tenantFrom, goBack);
}, [stripes, tenantFrom, goBack]);

const onSubmit = useCallback((newHolding) => {
return mutator.holding.POST(newHolding)
.then((holdingsRecord) => {
.then(async (holdingsRecord) => {
await onCancel();

callout.sendCallout({
type: 'success',
message: <FormattedMessage
id="ui-inventory.holdingsRecord.successfullySaved"
values={{ hrid: holdingsRecord.hrid }}
/>,
});
onCancel();
});
}, [onCancel, callout]);

Expand Down
25 changes: 22 additions & 3 deletions src/Holding/DuplicateHolding/DuplicateHolding.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@ import {
} from '../../hooks';
import HoldingsForm from '../../edit/holdings/HoldingsForm';
import withLocation from '../../withLocation';
import { switchAffiliation } from '../../utils';

const DuplicateHolding = ({
goTo,
history,
instanceId,
holdingId,
location: { search, state: locationState },
location: {
search,
state: {
backPathname: locationState,
tenantFrom,
} = {},
},
referenceTables,
}) => {
const callout = useCallout();
Expand All @@ -37,10 +44,18 @@ const DuplicateHolding = ({
sourceId,
}), [holding, sourceId]);

const goToDuplicatedHolding = useCallback((id) => {
history.push({
pathname: `/inventory/view/${instanceId}/${id}`,
search,
state: { tenantTo: stripes.okapi.tenant },
});
}, [search, instanceId]);

const onSuccess = useCallback(async (response) => {
const { id, hrid } = await response.json();

goTo(`/inventory/view/${instanceId}/${id}`);
await switchAffiliation(stripes, tenantFrom, () => goToDuplicatedHolding(id));

return callout.sendCallout({
type: 'success',
Expand All @@ -53,13 +68,17 @@ const DuplicateHolding = ({

const { mutateHolding } = useHoldingMutation({ onSuccess });

const onCancel = useCallback(() => {
const goBack = useCallback(() => {
history.push({
pathname: locationState?.backPathname ?? `/inventory/view/${instanceId}`,
search,
});
}, [search, instanceId]);

const onCancel = useCallback(async () => {
await switchAffiliation(stripes, tenantFrom, goBack);
}, [stripes, tenantFrom, goBack]);

const onSubmit = useCallback(holdingValues => (
mutateHolding(holdingValues)
), [mutateHolding]);
Expand Down
25 changes: 19 additions & 6 deletions src/Holding/EditHolding/EditHolding.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import {
} from '../../hooks';
import HoldingsForm from '../../edit/holdings/HoldingsForm';
import withLocation from '../../withLocation';
import { parseHttpError } from '../../utils';
import {
parseHttpError,
switchAffiliation,
} from '../../utils';

const EditHolding = ({
goTo,
Expand All @@ -28,7 +31,13 @@ const EditHolding = ({
referenceTables,
}) => {
const callout = useCallout();
const { search, state: locationState } = location;
const {
search,
state: {
backPathname: locationState,
tenantFrom,
} = {},
} = location;
const stripes = useStripes();
const [httpError, setHttpError] = useState();
const { instance, isLoading: isInstanceLoading } = useInstanceQuery(instanceId);
Expand All @@ -42,17 +51,21 @@ const EditHolding = ({
referenceTables?.holdingsSources?.find(source => source.id === holding?.sourceId)?.name === 'MARC'
), [holding]);

const onCancel = useCallback(() => {
const goBack = useCallback(() => {
history.push({
pathname: locationState?.backPathname ?? `/inventory/view/${instanceId}`,
search,
});
}, [search, instanceId]);

const onSuccess = useCallback(() => {
onCancel();
const onCancel = useCallback(async () => {
await switchAffiliation(stripes, tenantFrom, goBack);
}, [stripes, tenantFrom, goBack]);

const onSuccess = useCallback(async () => {
await onCancel();

return callout.sendCallout({
callout.sendCallout({
type: 'success',
message: <FormattedMessage
id="ui-inventory.holdingsRecord.successfullySaved"
Expand Down
8 changes: 6 additions & 2 deletions src/Instance/HoldingsList/Holding/HoldingButtonsGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ const HoldingButtonsGroup = ({
<Button
id={`clickable-view-holdings-${holding.id}`}
data-test-view-holdings
onClick={() => switchAffiliation(stripes, tenantId, onViewHolding)}
onClick={async () => {
await switchAffiliation(stripes, tenantId, onViewHolding);
}}
>
<FormattedMessage id="ui-inventory.viewHoldings" />
</Button>
Expand All @@ -58,7 +60,9 @@ const HoldingButtonsGroup = ({
<Button
id={`clickable-new-item-${holding.id}`}
data-test-add-item
onClick={() => switchAffiliation(stripes, tenantId, onAddItem)}
onClick={async () => {
await switchAffiliation(stripes, tenantId, onAddItem);
}}
buttonStyle="primary paneHeaderNewButton"
>
<FormattedMessage id="ui-inventory.addItem" />
Expand Down
13 changes: 6 additions & 7 deletions src/Instance/HoldingsList/HoldingsListContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ const HoldingsListContainer = ({
const stripes = useStripes();
const { holdingsRecords: holdings, isLoading } = useInstanceHoldingsQuery(instance.id, { tenantId });

const canViewHoldings = stripes.hasPerm('ui-inventory.instance.view');
const canCreateItem = stripes.hasPerm('ui-inventory.item.edit');
const canViewItems = stripes.hasPerm('ui-inventory.instance.view');
const canViewHoldingsAndItems = stripes.hasPerm('ui-inventory.instance.view');
const canCreateItem = stripes.hasPerm('ui-inventory.item.create');

if (isLoading) return <Loading size="large" />;

Expand All @@ -31,9 +30,9 @@ const HoldingsListContainer = ({
holdings={holdings}
instance={instance}
tenantId={tenantId}
showViewHoldingsButton={canViewHoldings}
showViewHoldingsButton={canViewHoldingsAndItems}
showAddItemButton={canCreateItem}
isBarcodeAsHotlink={canViewItems}
isBarcodeAsHotlink={canViewHoldingsAndItems}
pathToAccordionsState={pathToAccordionsState}
/>
) : (
Expand All @@ -42,9 +41,9 @@ const HoldingsListContainer = ({
holdings={holdings}
instance={instance}
tenantId={tenantId}
showViewHoldingsButton={canViewHoldings}
showViewHoldingsButton={canViewHoldingsAndItems}
showAddItemButton={canCreateItem}
isBarcodeAsHotlink={canViewItems}
isBarcodeAsHotlink={canViewHoldingsAndItems}
pathToAccordionsState={pathToAccordionsState}
/>
)
Expand Down
2 changes: 1 addition & 1 deletion src/Instance/InstanceDetails/InstanceDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ const InstanceDetails = forwardRef(({
const tags = instance?.tags?.tagList;
const isUserInCentralTenant = checkIfUserInCentralTenant(stripes);

const canCreateHoldings = stripes.hasPerm('ui-inventory.holdings.edit');
const canCreateHoldings = stripes.hasPerm('ui-inventory.holdings.create');

const detailsLastMenu = useMemo(() => {
if (isBasicPane) return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import PropTypes from 'prop-types';
import { withRouter } from 'react-router';
import { useHistory } from 'react-router-dom';

import {
IfPermission,
useStripes,
} from '@folio/stripes/core';
import { useStripes } from '@folio/stripes/core';
import {
Row,
Col,
Expand Down Expand Up @@ -39,21 +36,21 @@ const InstanceNewHolding = ({
}, [location.search, instance.id]);

return (
<IfPermission perm="ui-inventory.holdings.create">
<Row>
<Col sm={12}>
<Button
id="clickable-new-holdings-record"
aria-label={label}
buttonStyle="primary"
fullWidth
onClick={() => switchAffiliation(stripes, tenantId, onNewHolding)}
>
{label}
</Button>
</Col>
</Row>
</IfPermission>
<Row>
<Col sm={12}>
<Button
id="clickable-new-holdings-record"
aria-label={label}
buttonStyle="primary"
fullWidth
onClick={async () => {
await switchAffiliation(stripes, tenantId, onNewHolding);
}}
>
{label}
</Button>
</Col>
</Row>
);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('InstanceNewHolding', () => {
const { getByText } = renderInstanceNewHolding();
fireEvent.click(getByText(/ui-inventory.addHoldings/i));

expect(mockPush).toHaveBeenCalledWith();
expect(mockPush).toHaveBeenCalled();
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ const MemberTenantHoldings = ({
const { holdingsRecords, isLoading } = useInstanceHoldingsQuery(instance?.id, { tenantId: id });
const isUserInCentralTenant = checkIfUserInCentralTenant(stripes);

const canViewHoldings = hasMemberTenantPermission('ui-inventory.instance.view', id, userTenantPermissions);
const canCreateItem = hasMemberTenantPermission('ui-inventory.item.edit', id, userTenantPermissions);
const canCreateHoldings = hasMemberTenantPermission('ui-inventory.holdings.edit', id, userTenantPermissions);
const canViewItems = hasMemberTenantPermission('ui-inventory.instance.view', id, userTenantPermissions);
const canViewHoldingsAndItems = hasMemberTenantPermission('ui-inventory.instance.view', id, userTenantPermissions);
const canCreateItem = hasMemberTenantPermission('ui-inventory.item.create', id, userTenantPermissions);
const canCreateHoldings = hasMemberTenantPermission('ui-inventory.holdings.create', id, userTenantPermissions);

if (isEmpty(holdingsRecords)) return null;

Expand All @@ -66,9 +65,9 @@ const MemberTenantHoldings = ({
tenantId={id}
draggable={false}
droppable={false}
showViewHoldingsButton={canViewHoldings}
showViewHoldingsButton={canViewHoldingsAndItems}
showAddItemButton={canCreateItem}
isBarcodeAsHotlink={canViewItems}
isBarcodeAsHotlink={canViewHoldingsAndItems}
pathToAccordionsState={pathToHoldingsAccordion}
/>
</MoveItemsContext>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const mockMemberTenant = {
const userTenantPermissions = [{
tenantId: 'college',
permissionNames: [{
permissionName: 'ui-inventory.holdings.edit',
permissionName: 'ui-inventory.holdings.create',
subPermissions: ['test subPermission 1']
}],
}];
Expand Down
4 changes: 3 additions & 1 deletion src/Instance/ItemsList/ItemBarcode.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ const ItemBarcode = ({
<Button
buttonStyle="link"
buttonClass={css.linkWithoutBorder}
onClick={() => switchAffiliation(stripes, tenantId, onViewItem)}
onClick={async () => {
await switchAffiliation(stripes, tenantId, onViewItem);
}}
>
{itemBarcode}
</Button>
Expand Down
10 changes: 5 additions & 5 deletions src/Item/CreateItem/CreateItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ const CreateItem = ({
state: {
tenantTo,
tenantFrom,
},
},
} = {},
} = {},
} = useHistory();

const { isLoading: isInstanceLoading, instance } = useInstanceQuery(instanceId, { tenantId: tenantTo });
Expand All @@ -51,14 +51,14 @@ const CreateItem = ({
});
}, [instanceId, search]);

const onCancel = useCallback(() => {
switchAffiliation(stripes, tenantFrom, goBack);
const onCancel = useCallback(async () => {
await switchAffiliation(stripes, tenantFrom, goBack);
}, [stripes, tenantFrom]);

const onSuccess = useCallback(async (response) => {
const { hrid } = await response.json();

onCancel();
await onCancel();

return callout.sendCallout({
type: 'success',
Expand Down
19 changes: 15 additions & 4 deletions src/Item/DuplicateItem/DuplicateItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {
} from '../hooks';

import { itemStatusesMap } from '../../constants';
import { switchAffiliation } from '../../utils';

const OMITTED_INITIAL_FIELDS = ['id', 'hrid', 'barcode', 'lastCheckIn'];

Expand All @@ -53,13 +54,18 @@ const DuplicateItem = ({
return duplicatedItem;
}, [item]);

const onSuccess = useCallback(async (response) => {
const { id, hrid } = await response.json();

const goToDuplicatedItem = useCallback((id) => {
history.push({
pathname: `/inventory/view/${instanceId}/${holdingId}/${id}`,
search: location.search,
state: { tenantTo: stripes.okapi.tenant },
});
}, [location.search, instanceId]);

const onSuccess = useCallback(async (response) => {
const { id, hrid } = await response.json();

await switchAffiliation(stripes, location?.state?.tenantFrom, () => goToDuplicatedItem(id));

return callout.sendCallout({
type: 'success',
Expand All @@ -72,13 +78,18 @@ const DuplicateItem = ({

const { mutateItem } = useItemMutation({ onSuccess });

const onCancel = useCallback(() => {
const goBack = useCallback(() => {
history.push({
pathname: `/inventory/view/${instanceId}/${holdingId}/${itemId}`,
search: location.search,
state: { tenantTo: stripes.okapi.tenant },
});
}, [location.search, instanceId, holdingId, itemId]);

const onCancel = useCallback(async () => {
await switchAffiliation(stripes, location?.state?.tenantFrom, goBack);
}, [stripes, location?.state?.tenantFrom, goBack]);

const onSubmit = useCallback((values) => {
if (!values.barcode) {
delete values.barcode;
Expand Down
Loading
Loading