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

UIOR-1142: POL - Display only active account numbers in dropdown list #1505

Merged
merged 4 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -21,6 +21,7 @@
* Show a message about the missing version in the history. Refs UIOR-1136.
* *BREAKING* bump `react-intl` to `v6.4.4`. Refs UIOR-1146.
* When order line contains bad product IDs - the save & close does not work. Refs UIOR-1141.
* POL - Display only active account numbers in dropdown list. Refs UIOR-1142.

## [4.0.2](https://github.com/folio-org/ui-orders/tree/v4.0.2) (2023-03-17)
[Full Changelog](https://github.com/folio-org/ui-orders/compare/v4.0.1...v4.0.2)
Expand Down
18 changes: 12 additions & 6 deletions src/components/POLine/Vendor/VendorForm.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useCallback } from 'react';
import React, { useCallback, useMemo } from 'react';
import PropTypes from 'prop-types';
import { useForm } from 'react-final-form';

Expand All @@ -15,6 +15,7 @@ import {
import { IfFieldVisible } from '../../../common/IfFieldVisible';
import { isWorkflowStatusIsPending } from '../../PurchaseOrder/util';
import { toggleAutomaticExport } from '../../Utils/toggleAutomaticExport';
import { ACCOUNT_STATUS } from '../const';

const VendorForm = ({
order,
Expand All @@ -24,10 +25,15 @@ const VendorForm = ({
}) => {
const { change, getState } = useForm();
const isPostPendingOrder = !isWorkflowStatusIsPending(order);
const accountsDataOptions = accounts.map(({ name, accountNo }) => ({
label: `${name} (${accountNo})`,
value: accountNo,
}));

const activeAccountOptions = useMemo(() => {
const activeAccounts = accounts.filter(({ accountStatus }) => accountStatus === ACCOUNT_STATUS.ACTIVE);

return activeAccounts.map(({ name, accountNo }) => ({
label: `${name} (${accountNo})`,
value: accountNo,
}));
}, [accounts]);

const onAccountChange = useCallback(
({ target: { value } }) => {
Expand All @@ -50,7 +56,7 @@ const VendorForm = ({
md={3}
>
<FieldVendorAccountNumber
accounts={accountsDataOptions}
accounts={activeAccountOptions}
disabled={isPostPendingOrder}
onChange={onAccountChange}
/>
Expand Down
29 changes: 29 additions & 0 deletions src/components/POLine/Vendor/VendorForm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ import { render, screen } from '@folio/jest-config-stripes/testing-library/react
import { arrayMutators } from 'fixtures/arrayMutatorsMock';
import VendorForm from './VendorForm';

jest.mock('../../../common/IfFieldVisible', () => ({
IfFieldVisible: jest.fn(({ children }) => children),
alisher-epam marked this conversation as resolved.
Show resolved Hide resolved
}));

const defaultProps = {
accounts: [{
name: 'name',
Expand Down Expand Up @@ -38,4 +42,29 @@ describe('VendorForm', () => {
expect(screen.getByText('ui-orders.vendor.accountNumber')).toBeInTheDocument();
expect(screen.getByText('ui-orders.vendor.instructions')).toBeInTheDocument();
});

it('should render active account numbers', () => {
const accounts = [
{
name: 'name',
accountNo: '1',
accountStatus: 'Active',
},
{
name: 'name2',
accountNo: '2',
accountStatus: 'Inactive',
},
{
name: 'name3',
accountNo: '3',
accountStatus: 'Active',
},
];

renderVendorForm({ accounts });

expect(screen.getByText(`${accounts[0].name} (${accounts[0].accountNo})`)).toBeInTheDocument();
expect(screen.getByText(`${accounts[0].name} (${accounts[0].accountNo})`)).toBeInTheDocument();
alisher-epam marked this conversation as resolved.
Show resolved Hide resolved
});
});
6 changes: 6 additions & 0 deletions src/components/POLine/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,9 @@ export const POL_TEMPLATE_FIELDS_MAP = {
export const INITIAL_SECTIONS = Object.values(ACCORDION_ID).reduce(
(accum, id) => ({ ...accum, [id]: true }), {},
);

export const ACCOUNT_STATUS = {
ACTIVE: 'Active',
INACTIVE: 'Inactive',
PENDING: 'Pending',
};