Skip to content

Commit

Permalink
UIQM-592 Fix input polish chars into fields (#726)
Browse files Browse the repository at this point in the history
* UIQM-592

On Windows fix by prevent action Save record with shortcut ctrl + s when input ś or Ś into text field

* UIQM-592. Added comment.

* UIQM-592 after changes

Added utils function to detect diacritics chars - polish, romanian, czech etc.
In polish ł, Ł chars is special diactritics that is not normalized char to l, L.
  • Loading branch information
przemyslawturek authored Sep 18, 2024
1 parent 42dfeef commit 0e3356c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* [UIQM-691](https://issues.folio.org/browse/UIQM-691) Show correct field and toast color when validation returns warnings.
* [UIQM-665](https://issues.folio.org/browse/UIQM-665) Fix to generate array content in 008 after changing document type of MARC bib.
* [UIQM-694](https://issues.folio.org/browse/UIQM-694) Separate error messages triggered by controlled subfields of different linked fields.
* [UIQM-592](https://issues.folio.org/browse/UIQM-592) Fix to input polish special chars into fields.

## [8.0.1] (https://github.com/folio-org/ui-quick-marc/tree/v8.0.1) (2024-04-18)

Expand Down
3 changes: 3 additions & 0 deletions src/QuickMarcEditor/QuickMarcEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import {
updateRecordAtIndex,
markLinkedRecords,
getLeaderPositions,
isDiacritic,
} from './utils';

import css from './QuickMarcEditor.css';
Expand Down Expand Up @@ -465,6 +466,8 @@ const QuickMarcEditor = ({
name: 'save',
shortcut: 'mod+s',
handler: async (e) => {
if (isDiacritic(e.key)) return;

if (!saveFormDisabled) {
e.preventDefault();
confirmationChecks.current = { ...REQUIRED_CONFIRMATIONS };
Expand Down
8 changes: 8 additions & 0 deletions src/QuickMarcEditor/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1220,3 +1220,11 @@ export const isFolioSourceFileNotSelected = ({ selectedSourceFile }) => {
export const joinErrors = (errorsA, errorsB) => {
return assignWith({}, errorsA, errorsB, (objValue = [], srcValue = []) => objValue.concat(srcValue));
};

export const isDiacritic = (char) => {
const specialDiactrics = 'łŁøß';

if (specialDiactrics.includes(char)) return true;

return char.normalize('NFD') !== char;
};
18 changes: 18 additions & 0 deletions src/QuickMarcEditor/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1793,4 +1793,22 @@ describe('QuickMarcEditor utils', () => {
});
});
});

describe('isDiacritic', () => {
it('should all chars to be detected as diacritics', () => {
const diacriticArray = 'ąćęłńóśźżĄĆĘŁŃÓŚŹŻøã鞎šŠşŞß';

[...diacriticArray].forEach(c => {
expect(utils.isDiacritic(c)).toBeTruthy();
});
});

it('should all chars to be detected as not diacritics', () => {
const diacriticArray = 'acelnoszACELNOSZ';

[...diacriticArray].forEach(c => {
expect(utils.isDiacritic(c)).toBeFalsy();
});
});
});
});

0 comments on commit 0e3356c

Please sign in to comment.