Skip to content

Commit

Permalink
UIQM-251: quickMARC - Edit/Derive Bib and Create/Edit Holdings - URL …
Browse files Browse the repository at this point in the history
…in error toast notifications does not work (#330)

* UIQM-251 Edit/Derive Bib and Create/Edit Holdings - URL in error toast notifications does not work

* UIQM-251 Fix eslint warnings
  • Loading branch information
BogdanDenis authored Jul 8, 2022
1 parent 724bbda commit 1620788
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 30 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 @@
* [UIQM-243](https://issues.folio.org/browse/UIQM-243) Optimistic Locking: Do not send update request when user attempts to update older version of MARC bib/holdings/authority
* [UIQM-244](https://issues.folio.org/browse/UIQM-244) Fix undefined user name
* [UIQM-246] (https://issues.folio.org/browse/UIQM-246) MARC Holdings | Update error toast notification message when user edit 18 position of LDR
* [UIQM-251] (https://issues.folio.org/browse/UIQM-251) Edit/Derive Bib and Create/Edit Holdings - URL in error toast notifications does not work

## [5.0.3](https://github.com/folio-org/ui-quick-marc/tree/v5.0.3) (2022-06-15)

Expand Down
1 change: 0 additions & 1 deletion src/QuickMarcEditor/QuickMarcEditWrapper.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
act,
fireEvent,
waitFor,
screen,
} from '@testing-library/react';
import faker from 'faker';
import noop from 'lodash/noop';
Expand Down
5 changes: 1 addition & 4 deletions src/QuickMarcEditor/QuickMarcEditorContainer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import '@folio/stripes-acq-components/test/jest/__mock__';
import QuickMarcEditorContainer from './QuickMarcEditorContainer';
import QuickMarcEditWrapper from './QuickMarcEditWrapper';
import { QUICK_MARC_ACTIONS } from './constants';
import {
EXTERNAL_INSTANCE_APIS,
MARC_TYPES,
} from '../common/constants';
import { MARC_TYPES } from '../common/constants';

const getInstance = () => ({
id: faker.random.uuid(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const LocationField = ({
}

input.onChange(newInputValue);
}, [permanentLocation]);
}, [permanentLocation, input, action]);

return (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ const QuickMarcEditorRows = ({
const intl = useIntl();
const { initialValues } = useFormState();

const isNewRow = (row) => !initialValues.records.find(record => record.id === row.id);
const isNewRow = useCallback((row) => {
return !initialValues.records.find(record => record.id === row.id);
}, [initialValues.records]);

const addNewRow = useCallback(({ target }) => {
addRecord({ index: parseInt(target.dataset.index, 10) });
Expand All @@ -75,7 +77,7 @@ const QuickMarcEditorRows = ({
},
]);
}
}, [fields, deleteRecord, setDeletedRecords]);
}, [fields, deleteRecord, setDeletedRecords, isNewRow]);

const moveRow = useCallback(({ target }) => {
moveRecord({
Expand Down
30 changes: 8 additions & 22 deletions src/QuickMarcEditor/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,37 +241,23 @@ const joinFailedPositions = (failedPositions) => {
return joinedPositions;
};

const validateLeaderPositions = (prevLeader, leader, marcType) => {
const prevLeaderFailedPositions = getInvalidLeaderPositions(prevLeader, marcType);
const prevLeaderJoinedPositions = joinFailedPositions(prevLeaderFailedPositions);
const validateLeaderPositions = (leader, marcType) => {
const failedPositions = getInvalidLeaderPositions(leader, marcType);
const joinedPositions = joinFailedPositions(failedPositions);

if (prevLeaderFailedPositions.length && prevLeader === leader) {
// invalid leader positions came from backend
return (
<FormattedMessage
id="ui-quick-marc.record.error.leader.initial.invalidPositionValue"
values={{
positions: prevLeaderJoinedPositions,
link: (
<Link to={LEADER_DOCUMENTATION_LINKS[marcType]}>
{LEADER_DOCUMENTATION_LINKS[marcType]}
</Link>
),
}}
/>
);
}

if (failedPositions.length) {
return (
<FormattedMessage
id="ui-quick-marc.record.error.leader.invalidPositionValue"
values={{
positions: joinedPositions,
link: (
<Link to={LEADER_DOCUMENTATION_LINKS[marcType]}>
<Link
to={{
pathname: LEADER_DOCUMENTATION_LINKS[marcType],
}}
target="_blank"
>
{LEADER_DOCUMENTATION_LINKS[marcType]}
</Link>
),
Expand Down Expand Up @@ -300,7 +286,7 @@ export const validateLeader = (prevLeader = '', leader = '', marcType = MARC_TYP
return <FormattedMessage id={`ui-quick-marc.record.error.leader.forbiddenBytes.${marcType}`} />;
}

const leaderValidationError = validateLeaderPositions(prevLeader, leader, marcType);
const leaderValidationError = validateLeaderPositions(leader, marcType);

if (leaderValidationError) {
return leaderValidationError;
Expand Down

0 comments on commit 1620788

Please sign in to comment.