Files
bigcapital/client/src/containers/Items/ItemsActionsBar.js
2021-02-08 13:17:11 +02:00

126 lines
3.1 KiB
JavaScript

import React from 'react';
import { useHistory } from 'react-router-dom';
import classNames from 'classnames';
import {
Popover,
NavbarGroup,
NavbarDivider,
PopoverInteractionKind,
Position,
Button,
Classes,
Intent,
} from '@blueprintjs/core';
import { FormattedMessage as T, useIntl } from 'react-intl';
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
import Icon from 'components/Icon';
import { If, DashboardActionViewsList } from 'components';
import { useItemsListContext } from './ItemsListProvider';
import withItems from 'containers/Items/withItems';
import withItemsActions from './withItemsActions';
import withAlertActions from 'containers/Alert/withAlertActions';
import { compose } from 'utils';
/**
* Items actions bar.
*/
function ItemsActionsBar({
// #withItems
itemsSelectedRows,
// #withItemActions
addItemsTableQueries,
// #withAlertActions
openAlert,
}) {
// Items list context.
const { itemsViews } = useItemsListContext();
const { formatMessage } = useIntl();
// History context.
const history = useHistory();
// Handle `new item` button click.
const onClickNewItem = () => {
history.push('/items/new');
};
// Handle tab changing.
const handleTabChange = (viewId) => {
addItemsTableQueries({
customViewId: viewId.id || null,
});
};
// Handle cancel/confirm items bulk.
const handleBulkDelete = () => {
openAlert('items-bulk-delete', { itemsIds: itemsSelectedRows });
};
return (
<DashboardActionsBar>
<NavbarGroup>
<DashboardActionViewsList
resourceName={'items'}
views={itemsViews}
onChange={handleTabChange}
/>
<NavbarDivider />
<Button
className={Classes.MINIMAL}
icon={<Icon icon="plus" />}
text={<T id={'new_item'} />}
onClick={onClickNewItem}
/>
<NavbarDivider />
<Popover
content={''}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
>
<Button
className={classNames(Classes.MINIMAL, 'button--filter')}
text={`${formatMessage({ id: 'filter' })}`}
icon={<Icon icon="filter-16" iconSize={16} />}
/>
</Popover>
<If condition={itemsSelectedRows.length}>
<Button
className={Classes.MINIMAL}
icon={<Icon icon="trash-16" iconSize={16} />}
text={<T id={'delete'} />}
intent={Intent.DANGER}
onClick={handleBulkDelete}
/>
</If>
<Button
className={Classes.MINIMAL}
icon={<Icon icon="file-import-16" iconSize={16} />}
text={<T id={'import'} />}
/>
<Button
className={Classes.MINIMAL}
icon={<Icon icon="file-export-16" iconSize={16} />}
text={<T id={'export'} />}
/>
</NavbarGroup>
</DashboardActionsBar>
);
};
export default compose(
withItems(({ itemsSelectedRows }) => ({ itemsSelectedRows })),
withItemsActions,
withAlertActions,
)(ItemsActionsBar);