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-2453:Instance 3rd pane: Adjust behavior when returning to instance from holdings/item full screen #2305

Merged
merged 5 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change history for ui-inventory

## 10.0.1 IN PROGRESS

* Instance 3rd pane: Adjust behavior when returning to instance from holdings/item full screen. Refs UIIN-2453.

## [10.0.0](https://github.com/folio-org/ui-inventory/tree/v10.0.0) (2023-10-13)
[Full Changelog](https://github.com/folio-org/ui-inventory/compare/v9.4.12...v10.0.0)

Expand Down
7 changes: 7 additions & 0 deletions src/Instance/HoldingsList/Holding/Holding.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const Holding = ({
isDraggable,
isItemsDroppable,
tenantId,
instanceId,
pathToAccordionsState,
}) => {
return (
<div>
Expand Down Expand Up @@ -49,6 +51,8 @@ const Holding = ({
onViewHolding={onViewHolding}
onAddItem={onAddItem}
tenantId={tenantId}
instanceId={instanceId}
pathToAccordionsState={pathToAccordionsState}
>
<ItemsListContainer
holding={holding}
Expand All @@ -66,6 +70,7 @@ Holding.propTypes = {
holding: PropTypes.object.isRequired,
onViewHolding: PropTypes.func.isRequired,
onAddItem: PropTypes.func.isRequired,
instanceId: PropTypes.string.isRequired,
holdings: PropTypes.arrayOf(PropTypes.object),
draggable: PropTypes.bool,
droppable: PropTypes.bool,
Expand All @@ -74,10 +79,12 @@ Holding.propTypes = {
isHoldingDragSelected: PropTypes.func,
isItemsDroppable: PropTypes.bool,
tenantId: PropTypes.string,
pathToAccordionsState: PropTypes.arrayOf(PropTypes.string),
};

Holding.defaultProps = {
isItemsDroppable: true,
pathToAccordionsState: [],
};

export default Holding;
2 changes: 2 additions & 0 deletions src/Instance/HoldingsList/Holding/Holding.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ const HoldingSetup = () => (
<Router>
<Holding
holding={holding}
instanceId="instanceId"
onViewHolding={onViewHolding}
onAddItem={onAddItem}
holdings={holdings}
Expand All @@ -38,6 +39,7 @@ const HoldingSetup = () => (
isHoldingDragSelected={isHoldingDragSelected}
isDraggable={isDraggable}
isItemsDroppable={isItemsDroppable}
pathToAccordionsState={['holdings']}
/>
</Router>
);
Expand Down
14 changes: 12 additions & 2 deletions src/Instance/HoldingsList/Holding/HoldingAccordion.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import {
import { callNumberLabel } from '../../../utils';
import HoldingButtonsGroup from './HoldingButtonsGroup';
import useHoldingItemsQuery from '../../../hooks/useHoldingItemsQuery';
import { useLocationsQuery } from '../../../hooks';
import {
useHoldingsAccordionState,
useLocationsQuery,
} from '../../../hooks';

const HoldingAccordion = ({
children,
Expand All @@ -23,13 +26,16 @@ const HoldingAccordion = ({
onAddItem,
withMoveDropdown,
tenantId,
instanceId,
pathToAccordionsState,
}) => {
const searchParams = {
limit: 0,
offset: 0,
};

const [open, setOpen] = useState(false);
const pathToAccordion = [...pathToAccordionsState, holding?.id];
const [open, setOpen] = useHoldingsAccordionState({ instanceId, pathToAccordion });
const [openFirstTime, setOpenFirstTime] = useState(false);
const { totalRecords, isFetching } = useHoldingItemsQuery(holding.id, { searchParams, key: 'itemCount', tenantId });
const { data: locations } = useLocationsQuery({ tenantId });
Expand Down Expand Up @@ -113,10 +119,14 @@ HoldingAccordion.propTypes = {
holding: PropTypes.object.isRequired,
onViewHolding: PropTypes.func.isRequired,
onAddItem: PropTypes.func.isRequired,
instanceId: PropTypes.string.isRequired,
holdings: PropTypes.arrayOf(PropTypes.object),
withMoveDropdown: PropTypes.bool,
children: PropTypes.object,
tenantId: PropTypes.string,
pathToAccordionsState: PropTypes.arrayOf(PropTypes.string),
};

HoldingAccordion.defaultProps = { pathToAccordionsState: [] };

export default HoldingAccordion;
2 changes: 2 additions & 0 deletions src/Instance/HoldingsList/Holding/HoldingAccordion.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const HoldingAccordionSetup = () => (
onViewHolding={noop}
onAddItem={noop}
withMoveDropdown={false}
instanceId="instanceId"
pathToAccordionsState={['holdings']}
>
<></>
</HoldingAccordion>
Expand Down
16 changes: 16 additions & 0 deletions src/Instance/HoldingsList/Holding/HoldingContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const DraggableHolding = ({
onViewHolding,
onAddItem,
tenantId,
instanceId,
pathToAccordionsState,
...rest
}) => {
const rowStyles = useMemo(() => (
Expand Down Expand Up @@ -68,6 +70,8 @@ const DraggableHolding = ({
onViewHolding={onViewHolding}
onAddItem={onAddItem}
tenantId={tenantId}
instanceId={instanceId}
pathToAccordionsState={pathToAccordionsState}
/>
)
}
Expand All @@ -83,12 +87,16 @@ DraggableHolding.propTypes = {
draggingHoldingsCount: PropTypes.number,
provided: PropTypes.object.isRequired,
snapshot: PropTypes.object.isRequired,
instanceId: PropTypes.string.isRequired,
holding: PropTypes.object,
onViewHolding: PropTypes.func,
onAddItem: PropTypes.func,
tenantId: PropTypes.string,
pathToAccordionsState: PropTypes.arrayOf(PropTypes.string),
};

DraggableHolding.defaultProps = { pathToAccordionsState: [] };

const HoldingContainer = ({
location,
history,
Expand All @@ -99,6 +107,7 @@ const HoldingContainer = ({
holdingIndex,
draggingHoldingsCount,
tenantId,
pathToAccordionsState,
...rest
}) => {
const onViewHolding = useCallback(() => {
Expand Down Expand Up @@ -130,6 +139,8 @@ const HoldingContainer = ({
onViewHolding={onViewHolding}
onAddItem={onAddItem}
tenantId={tenantId}
instanceId={instance?.id}
pathToAccordionsState={pathToAccordionsState}
{...rest}
/>
)}
Expand All @@ -141,6 +152,8 @@ const HoldingContainer = ({
onViewHolding={onViewHolding}
onAddItem={onAddItem}
tenantId={tenantId}
instanceId={instance?.id}
pathToAccordionsState={pathToAccordionsState}
/>
);
};
Expand All @@ -157,6 +170,9 @@ HoldingContainer.propTypes = {
isDraggable: PropTypes.bool,
draggingHoldingsCount: PropTypes.number,
tenantId: PropTypes.string,
pathToAccordionsState: PropTypes.arrayOf(PropTypes.string),
};

HoldingContainer.defaultProps = { pathToAccordionsState: [] };

export default withRouter(HoldingContainer);
1 change: 1 addition & 0 deletions src/Instance/HoldingsList/Holding/HoldingContainer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ const renderHoldingContainer = (props = {}) => renderWithIntl(
provided={{ draggableProps: { style: true } }}
onViewHolding={jest.fn()}
onAddItem={jest.fn()}
pathToAccordionsState={['holdings']}
{...props}
/>
</DnDContext.Provider>
Expand Down
4 changes: 4 additions & 0 deletions src/Instance/HoldingsList/HoldingsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const HoldingsList = ({
instance,
holdings,
tenantId,
pathToAccordionsState,

draggable,
droppable,
Expand All @@ -19,20 +20,23 @@ const HoldingsList = ({
droppable={droppable}
holdings={holdings}
tenantId={tenantId}
pathToAccordionsState={pathToAccordionsState}
/>
));

HoldingsList.propTypes = {
instance: PropTypes.object.isRequired,
holdings: PropTypes.arrayOf(PropTypes.object),
tenantId: PropTypes.string,
pathToAccordionsState: PropTypes.arrayOf(PropTypes.string),

draggable: PropTypes.bool,
droppable: PropTypes.bool,
};

HoldingsList.defaultProps = {
holdings: [],
pathToAccordionsState: [],
};

export default HoldingsList;
10 changes: 7 additions & 3 deletions src/Instance/HoldingsList/HoldingsListContainer.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React from 'react';
import PropTypes from 'prop-types';

import {
Loading,
} from '@folio/stripes/components';
import { Loading } from '@folio/stripes/components';

import HoldingsList from './HoldingsList';
import { HoldingsListMovement } from '../InstanceMovement/HoldingMovementList';
Expand All @@ -13,6 +11,7 @@ const HoldingsListContainer = ({
instance,
isHoldingsMove,
tenantId,
pathToAccordionsState,
...rest
}) => {
const { holdingsRecords: holdings, isLoading } = useInstanceHoldingsQuery(instance.id, { tenantId });
Expand All @@ -26,13 +25,15 @@ const HoldingsListContainer = ({
holdings={holdings}
instance={instance}
tenantId={tenantId}
pathToAccordionsState={pathToAccordionsState}
/>
) : (
<HoldingsList
{...rest}
holdings={holdings}
instance={instance}
tenantId={tenantId}
pathToAccordionsState={pathToAccordionsState}
/>
)
);
Expand All @@ -42,6 +43,9 @@ HoldingsListContainer.propTypes = {
instance: PropTypes.object.isRequired,
isHoldingsMove: PropTypes.bool,
tenantId: PropTypes.string,
pathToAccordionsState: PropTypes.arrayOf(PropTypes.string),
};

HoldingsListContainer.defaultProps = { pathToAccordionsState: [] };

export default HoldingsListContainer;
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import React, { useContext } from 'react';
import React, {
useContext,
useEffect,
useRef,
} from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';

Expand All @@ -13,33 +17,50 @@ import {

import { MemberTenantHoldings } from '../MemberTenantHoldings';
import { DataContext } from '../../../contexts';
import { useSearchForShadowInstanceTenants } from '../../../hooks';
import {
useHoldingsAccordionState,
useSearchForShadowInstanceTenants,
} from '../../../hooks';

const ConsortialHoldings = ({ instance }) => {
const instanceId = instance?.id;
const prevInstanceId = useRef(instanceId);

const stripes = useStripes();
const { consortiaTenantsById } = useContext(DataContext);

const { tenants } = useSearchForShadowInstanceTenants({ instanceId: instance?.id });
const { tenants } = useSearchForShadowInstanceTenants({ instanceId });

const memberTenants = tenants
.map(tenant => consortiaTenantsById[tenant.id])
.filter(tenant => !tenant?.isCentral && (tenant?.id !== stripes.okapi.tenant))
.sort((a, b) => a.name.localeCompare(b.name));

const pathToAccordion = ['consortialHoldings', '_state'];
const [isConsortialAccOpen, setConsortialAccOpen] = useHoldingsAccordionState({ instanceId, pathToAccordion });

useEffect(() => {
if (instanceId !== prevInstanceId.current) {
setConsortialAccOpen(false);
prevInstanceId.current = instanceId;
}
}, [instanceId]);

return (
<IfInterface name="consortia">
<Accordion
id="consortial-holdings"
label={<FormattedMessage id="ui-inventory.consortialHoldings" />}
closedByDefault
open={isConsortialAccOpen}
onToggle={() => setConsortialAccOpen(prevState => !prevState)}
>
{!memberTenants.length
? <FormattedMessage id="stripes-components.tableEmpty" />
: (
<AccordionSet>
{memberTenants.map(memberTenant => (
<MemberTenantHoldings
key={memberTenant.id}
key={`${memberTenant.id}.${instanceId}`}
memberTenant={memberTenant}
instance={instance}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { InstanceNewHolding } from '../InstanceNewHolding';
import { MoveItemsContext } from '../../MoveItemsContext';

import { useInstanceHoldingsQuery } from '../../../providers';
import { useHoldingsAccordionState } from '../../../hooks';

import css from './MemberTenantHoldings.css';

Expand All @@ -27,7 +28,13 @@ const MemberTenantHoldings = ({
name,
id,
} = memberTenant;
const instanceId = instance?.id;
const stripes = useStripes();

const pathToAccordion = ['consortialHoldings', id, '_state'];
const pathToHoldingsAccordion = ['consortialHoldings', id];
const [isMemberTenantAccOpen, setMemberTenantAccOpen] = useHoldingsAccordionState({ instanceId, pathToAccordion });

const { holdingsRecords, isLoading } = useInstanceHoldingsQuery(instance?.id, { tenantId: id });
const isUserInCentralTenant = checkIfUserInCentralTenant(stripes);

Expand All @@ -38,7 +45,8 @@ const MemberTenantHoldings = ({
className={css.memberTenantHoldings}
id={`${name}-holdings`}
label={name}
closedByDefault
open={isMemberTenantAccOpen}
onToggle={() => setMemberTenantAccOpen(prevValue => !prevValue)}
>
<div className={css.memberTenantHoldings}>
{isLoading
Expand All @@ -51,6 +59,7 @@ const MemberTenantHoldings = ({
tenantId={id}
draggable={false}
droppable={false}
pathToAccordionsState={pathToHoldingsAccordion}
/>
</MoveItemsContext>
)}
Expand Down
Loading