Skip to content

Commit

Permalink
UIIN-3170: Add Version history button and Version history pane to det…
Browse files Browse the repository at this point in the history
…ails view of Instance
  • Loading branch information
mariia-aloshyna committed Feb 7, 2025
1 parent 2a2251e commit 0437f04
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
* Remove hover-over text next to "Shelving order" on the Item record detail view. Refs UIIN-3210.
* CI: Switch to centralized/shared workflow from https://github.com/folio-org/.github. Fixes UIIN-3218.
* Add Version history button and Version history pane to details view of Item. Refs UIIN-3172.
* Add Version history button and Version history pane to details view of Instance. Refs UIIN-3170.

## [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
68 changes: 41 additions & 27 deletions src/Instance/InstanceDetails/InstanceDetails.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ import {
Row,
MessageBanner,
PaneCloseLink,
Paneset,
} from '@folio/stripes/components';
import { VersionHistoryButton } from '@folio/stripes-acq-components';

import { InstanceTitle } from './InstanceTitle';
import { InstanceAdministrativeView } from './InstanceAdministrativeView';
Expand All @@ -42,6 +44,7 @@ import { InstanceRelationshipView } from './InstanceRelationshipView';
import { InstanceNewHolding } from './InstanceNewHolding';
import { InstanceAcquisition } from './InstanceAcquisition';
import HelperApp from '../../components/HelperApp';
import { VersionHistory } from '../../views/VersionHistory';

