Skip to content

Commit

Permalink
UIORGS-392 Search organization on bank account number (#585)
Browse files Browse the repository at this point in the history
* UIORGS-392 Search organization on bank account number

* add tests

* fix lint issue

* comment
  • Loading branch information
usavkov-epam authored Nov 27, 2023
1 parent 9928d2e commit cf2c36c
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion src/Organizations/OrganizationsList/OrganizationsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ import {
useLocationSorting,
} from '@folio/stripes-acq-components';
import {
getSearchableIndexes,
OrganizationsListFilter,
searchableIndexes,
} from '@folio/plugin-find-organization';

import {
Expand Down Expand Up @@ -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]);
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -16,14 +15,16 @@ const CUSTOM_SORT_MAP = {
};

export const useBuildQuery = () => {
const stripes = useStripes();

return useCallback(makeQueryBuilder(

Check warning on line 20 in src/Organizations/OrganizationsList/hooks/useBuildQuery/useBuildQuery.js

View workflow job for this annotation

GitHub Actions / github-actions-ci

React Hook useCallback received a function whose dependencies are unknown. Pass an inline function instead
'cql.allRecords=1',
(query, qindex) => {
if (qindex) {
return `(${qindex}=${query}*)`;
}

return getKeywordQuery(query);
return getKeywordQuery(query, stripes);
},
'sortby name/sort.ascending',
filterMap,
Expand Down
Original file line number Diff line number Diff line change
@@ -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*"');
});
});
});
1 change: 1 addition & 0 deletions translations/ui-organizations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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}?",
Expand Down

0 comments on commit cf2c36c

Please sign in to comment.