diff --git a/CHANGELOG.md b/CHANGELOG.md index 9859bea2..6119fd95 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * Implement organization's banking information details view. Refs UIORGS-389. * Modify summary display in organization view mode. Refs UIORGS-398. * Protection of viewing and changes of banking information by permissions. Refs UIORGS-388. +* Search organization on bank account number. Refs UIORGS-392. ## [5.0.0](https://github.com/folio-org/ui-organizations/tree/v5.0.0) (2023-10-12) [Full Changelog](https://github.com/folio-org/ui-organizations/compare/v4.0.0...v5.0.0) diff --git a/src/Organizations/OrganizationsList/OrganizationsList.js b/src/Organizations/OrganizationsList/OrganizationsList.js index c71377cb..da5a063b 100644 --- a/src/Organizations/OrganizationsList/OrganizationsList.js +++ b/src/Organizations/OrganizationsList/OrganizationsList.js @@ -32,8 +32,8 @@ import { useLocationSorting, } from '@folio/stripes-acq-components'; import { + getSearchableIndexes, OrganizationsListFilter, - searchableIndexes, } from '@folio/plugin-find-organization'; import { @@ -105,6 +105,10 @@ const OrganizationsList = ({ const { isFiltersOpened, toggleFilters } = useFiltersToogle('ui-organizations/filters'); + const searchableIndexes = useMemo(() => ( + getSearchableIndexes(stripes) + ), [stripes]); + const urlParams = useMemo(() => ( matchPath(location.pathname, { path: `${VIEW_ORG_DETAILS}:id` }) ), [location.pathname]); diff --git a/src/Organizations/OrganizationsList/hooks/useBuildQuery/useBuildQuery.js b/src/Organizations/OrganizationsList/hooks/useBuildQuery/useBuildQuery.js index 1948d180..cfaf483f 100644 --- a/src/Organizations/OrganizationsList/hooks/useBuildQuery/useBuildQuery.js +++ b/src/Organizations/OrganizationsList/hooks/useBuildQuery/useBuildQuery.js @@ -1,8 +1,7 @@ import { useCallback } from 'react'; -import { - makeQueryBuilder, -} from '@folio/stripes-acq-components'; +import { useStripes } from '@folio/stripes/core'; +import { makeQueryBuilder } from '@folio/stripes-acq-components'; import { filterMap, getKeywordQuery, @@ -16,6 +15,8 @@ const CUSTOM_SORT_MAP = { }; export const useBuildQuery = () => { + const stripes = useStripes(); + return useCallback(makeQueryBuilder( 'cql.allRecords=1', (query, qindex) => { @@ -23,7 +24,7 @@ export const useBuildQuery = () => { return `(${qindex}=${query}*)`; } - return getKeywordQuery(query); + return getKeywordQuery(query, stripes); }, 'sortby name/sort.ascending', filterMap, diff --git a/src/Organizations/OrganizationsList/hooks/useBuildQuery/useBuildQuery.test.js b/src/Organizations/OrganizationsList/hooks/useBuildQuery/useBuildQuery.test.js index 7f0ed07a..ac745998 100644 --- a/src/Organizations/OrganizationsList/hooks/useBuildQuery/useBuildQuery.test.js +++ b/src/Organizations/OrganizationsList/hooks/useBuildQuery/useBuildQuery.test.js @@ -1,12 +1,56 @@ -import queryString from 'query-string'; import { renderHook } from '@folio/jest-config-stripes/testing-library/react'; +import { useStripes } from '@folio/stripes/core'; +import { + SEARCH_INDEX_PARAMETER, + SEARCH_PARAMETER, +} from '@folio/stripes-acq-components'; import { useBuildQuery } from './useBuildQuery'; +jest.mock('@folio/stripes/core', () => ({ + ...jest.requireActual('@folio/stripes/core'), + useStripes: jest.fn(), +})); + +const stripesStub = { + hasPerm: jest.fn(() => true), +}; + describe('useBuildQuery', () => { + beforeEach(() => { + stripesStub.hasPerm.mockClear(); + + useStripes + .mockClear() + .mockReturnValue(stripesStub); + }); + it('should return function, that return query', () => { const { result } = renderHook(() => useBuildQuery()); - expect(result.current(queryString.parse('?foo=bar'))).toBe('(foo=="bar") sortby name/sort.ascending'); + expect(result.current({ + [SEARCH_PARAMETER]: 'bar', + [SEARCH_INDEX_PARAMETER]: 'foo', + })).toBe('(((foo=bar*))) sortby name/sort.ascending'); + }); + + describe('Banking information', () => { + const params = { + [SEARCH_PARAMETER]: 'qwerty', + }; + + it('should include banking information index in the query if a user has the appropriate permission', () => { + const { result } = renderHook(() => useBuildQuery()); + + expect(result.current(params)).toContain('bankingInformation.bankAccountNumber="qwerty*"'); + }); + + it('should NOT include banking information index in the query if a user does not have the appropriate permission', async () => { + stripesStub.hasPerm.mockReturnValue(false); + + const { result } = renderHook(() => useBuildQuery()); + + expect(result.current(params)).not.toContain('bankingInformation.bankAccountNumber="qwerty*"'); + }); }); }); diff --git a/translations/ui-organizations/en.json b/translations/ui-organizations/en.json index 9434d9ae..55ea98f8 100644 --- a/translations/ui-organizations/en.json +++ b/translations/ui-organizations/en.json @@ -61,6 +61,7 @@ "search.erpCode": "Accounting code", "search.taxId": "Tax ID", "search.interfaces": "Interfaces", + "search.bankingInformation.bankAccountNumber": "Bank account number", "search.placeholder.language": "Search with language code", "organization.delete.heading": "Delete {organizationName}?",