mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
fix(DataTable): cells type.
This commit is contained in:
7
src/common/cellTypes.js
Normal file
7
src/common/cellTypes.js
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
|
||||
export const CellType = {
|
||||
Text: 'text',
|
||||
Field: 'field',
|
||||
Button: 'button'
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
export * from './TableStyle';
|
||||
export * from './features';
|
||||
export * from './cellTypes';
|
||||
|
||||
export const Align = { Left: 'left', Right: 'right', Center: 'center' };
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import React, { useRef, useCallback, useMemo } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { useCellAutoFocus } from 'hooks';
|
||||
import { FormGroup, Classes, Intent } from '@blueprintjs/core';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import { CellType } from 'common';
|
||||
import { useCellAutoFocus } from 'hooks';
|
||||
import AccountsSuggestField from 'components/AccountsSuggestField';
|
||||
|
||||
// import AccountsSelectList from 'components/AccountsSelectList';
|
||||
import { FormGroup, Classes, Intent } from '@blueprintjs/core';
|
||||
|
||||
/**
|
||||
* Account cell renderer.
|
||||
*/
|
||||
@@ -74,3 +73,4 @@ export default function AccountCellRenderer({
|
||||
</FormGroup>
|
||||
);
|
||||
}
|
||||
AccountCellRenderer.cellType = CellType.Field;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import React from 'react';
|
||||
import { FormGroup, Intent, Classes } from '@blueprintjs/core';
|
||||
import classNames from 'classnames';
|
||||
|
||||
import { CellType } from 'common';
|
||||
import BranchSuggestField from '../BranchSuggestField';
|
||||
|
||||
/**
|
||||
@@ -38,3 +40,5 @@ export default function BranchesListFieldCell({
|
||||
</FormGroup>
|
||||
);
|
||||
}
|
||||
|
||||
BranchesListFieldCell.cellType = CellType.Field;
|
||||
@@ -2,6 +2,7 @@ import React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { get } from 'lodash';
|
||||
import { Classes, Checkbox, FormGroup, Intent } from '@blueprintjs/core';
|
||||
import { CellType } from 'common';
|
||||
|
||||
const CheckboxEditableCell = ({
|
||||
row: { index, original },
|
||||
@@ -45,4 +46,6 @@ const CheckboxEditableCell = ({
|
||||
);
|
||||
};
|
||||
|
||||
CheckboxEditableCell.cellType = CellType.Field;
|
||||
|
||||
export default CheckboxEditableCell;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import React, { useCallback } from 'react';
|
||||
import { FormGroup, Intent, Classes } from '@blueprintjs/core';
|
||||
import classNames from 'classnames';
|
||||
import { ContactSelecetList } from 'components';
|
||||
import ContactsSuggestField from 'components/ContactsSuggestField';
|
||||
|
||||
import { CellType } from 'common';
|
||||
import ContactsSuggestField from 'components/ContactsSuggestField';
|
||||
export default function ContactsListCellRenderer({
|
||||
column: { id },
|
||||
row: { index, original },
|
||||
@@ -37,3 +37,5 @@ export default function ContactsListCellRenderer({
|
||||
</FormGroup>
|
||||
);
|
||||
}
|
||||
|
||||
ContactsListCellRenderer.cellType = CellType.Field;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { Classes, InputGroup, FormGroup, Intent } from '@blueprintjs/core';
|
||||
import { CellType } from 'common';
|
||||
|
||||
const InputEditableCell = ({
|
||||
row: { index },
|
||||
@@ -37,4 +38,6 @@ const InputEditableCell = ({
|
||||
);
|
||||
};
|
||||
|
||||
InputEditableCell.cellType = CellType.Field;
|
||||
|
||||
export default InputEditableCell;
|
||||
|
||||
@@ -3,6 +3,7 @@ import classNames from 'classnames';
|
||||
import { FormGroup, Classes, Intent } from '@blueprintjs/core';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import { CellType } from 'common';
|
||||
import ItemsSuggestField from 'components/ItemsSuggestField';
|
||||
|
||||
import { useCellAutoFocus } from 'hooks';
|
||||
@@ -54,3 +55,5 @@ export default function ItemsListCell({
|
||||
</FormGroup>
|
||||
);
|
||||
}
|
||||
|
||||
ItemsListCell.cellType = CellType.Field;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import React, { useCallback, useState, useEffect } from 'react';
|
||||
import { FormGroup, Intent } from '@blueprintjs/core';
|
||||
|
||||
import { MoneyInputGroup } from 'components';
|
||||
import { CLASSES } from 'common/classes';
|
||||
import { CellType } from 'common';
|
||||
|
||||
// Input form cell renderer.
|
||||
const MoneyFieldCellRenderer = ({
|
||||
@@ -48,4 +50,6 @@ const MoneyFieldCellRenderer = ({
|
||||
);
|
||||
};
|
||||
|
||||
MoneyFieldCellRenderer.cellType = CellType.Field;
|
||||
|
||||
export default MoneyFieldCellRenderer;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { FormGroup, NumericInput, Intent } from '@blueprintjs/core';
|
||||
import classNames from 'classnames';
|
||||
|
||||
import { CellType } from 'common';
|
||||
import { CLASSES } from 'common/classes';
|
||||
|
||||
/**
|
||||
@@ -36,8 +38,10 @@ export default function NumericInputCell({
|
||||
onValueChange={handleValueChange}
|
||||
onBlur={onBlur}
|
||||
fill={true}
|
||||
buttonPosition={"none"}
|
||||
buttonPosition={'none'}
|
||||
/>
|
||||
</FormGroup>
|
||||
);
|
||||
}
|
||||
|
||||
NumericInputCell.cellType = CellType.Field;
|
||||
@@ -1,8 +1,9 @@
|
||||
import React, { useCallback } from 'react';
|
||||
import PaymentReceiveListField from 'components/PaymentReceiveListField';
|
||||
import classNames from 'classnames';
|
||||
import { FormGroup, Classes, Intent } from '@blueprintjs/core';
|
||||
|
||||
import PaymentReceiveListField from 'components/PaymentReceiveListField';
|
||||
import { CellType } from 'common';
|
||||
function PaymentReceiveListFieldCell({
|
||||
column: { id },
|
||||
row: { index },
|
||||
@@ -32,4 +33,6 @@ function PaymentReceiveListFieldCell({
|
||||
);
|
||||
}
|
||||
|
||||
PaymentReceiveListFieldCell.cellType = CellType.Field;
|
||||
|
||||
export default PaymentReceiveListFieldCell;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import React, { useCallback, useState, useEffect } from 'react';
|
||||
import { FormGroup, Intent } from '@blueprintjs/core';
|
||||
|
||||
import { MoneyInputGroup } from 'components';
|
||||
import { CellType } from 'common';
|
||||
|
||||
const PercentFieldCell = ({
|
||||
cell: { value: initialValue },
|
||||
@@ -38,4 +40,6 @@ const PercentFieldCell = ({
|
||||
);
|
||||
};
|
||||
|
||||
PercentFieldCell.cellType = CellType.Field;
|
||||
|
||||
export default PercentFieldCell;
|
||||
|
||||
@@ -2,6 +2,7 @@ import React from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { Classes, Switch, FormGroup, Intent } from '@blueprintjs/core';
|
||||
|
||||
import { CellType } from 'common';
|
||||
import { safeInvoke } from 'utils';
|
||||
|
||||
/**
|
||||
@@ -48,4 +49,6 @@ const SwitchEditableCell = ({
|
||||
);
|
||||
};
|
||||
|
||||
export default SwitchEditableCell;
|
||||
SwitchEditableCell.cellType = CellType.Field;
|
||||
|
||||
export default SwitchEditableCell;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { Classes, TextArea, FormGroup, Intent } from '@blueprintjs/core';
|
||||
import { CellType } from 'common';
|
||||
|
||||
const TextAreaEditableCell = ({
|
||||
row: { index },
|
||||
@@ -39,4 +40,6 @@ const TextAreaEditableCell = ({
|
||||
);
|
||||
};
|
||||
|
||||
TextAreaEditableCell.cellType = CellType.Field;
|
||||
|
||||
export default TextAreaEditableCell;
|
||||
|
||||
@@ -54,10 +54,15 @@ const DatatableEditableRoot = styled.div`
|
||||
}
|
||||
.tbody {
|
||||
.tr .td {
|
||||
padding: 2px;
|
||||
border-bottom: 0;
|
||||
border-bottom: 1px solid #d8d8d8;
|
||||
min-height: 38px;
|
||||
padding: 4px 14px;
|
||||
|
||||
&.td-field-type,
|
||||
&.td-button-type{
|
||||
padding: 2px;
|
||||
}
|
||||
}
|
||||
.tr:last-of-type .td {
|
||||
border-bottom: 0;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import React, { useContext } from 'react';
|
||||
import classNames from 'classnames';
|
||||
import { If } from 'components';
|
||||
import { Skeleton } from 'components';
|
||||
import { camelCase} from 'lodash';
|
||||
|
||||
import { If, Skeleton } from 'components';
|
||||
import { useAppIntlContext } from 'components/AppIntlProvider';
|
||||
import TableContext from './TableContext';
|
||||
import { saveInvoke, ignoreEventFromSelectors } from 'utils';
|
||||
@@ -56,7 +57,8 @@ export default function TableCell({ cell, row, index }) {
|
||||
return;
|
||||
}
|
||||
saveInvoke(onCellClick, cell, event);
|
||||
};
|
||||
};
|
||||
const cellType = camelCase(cell.column.Cell.cellType) || 'text';
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -65,6 +67,8 @@ export default function TableCell({ cell, row, index }) {
|
||||
'is-text-overview': cell.column.textOverview,
|
||||
clickable: cell.column.clickable,
|
||||
'align-right': cell.column.align === 'right',
|
||||
[`td-${cell.column.id}`]: cell.column.id,
|
||||
[`td-${cellType}-type`]: !!cellType,
|
||||
}),
|
||||
onClick: handleCellClick,
|
||||
})}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import { Checkbox } from '@blueprintjs/core';
|
||||
|
||||
import { CellType } from 'common';
|
||||
export default function TableIndeterminateCheckboxRow({ row }) {
|
||||
return (
|
||||
<div class="selection-checkbox">
|
||||
@@ -8,3 +8,5 @@ export default function TableIndeterminateCheckboxRow({ row }) {
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
TableIndeterminateCheckboxRow.cellType = CellType.Field;
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import React from 'react';
|
||||
import { Intent, Position, Button, Tooltip } from '@blueprintjs/core';
|
||||
import { Menu, MenuItem, Position, Button } from '@blueprintjs/core';
|
||||
import { Popover2 } from '@blueprintjs/popover2';
|
||||
import { useFormikContext } from 'formik';
|
||||
import intl from 'react-intl-universal';
|
||||
import { Icon, Hint, FormattedMessage as T } from 'components';
|
||||
|
||||
import { ExchangeRateInputGroup, Icon, Hint, FormattedMessage as T } from 'components';
|
||||
import {
|
||||
AccountsListFieldCell,
|
||||
MoneyFieldCell,
|
||||
@@ -9,12 +12,12 @@ import {
|
||||
ContactsListFieldCell,
|
||||
BranchesListFieldCell,
|
||||
} from 'components/DataTableCells';
|
||||
|
||||
import { CellType, Features } from 'common';
|
||||
|
||||
import { useFeatureCan } from 'hooks/state';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { ExchangeRateInputGroup } from 'components';
|
||||
import { useCurrentOrganization } from 'hooks/state';
|
||||
import { useJournalIsForeign } from './utils';
|
||||
import { Features } from 'common';
|
||||
|
||||
/**
|
||||
* Contact header cell.
|
||||
@@ -55,22 +58,26 @@ export const ActionsCellRenderer = ({
|
||||
data,
|
||||
payload,
|
||||
}) => {
|
||||
const onClickRemoveRole = () => {
|
||||
const handleClickRemoveRole = () => {
|
||||
payload.removeRow(index);
|
||||
};
|
||||
const exampleMenu = (
|
||||
<Menu>
|
||||
<MenuItem onClick={handleClickRemoveRole} text="Remove line" />
|
||||
</Menu>
|
||||
);
|
||||
return (
|
||||
<Tooltip content={<T id={'remove_the_line'} />} position={Position.LEFT}>
|
||||
<Popover2 content={exampleMenu} placement="left-start">
|
||||
<Button
|
||||
icon={<Icon icon="times-circle" iconSize={14} />}
|
||||
icon={<Icon icon={'more-13'} iconSize={13} />}
|
||||
iconSize={14}
|
||||
className="ml2"
|
||||
className="m12"
|
||||
minimal={true}
|
||||
intent={Intent.DANGER}
|
||||
onClick={onClickRemoveRole}
|
||||
/>
|
||||
</Tooltip>
|
||||
</Popover2>
|
||||
);
|
||||
};
|
||||
ActionsCellRenderer.cellType = CellType.Button;
|
||||
|
||||
/**
|
||||
* Retrieve columns of make journal entries table.
|
||||
@@ -140,7 +147,6 @@ export const useJournalTableEntriesColumns = () => {
|
||||
Header: '',
|
||||
accessor: 'action',
|
||||
Cell: ActionsCellRenderer,
|
||||
className: 'actions',
|
||||
disableSortBy: true,
|
||||
disableResizing: true,
|
||||
width: 45,
|
||||
@@ -154,7 +160,7 @@ export const useJournalTableEntriesColumns = () => {
|
||||
* Journal exchange rate input field.
|
||||
* @returns {JSX.Element}
|
||||
*/
|
||||
export function JournalExchangeRateInputField({ ...props }) {
|
||||
export function JournalExchangeRateInputField({ ...props }) {
|
||||
const currentOrganization = useCurrentOrganization();
|
||||
const { values } = useFormikContext();
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import intl from 'react-intl-universal';
|
||||
import { MenuItem, Menu, Button, Position } from '@blueprintjs/core';
|
||||
import { Popover2 } from '@blueprintjs/popover2';
|
||||
|
||||
import { Align } from 'common';
|
||||
import { Align, CellType } from 'common';
|
||||
import { Hint, Icon, FormattedMessage as T } from 'components';
|
||||
import { formattedAmount } from 'utils';
|
||||
import {
|
||||
@@ -58,6 +58,7 @@ export function ActionsCellRenderer({
|
||||
</Popover2>
|
||||
);
|
||||
}
|
||||
ActionsCellRenderer.cellType = CellType.Button;
|
||||
|
||||
/**
|
||||
* Total accessor.
|
||||
|
||||
@@ -1,16 +1,23 @@
|
||||
import React from 'react';
|
||||
import { Button, Tooltip, Intent, Position, Checkbox } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T } from 'components';
|
||||
import { Icon, Hint } from 'components';
|
||||
import { Button, Menu, MenuItem } from '@blueprintjs/core';
|
||||
import { Popover2 } from '@blueprintjs/popover2';
|
||||
import intl from 'react-intl-universal';
|
||||
import { useFormikContext } from 'formik';
|
||||
|
||||
import {
|
||||
Icon,
|
||||
Hint,
|
||||
ExchangeRateInputGroup,
|
||||
FormattedMessage as T,
|
||||
} from 'components';
|
||||
import {
|
||||
InputGroupCell,
|
||||
MoneyFieldCell,
|
||||
AccountsListFieldCell,
|
||||
CheckBoxFieldCell,
|
||||
} from 'components/DataTableCells';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { ExchangeRateInputGroup } from 'components';
|
||||
import { CellType } from 'common';
|
||||
|
||||
import { useCurrentOrganization } from 'hooks/state';
|
||||
import { useExpensesIsForeign } from './utils';
|
||||
|
||||
@@ -36,22 +43,26 @@ const ActionsCellRenderer = ({
|
||||
data,
|
||||
payload,
|
||||
}) => {
|
||||
const onClickRemoveRole = () => {
|
||||
const handleClickRemoveRole = () => {
|
||||
payload.removeRow(index);
|
||||
};
|
||||
const exampleMenu = (
|
||||
<Menu>
|
||||
<MenuItem onClick={handleClickRemoveRole} text="Remove line" />
|
||||
</Menu>
|
||||
);
|
||||
return (
|
||||
<Tooltip content={<T id={'remove_the_line'} />} position={Position.LEFT}>
|
||||
<Popover2 content={exampleMenu} placement="left-start">
|
||||
<Button
|
||||
icon={<Icon icon="times-circle" iconSize={14} />}
|
||||
icon={<Icon icon={'more-13'} iconSize={13} />}
|
||||
iconSize={14}
|
||||
className="ml2"
|
||||
className="m12"
|
||||
minimal={true}
|
||||
intent={Intent.DANGER}
|
||||
onClick={onClickRemoveRole}
|
||||
/>
|
||||
</Tooltip>
|
||||
</Popover2>
|
||||
);
|
||||
};
|
||||
ActionsCellRenderer.cellType = CellType.Button;
|
||||
|
||||
/**
|
||||
* Landed cost header cell.
|
||||
@@ -122,7 +133,6 @@ export function useExpenseFormTableColumns({ landedCost }) {
|
||||
Header: '',
|
||||
accessor: 'action',
|
||||
Cell: ActionsCellRenderer,
|
||||
className: 'actions',
|
||||
disableSortBy: true,
|
||||
disableResizing: true,
|
||||
width: 45,
|
||||
@@ -131,8 +141,6 @@ export function useExpenseFormTableColumns({ landedCost }) {
|
||||
[],
|
||||
);
|
||||
}
|
||||
;
|
||||
|
||||
/**
|
||||
* Expense exchange rate input field.
|
||||
* @returns {JSX.Element}
|
||||
|
||||
@@ -29,40 +29,39 @@ export function usePaymentMadeEntriesTableColumns() {
|
||||
return React.useMemo(
|
||||
() => [
|
||||
{
|
||||
Header: intl.get('Date'),
|
||||
Header: 'Bill date',
|
||||
id: 'bill_date',
|
||||
accessor: 'bill_date',
|
||||
Cell: BillDateCell,
|
||||
disableSortBy: true,
|
||||
width: 250,
|
||||
className: 'bill_date',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
Header: intl.get('bill_number'),
|
||||
accessor: BillNumberAccessor,
|
||||
disableSortBy: true,
|
||||
className: 'bill_number',
|
||||
width: 120,
|
||||
},
|
||||
{
|
||||
Header: intl.get('bill_amount'),
|
||||
accessor: 'amount',
|
||||
Cell: MoneyTableCell,
|
||||
disableSortBy: true,
|
||||
className: 'amount',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
Header: intl.get('amount_due'),
|
||||
accessor: 'due_amount',
|
||||
Cell: MoneyTableCell,
|
||||
disableSortBy: true,
|
||||
className: 'due_amount',
|
||||
width: 150,
|
||||
},
|
||||
{
|
||||
Header: intl.get('payment_amount'),
|
||||
accessor: 'payment_amount',
|
||||
Cell: MoneyFieldCell,
|
||||
disableSortBy: true,
|
||||
className: 'payment_amount',
|
||||
width: 150,
|
||||
},
|
||||
],
|
||||
[],
|
||||
|
||||
Reference in New Issue
Block a user