Skip to content

Commit

Permalink
UXPROD-4125: Add Change log icon to details view of Instance, Holding…
Browse files Browse the repository at this point in the history
…s, Items (#2741)

* UIIN-3172: Add Version history button and Version history pane to details view of Item

* UIIN-3171: Add Version history button and Version history pane to details view of Holdings

* UIIN-3170: Add Version history button and Version history pane to details view of Instance

---------

Co-authored-by: Oleksandr Hladchenko <[email protected]>
Co-authored-by: Oleksandr Hladchenko1 <[email protected]>
  • Loading branch information
3 people authored Feb 12, 2025
1 parent 99ed763 commit 04fcc5d
Show file tree
Hide file tree
Showing 9 changed files with 574 additions and 361 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
* CI: Switch to centralized/shared workflow from https://github.com/folio-org/.github. Fixes UIIN-3218.
* Set correct widths for Call number browse results columns. Fixes UIIN-3229.
* Display actual instance state (shared or local) when user is using "Drag and drop" to move inventory records. Fixes UIIN-3185.
* 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 Holdings. Refs UIIN-3171.
* 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
64 changes: 39 additions & 25 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,

Check warning on line 29 in src/Instance/InstanceDetails/InstanceDetails.js

View workflow job for this annotation

GitHub Actions / ui / Install and lint / Install and lint

'Paneset' is defined but never used. Allowed unused vars must match /React/u
} 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 @@ -161,14 +170,14 @@ const InstanceDetails = forwardRef(({
{...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 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();
});
});
});
});
Loading

0 comments on commit 04fcc5d

Please sign in to comment.