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, entries,
defaultEntry, defaultEntry,
error, error,
initialLinesNumber = 4, initialLinesNumber = 1,
minLinesNumber = 4, minLinesNumber = 1,
currencyCode, currencyCode,
}) { }) {
const { accounts, contacts, branches } = useMakeJournalFormContext(); const { accounts, contacts, branches } = useMakeJournalFormContext();

View File

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

View File

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

View File

@@ -23,6 +23,7 @@ export default function ExpenseFormEntriesTable({
onChange, onChange,
currencyCode, currencyCode,
landedCost = true, landedCost = true,
minLines,
}) { }) {
// Expense form context. // Expense form context.
const { accounts } = useExpenseFormContext(); const { accounts } = useExpenseFormContext();
@@ -50,14 +51,14 @@ export default function ExpenseFormEntriesTable({
(rowIndex) => { (rowIndex) => {
const newRows = compose( const newRows = compose(
// Ensure minimum lines count. // Ensure minimum lines count.
updateMinEntriesLines(4, defaultEntry), updateMinEntriesLines(minLines, defaultEntry),
// Remove the line by the given index. // Remove the line by the given index.
updateRemoveLineByIndex(rowIndex), updateRemoveLineByIndex(rowIndex),
)(entries); )(entries);
saveInvoke(onChange, newRows); saveInvoke(onChange, newRows);
}, },
[entries, defaultEntry, onChange], [minLines, entries, defaultEntry, onChange],
); );
return ( return (
@@ -77,3 +78,7 @@ 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) => { export const deleteTableRow = R.curry((rowIndex, defaultEntry, rows) => {
return compose( return compose(
// Ensure minimum lines count. // Ensure minimum lines count.
updateMinEntriesLines(4, defaultEntry), updateMinEntriesLines(MIN_LINES_NUMBER, defaultEntry),
// Remove the line by the given index. // Remove the line by the given index.
updateRemoveLineByIndex(rowIndex), updateRemoveLineByIndex(rowIndex),
)(rows); )(rows);