import { DataContext } from '../../contexts';
import { ConsortialHoldings } from '../HoldingsList/consortium/ConsortialHoldings';
Expand Down Expand Up @@ -92,11 +95,13 @@ const InstanceDetails = forwardRef(({
const accordionState = useMemo(() => getAccordionState(instance, accordions), [instance]);
const [helperApp, setHelperApp] = useState();
const [isAllExpanded, setIsAllExpanded] = useState();
const [isVersionHistoryOpen, setIsVersionHistoryOpen] = useState(false);

const canCreateHoldings = stripes.hasPerm('ui-inventory.holdings.create');
const tags = instance?.tags?.tagList;
const isUserInCentralTenant = checkIfUserInCentralTenant(stripes);
const isConsortialHoldingsVisible = instance?.shared || isInstanceShadowCopy(instance?.source);
const isUserInConsortium = isUserInConsortiumMode(stripes);

const detailsLastMenu = useMemo(() => {
return (
Expand All @@ -112,6 +117,7 @@ const InstanceDetails = forwardRef(({
/>
)
}
<VersionHistoryButton onClick={() => setIsVersionHistoryOpen(true)} />
</PaneMenu>
);
}, [tagsEnabled, tags, intl]);
Expand All @@ -122,32 +128,35 @@ const InstanceDetails = forwardRef(({

const getEntity = () => instance;

const renderPaneTitle = () => {
const isInstanceShared = Boolean(isShared || isInstanceShadowCopy(instance?.source));
const paneTitle = useMemo(
() => {
const isInstanceShared = Boolean(isShared || isInstanceShadowCopy(instance?.source));

return (
<FormattedMessage
id={`ui-inventory.${isUserInConsortiumMode(stripes) ? 'consortia.' : ''}instanceRecordTitle`}
values={{
return intl.formatMessage(
{ id: `ui-inventory.${isUserInConsortium ? 'consortia.' : ''}instanceRecordTitle` },
{
isShared: isInstanceShared,
title: instance?.title,
publisherAndDate: getPublishingInfo(instance),
}}
/>
);
};

const renderPaneSubtitle = () => {
return (
<FormattedMessage
id="ui-inventory.instanceRecordSubtitle"
values={{
hrid: instance?.hrid,
updatedDate: getDate(instance?.metadata?.updatedDate),
}}
/>
);
};
}
);
},
[isShared, instance?.source, isUserInConsortium],
);
const paneSubTitle = useMemo(
() => {
return (
<FormattedMessage
id="ui-inventory.instanceRecordSubtitle"
values={{
hrid: instance?.hrid,
updatedDate: getDate(instance?.metadata?.updatedDate),
}}
/>
);
},
[instance?.hrid, instance?.metadata?.updatedDate],
);

const onToggle = newState => {
const isExpanded = Object.values(newState)[0];
Expand All @@ -156,19 +165,19 @@ const InstanceDetails = forwardRef(({
};

return (
<>
<Paneset>
<Pane
{...rest}
data-test-instance-details
appIcon={<AppIcon app="inventory" iconKey="instance" />}
paneTitle={renderPaneTitle()}
paneSub={renderPaneSubtitle()}
paneTitle={paneTitle}
paneSub={paneSubTitle}
actionMenu={actionMenu}
firstMenu={(
<PaneCloseLink
autoFocus={location.state?.isClosingFocused}
onClick={onClose}
aria-label={intl.formatMessage({ id: 'stripes-components.closeItem' }, { item: renderPaneTitle() })}
aria-label={intl.formatMessage({ id: 'stripes-components.closeItem' }, { item: paneTitle })}
/>
)}
lastMenu={detailsLastMenu}
Expand Down Expand Up @@ -301,6 +310,11 @@ const InstanceDetails = forwardRef(({
</AccordionSet>
</AccordionStatus>
</Pane>
{isVersionHistoryOpen && (
<VersionHistory
onClose={() => setIsVersionHistoryOpen(false)}
/>
)}
{ helperApp &&
<HelperApp
getEntity={getEntity}
Expand All @@ -309,7 +323,7 @@ const InstanceDetails = forwardRef(({
onClose={setHelperApp}
/>
}
</>
</Paneset>
);
});

Expand Down
45 changes: 43 additions & 2 deletions src/Instance/InstanceDetails/InstanceDetails.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import React from 'react';
import React, { act } from 'react';
import '../../../test/jest/__mock__';
import { QueryClient, QueryClientProvider } from 'react-query';
import { screen, fireEvent } from '@folio/jest-config-stripes/testing-library/react';
import {
screen,
fireEvent,
within,
} from '@folio/jest-config-stripes/testing-library/react';
import userEvent from '@folio/jest-config-stripes/testing-library/user-event';
import { MemoryRouter } from 'react-router-dom';
import { DataContext } from '../../contexts';
import { renderWithIntl, translationsProperties } from '../../../test/jest/helpers';
Expand Down Expand Up @@ -206,4 +211,40 @@ describe('InstanceDetails', () => {
expect(screen.queryByRole('button', { name: 'Consortial holdings' })).not.toBeInTheDocument();
});
});

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

beforeEach(async () => {
await act(async () => { renderInstanceDetails(); });

versionHistoryButton = screen.getByRole('button', { name: /version history/i });
});

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

describe('when click the button', () => {
it('should render version history pane', async () => {
await act(() => userEvent.click(versionHistoryButton));

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

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

const versionHistoryPane = await screen.findByRole('region', { name: /version history/i });
expect(versionHistoryPane).toBeInTheDocument();

const closeButton = await within(versionHistoryPane).findByRole('button', { name: /close/i });
await act(() => userEvent.click(closeButton));

expect(screen.queryByRole('region', { name: /version history/i })).not.toBeInTheDocument();
});
});
});
});
9 changes: 7 additions & 2 deletions src/views/VersionHistory/VersionHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ import {
} from '@folio/stripes-acq-components';

const VersionHistory = ({ onClose }) => {
// TODO: remove once API for inventory version history is implemented and pass currentVersion and versionId to props
// set mocked data to avoid unit tests warnings, because these props are required
const currentVersion = 'mockedVersion';
const versionId = 'mockedVersionId';

return (
<VersionViewContextProvider
snapshotPath=""
versions={[]}
versionId={null}
versionId={versionId}
>
<VersionHistoryPane
currentVersion={null}
currentVersion={currentVersion}
id="inventory"
isLoading={false}
onClose={onClose}
Expand Down

0 comments on commit 0437f04

Please sign in to comment.