Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIORGS-392 Search organization on bank account number #585

Merged
merged 4 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
};

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

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
Loading