From cd33bd1456c0f3772c5458dc8c30a945f8475f1b Mon Sep 17 00:00:00 2001 From: vashjs <86330150+vashjs@users.noreply.github.com> Date: Mon, 16 Oct 2023 13:55:27 +0100 Subject: [PATCH] Revert "UIBULKED-315 Group holdings record properties using optgroup component (#396)" This reverts commit 988d3fb5419c78fcbbc73f22d97c922da8dc0189. --- CHANGELOG.md | 1 - package.json | 3 +- .../BulkEditListFilters.js | 2 +- .../BulkEditInApp/BulkEditInApp.js | 7 ++-- .../BulkEditInApp/BulkEditInApp.test.js | 13 +++----- .../ContentUpdatesForm/ContentUpdatesForm.js | 2 +- src/constants/selectOptions.js | 18 ++--------- .../{RootContext.js => RootContext.ts} | 0 src/hooks/api/useHoldingsNotes.js | 32 ------------------- src/hooks/api/useItemNotes.js | 18 +++++++---- src/utils/{helpers.js => filters.js} | 21 ------------ translations/ui-bulk-edit/en.json | 1 - 12 files changed, 24 insertions(+), 94 deletions(-) rename src/context/{RootContext.js => RootContext.ts} (100%) delete mode 100644 src/hooks/api/useHoldingsNotes.js rename src/utils/{helpers.js => filters.js} (78%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 724edd41..8b167b67 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,6 @@ ## In progress * [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 ## [4.0.0](https://github.com/folio-org/ui-bulk-edit/tree/v4.0.0) (2023-10-12) diff --git a/package.json b/package.json index fe5e2430..19b442e1 100644 --- a/package.json +++ b/package.json @@ -101,8 +101,7 @@ "subPermissions": [ "ui-bulk-edit.app-view", "ui-bulk-edit.edit.base", - "inventory-storage.item-note-types.collection.get", - "inventory-storage.holdings-note-types.collection.get" + "inventory-storage.item-note-types.collection.get" ], "visible": true }, diff --git a/src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js b/src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js index 4173f194..99aa7f83 100644 --- a/src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js +++ b/src/components/BulkEditList/BulkEditListFilters/BulkEditListFilters.js @@ -30,7 +30,7 @@ import { } from '../../../hooks/api'; import { useBulkPermissions, useLocationFilters } from '../../../hooks'; import { LogsFilters } from './LogsFilters/LogsFilters'; -import { getCapabilityOptions, isCapabilityDisabled } from '../../../utils/helpers'; +import { getCapabilityOptions, isCapabilityDisabled } from '../../../utils/filters'; import FilterTabs from './FilterTabs/FilterTabs'; import Capabilities from './Capabilities/Capabilities'; import { getIsDisabledByPerm } from './utils/getIsDisabledByPerm'; diff --git a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/BulkEditInApp.js b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/BulkEditInApp.js index 24c95c5d..c0db3a87 100644 --- a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/BulkEditInApp.js +++ b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/BulkEditInApp.js @@ -13,7 +13,6 @@ import { BulkEditInAppTitle } from './BulkEditInAppTitle/BulkEditInAppTitle'; import { ContentUpdatesForm } from './ContentUpdatesForm/ContentUpdatesForm'; import { CAPABILITIES, getHoldingsOptions, getItemsOptions, getUserOptions } from '../../../../constants'; import { useItemNotes } from '../../../../hooks/api/useItemNotes'; -import { useHoldingsNotes } from '../../../../hooks/api/useHoldingsNotes'; export const BulkEditInApp = ({ onContentUpdatesChanged, @@ -25,19 +24,17 @@ export const BulkEditInApp = ({ const fileUploadedName = search.get('fileName'); const isItemCapability = capabilities === CAPABILITIES.ITEM; - const isHoldingsCapability = capabilities === CAPABILITIES.HOLDING; const { itemNotes, isItemNotesLoading } = useItemNotes({ enabled: isItemCapability }); - const { holdingNotes, isHoldingsNotesLoading } = useHoldingsNotes({ enabled: isHoldingsCapability }); const optionsMap = { [CAPABILITIES.ITEM]: getItemsOptions(intl.formatMessage, itemNotes), [CAPABILITIES.USER]: getUserOptions(intl.formatMessage), - [CAPABILITIES.HOLDING]: getHoldingsOptions(intl.formatMessage, holdingNotes), + [CAPABILITIES.HOLDING]: getHoldingsOptions(intl.formatMessage), }; const options = optionsMap[capabilities]; - const showContentUpdatesForm = options && !isItemNotesLoading && !isHoldingsNotesLoading; + const showContentUpdatesForm = options && !isItemNotesLoading; return ( <> diff --git a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/BulkEditInApp.test.js b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/BulkEditInApp.test.js index 69e7d675..bc909b37 100644 --- a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/BulkEditInApp.test.js +++ b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/BulkEditInApp.test.js @@ -1,6 +1,6 @@ import { MemoryRouter } from 'react-router-dom'; import { QueryClientProvider } from 'react-query'; -import { act, render, screen, waitFor } from '@testing-library/react'; +import { act, render, screen } from '@testing-library/react'; import userEvent from '@testing-library/user-event'; import { useOkapiKy } from '@folio/stripes/core'; @@ -256,16 +256,11 @@ describe('BulkEditInApp', () => { expect(optionPatronGroup.selected).toBeTruthy(); }); - it('should display holdings permanent location', async () => { + it('should display holdings permanent location', () => { renderBulkEditInApp({ capability: CAPABILITIES.HOLDING }); - let selectOption; - let optionStatus; - - await waitFor(() => { - selectOption = screen.getByTestId('select-option-0'); - optionStatus = screen.getByRole('option', { name: /layer.options.holdings.permanentLocation/ }); - }); + const selectOption = screen.getByTestId('select-option-0'); + const optionStatus = screen.getByRole('option', { name: /layer.options.holdings.permanentLocation/ }); act(() => userEvent.selectOptions(selectOption, optionStatus)); diff --git a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/ContentUpdatesForm.js b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/ContentUpdatesForm.js index 0274f644..da22756f 100644 --- a/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/ContentUpdatesForm.js +++ b/src/components/BulkEditList/BulkEditListResult/BulkEditInApp/ContentUpdatesForm/ContentUpdatesForm.js @@ -24,7 +24,7 @@ import { getFilteredFields, getExtraActions, } from './helpers'; -import { groupByCategory } from '../../../../../utils/helpers'; +import { groupByCategory } from '../../../../../utils/filters'; export const ContentUpdatesForm = ({ onContentUpdatesChanged, diff --git a/src/constants/selectOptions.js b/src/constants/selectOptions.js index 3b51840d..1b002b88 100644 --- a/src/constants/selectOptions.js +++ b/src/constants/selectOptions.js @@ -19,7 +19,6 @@ export const OPTIONS = { TEMPORARY_HOLDINGS_LOCATION: 'TEMPORARY_HOLDINGS_LOCATION', PERMANENT_HOLDINGS_LOCATION: 'PERMANENT_HOLDINGS_LOCATION', ITEM_NOTE: 'ITEM_NOTE', - HOLDINGS_NOTE: 'HOLDINGS_NOTE', ADMINISTRATIVE_NOTE: 'ADMINISTRATIVE_NOTE', CHECK_IN_NOTE: 'CHECK_IN_NOTE', CHECK_OUT_NOTE: 'CHECK_OUT_NOTE', @@ -27,7 +26,6 @@ export const OPTIONS = { export const PARAMETERS_KEYS = { ITEM_NOTE_TYPE_ID_KEY: 'ITEM_NOTE_TYPE_ID_KEY', - HOLDINGS_NOTE_TYPE_ID_KEY: 'HOLDINGS_NOTE_TYPE_ID_KEY', }; export const OPTIONS_WITH_ADDITIONAL_PARAMETERS = [ @@ -170,30 +168,20 @@ export const getUserOptions = (formatMessage) => [ }, ]; -export const getHoldingsOptions = (formatMessage, holdingsNotes = []) => [ +export const getHoldingsOptions = (formatMessage) => [ { value: '', label: formatMessage({ id: 'ui-bulk-edit.options.placeholder' }), disabled: true, }, - { - value: OPTIONS.ADMINISTRATIVE_NOTE, - label: formatMessage({ id: 'ui-bulk-edit.layer.options.administrativeNote' }), - disabled: false, - }, - { - value: OPTIONS.TEMPORARY_HOLDINGS_LOCATION, + { value: OPTIONS.TEMPORARY_HOLDINGS_LOCATION, label: formatMessage({ id: 'ui-bulk-edit.layer.options.holdings.temporaryLocation' }), - disabled: false, - categoryName: 'Holdings location' - }, + disabled: false }, { value: OPTIONS.PERMANENT_HOLDINGS_LOCATION, label: formatMessage({ id: 'ui-bulk-edit.layer.options.holdings.permanentLocation' }), disabled: false, - categoryName: 'Holdings location' }, - ...holdingsNotes, { value: OPTIONS.SUPPRESS_FROM_DISCOVERY, label: formatMessage({ id: 'ui-bulk-edit.layer.options.holdings.suppress' }), diff --git a/src/context/RootContext.js b/src/context/RootContext.ts similarity index 100% rename from src/context/RootContext.js rename to src/context/RootContext.ts diff --git a/src/hooks/api/useHoldingsNotes.js b/src/hooks/api/useHoldingsNotes.js deleted file mode 100644 index c7fab95b..00000000 --- a/src/hooks/api/useHoldingsNotes.js +++ /dev/null @@ -1,32 +0,0 @@ -import { useOkapiKy } from '@folio/stripes/core'; -import { useQuery } from 'react-query'; -import { useIntl } from 'react-intl'; -import { OPTIONS, PARAMETERS_KEYS } from '../../constants'; -import { getMappedAndSortedNotes } from '../../utils/helpers'; - -export const useHoldingsNotes = (options = {}) => { - const ky = useOkapiKy(); - const { formatMessage } = useIntl(); - - const { data, isLoading: isHoldingsNotesLoading } = useQuery( - { - queryKey: 'holdingNotes', - cacheTime: Infinity, - staleTime: Infinity, - queryFn: () => ky.get('holdings-note-types').json(), - ...options, - }, - ); - - const holdingNotes = getMappedAndSortedNotes({ - notes: data?.holdingsNoteTypes, - categoryName: formatMessage({ id: 'ui-bulk-edit.category.holdingNotes' }), - type: OPTIONS.HOLDINGS_NOTE, - key: PARAMETERS_KEYS.HOLDINGS_NOTE_TYPE_ID_KEY, - }); - - return { - holdingNotes, - isHoldingsNotesLoading, - }; -}; diff --git a/src/hooks/api/useItemNotes.js b/src/hooks/api/useItemNotes.js index b540aa42..bd29a151 100644 --- a/src/hooks/api/useItemNotes.js +++ b/src/hooks/api/useItemNotes.js @@ -2,7 +2,6 @@ import { useOkapiKy } from '@folio/stripes/core'; import { useQuery } from 'react-query'; import { useIntl } from 'react-intl'; import { OPTIONS, PARAMETERS_KEYS } from '../../constants'; -import { getMappedAndSortedNotes } from '../../utils/helpers'; export const useItemNotes = (options = {}) => { const ky = useOkapiKy(); @@ -18,12 +17,19 @@ export const useItemNotes = (options = {}) => { }, ); - const itemNotes = getMappedAndSortedNotes({ - notes: data?.itemNoteTypes, - categoryName: formatMessage({ id: 'ui-bulk-edit.category.itemNotes' }), + const mappedNotes = data?.itemNoteTypes?.map(type => ({ + label: type.name, + value: type.id, type: OPTIONS.ITEM_NOTE, - key: PARAMETERS_KEYS.ITEM_NOTE_TYPE_ID_KEY, - }); + parameters: [{ + key: PARAMETERS_KEYS.ITEM_NOTE_TYPE_ID_KEY, + value: type.id, + }], + disabled: false, + categoryName: formatMessage({ id: 'ui-bulk-edit.category.itemNotes' }), + })) || []; + + const itemNotes = mappedNotes.sort((a, b) => a.label.localeCompare(b.label)); return { itemNotes, diff --git a/src/utils/helpers.js b/src/utils/filters.js similarity index 78% rename from src/utils/helpers.js rename to src/utils/filters.js index 5b8c1d15..8f9be1ef 100644 --- a/src/utils/helpers.js +++ b/src/utils/filters.js @@ -50,25 +50,4 @@ export const groupByCategory = (array) => { }, {}); }; -export const getMappedAndSortedNotes = ({ - notes, - categoryName, - key, - type -}) => { - const mappedNotes = notes?.map(note => ({ - label: note.name, - value: note.id, - type, - parameters: [{ - key, - value: note.id, - }], - disabled: false, - categoryName, - })) || []; - - return mappedNotes.sort((a, b) => a.label.localeCompare(b.label)); -}; - diff --git a/translations/ui-bulk-edit/en.json b/translations/ui-bulk-edit/en.json index 4134a665..9e92deac 100644 --- a/translations/ui-bulk-edit/en.json +++ b/translations/ui-bulk-edit/en.json @@ -116,7 +116,6 @@ "category.loanType": "Loan type", "category.location": "Location", "category.itemNotes": "Item notes", - "category.holdingNotes": "Holdings notes", "columns.USER.User name": "Username", "columns.USER.User id": "User id",