fix: remote line min lines.

This commit is contained in:
a.bouhuolia
2022-03-21 13:41:07 +02:00
parent a533c3cb76
commit 932afddf11
5 changed files with 17 additions and 13 deletions

View File

@@ -21,8 +21,8 @@ export default function MakeJournalEntriesTable({
entries,
defaultEntry,
error,
initialLinesNumber = 4,
minLinesNumber = 4,
initialLinesNumber = 1,
minLinesNumber = 1,
currencyCode,
}) {
const { accounts, contacts, branches } = useMakeJournalFormContext();

View File

@@ -13,7 +13,7 @@ import {
BranchesListFieldCell,
} from 'components/DataTableCells';
import { CellType, Features } from 'common';
import { CellType, Features, Align } from 'common';
import { useFeatureCan } from 'hooks/state';
import { useCurrentOrganization } from 'hooks/state';
@@ -92,7 +92,6 @@ export const useJournalTableEntriesColumns = () => {
id: 'account_id',
accessor: 'account_id',
Cell: AccountsListFieldCell,
className: 'account',
disableSortBy: true,
width: 160,
fieldProps: { allowCreate: true },
@@ -101,24 +100,23 @@ export const useJournalTableEntriesColumns = () => {
Header: CreditHeaderCell,
accessor: 'credit',
Cell: MoneyFieldCell,
className: 'credit',
disableSortBy: true,
width: 100,
align: Align.Right,
},
{
Header: DebitHeaderCell,
accessor: 'debit',
Cell: MoneyFieldCell,
className: 'debit',
disableSortBy: true,
width: 100,
align: Align.Right,
},
{
Header: ContactHeaderCell,
id: 'contact_id',
accessor: 'contact_id',
Cell: ContactsListFieldCell,
className: 'contact',
disableSortBy: true,
width: 120,
},
@@ -129,7 +127,6 @@ export const useJournalTableEntriesColumns = () => {
id: 'branch_id',
accessor: 'branch_id',
Cell: BranchesListFieldCell,
className: 'branch',
disableSortBy: true,
width: 120,
},
@@ -140,7 +137,6 @@ export const useJournalTableEntriesColumns = () => {
accessor: 'note',
Cell: InputGroupCell,
disableSortBy: true,
className: 'note',
width: 200,
},
{
@@ -150,6 +146,7 @@ export const useJournalTableEntriesColumns = () => {
disableSortBy: true,
disableResizing: true,
width: 45,
align: Align.Center,
},
],
[],

View File

@@ -31,6 +31,7 @@ function ItemsEntriesTable({
currencyCode,
itemType, // sellable or purchasable
landedCost = false,
minLinesNumber
}) {
const [rows, setRows] = React.useState(initialEntries);
@@ -76,7 +77,7 @@ function ItemsEntriesTable({
const handleRemoveRow = (rowIndex) => {
const newRows = compose(
// Ensure minimum lines count.
updateMinEntriesLines(4, defaultEntry),
updateMinEntriesLines(minLinesNumber, defaultEntry),
// Remove the line by the given index.
updateRemoveLineByIndex(rowIndex),
)(rows);
@@ -117,6 +118,7 @@ ItemsEntriesTable.defaultProps = {
},
initialEntries: [],
linesNumber: 1,
minLinesNumber: 1,
};
export default ItemsEntriesTable;

View File

@@ -23,6 +23,7 @@ export default function ExpenseFormEntriesTable({
onChange,
currencyCode,
landedCost = true,
minLines,
}) {
// Expense form context.
const { accounts } = useExpenseFormContext();
@@ -50,14 +51,14 @@ export default function ExpenseFormEntriesTable({
(rowIndex) => {
const newRows = compose(
// Ensure minimum lines count.
updateMinEntriesLines(4, defaultEntry),
updateMinEntriesLines(minLines, defaultEntry),
// Remove the line by the given index.
updateRemoveLineByIndex(rowIndex),
)(entries);
saveInvoke(onChange, newRows);
},
[entries, defaultEntry, onChange],
[minLines, entries, defaultEntry, onChange],
);
return (
@@ -76,4 +77,8 @@ export default function ExpenseFormEntriesTable({
}}
/>
);
}
ExpenseFormEntriesTable.defaultProps = {
minLines: 1,
}

View File

@@ -177,7 +177,7 @@ export const mutateTableRow = R.curry((rowIndex, newRow, rows) => {
export const deleteTableRow = R.curry((rowIndex, defaultEntry, rows) => {
return compose(
// Ensure minimum lines count.
updateMinEntriesLines(4, defaultEntry),
updateMinEntriesLines(MIN_LINES_NUMBER, defaultEntry),
// Remove the line by the given index.
updateRemoveLineByIndex(rowIndex),
)(rows);