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-3172: Add Version history button and Version history pane to details view of Item #2730

Merged
merged 5 commits into from
Feb 5, 2025
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
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.
* Add Version history button and Version history pane to details view of Item. Refs UIIN-3172.

## [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
21 changes: 20 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,6 +164,7 @@ 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);
Expand Down Expand Up @@ -621,6 +625,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 +992,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 +1023,11 @@ const ItemView = props => {
dismissible
onClose={onCloseViewItem}
actionMenu={getActionMenu}
lastMenu={(
<PaneMenu>
<VersionHistoryButton onClick={openVersionHistory} />
</PaneMenu>
)}
>
<UpdateItemOwnershipModal
isOpen={isUpdateOwnershipModalOpen}
Expand Down Expand Up @@ -1732,6 +1746,11 @@ const ItemView = props => {
</AccordionSet>
</AccordionStatus>
</Pane>
{isVersionHistoryOpen && (
<VersionHistory
onClose={() => setIsSetVersionHistoryOpen(false)}
/>
)}
</Paneset>
</HasCommand>
);
Expand Down
36 changes: 36 additions & 0 deletions src/views/ItemView.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
fireEvent,
within,
} from '@folio/jest-config-stripes/testing-library/react';
import userEvent from '@folio/jest-config-stripes/testing-library/user-event';
import { runAxeTest } from '@folio/stripes-testing';

import '../../test/jest/__mock__';
Expand Down Expand Up @@ -296,6 +297,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', async () => {
await 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 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 userEvent.click(closeButton);

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

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

import {
VersionHistoryPane,
VersionViewContextProvider,
} from '@folio/stripes-acq-components';

const VersionHistory = ({ onClose }) => {
return (
<VersionViewContextProvider
snapshotPath=""
versions={[]}
versionId={null}
>
<VersionHistoryPane
currentVersion={null}
id="inventory"
isLoading={false}
onClose={onClose}
onSelectVersion={() => {}}
snapshotPath=""
labelsMap={{}}
versions={[]}
hiddenFields={[]}
/>
</VersionViewContextProvider>
);
};

VersionHistory.propTypes = {
onClose: PropTypes.func,
};


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';
4 changes: 3 additions & 1 deletion translations/ui-inventory/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -879,5 +879,7 @@
"settings.section.displaySettings": "Display settings",
"settings.displaySettings.defaultSort": "Default sort",

"instance.linked.id": "Linked instance ID - {id}"
"instance.linked.id": "Linked instance ID - {id}",

"versionHistory.paneTitle": "Version history"
}
Loading