From 4ced810a6f8820771d7d87a3b70fe79eb04fbec1 Mon Sep 17 00:00:00 2001 From: Uladzislau_Kutarkin Date: Wed, 4 Oct 2023 14:12:57 +0400 Subject: [PATCH 01/10] UIBULKED-343: Refactor logic for downloading file from actions menu --- test/jest/__mock__/reactItl.mock.js | 33 +++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 test/jest/__mock__/reactItl.mock.js diff --git a/test/jest/__mock__/reactItl.mock.js b/test/jest/__mock__/reactItl.mock.js new file mode 100644 index 00000000..e58bb7be --- /dev/null +++ b/test/jest/__mock__/reactItl.mock.js @@ -0,0 +1,33 @@ +import React from 'react'; + +jest.mock('react-intl', () => { + const intl = { + formatMessage: ({ id }) => id, + formatNumber: (value) => value + }; + + return { + ...jest.requireActual('react-intl'), + FormattedMessage: jest.fn(({ id, values, children }) => { + if (children) { + return children([id]); + } + + const valuesString = values ? (`-${JSON.stringify(values)}`) : ''; + + return `${id}${valuesString}`; + }), + FormattedTime: jest.fn(({ value, children }) => { + if (children) { + return children([value]); + } + + return value; + }), + FormattedNumber: jest.fn((value) => { + return value; + }), + useIntl: () => intl, + injectIntl: (Component) => (props) => , + }; +}); From 10c424ad7770f0116db6cd41869d4f67972ad075 Mon Sep 17 00:00:00 2001 From: Uladzislau_Kutarkin Date: Tue, 24 Oct 2023 23:27:09 +0400 Subject: [PATCH 02/10] UIBULKED-316: Bulk edit actions for holdings notes - add and remove Mark as staff only --- CHANGELOG.md | 1 + .../ContentUpdatesForm/helpers.js | 20 +++++++++++++ .../ContentUpdatesForm/helpers.test.js | 28 +++++++++++++++++++ src/constants/inAppActions.js | 6 ++++ 4 files changed, 55 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a7cf796..95ac4a09 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,7 @@ * [UIBULKED-355](https://issues.folio.org/browse/UIBULKED-355) Remove reference to Query tab on the landing page. * [UIBULKED-315](https://issues.folio.org/browse/UIBULKED-315) Group holdings record properties using optgroup component +* [UIBULKED-316](https://issues.folio.org/browse/UIBULKED-316) Bulk edit actions for holdings notes - add and remove Mark as staff only. ## [4.0.0](https://github.com/folio-org/ui-bulk-edit/tree/v4.0.0) (2023-10-12) diff --git a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.js b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.js index adba3617..d140d452 100644 --- a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.js +++ b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.js @@ -20,6 +20,7 @@ import { noteActions, noteActionsWithMark, noteActionsWithDuplicate, + noteActionHoldings, } from '../../../../../constants'; export const ACTION_VALUE_KEY = 'name'; @@ -91,6 +92,7 @@ export const getDefaultActions = (option, options, formatMessage) => { const noteDefaultActions = noteActions(formatMessage); const noteWithMarkDefaultActions = noteActionsWithMark(formatMessage); const noteDuplicateDefaultActions = noteActionsWithDuplicate(formatMessage); + const noteHoldingsDefaultActions = noteActionHoldings(formatMessage); const replaceClearInitialVal = replaceClearDefaultActions[0].value; @@ -290,6 +292,24 @@ export const getDefaultActions = (option, options, formatMessage) => { ], }; + case OPTIONS.HOLDINGS_NOTE: + return { + type: '', + actions: [ + null, + { + actionsList: noteHoldingsDefaultActions, + controlType: (action) => { + return action === ACTIONS.CHANGE_TYPE + ? CONTROL_TYPES.NOTE_SELECT + : CONTROL_TYPES.TEXTAREA; + }, + [ACTION_VALUE_KEY]: noteHoldingsDefaultActions[0].value, + [FIELD_VALUE_KEY]: '', + }, + ], + }; + default: return { type: null, diff --git a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.test.js b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.test.js index cb90c6c9..9e83b593 100644 --- a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.test.js +++ b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.test.js @@ -491,6 +491,34 @@ describe('ContentUpdatesForm helpers', () => { }); }); + it('returns the correct object for the HOLDINGS_NOTE option', () => { + expect(JSON.stringify(getDefaultActions(OPTIONS.HOLDINGS_NOTE, [], formatMessage))).toEqual( + JSON.stringify({ + type: '', + actions: [ + null, + { + actionsList: [{ + value: '', + disabled: true, + label: undefined, + }, + { value: 'MARK_AS_STAFF_ONLY', + disabled: false, + label: undefined }, + { value: 'REMOVE_MARK_AS_STAFF_ONLY', + disabled: false, + label: undefined }, + ], + controlType: () => CONTROL_TYPES.TEXTAREA, + [ACTION_VALUE_KEY]: '', + [FIELD_VALUE_KEY]: '', + }, + ], + }), + ); + }); + it('returns the correct object for the default case', () => { expect(getDefaultActions('unknown', [], formatMessage)).toEqual({ type: null, diff --git a/src/constants/inAppActions.js b/src/constants/inAppActions.js index a2c07772..2d09e89c 100644 --- a/src/constants/inAppActions.js +++ b/src/constants/inAppActions.js @@ -150,6 +150,12 @@ export const noteActionsWithMark = (formatMessage) => [ getChangeNoteTypeAction(formatMessage), ]; +export const noteActionHoldings = (formatMessage) => [ + getPlaceholder(formatMessage), + getMarkAsStuffOnlyAction(formatMessage), + getRemoveMarkAsStuffOnlyAction(formatMessage) +]; + export const noteActionsWithDuplicate = (formatMessage) => [ getPlaceholder(formatMessage), getMarkAsStuffOnlyAction(formatMessage), From 53dd522dc4dc9141cf7152dd6357df51fd965a73 Mon Sep 17 00:00:00 2001 From: UladzislauKutarkin <72550466+UladzislauKutarkin@users.noreply.github.com> Date: Tue, 24 Oct 2023 23:29:34 +0400 Subject: [PATCH 03/10] Delete test/jest/__mock__/reactItl.mock.js --- test/jest/__mock__/reactItl.mock.js | 33 ----------------------------- 1 file changed, 33 deletions(-) delete mode 100644 test/jest/__mock__/reactItl.mock.js diff --git a/test/jest/__mock__/reactItl.mock.js b/test/jest/__mock__/reactItl.mock.js deleted file mode 100644 index e58bb7be..00000000 --- a/test/jest/__mock__/reactItl.mock.js +++ /dev/null @@ -1,33 +0,0 @@ -import React from 'react'; - -jest.mock('react-intl', () => { - const intl = { - formatMessage: ({ id }) => id, - formatNumber: (value) => value - }; - - return { - ...jest.requireActual('react-intl'), - FormattedMessage: jest.fn(({ id, values, children }) => { - if (children) { - return children([id]); - } - - const valuesString = values ? (`-${JSON.stringify(values)}`) : ''; - - return `${id}${valuesString}`; - }), - FormattedTime: jest.fn(({ value, children }) => { - if (children) { - return children([value]); - } - - return value; - }), - FormattedNumber: jest.fn((value) => { - return value; - }), - useIntl: () => intl, - injectIntl: (Component) => (props) => , - }; -}); From 2469b057674e5618bc9dcc894415fdaa2de3b2d7 Mon Sep 17 00:00:00 2001 From: Uladzislau_Kutarkin Date: Tue, 24 Oct 2023 23:50:46 +0400 Subject: [PATCH 04/10] UIBULKED-316: Bulk edit actions for holdings notes - add and remove Mark as staff only --- .../BulkEditInApp/ContentUpdatesForm/helpers.js | 6 ++---- .../BulkEditInApp/ContentUpdatesForm/helpers.test.js | 6 +++++- src/constants/inAppActions.js | 6 ------ 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.js b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.js index d140d452..b201dfba 100644 --- a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.js +++ b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.js @@ -20,7 +20,6 @@ import { noteActions, noteActionsWithMark, noteActionsWithDuplicate, - noteActionHoldings, } from '../../../../../constants'; export const ACTION_VALUE_KEY = 'name'; @@ -92,7 +91,6 @@ export const getDefaultActions = (option, options, formatMessage) => { const noteDefaultActions = noteActions(formatMessage); const noteWithMarkDefaultActions = noteActionsWithMark(formatMessage); const noteDuplicateDefaultActions = noteActionsWithDuplicate(formatMessage); - const noteHoldingsDefaultActions = noteActionHoldings(formatMessage); const replaceClearInitialVal = replaceClearDefaultActions[0].value; @@ -298,13 +296,13 @@ export const getDefaultActions = (option, options, formatMessage) => { actions: [ null, { - actionsList: noteHoldingsDefaultActions, + actionsList: noteWithMarkDefaultActions, controlType: (action) => { return action === ACTIONS.CHANGE_TYPE ? CONTROL_TYPES.NOTE_SELECT : CONTROL_TYPES.TEXTAREA; }, - [ACTION_VALUE_KEY]: noteHoldingsDefaultActions[0].value, + [ACTION_VALUE_KEY]: noteWithMarkDefaultActions[0].value, [FIELD_VALUE_KEY]: '', }, ], diff --git a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.test.js b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.test.js index 9e83b593..d0a0de71 100644 --- a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.test.js +++ b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.test.js @@ -510,7 +510,11 @@ describe('ContentUpdatesForm helpers', () => { disabled: false, label: undefined }, ], - controlType: () => CONTROL_TYPES.TEXTAREA, + controlType: (action) => { + return action === ACTIONS.CHANGE_TYPE + ? CONTROL_TYPES.NOTE_SELECT + : CONTROL_TYPES.TEXTAREA; + }, [ACTION_VALUE_KEY]: '', [FIELD_VALUE_KEY]: '', }, diff --git a/src/constants/inAppActions.js b/src/constants/inAppActions.js index 2d09e89c..a2c07772 100644 --- a/src/constants/inAppActions.js +++ b/src/constants/inAppActions.js @@ -150,12 +150,6 @@ export const noteActionsWithMark = (formatMessage) => [ getChangeNoteTypeAction(formatMessage), ]; -export const noteActionHoldings = (formatMessage) => [ - getPlaceholder(formatMessage), - getMarkAsStuffOnlyAction(formatMessage), - getRemoveMarkAsStuffOnlyAction(formatMessage) -]; - export const noteActionsWithDuplicate = (formatMessage) => [ getPlaceholder(formatMessage), getMarkAsStuffOnlyAction(formatMessage), From 8285b9f848d0d6b3de6fbd2caf5b803a9597b619 Mon Sep 17 00:00:00 2001 From: Uladzislau_Kutarkin Date: Tue, 24 Oct 2023 23:57:37 +0400 Subject: [PATCH 05/10] UIBULKED-316: fix test --- .../ContentUpdatesForm/helpers.test.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.test.js b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.test.js index d0a0de71..f6023546 100644 --- a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.test.js +++ b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.test.js @@ -509,6 +509,20 @@ describe('ContentUpdatesForm helpers', () => { { value: 'REMOVE_MARK_AS_STAFF_ONLY', disabled: false, label: undefined }, + { value: 'ADD_TO_EXISTING', + disabled: false, + label: undefined }, + { value: 'REMOVE_ALL', + disabled: false, + label: undefined }, + { value: 'FIND', + disabled: false, + label: undefined }, + { + value: 'CHANGE_TYPE', + disabled: false, + label: undefined, + }, ], controlType: (action) => { return action === ACTIONS.CHANGE_TYPE From 11692cb9a98df6d0e0156b7fcd9c639595b8f2e7 Mon Sep 17 00:00:00 2001 From: Uladzislau_Kutarkin Date: Wed, 25 Oct 2023 00:05:37 +0400 Subject: [PATCH 06/10] UIBULKED-316: refactor code --- .../ContentUpdatesForm/helpers.js | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.js b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.js index b201dfba..690aa3f9 100644 --- a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.js +++ b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.js @@ -272,25 +272,8 @@ export const getDefaultActions = (option, options, formatMessage) => { }, ], }; - case OPTIONS.ITEM_NOTE: - return { - type: '', - actions: [ - null, - { - actionsList: noteWithMarkDefaultActions, - controlType: (action) => { - return action === ACTIONS.CHANGE_TYPE - ? CONTROL_TYPES.NOTE_SELECT - : CONTROL_TYPES.TEXTAREA; - }, - [ACTION_VALUE_KEY]: noteWithMarkDefaultActions[0].value, - [FIELD_VALUE_KEY]: '', - }, - ], - }; - case OPTIONS.HOLDINGS_NOTE: + case OPTIONS.ITEM_NOTE: return { type: '', actions: [ From ee1dd81162ea496128ede2454916d5ea900532e5 Mon Sep 17 00:00:00 2001 From: Uladzislau_Kutarkin Date: Wed, 25 Oct 2023 11:08:24 +0400 Subject: [PATCH 07/10] UIBULKED-316: update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 95ac4a09..211b6d75 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ * [UIBULKED-355](https://issues.folio.org/browse/UIBULKED-355) Remove reference to Query tab on the landing page. * [UIBULKED-315](https://issues.folio.org/browse/UIBULKED-315) Group holdings record properties using optgroup component * [UIBULKED-316](https://issues.folio.org/browse/UIBULKED-316) Bulk edit actions for holdings notes - add and remove Mark as staff only. +* [UIBULKED-331](https://issues.folio.org/browse/UIBULKED-331) Bulk edit actions for holdings notes - add and remove notes. +* [UIBULKED-332](https://issues.folio.org/browse/UIBULKED-332) Bulk edit actions for holdings notes - find and replace or remove. +* [UIBULKED-333](https://issues.folio.org/browse/UIBULKED-333) Bulk edit actions for holdings notes - change note type. ## [4.0.0](https://github.com/folio-org/ui-bulk-edit/tree/v4.0.0) (2023-10-12) From ca5d4270b63890202a938353d8c6510abf4d8429 Mon Sep 17 00:00:00 2001 From: Uladzislau_Kutarkin Date: Fri, 27 Oct 2023 15:07:12 +0400 Subject: [PATCH 08/10] UIBULKED-316: update logic --- .../ContentUpdatesForm/ValuesColumn.js | 23 ++++++++++++++++++- .../ContentUpdatesForm/helpers.js | 2 +- src/constants/core.js | 1 + src/constants/selectOptions.js | 14 +++++++++++ 4 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/ValuesColumn.js b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/ValuesColumn.js index 140065c1..6e8ff139 100644 --- a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/ValuesColumn.js +++ b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/ValuesColumn.js @@ -15,7 +15,7 @@ import { BASE_DATE_FORMAT, CAPABILITIES, CONTROL_TYPES, - getDuplicateNoteOptions, + getDuplicateNoteOptions, getHoldingsNotes, getItemStatusOptions, getNotesOptions, } from '../../../../../constants'; @@ -23,6 +23,7 @@ import { FIELD_VALUE_KEY, TEMPORARY_LOCATIONS } from './helpers'; import { useLoanTypes, usePatronGroup } from '../../../../../hooks/api'; import { useItemNotes } from '../../../../../hooks/api/useItemNotes'; import { usePreselectedValue } from '../../../../../hooks/usePreselectedValue'; +import { useHoldingsNotes } from '../../../../../hooks/api/useHoldingsNotes'; export const ValuesColumn = ({ action, actionIndex, onChange, option }) => { const { formatMessage } = useIntl(); @@ -32,15 +33,22 @@ export const ValuesColumn = ({ action, actionIndex, onChange, option }) => { const isUserCapability = capability === CAPABILITIES.USER; const isItemCapability = capability === CAPABILITIES.ITEM; + const isHoldingsCapability = capability === CAPABILITIES.HOLDING; const { userGroups } = usePatronGroup({ enabled: isUserCapability }); const { loanTypes, isLoanTypesLoading } = useLoanTypes({ enabled: isItemCapability }); const { itemNotes, usItemNotesLoading } = useItemNotes({ enabled: isItemCapability }); + const { holdingsNotes, isHoldingsNotesLoading } = useHoldingsNotes({ enabled: isHoldingsCapability }); const duplicateNoteOptions = getDuplicateNoteOptions(formatMessage).filter(el => el.value !== option); const filteredAndMappedNotes = getNotesOptions(formatMessage, itemNotes) .filter(obj => obj.value !== option) .map(({ label, value }) => ({ label, value })); + + const filteredAndMappedHoldingsNotes = getHoldingsNotes(formatMessage, holdingsNotes) + .filter(obj => obj.value !== option) + .map(({ label, value, disabled }) => ({ label, value, disabled })); + const sortWithoutPlaceholder = (array) => { const [placeholder, ...rest] = array; @@ -48,6 +56,7 @@ export const ValuesColumn = ({ action, actionIndex, onChange, option }) => { }; const sortedNotes = sortWithoutPlaceholder(filteredAndMappedNotes); + const sortedHoldingsNotes = sortWithoutPlaceholder(filteredAndMappedHoldingsNotes); const statuses = getItemStatusOptions(formatMessage); const actionValue = action.value; @@ -181,6 +190,17 @@ export const ValuesColumn = ({ action, actionIndex, onChange, option }) => { /> ); + const renderNoteHoldingsTypeSelect = () => controlType === CONTROL_TYPES.HOLDINGS_NOTE && ( + onChange({ actionIndex, value: e.target.value, fieldName: FIELD_VALUE_KEY })} - dataOptions={sortedNotes} - aria-label={formatMessage({ id: 'ui-bulk-edit.ariaLabel.loanTypeSelect' })} - /> + isHoldingsCapability ? ( + onChange({ + actionIndex, + value: e.target.value, + fieldName: FIELD_VALUE_KEY + })} + dataOptions={sortedNotes} + aria-label={formatMessage({ id: 'ui-bulk-edit.ariaLabel.loanTypeSelect' })} + />) ); const renderNoteDuplicateTypeSelect = () => controlType === CONTROL_TYPES.NOTE_DUPLICATE_SELECT && ( From f67a0b984313906ee5398da04cd8ae0025f47437 Mon Sep 17 00:00:00 2001 From: Uladzislau_Kutarkin Date: Tue, 31 Oct 2023 14:08:11 +0400 Subject: [PATCH 10/10] UIBULKED-316: add additional action --- .../BulkEditInApp/ContentUpdatesForm/helpers.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.js b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.js index 51203210..691b55e2 100644 --- a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.js +++ b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/helpers.js @@ -360,6 +360,7 @@ export const getExtraActions = (option, action, formattedMessage) => { case `${OPTIONS.ADMINISTRATIVE_NOTE}-${ACTIONS.FIND}`: case `${OPTIONS.CHECK_IN_NOTE}-${ACTIONS.FIND}`: case `${OPTIONS.CHECK_OUT_NOTE}-${ACTIONS.FIND}`: + case `${OPTIONS.HOLDINGS_NOTE}-${ACTIONS.FIND}`: return [{ actionsList: noteAdditionalActions(formattedMessage), controlType: () => CONTROL_TYPES.TEXTAREA,