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-3175: Add Version history pane for Item view component #2728

Closed
wants to merge 2 commits into from
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* ECS: Disable opening item details if a user is not affiliated with item's member tenant. Fixes UIIN-3187.
* Correctly depend on `inflected`. Refs UIIN-3203.
* Decrease the amount of rerenders in `ConsortialHoldings` component. Fixes UIIN-3196.
* Item view page: Display View history button and View history second pane. Refs UIIN-3175.

## [12.0.12](https://github.com/folio-org/ui-inventory/tree/v12.0.12) (2025-01-27)
[Full Changelog](https://github.com/folio-org/ui-inventory/compare/v12.0.11...v12.0.12)
Expand Down
29 changes: 28 additions & 1 deletion src/views/ItemView.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import {
MenuSection,
NoValue,
TextLink,
PaneMenu,
} from '@folio/stripes/components';

import {
Expand All @@ -69,6 +70,7 @@ import {
useOkapiKy,
} from '@folio/stripes/core';

import { VersionHistoryButton } from '@folio/stripes-acq-components';
import { requestsStatusString } from '../Instance/ViewRequests/utils';

import ModalContent from '../components/ModalContent';
Expand Down Expand Up @@ -117,6 +119,7 @@ import {
useHoldingMutation,
useUpdateOwnership,
} from '../hooks';
import { VersionHistory } from './VersionHistory';

export const requestStatusFiltersString = map(REQUEST_OPEN_STATUSES, requestStatus => `requestStatus.${requestStatus}`).join(',');

Expand Down Expand Up @@ -161,13 +164,21 @@ const ItemView = props => {
const [updateOwnershipData, setUpdateOwnershipData] = useState({});
const [tenants, setTenants] = useState([]);
const [targetTenant, setTargetTenant] = useState({});
const [isVersionHistoryOpen, setIsSetVersionHistoryOpen] = useState(false);

const intl = useIntl();
const calloutContext = useContext(CalloutContext);
const accordionStatusRef = useRef();
const paneTitleRef = useRef();
const { mutateHolding } = useHoldingMutation(targetTenant?.id);
const { updateOwnership } = useUpdateOwnership(UPDATE_OWNERSHIP_API.ITEMS);

useEffect(() => {
if (paneTitleRef.current) {
paneTitleRef.current.focus();
}
}, [isVersionHistoryOpen]);

useEffect(() => {
if (checkIfUserInMemberTenant(stripes)) {
setTenants(omitCurrentAndCentralTenants(stripes));
Expand Down Expand Up @@ -621,6 +632,10 @@ const ItemView = props => {
const temporaryHoldingsLocation = locationsById[holdingsRecord?.temporaryLocationId];
const tagsEnabled = !tagSettings?.records?.length || tagSettings?.records?.[0]?.value === 'true';

const openVersionHistory = useCallback(() => {
setIsSetVersionHistoryOpen(true);
}, []);

const refLookup = (referenceTable, id) => {
const ref = (referenceTable && id) ? referenceTable.find(record => record.id === id) : {};

Expand Down Expand Up @@ -984,7 +999,8 @@ const ItemView = props => {
<Paneset isRoot>
<Pane
data-test-item-view-page
defaultWidth="100%"
defaultWidth="fill"
id="item-view-pane"
appIcon={(
<AppIcon
app="inventory"
Expand Down Expand Up @@ -1014,6 +1030,11 @@ const ItemView = props => {
dismissible
onClose={onCloseViewItem}
actionMenu={getActionMenu}
lastMenu={(
<PaneMenu>
<VersionHistoryButton onClick={openVersionHistory} />
</PaneMenu>
)}
>
<UpdateItemOwnershipModal
isOpen={isUpdateOwnershipModalOpen}
Expand Down Expand Up @@ -1732,6 +1753,12 @@ const ItemView = props => {
</AccordionSet>
</AccordionStatus>
</Pane>
{isVersionHistoryOpen && (
<VersionHistory
onClose={() => setIsSetVersionHistoryOpen(false)}
paneTitleRef={paneTitleRef}
/>
)}
</Paneset>
</HasCommand>
);
Expand Down
35 changes: 35 additions & 0 deletions src/views/ItemView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,41 @@ describe('ItemView', () => {
expect(mockPush).toHaveBeenCalled();
});
});

describe('Version history component', () => {
let versionHistoryButton;

beforeEach(() => {
const { container } = renderWithIntl(<ItemViewSetup />, translationsProperties);

versionHistoryButton = container.querySelector('#version-history-btn');
});

it('should render version history button', () => {
expect(versionHistoryButton).toBeInTheDocument();
});

describe('when click the button', () => {
it('should render version history pane', () => {
fireEvent.click(versionHistoryButton);
OleksandrHladchenko1 marked this conversation as resolved.
Show resolved Hide resolved

expect(screen.getByRole('region', { name: /version history/i })).toBeInTheDocument();
});
});

describe('when click the close button', () => {
it('should hide the pane', () => {
fireEvent.click(versionHistoryButton);

expect(screen.getByRole('region', { name: /version history/i })).toBeInTheDocument();

const closeButton = screen.getByRole('button', { name: /close version history/i });
fireEvent.click(closeButton);

expect(screen.queryByRole('region', { name: /version history/i })).not.toBeInTheDocument();
});
});
});
});

describe('action menu', () => {
Expand Down
27 changes: 27 additions & 0 deletions src/views/VersionHistory/VersionHistory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import PropTypes from 'prop-types';

import { Pane } from '@folio/stripes/components';


const VersionHistory = ({ onClose, paneTitleRef }) => {
return (
<Pane
id="version-history-pane"
defaultWidth="20%"
onClose={onClose}
paneTitle="Version history"
OleksandrHladchenko1 marked this conversation as resolved.
Show resolved Hide resolved
dismissible
paneTitleRef={paneTitleRef}
>
<span>Versions</span>
OleksandrHladchenko1 marked this conversation as resolved.
Show resolved Hide resolved
</Pane>
);
};

VersionHistory.propTypes = {
onClose: PropTypes.func,
paneTitleRef: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
};


export default VersionHistory;
1 change: 1 addition & 0 deletions src/views/VersionHistory/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as VersionHistory } from './VersionHistory';
Loading