Skip to content

Commit

Permalink
Supress Add holding & Add item & View holdings buttons if user doesn'…
Browse files Browse the repository at this point in the history
…t have permissions
  • Loading branch information
OleksandrHladchenko1 committed Oct 18, 2023
1 parent a603d03 commit f72699c
Show file tree
Hide file tree
Showing 13 changed files with 71 additions and 75 deletions.
12 changes: 6 additions & 6 deletions src/Instance/HoldingsList/Holding/Holding.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const Holding = ({
isDraggable,
isItemsDroppable,
tenantId,
isViewHoldingsDisabled,
isAddItemDisabled,
showViewHoldingsButton,
showAddItemButton,
isBarcodeAsHotlink,
}) => {
return (
Expand Down Expand Up @@ -55,8 +55,8 @@ const Holding = ({
onViewHolding={onViewHolding}
onAddItem={onAddItem}
tenantId={tenantId}
isViewHoldingsDisabled={isViewHoldingsDisabled}
isAddItemDisabled={isAddItemDisabled}
showViewHoldingsButton={showViewHoldingsButton}
showAddItemButton={showAddItemButton}
>
<ItemsListContainer
holding={holding}
Expand All @@ -83,8 +83,8 @@ Holding.propTypes = {
isHoldingDragSelected: PropTypes.func,
isItemsDroppable: PropTypes.bool,
tenantId: PropTypes.string,
isViewHoldingsDisabled: PropTypes.bool,
isAddItemDisabled: PropTypes.bool,
showViewHoldingsButton: PropTypes.bool,
showAddItemButton: PropTypes.bool,
isBarcodeAsHotlink: PropTypes.bool,
};

Expand Down
12 changes: 6 additions & 6 deletions src/Instance/HoldingsList/Holding/HoldingAccordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ const HoldingAccordion = ({
onAddItem,
withMoveDropdown,
tenantId,
isViewHoldingsDisabled,
isAddItemDisabled,
showViewHoldingsButton,
showAddItemButton,
}) => {
const searchParams = {
limit: 0,
Expand Down Expand Up @@ -63,8 +63,8 @@ const HoldingAccordion = ({
withMoveDropdown={withMoveDropdown}
isOpen={open}
tenantId={tenantId}
isViewHoldingsDisabled={isViewHoldingsDisabled}
isAddItemDisabled={isAddItemDisabled}
showViewHoldingsButton={showViewHoldingsButton}
showAddItemButton={showAddItemButton}
/>;

const location = labelLocation?.isActive ?
Expand Down Expand Up @@ -125,8 +125,8 @@ HoldingAccordion.propTypes = {
withMoveDropdown: PropTypes.bool,
children: PropTypes.object,
tenantId: PropTypes.string,
isViewHoldingsDisabled: PropTypes.bool,
isAddItemDisabled: PropTypes.bool,
showViewHoldingsButton: PropTypes.bool,
showAddItemButton: PropTypes.bool,
};

export default HoldingAccordion;
29 changes: 14 additions & 15 deletions src/Instance/HoldingsList/Holding/HoldingButtonsGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ const HoldingButtonsGroup = ({
itemCount,
isOpen,
tenantId,
isViewHoldingsDisabled,
isAddItemDisabled,
showViewHoldingsButton,
showAddItemButton,
}) => {
const stripes = useStripes();
const isUserInCentralTenant = checkIfUserInCentralTenant(stripes);
Expand All @@ -44,23 +44,22 @@ const HoldingButtonsGroup = ({
/>
)
}
<Button
id={`clickable-view-holdings-${holding.id}`}
data-test-view-holdings
onClick={() => switchAffiliation(stripes, tenantId, onViewHolding)}
disabled={isViewHoldingsDisabled}
>
<FormattedMessage id="ui-inventory.viewHoldings" />
</Button>

{!isUserInCentralTenant && (
{showViewHoldingsButton &&
<Button
id={`clickable-view-holdings-${holding.id}`}
data-test-view-holdings
onClick={() => switchAffiliation(stripes, tenantId, onViewHolding)}
>
<FormattedMessage id="ui-inventory.viewHoldings" />
</Button>
}
{!isUserInCentralTenant && showAddItemButton && (
<IfPermission perm="ui-inventory.item.create">
<Button
id={`clickable-new-item-${holding.id}`}
data-test-add-item
onClick={() => switchAffiliation(stripes, tenantId, onAddItem)}
buttonStyle="primary paneHeaderNewButton"
disabled={isAddItemDisabled}
>
<FormattedMessage id="ui-inventory.addItem" />
</Button>
Expand All @@ -80,8 +79,8 @@ HoldingButtonsGroup.propTypes = {
onAddItem: PropTypes.func.isRequired,
onViewHolding: PropTypes.func.isRequired,
withMoveDropdown: PropTypes.bool,
isViewHoldingsDisabled: PropTypes.bool,
isAddItemDisabled: PropTypes.bool,
showViewHoldingsButton: PropTypes.bool,
showAddItemButton: PropTypes.bool,
tenantId: PropTypes.string,
};

Expand Down
16 changes: 8 additions & 8 deletions src/Instance/HoldingsList/Holding/HoldingButtonsGroup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ const HoldingButtonsGroupSetup = props => (
onAddItem={mockOnAddItem}
itemCount={mockItemCount}
isOpen={false}
isViewHoldingsDisabled={false}
isAddItemDisabled={false}
showViewHoldingsButton
showAddItemButton
{...props}
>
{() => null}
Expand Down Expand Up @@ -64,18 +64,18 @@ describe('HoldingButtonsGroup', () => {
});

describe('when user has no permissions to view holdings', () => {
it('should render "View Holdings" button as disabled', () => {
const { getByRole } = renderHoldingButtonsGroup({ isViewHoldingsDisabled: true });
it('should supress "View Holdings" button', () => {
const { queryByRole } = renderHoldingButtonsGroup({ showViewHoldingsButton: false });

expect(getByRole('button', { name: 'View holdings' })).toBeDisabled();
expect(queryByRole('button', { name: 'View holdings' })).not.toBeInTheDocument();
});
});

describe('when user has no permissions to create items', () => {
it('should render "Add item" button as disabled', () => {
const { getByRole } = renderHoldingButtonsGroup({ isAddItemDisabled: true });
it('should supress "Add item" button', () => {
const { queryByRole } = renderHoldingButtonsGroup({ showAddItemButton: false });

expect(getByRole('button', { name: 'Add item' })).toBeDisabled();
expect(queryByRole('button', { name: 'Add item' })).not.toBeInTheDocument();
});
});

Expand Down
28 changes: 14 additions & 14 deletions src/Instance/HoldingsList/Holding/HoldingContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ const DraggableHolding = ({
onViewHolding,
onAddItem,
tenantId,
isViewHoldingsDisabled,
isAddItemDisabled,
showViewHoldingsButton,
showAddItemButton,
isBarcodeAsHotlink,
...rest
}) => {
Expand Down Expand Up @@ -73,8 +73,8 @@ const DraggableHolding = ({
onViewHolding={onViewHolding}
onAddItem={onAddItem}
tenantId={tenantId}
isViewHoldingsDisabled={isViewHoldingsDisabled}
isAddItemDisabled={isAddItemDisabled}
showViewHoldingsButton={showViewHoldingsButton}
showAddItemButton={showAddItemButton}
isBarcodeAsHotlink={isBarcodeAsHotlink}
/>
)
Expand All @@ -95,16 +95,16 @@ DraggableHolding.propTypes = {
onViewHolding: PropTypes.func,
onAddItem: PropTypes.func,
tenantId: PropTypes.string,
isViewHoldingsDisabled: PropTypes.bool,
isAddItemDisabled: PropTypes.bool,
showViewHoldingsButton: PropTypes.bool,
showAddItemButton: PropTypes.bool,
isBarcodeAsHotlink: PropTypes.bool,
};

const HoldingContainer = ({
location,
history,
isViewHoldingsDisabled,
isAddItemDisabled,
showViewHoldingsButton,
showAddItemButton,
isBarcodeAsHotlink,
instance,
holding,
Expand Down Expand Up @@ -153,8 +153,8 @@ const HoldingContainer = ({
onViewHolding={onViewHolding}
onAddItem={onAddItem}
tenantId={tenantId}
isViewHoldingsDisabled={isViewHoldingsDisabled}
isAddItemDisabled={isAddItemDisabled}
showViewHoldingsButton={showViewHoldingsButton}
showAddItemButton={showAddItemButton}
isBarcodeAsHotlink={isBarcodeAsHotlink}
{...rest}
/>
Expand All @@ -167,8 +167,8 @@ const HoldingContainer = ({
onViewHolding={onViewHolding}
onAddItem={onAddItem}
tenantId={tenantId}
isViewHoldingsDisabled={isViewHoldingsDisabled}
isAddItemDisabled={isAddItemDisabled}
showViewHoldingsButton={showViewHoldingsButton}
showAddItemButton={showAddItemButton}
isBarcodeAsHotlink={isBarcodeAsHotlink}
/>
);
Expand All @@ -185,8 +185,8 @@ HoldingContainer.propTypes = {
isDraggable: PropTypes.bool,
draggingHoldingsCount: PropTypes.number,
tenantId: PropTypes.string,
isViewHoldingsDisabled: PropTypes.bool,
isAddItemDisabled: PropTypes.bool,
showViewHoldingsButton: PropTypes.bool,
showAddItemButton: PropTypes.bool,
isBarcodeAsHotlink: PropTypes.bool,
};

Expand Down
2 changes: 2 additions & 0 deletions src/Instance/HoldingsList/Holding/HoldingContainer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ const renderHoldingContainer = (props = {}) => renderWithIntl(
provided={{ draggableProps: { style: true } }}
onViewHolding={jest.fn()}
onAddItem={jest.fn()}
showViewHoldingsButton
showAddItemButton
{...props}
/>
</DnDContext.Provider>
Expand Down
12 changes: 6 additions & 6 deletions src/Instance/HoldingsList/HoldingsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const HoldingsList = ({
instance,
holdings,
tenantId,
isViewHoldingsDisabled,
isAddItemDisabled,
showViewHoldingsButton,
showAddItemButton,
isBarcodeAsHotlink,
draggable,
droppable,
Expand All @@ -21,8 +21,8 @@ const HoldingsList = ({
droppable={droppable}
holdings={holdings}
tenantId={tenantId}
isViewHoldingsDisabled={isViewHoldingsDisabled}
isAddItemDisabled={isAddItemDisabled}
showViewHoldingsButton={showViewHoldingsButton}
showAddItemButton={showAddItemButton}
isBarcodeAsHotlink={isBarcodeAsHotlink}
/>
));
Expand All @@ -31,8 +31,8 @@ HoldingsList.propTypes = {
instance: PropTypes.object.isRequired,
holdings: PropTypes.arrayOf(PropTypes.object),
tenantId: PropTypes.string,
isViewHoldingsDisabled: PropTypes.bool,
isAddItemDisabled: PropTypes.bool,
showViewHoldingsButton: PropTypes.bool,
showAddItemButton: PropTypes.bool,
isBarcodeAsHotlink: PropTypes.bool,
draggable: PropTypes.bool,
droppable: PropTypes.bool,
Expand Down
8 changes: 4 additions & 4 deletions src/Instance/HoldingsList/HoldingsListContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const HoldingsListContainer = ({
holdings={holdings}
instance={instance}
tenantId={tenantId}
isViewHoldingsDisabled={!canViewHoldings}
isAddItemDisabled={!canCreateItem}
showViewHoldingsButton={canViewHoldings}
showAddItemButton={canCreateItem}
isBarcodeAsHotlink={canViewItems}
/>
) : (
Expand All @@ -42,8 +42,8 @@ const HoldingsListContainer = ({
holdings={holdings}
instance={instance}
tenantId={tenantId}
isViewHoldingsDisabled={!canViewHoldings}
isAddItemDisabled={!canCreateItem}
showViewHoldingsButton={canViewHoldings}
showAddItemButton={canCreateItem}
isBarcodeAsHotlink={canViewItems}
/>
)
Expand Down
3 changes: 1 addition & 2 deletions src/Instance/InstanceDetails/InstanceDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,9 @@ const InstanceDetails = forwardRef(({
<AccordionSet initialStatus={accordionState}>
{children}

{!isUserInCentralTenant && (
{!isUserInCentralTenant && canCreateHoldings && (
<InstanceNewHolding
instance={instance}
disabled={!canCreateHoldings}
tenantId={tenantId}
/>
)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const InstanceNewHolding = ({
location,
instance,
tenantId,
disabled,
}) => {
const intl = useIntl();
const stripes = useStripes();
Expand Down Expand Up @@ -49,7 +48,6 @@ const InstanceNewHolding = ({
buttonStyle="primary"
fullWidth
onClick={() => switchAffiliation(stripes, tenantId, onNewHolding)}
disabled={disabled}
>
{label}
</Button>
Expand All @@ -63,7 +61,6 @@ InstanceNewHolding.propTypes = {
location: PropTypes.object.isRequired,
instance: PropTypes.object,
tenantId: PropTypes.string,
disabled: PropTypes.bool,
};

export default withRouter(InstanceNewHolding);
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,17 @@ const MemberTenantHoldings = ({
tenantId={id}
draggable={false}
droppable={false}
isViewHoldingsDisabled={!canViewHoldings}
isAddItemDisabled={!canCreateItem}
showViewHoldingsButton={canViewHoldings}
showAddItemButton={canCreateItem}
isBarcodeAsHotlink={canViewItems}
/>
</MoveItemsContext>
)}
</div>
{!isUserInCentralTenant && (
{!isUserInCentralTenant && canCreateHoldings && (
<InstanceNewHolding
instance={instance}
tenantId={id}
disabled={!canCreateHoldings}
/>
)}
</Accordion>
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: 'test Permission name 1',
permissionName: 'ui-inventory.holdings.edit',
subPermissions: ['test subPermission 1']
}],
}];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const HoldingsListMovement = ({
draggable,
droppable,
tenantId,
isViewHoldingsDisabled,
isAddItemDisabled,
showViewHoldingsButton,
showAddItemButton,
isBarcodeAsHotlink,
}) => {
const {
Expand Down Expand Up @@ -61,8 +61,8 @@ const HoldingsListMovement = ({
holdingIndex={index}
draggingHoldingsCount={draggingHoldingsCount}
tenantId={tenantId}
isViewHoldingsDisabled={isViewHoldingsDisabled}
isAddItemDisabled={isAddItemDisabled}
showViewHoldingsButton={showViewHoldingsButton}
showAddItemButton={showAddItemButton}
isBarcodeAsHotlink={isBarcodeAsHotlink}
/>
))
Expand All @@ -82,8 +82,8 @@ const HoldingsListMovement = ({
HoldingsListMovement.propTypes = {
instance: PropTypes.object.isRequired,
holdings: PropTypes.arrayOf(PropTypes.object),
isViewHoldingsDisabled: PropTypes.bool,
isAddItemDisabled: PropTypes.bool,
showViewHoldingsButton: PropTypes.bool,
showAddItemButton: PropTypes.bool,
isBarcodeAsHotlink: PropTypes.bool,
draggable: PropTypes.bool,
droppable: PropTypes.bool,
Expand Down

0 comments on commit f72699c

Please sign in to comment.