Skip to content

Commit

Permalink
UIIN-2896 Inventory app: Define and implement shortcut key for editin…
Browse files Browse the repository at this point in the history
…g a quickMARC bib record
  • Loading branch information
BogdanDenis committed May 9, 2024
1 parent 12878f7 commit 54f4d9c
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 41 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* Jest/RTL: Cover MoveHoldingContext component with unit tests. Refs UIIN-2664.
* Use consolidated locations endpoint to fetch all locations when in central tenant context. Refs UIIN-2811.
* Change label of eye-readable call number search option in holdings/items. Refs UIIN-2797.
* Inventory app: Define and implement shortcut key for editing a quickMARC bib record. Refs UIIN-2896.

## [11.0.4](https://github.com/folio-org/ui-inventory/tree/v11.0.4) (2024-04-30)
[Full Changelog](https://github.com/folio-org/ui-inventory/compare/v11.0.3...v11.0.4)
Expand Down
6 changes: 6 additions & 0 deletions src/ViewHoldingsRecord.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,12 @@ class ViewHoldingsRecord extends React.Component {
if (stripes.hasPerm('ui-inventory.holdings.edit')) this.onEditHolding();
}),
},
{
name: 'editMARC',
handler: handleKeyCommand(() => {
if (stripes.hasPerm('ui-quick-marc.quick-marc-editor.all')) this.handleEditInQuickMarc();
}),
},
{
name: 'expandAllSections',
handler: (e) => expandAllSections(e, this.accordionStatusRef),
Expand Down
6 changes: 6 additions & 0 deletions src/ViewInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,12 @@ class ViewInstance extends React.Component {
if (stripes.hasPerm('ui-inventory.instance.edit')) this.onClickEditInstance();
}),
},
{
name: 'editMARC',
handler: handleKeyCommand(() => {
if (stripes.hasPerm('ui-quick-marc.quick-marc-editor.all')) this.editInstanceMarc();
}),
},
{
name: 'duplicateRecord',
handler: handleKeyCommand(() => {
Expand Down
93 changes: 68 additions & 25 deletions src/components/ViewSource/ViewSource.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import React, {
useState,
useEffect,
useMemo,
useCallback,
} from 'react';
import {
useLocation,
useHistory,
} from 'react-router-dom';
import PropTypes from 'prop-types';
import { FormattedMessage } from 'react-intl';

import {
Button,
LoadingView,
HasCommand,
checkScope,
} from '@folio/stripes/components';
import { useStripes } from '@folio/stripes/core';
import {
Expand All @@ -18,7 +26,10 @@ import {

import { useGoBack } from '../../common/hooks';

import { isUserInConsortiumMode } from '../../utils';
import {
isUserInConsortiumMode,
handleKeyCommand,
} from '../../utils';
import MARC_TYPES from './marcTypes';

import styles from './ViewSource.css';
Expand All @@ -33,6 +44,8 @@ const ViewSource = ({
marcType,
}) => {
const stripes = useStripes();
const location = useLocation();
const history = useHistory();
const [isShownPrintPopup, setIsShownPrintPopup] = useState(false);
const openPrintPopup = () => setIsShownPrintPopup(true);
const closePrintPopup = () => setIsShownPrintPopup(false);
Expand All @@ -51,6 +64,30 @@ const ViewSource = ({
const [marc, setMarc] = useState();
const [isMarcLoading, setIsMarcLoading] = useState(true);

const redirectToMARCEdit = useCallback(() => {
const urlId = isHoldingsRecord ? `${instanceId}/${holdingsRecordId}` : instanceId;
const pathname = `/inventory/quick-marc/edit-${isHoldingsRecord ? 'holdings' : 'bib'}/${urlId}`;

const searchParams = new URLSearchParams(location.search);

searchParams.delete('relatedRecordVersion');
searchParams.append('shared', instance.shared?.toString());

history.push({
pathname,
search: searchParams.toString(),
});
}, [isHoldingsRecord]);

const shortcuts = useMemo(() => [
{
name: 'editMARC',
handler: handleKeyCommand(() => {
if (stripes.hasPerm('ui-quick-marc.quick-marc-editor.all')) redirectToMARCEdit();
}),
},
]);

useEffect(() => {
setIsMarcLoading(true);

Expand Down Expand Up @@ -94,32 +131,38 @@ const ViewSource = ({
);

return (
<div className={styles.viewSource}>
<MarcView
paneTitle={paneTitle}
marcTitle={marcTitle}
marc={marc}
onClose={goBack}
lastMenu={
isPrintAvailable &&
<Button
marginBottom0
buttonStyle="primary"
onClick={openPrintPopup}
>
<FormattedMessage id="ui-quick-marc.print" />
</Button>
}
/>
{isPrintAvailable && isShownPrintPopup && (
<PrintPopup
marc={marc}
paneTitle={instance.title}
<HasCommand
commands={shortcuts}
isWithinScope={checkScope}
scope={document.body}
>
<div className={styles.viewSource}>
<MarcView
paneTitle={paneTitle}
marcTitle={marcTitle}
onAfterPrint={closePrintPopup}
marc={marc}
onClose={goBack}
lastMenu={
isPrintAvailable &&
<Button
marginBottom0
buttonStyle="primary"
onClick={openPrintPopup}
>
<FormattedMessage id="ui-quick-marc.print" />
</Button>
}
/>
)}
</div>
{isPrintAvailable && isShownPrintPopup && (
<PrintPopup
marc={marc}
paneTitle={instance.title}
marcTitle={marcTitle}
onAfterPrint={closePrintPopup}
/>
)}
</div>
</HasCommand>
);
};

Expand Down
33 changes: 18 additions & 15 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,23 @@ const InventoryRouting = (props) => {
const [isShortcutsModalOpen, setIsShortcutsModalOpen] = useState(false);
const { showSettings, match: { path } } = props;

const keyboardShortcuts = [
...defaultKeyboardShortcuts.slice(0, 9),
{
label: <FormattedMessage id="ui-inventory.shortcut.nextSubfield" />,
name: 'NEXT_SUBFIELD',
shortcut: 'Ctrl + ]',
},
{
label: <FormattedMessage id="ui-inventory.shortcut.prevSubfield" />,
name: 'PREV_SUBFIELD',
shortcut: 'Ctrl + [',
},
...defaultKeyboardShortcuts.slice(9),
];
const keyboardShortcuts = [...defaultKeyboardShortcuts];

keyboardShortcuts.splice(4, 0, {
label: (<FormattedMessage id="ui-inventory.shortcut.editMARC" />),
name: 'editMARC',
shortcut: 'ctrl+shift+e',
});
keyboardShortcuts.splice(11, 0, {
label: <FormattedMessage id="ui-inventory.shortcut.nextSubfield" />,
name: 'NEXT_SUBFIELD',
shortcut: 'Ctrl + ]',
},
{
label: <FormattedMessage id="ui-inventory.shortcut.prevSubfield" />,
name: 'PREV_SUBFIELD',
shortcut: 'Ctrl + [',
});

useEffect(() => {
return () => {
Expand Down Expand Up @@ -112,7 +115,7 @@ const InventoryRouting = (props) => {
<DataProvider>
<HoldingsProvider>
<LastSearchTermsProvider>
<CommandList commands={defaultKeyboardShortcuts}>
<CommandList commands={keyboardShortcuts}>
<HasCommand
commands={shortcuts}
isWithinScope={checkScope}
Expand Down
3 changes: 2 additions & 1 deletion translations/ui-inventory/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -874,5 +874,6 @@
"info.shelvingOrder": "This field is the normalized form of the call number which determines how the call number is sorted while browsing.",

"shortcut.nextSubfield": "quickMARC only: Move to the next subfield in a text box",
"shortcut.prevSubfield": "quickMARC only: Move to the previous subfield in a text box"
"shortcut.prevSubfield": "quickMARC only: Move to the previous subfield in a text box",
"shortcut.editMARC": "Edit MARC record"
}

0 comments on commit 54f4d9c

Please sign in to comment.