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

UIQM 351: MARC Authority | Print Source record #468

Merged
merged 4 commits into from
Feb 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* [UIQM-386](https://issues.folio.org/browse/UIQM-386) Edit MARC authority | Add/Edit 010 $a when linking is based on 001.
* [UIQM-385](https://issues.folio.org/browse/UIQM-385) Edit/Derive quickMARC | Allow user to drag text boxes to view all content
* [UIQM-402](https://issues.folio.org/browse/UIQM-402) Add linkingRuleId to the request body for linked fields
* [UIQM-351](https://issues.folio.org/browse/UIQM-351) MARC Authority | Print Source record

## [5.2.0](https://github.com/folio-org/ui-quick-marc/tree/v5.2.0) (2022-10-26)

Expand Down
18 changes: 11 additions & 7 deletions src/QuickMarcView/PrintPopup/PrintPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,16 @@ const PrintPopup = ({
return (
<div className={styles.hidden}>
<div ref={contentToPrintRef} data-testid="print-popup">
<h2 className={styles.paneTitle}>
<span>
{paneTitle}
</span>
</h2>
<hr />
{paneTitle &&
<>
<h2 className={styles.paneTitle} data-testid="print-popup-title">
<span>
{paneTitle}
</span>
</h2>
<hr />
</>
}
<MarcContent
isPrint
marcTitle={marcTitle}
Expand All @@ -65,7 +69,7 @@ PrintPopup.propTypes = {
paneTitle: PropTypes.oneOfType([
PropTypes.node,
PropTypes.string,
]).isRequired,
]),
};

export default PrintPopup;
8 changes: 7 additions & 1 deletion src/QuickMarcView/PrintPopup/PrintPopup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ describe('Given PrintPopup', () => {
});
});

it('should show the pane title', () => {
it('should show the pane title if a paneTitle prop is given', () => {
const { getByText } = renderPrintPopup();

expect(getByText('fakePaneTitle')).toBeVisible();
});

it('should not show the pane title if a paneTitle prop is not given', () => {
const { queryByTestId } = renderPrintPopup({ paneTitle: undefined });

expect(queryByTestId('print-popup-title')).not.toBeInTheDocument();
});

it('should display the content of the marc record', () => {
const { getByText } = renderPrintPopup();

Expand Down
56 changes: 2 additions & 54 deletions src/QuickMarcView/QuickMarcView.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import React, { useState } from 'react';
import { FormattedMessage } from 'react-intl';
import React from 'react';
import PropTypes from 'prop-types';

import { IfPermission } from '@folio/stripes/core';
import {
PaneMenu,
Pane,
Paneset,
Button,
} from '@folio/stripes/components';

import MarcContent from './MarcContent';
import PrintPopup from './PrintPopup';

const propTypes = {
isPaneset: PropTypes.bool,
Expand Down Expand Up @@ -42,45 +37,6 @@ const QuickMarcView = ({
lastMenu,
isPaneset,
}) => {
const [showPrintPopup, setShowPrintPopup] = useState(false);

const isMarcBibRecord = marc.recordType === 'MARC_BIB';

const openPrintPopup = () => {
setShowPrintPopup(true);
};

const closePrintPopup = () => {
setShowPrintPopup(false);
};

const renderPrintButton = () => (
<IfPermission perm="ui-quick-marc.quick-marc-editor.view">
<Button
marginBottom0
buttonStyle="primary"
onClick={openPrintPopup}
>
<FormattedMessage id="ui-quick-marc.print" />
</Button>
</IfPermission>
);

const optionalProps = {};

if (isMarcBibRecord && !lastMenu) {
optionalProps.lastMenu = renderPrintButton();
}

if (lastMenu) {
optionalProps.lastMenu = (
<PaneMenu>
{lastMenu}
{isMarcBibRecord && renderPrintButton()}
</PaneMenu>
);
}

const renderContent = () => (
<Pane
paneTitle={paneTitle}
Expand All @@ -92,20 +48,12 @@ const QuickMarcView = ({
data-test-instance-marc
data-testid="marc-view-pane"
height={paneHeight}
{...optionalProps}
lastMenu={lastMenu}
>
<MarcContent
marcTitle={marcTitle}
marc={marc}
/>
{showPrintPopup && (
<PrintPopup
marc={marc}
paneTitle={paneTitle}
marcTitle={marcTitle}
onAfterPrint={closePrintPopup}
/>
)}
</Pane>
);

Expand Down
31 changes: 1 addition & 30 deletions src/QuickMarcView/QuickMarcView.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { fireEvent, render } from '@testing-library/react';
import { render } from '@testing-library/react';

import { runAxeTest } from '@folio/stripes-testing';

Expand Down Expand Up @@ -148,33 +148,4 @@ describe('Given QuickMarcView', () => {
expect(getByText('Last Menu Node')).toBeDefined();
});
});

describe('when it is the marc bib record', () => {
describe('and "lastMenu" is present', () => {
it('should render "lastMenu" and "Print" button', () => {
const { getByText } = renderQuickMarcView({
lastMenu: <div>Last Menu Node</div>,
});

expect(getByText('Last Menu Node')).toBeDefined();
expect(getByText('ui-quick-marc.print')).toBeDefined();
});
});

describe('and the "lastMenu" is not present', () => {
it('should render the "Print" button', () => {
const { getByText } = renderQuickMarcView();

expect(getByText('ui-quick-marc.print')).toBeDefined();
});
});

it('should display the print popup after clicking on the "Print" button', () => {
const { getByText, getByTestId } = renderQuickMarcView();

fireEvent.click(getByText('ui-quick-marc.print'));

expect(getByTestId('print-popup')).toBeInTheDocument();
});
});
});