mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
Merge remote-tracking branch 'origin/Fix/View'
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import React, { useMemo } from 'react';
|
import React, { useMemo, useState } from 'react';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
@@ -15,15 +15,21 @@ import { Icon } from 'components';
|
|||||||
|
|
||||||
export default function DashboardActionViewsList({
|
export default function DashboardActionViewsList({
|
||||||
resourceName,
|
resourceName,
|
||||||
views
|
views,
|
||||||
|
onChange,
|
||||||
}) {
|
}) {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
const handleClickViewItem = (view) => {
|
const handleClickViewItem = (view) => {
|
||||||
history.push(view ? `/${resourceName}/${view.id}/custom_view` : '/accounts');
|
history.push(
|
||||||
|
view ? `/${resourceName}/${view.id}/custom_view` : '/accounts',
|
||||||
|
);
|
||||||
|
onChange && onChange(view);
|
||||||
};
|
};
|
||||||
const viewsMenuItems = views.map((view) => {
|
const viewsMenuItems = views.map((view) => {
|
||||||
return <MenuItem onClick={() => handleClickViewItem(view)} text={view.name} />;
|
return (
|
||||||
|
<MenuItem onClick={() => handleClickViewItem(view)} text={view.name} />
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ import FilterDropdown from 'components/FilterDropdown';
|
|||||||
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
||||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
|
|
||||||
import { If } from 'components';
|
import { If, DashboardActionViewsList } from 'components';
|
||||||
|
|
||||||
import withResourceDetail from 'containers/Resources/withResourceDetails';
|
import withResourceDetail from 'containers/Resources/withResourceDetails';
|
||||||
import withManualJournals from 'containers/Accounting/withManualJournals';
|
import withManualJournals from 'containers/Accounting/withManualJournals';
|
||||||
@@ -29,9 +29,11 @@ import withManualJournalsActions from 'containers/Accounting/withManualJournalsA
|
|||||||
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manual journal actions bar.
|
||||||
|
*/
|
||||||
function ManualJournalActionsBar({
|
function ManualJournalActionsBar({
|
||||||
// #withResourceDetail
|
// #withResourceDetail
|
||||||
resourceName = 'manual_journals',
|
|
||||||
resourceFields,
|
resourceFields,
|
||||||
|
|
||||||
// #withManualJournals
|
// #withManualJournals
|
||||||
@@ -39,21 +41,15 @@ function ManualJournalActionsBar({
|
|||||||
|
|
||||||
// #withManualJournalsActions
|
// #withManualJournalsActions
|
||||||
addManualJournalsTableQueries,
|
addManualJournalsTableQueries,
|
||||||
|
changeManualJournalCurrentView,
|
||||||
|
|
||||||
onFilterChanged,
|
onFilterChanged,
|
||||||
selectedRows = [],
|
selectedRows = [],
|
||||||
onBulkDelete,
|
onBulkDelete,
|
||||||
}) {
|
}) {
|
||||||
const { path } = useRouteMatch();
|
|
||||||
const [filterCount, setFilterCount] = useState(0);
|
const [filterCount, setFilterCount] = useState(0);
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
const viewsMenuItems = manualJournalsViews.map((view) => {
|
|
||||||
return (
|
|
||||||
<MenuItem href={`${path}/${view.id}/custom_view`} text={view.name} />
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
const onClickNewManualJournal = useCallback(() => {
|
const onClickNewManualJournal = useCallback(() => {
|
||||||
history.push('/make-journal-entry');
|
history.push('/make-journal-entry');
|
||||||
}, [history]);
|
}, [history]);
|
||||||
@@ -73,32 +69,30 @@ function ManualJournalActionsBar({
|
|||||||
onFilterChanged && onFilterChanged(filterConditions);
|
onFilterChanged && onFilterChanged(filterConditions);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
const hasSelectedRows = useMemo(
|
const hasSelectedRows = useMemo(() => selectedRows.length > 0, [
|
||||||
() => selectedRows.length > 0,
|
selectedRows,
|
||||||
[selectedRows]);
|
]);
|
||||||
|
|
||||||
// Handle delete button click.
|
// Handle delete button click.
|
||||||
const handleBulkDelete = useCallback(() => {
|
const handleBulkDelete = useCallback(() => {
|
||||||
onBulkDelete && onBulkDelete(selectedRows.map((r) => r.id));
|
onBulkDelete && onBulkDelete(selectedRows.map((r) => r.id));
|
||||||
}, [onBulkDelete, selectedRows]);
|
}, [onBulkDelete, selectedRows]);
|
||||||
|
|
||||||
|
const handleTabChange = (viewId) => {
|
||||||
|
changeManualJournalCurrentView(viewId.id || -1);
|
||||||
|
addManualJournalsTableQueries({
|
||||||
|
custom_view_id: viewId.id || null,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardActionsBar>
|
<DashboardActionsBar>
|
||||||
<NavbarGroup>
|
<NavbarGroup>
|
||||||
<Popover
|
<DashboardActionViewsList
|
||||||
content={<Menu>{viewsMenuItems}</Menu>}
|
resourceName={'manual-journals'}
|
||||||
minimal={true}
|
views={manualJournalsViews}
|
||||||
interactionKind={PopoverInteractionKind.HOVER}
|
onChange={handleTabChange}
|
||||||
position={Position.BOTTOM_LEFT}
|
/>
|
||||||
>
|
|
||||||
<Button
|
|
||||||
className={classNames(Classes.MINIMAL, 'button--table-views')}
|
|
||||||
icon={<Icon icon="table-16" iconSize={16} />}
|
|
||||||
text={<T id={'table_views'} />}
|
|
||||||
rightIcon={'caret-down'}
|
|
||||||
/>
|
|
||||||
</Popover>
|
|
||||||
|
|
||||||
<NavbarDivider />
|
<NavbarDivider />
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -26,7 +26,11 @@ import { CLASSES } from 'common/classes';
|
|||||||
import { useIsValuePassed } from 'hooks';
|
import { useIsValuePassed } from 'hooks';
|
||||||
|
|
||||||
import ManualJournalsEmptyStatus from './ManualJournalsEmptyStatus';
|
import ManualJournalsEmptyStatus from './ManualJournalsEmptyStatus';
|
||||||
import { AmountPopoverContent, NoteAccessor, StatusAccessor } from './components';
|
import {
|
||||||
|
AmountPopoverContent,
|
||||||
|
NoteAccessor,
|
||||||
|
StatusAccessor,
|
||||||
|
} from './components';
|
||||||
|
|
||||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
import withManualJournals from 'containers/Accounting/withManualJournals';
|
import withManualJournals from 'containers/Accounting/withManualJournals';
|
||||||
@@ -34,8 +38,6 @@ import withManualJournalsActions from 'containers/Accounting/withManualJournalsA
|
|||||||
|
|
||||||
import { compose, saveInvoke } from 'utils';
|
import { compose, saveInvoke } from 'utils';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function ManualJournalsDataTable({
|
function ManualJournalsDataTable({
|
||||||
// #withManualJournals
|
// #withManualJournals
|
||||||
manualJournalsCurrentPage,
|
manualJournalsCurrentPage,
|
||||||
@@ -52,6 +54,7 @@ function ManualJournalsDataTable({
|
|||||||
onDeleteJournal,
|
onDeleteJournal,
|
||||||
onPublishJournal,
|
onPublishJournal,
|
||||||
onSelectedRowsChange,
|
onSelectedRowsChange,
|
||||||
|
manualJournalViewLoading,
|
||||||
}) {
|
}) {
|
||||||
const { custom_view_id: customViewId } = useParams();
|
const { custom_view_id: customViewId } = useParams();
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
@@ -230,7 +233,11 @@ function ManualJournalsDataTable({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.DASHBOARD_DATATABLE)}>
|
<div className={classNames(CLASSES.DASHBOARD_DATATABLE)}>
|
||||||
<LoadingIndicator loading={manualJournalsLoading && !isLoadedBefore}>
|
<LoadingIndicator
|
||||||
|
loading={
|
||||||
|
(manualJournalsLoading && !isLoadedBefore) || manualJournalViewLoading
|
||||||
|
}
|
||||||
|
>
|
||||||
<Choose>
|
<Choose>
|
||||||
<Choose.When condition={showEmptyStatus}>
|
<Choose.When condition={showEmptyStatus}>
|
||||||
<ManualJournalsEmptyStatus />
|
<ManualJournalsEmptyStatus />
|
||||||
|
|||||||
@@ -151,7 +151,7 @@ function ManualJournalsTable({
|
|||||||
);
|
);
|
||||||
|
|
||||||
// Handle filter change to re-fetch data-table.
|
// Handle filter change to re-fetch data-table.
|
||||||
const handleFilterChanged = useCallback(() => {}, [fetchManualJournals]);
|
const handleFilterChanged = useCallback(() => {}, []);
|
||||||
|
|
||||||
// Handle view change to re-fetch data table.
|
// Handle view change to re-fetch data table.
|
||||||
// const handleViewChanged = useCallback(() => {
|
// const handleViewChanged = useCallback(() => {
|
||||||
@@ -243,6 +243,7 @@ function ManualJournalsTable({
|
|||||||
onEditJournal={handleEditJournal}
|
onEditJournal={handleEditJournal}
|
||||||
onPublishJournal={handlePublishMaunalJournal}
|
onPublishJournal={handlePublishMaunalJournal}
|
||||||
onSelectedRowsChange={handleSelectedRowsChange}
|
onSelectedRowsChange={handleSelectedRowsChange}
|
||||||
|
manualJournalViewLoading={fetchManualJournals.isFetching}
|
||||||
/>
|
/>
|
||||||
</Route>
|
</Route>
|
||||||
</Switch>
|
</Switch>
|
||||||
|
|||||||
@@ -1,15 +1,10 @@
|
|||||||
import React, { useEffect, useRef } from 'react';
|
import React, { useEffect } from 'react';
|
||||||
import { useHistory } from 'react-router';
|
import { useHistory } from 'react-router';
|
||||||
import {
|
import { Alignment, Navbar, NavbarGroup } from '@blueprintjs/core';
|
||||||
Alignment,
|
|
||||||
Navbar,
|
|
||||||
NavbarGroup,
|
|
||||||
} from '@blueprintjs/core';
|
|
||||||
import { useParams, withRouter } from 'react-router-dom';
|
import { useParams, withRouter } from 'react-router-dom';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { pick, debounce } from 'lodash';
|
import { pick } from 'lodash';
|
||||||
|
|
||||||
import { useUpdateEffect } from 'hooks';
|
|
||||||
import { DashboardViewsTabs, Icon } from 'components';
|
import { DashboardViewsTabs, Icon } from 'components';
|
||||||
|
|
||||||
import withManualJournals from './withManualJournals';
|
import withManualJournals from './withManualJournals';
|
||||||
@@ -19,6 +14,9 @@ import withViewDetail from 'containers/Views/withViewDetails';
|
|||||||
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Manual journal views tabs.
|
||||||
|
*/
|
||||||
function ManualJournalsViewTabs({
|
function ManualJournalsViewTabs({
|
||||||
// #withViewDetail
|
// #withViewDetail
|
||||||
viewId,
|
viewId,
|
||||||
@@ -38,50 +36,32 @@ function ManualJournalsViewTabs({
|
|||||||
// #ownProps
|
// #ownProps
|
||||||
onViewChanged,
|
onViewChanged,
|
||||||
}) {
|
}) {
|
||||||
const history = useHistory();
|
|
||||||
const { custom_view_id: customViewId } = useParams();
|
const { custom_view_id: customViewId } = useParams();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
changeManualJournalCurrentView(customViewId || -1);
|
|
||||||
setTopbarEditView(customViewId);
|
setTopbarEditView(customViewId);
|
||||||
changePageSubtitle(customViewId && viewItem ? viewItem.name : '');
|
changePageSubtitle(customViewId && viewItem ? viewItem.name : '');
|
||||||
|
|
||||||
addManualJournalsTableQueries({
|
|
||||||
custom_view_id: customViewId,
|
|
||||||
});
|
|
||||||
}, [customViewId, addManualJournalsTableQueries]);
|
|
||||||
|
|
||||||
useUpdateEffect(() => {
|
|
||||||
onViewChanged && onViewChanged(customViewId);
|
|
||||||
}, [customViewId]);
|
}, [customViewId]);
|
||||||
|
|
||||||
const tabs = manualJournalsViews.map((view) => ({
|
const tabs = manualJournalsViews.map((view) => ({
|
||||||
...pick(view, ['name', 'id']),
|
...pick(view, ['name', 'id']),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const debounceChangeHistory = useRef(
|
const handleClickNewView = () => {};
|
||||||
debounce((toUrl) => {
|
|
||||||
history.push(toUrl);
|
|
||||||
}, 250),
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleClickNewView = () => {
|
|
||||||
setTopbarEditView(null);
|
|
||||||
history.push('/custom_views/manual_journals/new');
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleTabChange = (viewId) => {
|
const handleTabChange = (viewId) => {
|
||||||
const toPath = viewId ? `${viewId}/custom_view` : '';
|
changeManualJournalCurrentView(viewId || -1);
|
||||||
debounceChangeHistory.current(`/manual-journals/${toPath}`);
|
addManualJournalsTableQueries({
|
||||||
setTopbarEditView(viewId);
|
custom_view_id: viewId || null,
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Navbar className="navbar--dashboard-views">
|
<Navbar className="navbar--dashboard-views">
|
||||||
<NavbarGroup align={Alignment.LEFT}>
|
<NavbarGroup align={Alignment.LEFT}>
|
||||||
<DashboardViewsTabs
|
<DashboardViewsTabs
|
||||||
|
resourceName={'manual-journals'}
|
||||||
initialViewId={customViewId}
|
initialViewId={customViewId}
|
||||||
baseUrl={'/manual-journals'}
|
|
||||||
tabs={tabs}
|
tabs={tabs}
|
||||||
onChange={handleTabChange}
|
onChange={handleTabChange}
|
||||||
onNewViewTabClick={handleClickNewView}
|
onNewViewTabClick={handleClickNewView}
|
||||||
|
|||||||
@@ -38,23 +38,8 @@ function AccountsViewsTabs({
|
|||||||
const { custom_view_id: customViewId = null } = useParams();
|
const { custom_view_id: customViewId = null } = useParams();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
changeAccountsCurrentView(customViewId || -1);
|
|
||||||
setTopbarEditView(customViewId);
|
setTopbarEditView(customViewId);
|
||||||
changePageSubtitle(customViewId && viewItem ? viewItem.name : '');
|
changePageSubtitle(customViewId && viewItem ? viewItem.name : '');
|
||||||
|
|
||||||
addAccountsTableQueries({
|
|
||||||
custom_view_id: customViewId,
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
setTopbarEditView(null);
|
|
||||||
changePageSubtitle('');
|
|
||||||
changeAccountsCurrentView(null);
|
|
||||||
};
|
|
||||||
}, [customViewId]);
|
|
||||||
|
|
||||||
useUpdateEffect(() => {
|
|
||||||
onViewChanged && onViewChanged(customViewId);
|
|
||||||
}, [customViewId]);
|
}, [customViewId]);
|
||||||
|
|
||||||
// Handle click a new view tab.
|
// Handle click a new view tab.
|
||||||
@@ -63,6 +48,13 @@ function AccountsViewsTabs({
|
|||||||
history.push('/custom_views/accounts/new');
|
history.push('/custom_views/accounts/new');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleTabChange = (viewId) => {
|
||||||
|
changeAccountsCurrentView(viewId || -1);
|
||||||
|
// addAccountsTableQueries({
|
||||||
|
// custom_view_id: viewId || null,
|
||||||
|
// });
|
||||||
|
};
|
||||||
|
|
||||||
const tabs = accountsViews.map((view) => ({
|
const tabs = accountsViews.map((view) => ({
|
||||||
...pick(view, ['name', 'id']),
|
...pick(view, ['name', 'id']),
|
||||||
}));
|
}));
|
||||||
@@ -72,6 +64,7 @@ function AccountsViewsTabs({
|
|||||||
<DashboardViewsTabs
|
<DashboardViewsTabs
|
||||||
initialViewId={customViewId}
|
initialViewId={customViewId}
|
||||||
resourceName={'accounts'}
|
resourceName={'accounts'}
|
||||||
|
onChange={handleTabChange}
|
||||||
tabs={tabs}
|
tabs={tabs}
|
||||||
/>
|
/>
|
||||||
</NavbarGroup>
|
</NavbarGroup>
|
||||||
|
|||||||
@@ -1,21 +1,24 @@
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import {
|
import {
|
||||||
getAccountsItems, getAccountsListFactory,
|
getAccountsItems,
|
||||||
|
getAccountsListFactory,
|
||||||
|
getAccountsTableQuery,
|
||||||
} from 'store/accounts/accounts.selectors';
|
} from 'store/accounts/accounts.selectors';
|
||||||
import {
|
import { getResourceViews } from 'store/customViews/customViews.selectors';
|
||||||
getResourceViews,
|
|
||||||
} from 'store/customViews/customViews.selectors';
|
|
||||||
|
|
||||||
export default (mapState) => {
|
export default (mapState) => {
|
||||||
const getAccountsList = getAccountsListFactory();
|
const getAccountsList = getAccountsListFactory();
|
||||||
|
|
||||||
const mapStateToProps = (state, props) => {
|
const mapStateToProps = (state, props) => {
|
||||||
|
const query = getAccountsTableQuery(state, props);
|
||||||
|
|
||||||
const mapped = {
|
const mapped = {
|
||||||
accountsViews: getResourceViews(state, props, 'accounts'),
|
accountsViews: getResourceViews(state, props, 'accounts'),
|
||||||
accountsTable: getAccountsItems(state, props),
|
accountsTable: getAccountsItems(state, props),
|
||||||
accountsList: getAccountsList(state, props),
|
accountsList: getAccountsList(state, props),
|
||||||
accountsTypes: state.accounts.accountsTypes,
|
accountsTypes: state.accounts.accountsTypes,
|
||||||
|
|
||||||
|
// accountsTableQuery: query,
|
||||||
accountsTableQuery: state.accounts.tableQuery,
|
accountsTableQuery: state.accounts.tableQuery,
|
||||||
accountsLoading: state.accounts.loading,
|
accountsLoading: state.accounts.loading,
|
||||||
accountErrors: state.accounts.errors,
|
accountErrors: state.accounts.errors,
|
||||||
|
|||||||
@@ -1,24 +1,31 @@
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import t from 'store/types';
|
import t from 'store/types';
|
||||||
import {
|
import { fetchAccountsTable } from 'store/accounts/accounts.actions';
|
||||||
fetchAccountsTable,
|
|
||||||
} from 'store/accounts/accounts.actions';
|
|
||||||
|
|
||||||
const mapActionsToProps = (dispatch) => ({
|
const mapActionsToProps = (dispatch) => ({
|
||||||
requestFetchAccountsTable: (query = {}) => dispatch(fetchAccountsTable({ query: { ...query } })),
|
requestFetchAccountsTable: (query = {}) =>
|
||||||
changeAccountsCurrentView: (id) => dispatch({
|
dispatch(fetchAccountsTable({ query: { ...query } })),
|
||||||
type: t.ACCOUNTS_SET_CURRENT_VIEW,
|
changeAccountsCurrentView: (id) =>
|
||||||
currentViewId: parseInt(id, 10),
|
dispatch({
|
||||||
}),
|
type: t.ACCOUNTS_SET_CURRENT_VIEW,
|
||||||
setAccountsTableQuery: (key, value) => dispatch({
|
currentViewId: parseInt(id, 10),
|
||||||
type: 'ACCOUNTS_TABLE_QUERY_SET', key, value,
|
}),
|
||||||
}),
|
setAccountsTableQuery: (key, value) =>
|
||||||
addAccountsTableQueries: (queries) => dispatch({
|
dispatch({
|
||||||
type: 'ACCOUNTS_TABLE_QUERIES_ADD', queries,
|
type: t.ACCOUNTS_TABLE_QUERY_SET,
|
||||||
}),
|
key,
|
||||||
setSelectedRowsAccounts: (ids) => dispatch({
|
value,
|
||||||
type: t.ACCOUNTS_SELECTED_ROWS_SET, payload: { ids },
|
}),
|
||||||
}),
|
addAccountsTableQueries: (queries) =>
|
||||||
|
dispatch({
|
||||||
|
type: t.ACCOUNTS_TABLE_QUERIES_ADD,
|
||||||
|
queries,
|
||||||
|
}),
|
||||||
|
setSelectedRowsAccounts: (ids) =>
|
||||||
|
dispatch({
|
||||||
|
type: t.ACCOUNTS_SELECTED_ROWS_SET,
|
||||||
|
payload: { ids },
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
export default connect(null, mapActionsToProps);
|
export default connect(null, mapActionsToProps);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useMemo, useCallback } from 'react';
|
import React, { useMemo, useCallback, useState } from 'react';
|
||||||
import Icon from 'components/Icon';
|
import Icon from 'components/Icon';
|
||||||
import {
|
import {
|
||||||
Button,
|
Button,
|
||||||
@@ -21,7 +21,7 @@ import FilterDropdown from 'components/FilterDropdown';
|
|||||||
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
||||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
|
|
||||||
import { If } from 'components';
|
import { If, DashboardActionViewsList } from 'components';
|
||||||
|
|
||||||
import withResourceDetail from 'containers/Resources/withResourceDetails';
|
import withResourceDetail from 'containers/Resources/withResourceDetails';
|
||||||
import withExpenses from 'containers/Expenses/withExpenses';
|
import withExpenses from 'containers/Expenses/withExpenses';
|
||||||
@@ -29,6 +29,9 @@ import withExpensesActions from 'containers/Expenses/withExpensesActions';
|
|||||||
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expenses actions bar.
|
||||||
|
*/
|
||||||
function ExpensesActionsBar({
|
function ExpensesActionsBar({
|
||||||
// #withResourceDetail
|
// #withResourceDetail
|
||||||
resourceFields,
|
resourceFields,
|
||||||
@@ -38,18 +41,15 @@ function ExpensesActionsBar({
|
|||||||
|
|
||||||
//#withExpensesActions
|
//#withExpensesActions
|
||||||
addExpensesTableQueries,
|
addExpensesTableQueries,
|
||||||
|
changeExpensesView,
|
||||||
|
|
||||||
onFilterChanged,
|
onFilterChanged,
|
||||||
selectedRows,
|
selectedRows,
|
||||||
onBulkDelete,
|
onBulkDelete,
|
||||||
}) {
|
}) {
|
||||||
const { path } = useRouteMatch();
|
const [filterCount, setFilterCount] = useState(0);
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
|
|
||||||
const viewsMenuItems = expensesViews.map((view) => (
|
|
||||||
<MenuItem href={`${path}/${view.id}/custom_view`} text={view.name} />
|
|
||||||
));
|
|
||||||
|
|
||||||
const onClickNewExpense = useCallback(() => {
|
const onClickNewExpense = useCallback(() => {
|
||||||
history.push('/expenses/new');
|
history.push('/expenses/new');
|
||||||
}, [history]);
|
}, [history]);
|
||||||
@@ -78,22 +78,20 @@ function ExpensesActionsBar({
|
|||||||
onBulkDelete && onBulkDelete(selectedRows.map((r) => r.id));
|
onBulkDelete && onBulkDelete(selectedRows.map((r) => r.id));
|
||||||
}, [onBulkDelete, selectedRows]);
|
}, [onBulkDelete, selectedRows]);
|
||||||
|
|
||||||
|
const handleTabChange = (viewId) => {
|
||||||
|
changeExpensesView(viewId.id || -1);
|
||||||
|
addExpensesTableQueries({
|
||||||
|
custom_view_id: viewId.id || null,
|
||||||
|
});
|
||||||
|
};
|
||||||
return (
|
return (
|
||||||
<DashboardActionsBar>
|
<DashboardActionsBar>
|
||||||
<NavbarGroup>
|
<NavbarGroup>
|
||||||
<Popover
|
<DashboardActionViewsList
|
||||||
content={<Menu>{viewsMenuItems}</Menu>}
|
resourceName={'expenses'}
|
||||||
minimal={true}
|
views={expensesViews}
|
||||||
interactionKind={PopoverInteractionKind.HOVER}
|
onChange={handleTabChange}
|
||||||
position={Position.BOTTOM_LEFT}
|
/>
|
||||||
>
|
|
||||||
<Button
|
|
||||||
className={classNames(Classes.MINIMAL, 'button--table-views')}
|
|
||||||
icon={<Icon icon="table-16" iconSize={16} />}
|
|
||||||
text={<T id={'table_views'} />}
|
|
||||||
rightIcon={'caret-down'}
|
|
||||||
/>
|
|
||||||
</Popover>
|
|
||||||
<NavbarDivider />
|
<NavbarDivider />
|
||||||
<Button
|
<Button
|
||||||
className={Classes.MINIMAL}
|
className={Classes.MINIMAL}
|
||||||
@@ -108,7 +106,9 @@ function ExpensesActionsBar({
|
|||||||
position={Position.BOTTOM_LEFT}
|
position={Position.BOTTOM_LEFT}
|
||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
className={classNames(Classes.MINIMAL, 'button--filter')}
|
className={classNames(Classes.MINIMAL, 'button--filter', {
|
||||||
|
'has-active-filters': filterCount > 0,
|
||||||
|
})}
|
||||||
text="Filter"
|
text="Filter"
|
||||||
icon={<Icon icon="filter-16" iconSize={16} />}
|
icon={<Icon icon="filter-16" iconSize={16} />}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -3,10 +3,9 @@ import { useHistory } from 'react-router';
|
|||||||
import { Alignment, Navbar, NavbarGroup } from '@blueprintjs/core';
|
import { Alignment, Navbar, NavbarGroup } from '@blueprintjs/core';
|
||||||
import { useParams, withRouter } from 'react-router-dom';
|
import { useParams, withRouter } from 'react-router-dom';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { pick, debounce } from 'lodash';
|
import { pick } from 'lodash';
|
||||||
|
|
||||||
import { DashboardViewsTabs } from 'components';
|
import { DashboardViewsTabs } from 'components';
|
||||||
import { useUpdateEffect } from 'hooks';
|
|
||||||
|
|
||||||
import withExpenses from './withExpenses';
|
import withExpenses from './withExpenses';
|
||||||
import withExpensesActions from './withExpensesActions';
|
import withExpensesActions from './withExpensesActions';
|
||||||
@@ -15,6 +14,9 @@ import withViewDetails from 'containers/Views/withViewDetails';
|
|||||||
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expesne views tabs.
|
||||||
|
*/
|
||||||
function ExpenseViewTabs({
|
function ExpenseViewTabs({
|
||||||
// #withExpenses
|
// #withExpenses
|
||||||
expensesViews,
|
expensesViews,
|
||||||
@@ -38,55 +40,32 @@ function ExpenseViewTabs({
|
|||||||
const { custom_view_id: customViewId = null } = useParams();
|
const { custom_view_id: customViewId = null } = useParams();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
changeExpensesView(customViewId || -1);
|
|
||||||
setTopbarEditView(customViewId);
|
setTopbarEditView(customViewId);
|
||||||
changePageSubtitle(customViewId && viewItem ? viewItem.name : '');
|
changePageSubtitle(customViewId && viewItem ? viewItem.name : '');
|
||||||
|
|
||||||
addExpensesTableQueries({
|
|
||||||
custom_view_id: customViewId,
|
|
||||||
});
|
|
||||||
return () => {
|
|
||||||
setTopbarEditView(null);
|
|
||||||
changePageSubtitle('');
|
|
||||||
changeExpensesView(null);
|
|
||||||
};
|
|
||||||
}, [customViewId, addExpensesTableQueries, changeExpensesView]);
|
|
||||||
|
|
||||||
useUpdateEffect(() => {
|
|
||||||
onViewChanged && onViewChanged(customViewId);
|
|
||||||
}, [customViewId]);
|
}, [customViewId]);
|
||||||
|
|
||||||
const debounceChangeHistory = useRef(
|
const handleTabChange = (viewId) => {
|
||||||
debounce((toUrl) => {
|
changeExpensesView(viewId || -1);
|
||||||
history.push(toUrl);
|
addExpensesTableQueries({
|
||||||
}, 250),
|
custom_view_id: viewId || null,
|
||||||
);
|
});
|
||||||
|
|
||||||
const handleTabsChange = (viewId) => {
|
|
||||||
const toPath = viewId ? `${viewId}/custom_view` : '';
|
|
||||||
debounceChangeHistory.current(`/expenses-list/${toPath}`);
|
|
||||||
setTopbarEditView(viewId);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const tabs = expensesViews.map((view) => ({
|
const tabs = expensesViews.map((view) => ({
|
||||||
...pick(view, ['name', 'id']),
|
...pick(view, ['name', 'id']),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
// Handle click a new view tab.
|
// Handle click a new view tab.
|
||||||
const handleClickNewView = () => {
|
const handleClickNewView = () => {};
|
||||||
setTopbarEditView(null);
|
|
||||||
history.push('/custom_views/expenses/new');
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Navbar className={'navbar--dashboard-views'}>
|
<Navbar className={'navbar--dashboard-views'}>
|
||||||
<NavbarGroup align={Alignment.LEFT}>
|
<NavbarGroup align={Alignment.LEFT}>
|
||||||
<DashboardViewsTabs
|
<DashboardViewsTabs
|
||||||
initialViewId={customViewId}
|
initialViewId={customViewId}
|
||||||
baseUrl={'/expenses-list'}
|
resourceName={'expenses'}
|
||||||
tabs={tabs}
|
tabs={tabs}
|
||||||
onNewViewTabClick={handleClickNewView}
|
onNewViewTabClick={handleClickNewView}
|
||||||
onChange={handleTabsChange}
|
onChange={handleTabChange}
|
||||||
/>
|
/>
|
||||||
</NavbarGroup>
|
</NavbarGroup>
|
||||||
</Navbar>
|
</Navbar>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React, { useMemo, useCallback, useState } from 'react';
|
import React, { useMemo, useCallback, useState, useEffect } from 'react';
|
||||||
import { useRouteMatch, useHistory } from 'react-router-dom';
|
import { useRouteMatch, useHistory, useParams } from 'react-router-dom';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import {
|
import {
|
||||||
MenuItem,
|
MenuItem,
|
||||||
@@ -14,13 +14,11 @@ import {
|
|||||||
Intent,
|
Intent,
|
||||||
} from '@blueprintjs/core';
|
} from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
|
|
||||||
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
||||||
import Icon from 'components/Icon';
|
import Icon from 'components/Icon';
|
||||||
import FilterDropdown from 'components/FilterDropdown';
|
import FilterDropdown from 'components/FilterDropdown';
|
||||||
import { If } from 'components';
|
import { If, DashboardActionViewsList } from 'components';
|
||||||
|
|
||||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
|
||||||
import withResourceDetail from 'containers/Resources/withResourceDetails';
|
import withResourceDetail from 'containers/Resources/withResourceDetails';
|
||||||
import withItems from 'containers/Items/withItems';
|
import withItems from 'containers/Items/withItems';
|
||||||
import withItemsActions from './withItemsActions';
|
import withItemsActions from './withItemsActions';
|
||||||
@@ -29,9 +27,7 @@ import { compose } from 'utils';
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
|
|
||||||
const ItemsActionsBar = ({
|
const ItemsActionsBar = ({
|
||||||
openDialog,
|
// #withResourceDetail
|
||||||
|
|
||||||
resourceName = 'items',
|
|
||||||
resourceFields,
|
resourceFields,
|
||||||
|
|
||||||
// #withItems
|
// #withItems
|
||||||
@@ -39,18 +35,15 @@ const ItemsActionsBar = ({
|
|||||||
|
|
||||||
//#withItemActions
|
//#withItemActions
|
||||||
addItemsTableQueries,
|
addItemsTableQueries,
|
||||||
|
changeItemsCurrentView,
|
||||||
|
|
||||||
onFilterChanged,
|
onFilterChanged,
|
||||||
selectedRows = [],
|
selectedRows = [],
|
||||||
onBulkDelete,
|
onBulkDelete,
|
||||||
}) => {
|
}) => {
|
||||||
const { path } = useRouteMatch();
|
const { formatMessage } = useIntl();
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const [filterCount, setFilterCount] = useState(0);
|
const [filterCount, setFilterCount] = useState(0);
|
||||||
const { formatMessage } = useIntl();
|
|
||||||
const viewsMenuItems = itemsViews.map((view) => (
|
|
||||||
<MenuItem href={`${path}/${view.id}/custom_view`} text={view.name} />
|
|
||||||
));
|
|
||||||
|
|
||||||
const onClickNewItem = useCallback(() => {
|
const onClickNewItem = useCallback(() => {
|
||||||
history.push('/items/new');
|
history.push('/items/new');
|
||||||
@@ -60,22 +53,13 @@ const ItemsActionsBar = ({
|
|||||||
selectedRows,
|
selectedRows,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// name
|
|
||||||
// const filterDropdown = FilterDropdown({
|
|
||||||
// fields: resourceFields,
|
|
||||||
// onFilterChange: (filterConditions) => {
|
|
||||||
// setFilterCount(filterConditions.length);
|
|
||||||
// onFilterChanged && onFilterChanged(filterConditions);
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
|
|
||||||
const filterDropdown = FilterDropdown({
|
const filterDropdown = FilterDropdown({
|
||||||
|
fields: resourceFields,
|
||||||
initialCondition: {
|
initialCondition: {
|
||||||
fieldKey: 'name',
|
fieldKey: 'name',
|
||||||
compatator: 'contains',
|
compatator: 'contains',
|
||||||
value: '',
|
value: '',
|
||||||
},
|
},
|
||||||
fields: resourceFields,
|
|
||||||
onFilterChange: (filterConditions) => {
|
onFilterChange: (filterConditions) => {
|
||||||
addItemsTableQueries({
|
addItemsTableQueries({
|
||||||
filter_roles: filterConditions || '',
|
filter_roles: filterConditions || '',
|
||||||
@@ -84,30 +68,25 @@ const ItemsActionsBar = ({
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// const onClickNewCategory = useCallback(() => {
|
|
||||||
// openDialog('item-form', {});
|
|
||||||
// }, [openDialog]);
|
|
||||||
|
|
||||||
const handleBulkDelete = useCallback(() => {
|
const handleBulkDelete = useCallback(() => {
|
||||||
onBulkDelete && onBulkDelete(selectedRows.map((r) => r.id));
|
onBulkDelete && onBulkDelete(selectedRows.map((r) => r.id));
|
||||||
}, [onBulkDelete, selectedRows]);
|
}, [onBulkDelete, selectedRows]);
|
||||||
|
|
||||||
|
const handleTabChange = (viewId) => {
|
||||||
|
changeItemsCurrentView(viewId.id || -1);
|
||||||
|
addItemsTableQueries({
|
||||||
|
custom_view_id: viewId.id || null,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DashboardActionsBar>
|
<DashboardActionsBar>
|
||||||
<NavbarGroup>
|
<NavbarGroup>
|
||||||
<Popover
|
<DashboardActionViewsList
|
||||||
content={<Menu>{viewsMenuItems}</Menu>}
|
resourceName={'items'}
|
||||||
minimal={true}
|
views={itemsViews}
|
||||||
interactionKind={PopoverInteractionKind.HOVER}
|
onChange={handleTabChange}
|
||||||
position={Position.BOTTOM_LEFT}
|
/>
|
||||||
>
|
|
||||||
<Button
|
|
||||||
className={classNames(Classes.MINIMAL, 'button--table-views')}
|
|
||||||
icon={<Icon icon="table-16" iconSize={16} />}
|
|
||||||
text={<T id={'table_views'} />}
|
|
||||||
rightIcon={'caret-down'}
|
|
||||||
/>
|
|
||||||
</Popover>
|
|
||||||
|
|
||||||
<NavbarDivider />
|
<NavbarDivider />
|
||||||
|
|
||||||
@@ -170,7 +149,6 @@ const withItemsActionsBar = connect(mapStateToProps);
|
|||||||
|
|
||||||
export default compose(
|
export default compose(
|
||||||
withItemsActionsBar,
|
withItemsActionsBar,
|
||||||
withDialogActions,
|
|
||||||
withItems(({ itemsViews }) => ({
|
withItems(({ itemsViews }) => ({
|
||||||
itemsViews,
|
itemsViews,
|
||||||
})),
|
})),
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ function ItemsDataTable({
|
|||||||
onInactiveItem,
|
onInactiveItem,
|
||||||
onActivateItem,
|
onActivateItem,
|
||||||
onSelectedRowsChange,
|
onSelectedRowsChange,
|
||||||
|
itemsViewLoading,
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const isLoadedBefore = useIsValuePassed(itemsTableLoading, false);
|
const isLoadedBefore = useIsValuePassed(itemsTableLoading, false);
|
||||||
@@ -238,7 +239,9 @@ function ItemsDataTable({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.DASHBOARD_DATATABLE)}>
|
<div className={classNames(CLASSES.DASHBOARD_DATATABLE)}>
|
||||||
<LoadingIndicator loading={itemsTableLoading && !isLoadedBefore}>
|
<LoadingIndicator
|
||||||
|
loading={(itemsTableLoading && !isLoadedBefore) || itemsViewLoading}
|
||||||
|
>
|
||||||
<Choose>
|
<Choose>
|
||||||
<Choose.When condition={showEmptyStatus}>
|
<Choose.When condition={showEmptyStatus}>
|
||||||
<ItemsEmptyStatus />
|
<ItemsEmptyStatus />
|
||||||
|
|||||||
@@ -261,6 +261,7 @@ function ItemsList({
|
|||||||
onInactiveItem={handleInactiveItem}
|
onInactiveItem={handleInactiveItem}
|
||||||
onActivateItem={handleActivateItem}
|
onActivateItem={handleActivateItem}
|
||||||
onSelectedRowsChange={handleSelectedRowsChange}
|
onSelectedRowsChange={handleSelectedRowsChange}
|
||||||
|
itemsViewLoading={fetchItems.isFetching}
|
||||||
/>
|
/>
|
||||||
<Alert
|
<Alert
|
||||||
cancelButtonText={<T id={'cancel'} />}
|
cancelButtonText={<T id={'cancel'} />}
|
||||||
|
|||||||
@@ -1,29 +1,21 @@
|
|||||||
import React, { useEffect, useRef } from 'react';
|
import React, { useCallback, useEffect, useRef } from 'react';
|
||||||
import { useHistory } from 'react-router';
|
import { useHistory } from 'react-router';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import {
|
import { Alignment, Navbar, NavbarGroup } from '@blueprintjs/core';
|
||||||
Alignment,
|
|
||||||
Navbar,
|
|
||||||
NavbarGroup,
|
|
||||||
Tabs,
|
|
||||||
Tab,
|
|
||||||
Button,
|
|
||||||
} from '@blueprintjs/core';
|
|
||||||
import { useParams } from 'react-router-dom';
|
import { useParams } from 'react-router-dom';
|
||||||
import Icon from 'components/Icon';
|
import { withRouter } from 'react-router-dom';
|
||||||
import { Link, withRouter } from 'react-router-dom';
|
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
import { useUpdateEffect } from 'hooks';
|
|
||||||
import { DashboardViewsTabs } from 'components';
|
import { DashboardViewsTabs } from 'components';
|
||||||
import { pick, debounce } from 'lodash';
|
import { pick } from 'lodash';
|
||||||
|
|
||||||
import withItemsActions from 'containers/Items/withItemsActions';
|
import withItemsActions from 'containers/Items/withItemsActions';
|
||||||
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
import withDashboardActions from 'containers/Dashboard/withDashboardActions';
|
||||||
import withViewDetail from 'containers/Views/withViewDetails';
|
import withViewDetail from 'containers/Views/withViewDetails';
|
||||||
import withItems from 'containers/Items/withItems';
|
import withItems from 'containers/Items/withItems';
|
||||||
|
|
||||||
import { FormattedMessage as T } from 'react-intl';
|
/**
|
||||||
|
* Items views tabs.
|
||||||
|
*/
|
||||||
function ItemsViewsTabs({
|
function ItemsViewsTabs({
|
||||||
// #withViewDetail
|
// #withViewDetail
|
||||||
viewId,
|
viewId,
|
||||||
@@ -43,62 +35,34 @@ function ItemsViewsTabs({
|
|||||||
// #props
|
// #props
|
||||||
onViewChanged,
|
onViewChanged,
|
||||||
}) {
|
}) {
|
||||||
const history = useHistory();
|
|
||||||
const { custom_view_id: customViewId = null } = useParams();
|
const { custom_view_id: customViewId = null } = useParams();
|
||||||
|
|
||||||
const handleClickNewView = () => {
|
|
||||||
setTopbarEditView(null);
|
|
||||||
history.push('/custom_views/items/new');
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleViewLinkClick = () => {
|
|
||||||
setTopbarEditView(customViewId);
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
changeItemsCurrentView(customViewId || -1);
|
|
||||||
setTopbarEditView(customViewId);
|
setTopbarEditView(customViewId);
|
||||||
changePageSubtitle(customViewId && viewItem ? viewItem.name : '');
|
changePageSubtitle(customViewId && viewItem ? viewItem.name : '');
|
||||||
|
|
||||||
addItemsTableQueries({
|
|
||||||
custom_view_id: customViewId || null,
|
|
||||||
});
|
|
||||||
|
|
||||||
return () => {
|
|
||||||
setTopbarEditView(null);
|
|
||||||
changeItemsCurrentView(-1);
|
|
||||||
changePageSubtitle('');
|
|
||||||
};
|
|
||||||
}, [customViewId, addItemsTableQueries, changeItemsCurrentView]);
|
|
||||||
|
|
||||||
useUpdateEffect(() => {
|
|
||||||
onViewChanged && onViewChanged(customViewId);
|
|
||||||
}, [customViewId]);
|
}, [customViewId]);
|
||||||
|
|
||||||
const debounceChangeHistory = useRef(
|
const handleClickNewView = () => {};
|
||||||
debounce((toUrl) => {
|
|
||||||
history.push(toUrl);
|
|
||||||
}, 250),
|
|
||||||
);
|
|
||||||
|
|
||||||
const handleTabsChange = (viewId) => {
|
|
||||||
const toPath = viewId ? `${viewId}/custom_view` : '';
|
|
||||||
debounceChangeHistory.current(`/items/${toPath}`);
|
|
||||||
setTopbarEditView(viewId);
|
|
||||||
};
|
|
||||||
|
|
||||||
const tabs = itemsViews.map((view) => ({
|
const tabs = itemsViews.map((view) => ({
|
||||||
...pick(view, ['name', 'id']),
|
...pick(view, ['name', 'id']),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const handleTabChange = (viewId) => {
|
||||||
|
changeItemsCurrentView(viewId || -1);
|
||||||
|
addItemsTableQueries({
|
||||||
|
custom_view_id: viewId || null,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Navbar className="navbar--dashboard-views">
|
<Navbar className="navbar--dashboard-views">
|
||||||
<NavbarGroup align={Alignment.LEFT}>
|
<NavbarGroup align={Alignment.LEFT}>
|
||||||
<DashboardViewsTabs
|
<DashboardViewsTabs
|
||||||
initialViewId={customViewId}
|
initialViewId={customViewId}
|
||||||
baseUrl={'/items'}
|
resourceName={'items'}
|
||||||
tabs={tabs}
|
tabs={tabs}
|
||||||
onNewViewTabClick={handleClickNewView}
|
onChange={handleTabChange}
|
||||||
onChange={handleTabsChange}
|
|
||||||
/>
|
/>
|
||||||
</NavbarGroup>
|
</NavbarGroup>
|
||||||
</Navbar>
|
</Navbar>
|
||||||
|
|||||||
@@ -1,6 +1,10 @@
|
|||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
import { repeat } from 'lodash';
|
import { repeat } from 'lodash';
|
||||||
import { pickItemsFromIds, getItemById } from 'store/selectors';
|
import {
|
||||||
|
pickItemsFromIds,
|
||||||
|
getItemById,
|
||||||
|
paginationLocationQuery,
|
||||||
|
} from 'store/selectors';
|
||||||
import { flatToNestedArray, treeToList } from 'utils';
|
import { flatToNestedArray, treeToList } from 'utils';
|
||||||
|
|
||||||
const accountsViewsSelector = (state) => state.accounts.views;
|
const accountsViewsSelector = (state) => state.accounts.views;
|
||||||
@@ -8,6 +12,16 @@ const accountsDataSelector = (state) => state.accounts.items;
|
|||||||
const accountsCurrentViewSelector = (state) => state.accounts.currentViewId;
|
const accountsCurrentViewSelector = (state) => state.accounts.currentViewId;
|
||||||
const accountIdPropSelector = (state, props) => props.accountId;
|
const accountIdPropSelector = (state, props) => props.accountId;
|
||||||
const accountsListSelector = (state) => state.accounts.listTree;
|
const accountsListSelector = (state) => state.accounts.listTree;
|
||||||
|
const accountsTableQuery = (state, props) => state.accounts.tableQuery;
|
||||||
|
|
||||||
|
export const getAccountsTableQuery = createSelector(
|
||||||
|
accountsTableQuery,
|
||||||
|
(tableQuery) => {
|
||||||
|
return {
|
||||||
|
...tableQuery,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
export const getAccountsItems = createSelector(
|
export const getAccountsItems = createSelector(
|
||||||
accountsViewsSelector,
|
accountsViewsSelector,
|
||||||
@@ -42,12 +56,13 @@ export const getAccountsListFactory = () =>
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...account,
|
...account,
|
||||||
htmlName: (depth > 1)
|
htmlName:
|
||||||
? (`${repeat(spaceChar, (depth - 1) * 2)}${account.name}`) :
|
depth > 1
|
||||||
account.name,
|
? `${repeat(spaceChar, (depth - 1) * 2)}${account.name}`
|
||||||
|
: account.name,
|
||||||
depth,
|
depth,
|
||||||
};
|
};
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -14,8 +14,10 @@ export default {
|
|||||||
|
|
||||||
ACCOUNTS_SET_CURRENT_VIEW: 'ACCOUNTS_SET_CURRENT_VIEW',
|
ACCOUNTS_SET_CURRENT_VIEW: 'ACCOUNTS_SET_CURRENT_VIEW',
|
||||||
|
|
||||||
ACCOUNTS_TABLE_QUERY_SET: 'ACCOUNTS_TABLE_QUERY_SET',
|
ACCOUNTS_TABLE_QUERY_SET: 'ACCOUNTS/TABLE_QUERY_SET',
|
||||||
ACCOUNTS_TABLE_QUERIES_SET: 'ACCOUNTS_TABLE_QUERIES_SET',
|
ACCOUNTS_TABLE_QUERIES_SET: 'ACCOUNTS/TABLE_QUERIES_SET',
|
||||||
|
ACCOUNTS_TABLE_QUERIES_ADD:'ACCOUNTS/TABLE_QUERIES_ADD',
|
||||||
|
|
||||||
|
|
||||||
ACCOUNTS_TABLE_LOADING: 'ACCOUNTS_TABLE_LOADING',
|
ACCOUNTS_TABLE_LOADING: 'ACCOUNTS_TABLE_LOADING',
|
||||||
|
|
||||||
|
|||||||
@@ -20,21 +20,23 @@ export const fetchExpensesTable = ({ query } = {}) => {
|
|||||||
payload: {
|
payload: {
|
||||||
expenses: response.data.expenses,
|
expenses: response.data.expenses,
|
||||||
pagination: response.data.pagination,
|
pagination: response.data.pagination,
|
||||||
customViewId: response.data.customViewId || -1,
|
customViewId:
|
||||||
|
response.data?.filter_meta?.view?.custom_view_id || -1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.EXPENSES_ITEMS_SET,
|
type: t.EXPENSES_ITEMS_SET,
|
||||||
payload: {
|
payload: {
|
||||||
expenses: response.data.expenses,
|
expenses: response.data.expenses,
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.EXPENSES_PAGINATION_SET,
|
type: t.EXPENSES_PAGINATION_SET,
|
||||||
payload: {
|
payload: {
|
||||||
pagination: response.data.pagination,
|
pagination: response.data.pagination,
|
||||||
customViewId: response.data.customViewId || -1,
|
customViewId:
|
||||||
}
|
response.data?.filter_meta?.view?.custom_view_id || -1,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.EXPENSES_TABLE_LOADING,
|
type: t.EXPENSES_TABLE_LOADING,
|
||||||
@@ -54,7 +56,7 @@ export const fetchExpense = ({ id }) => {
|
|||||||
return (dispatch) =>
|
return (dispatch) =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
ApiService.get(`expenses/${id}`)
|
ApiService.get(`expenses/${id}`)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.EXPENSE_SET,
|
type: t.EXPENSE_SET,
|
||||||
payload: {
|
payload: {
|
||||||
|
|||||||
@@ -12,12 +12,13 @@ export const editItem = ({ id, form }) => {
|
|||||||
export const fetchItems = ({ query }) => {
|
export const fetchItems = ({ query }) => {
|
||||||
return (dispatch, getState) =>
|
return (dispatch, getState) =>
|
||||||
new Promise((resolve, reject) => {
|
new Promise((resolve, reject) => {
|
||||||
const pageQuery = getState().items.tableQuery;
|
let pageQuery = getState().items.tableQuery;
|
||||||
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.ITEMS_TABLE_LOADING,
|
type: t.ITEMS_TABLE_LOADING,
|
||||||
payload: { loading: true },
|
payload: { loading: true },
|
||||||
});
|
});
|
||||||
|
|
||||||
ApiService.get(`items`, { params: { ...pageQuery, ...query } })
|
ApiService.get(`items`, { params: { ...pageQuery, ...query } })
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
dispatch({
|
dispatch({
|
||||||
@@ -27,16 +28,18 @@ export const fetchItems = ({ query }) => {
|
|||||||
dispatch({
|
dispatch({
|
||||||
type: t.ITEMS_PAGE_SET,
|
type: t.ITEMS_PAGE_SET,
|
||||||
items: response.data.items,
|
items: response.data.items,
|
||||||
customViewId: response.data?.filter_meta?.view?.custom_view_id,
|
customViewId:
|
||||||
|
response.data?.filter_meta?.view?.custom_view_id || -1,
|
||||||
paginationMeta: response.data.pagination,
|
paginationMeta: response.data.pagination,
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.ITEMS_PAGINATION_SET,
|
type: t.ITEMS_PAGINATION_SET,
|
||||||
payload: {
|
payload: {
|
||||||
pagination: response.data.pagination,
|
pagination: response.data.pagination,
|
||||||
customViewId: response.data.customViewId || -1,
|
customViewId:
|
||||||
}
|
response.data?.filter_meta?.view?.custom_view_id || -1,
|
||||||
})
|
},
|
||||||
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.ITEMS_TABLE_LOADING,
|
type: t.ITEMS_TABLE_LOADING,
|
||||||
payload: { loading: false },
|
payload: { loading: false },
|
||||||
@@ -44,9 +47,6 @@ export const fetchItems = ({ query }) => {
|
|||||||
resolve(response);
|
resolve(response);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
dispatch({
|
|
||||||
type: t.SET_DASHBOARD_REQUEST_COMPLETED,
|
|
||||||
});
|
|
||||||
reject(error);
|
reject(error);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import { paginationLocationQuery } from "store/selectors";
|
import { paginationLocationQuery } from 'store/selectors';
|
||||||
import { createSelector } from 'reselect';
|
import { createSelector } from 'reselect';
|
||||||
import {
|
import { pickItemsFromIds, defaultPaginationMeta } from 'store/selectors';
|
||||||
pickItemsFromIds,
|
|
||||||
defaultPaginationMeta,
|
|
||||||
} from 'store/selectors';
|
|
||||||
|
|
||||||
const itemsTableQuerySelector = (state) => state.items.tableQuery;
|
const itemsTableQuerySelector = (state) => state.items.tableQuery;
|
||||||
|
|
||||||
@@ -20,8 +17,9 @@ const itemsPaginationSelector = (state, props) => {
|
|||||||
const viewId = state.items.currentViewId;
|
const viewId = state.items.currentViewId;
|
||||||
return state.items.views?.[viewId]?.paginationMeta;
|
return state.items.views?.[viewId]?.paginationMeta;
|
||||||
};
|
};
|
||||||
const customersCurrentViewIdSelector = (state) => state.customers.currentViewId;
|
const itemsCurrentViewIdSelector = (state) => {
|
||||||
|
return state.items.currentViewId;
|
||||||
|
};
|
||||||
// Get items table query marged with location query.
|
// Get items table query marged with location query.
|
||||||
export const getItemsTableQueryFactory = () =>
|
export const getItemsTableQueryFactory = () =>
|
||||||
createSelector(
|
createSelector(
|
||||||
@@ -31,7 +29,7 @@ export const getItemsTableQueryFactory = () =>
|
|||||||
return {
|
return {
|
||||||
...locationQuery,
|
...locationQuery,
|
||||||
...tableQuery,
|
...tableQuery,
|
||||||
}
|
};
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -42,28 +40,22 @@ export const getItemsCurrentPageFactory = () =>
|
|||||||
itemsCurrentPageSelector,
|
itemsCurrentPageSelector,
|
||||||
(items, itemsIdsCurrentPage) => {
|
(items, itemsIdsCurrentPage) => {
|
||||||
return typeof itemsIdsCurrentPage === 'object'
|
return typeof itemsIdsCurrentPage === 'object'
|
||||||
? pickItemsFromIds(items, itemsIdsCurrentPage.ids) || []
|
? pickItemsFromIds(items, itemsIdsCurrentPage.ids) || []
|
||||||
: [];
|
: [];
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
// Retrieve items pagination meta.
|
// Retrieve items pagination meta.
|
||||||
export const getItemsPaginationMetaFactory = () =>
|
export const getItemsPaginationMetaFactory = () =>
|
||||||
createSelector(
|
createSelector(itemsPaginationSelector, (itemsPagination) => {
|
||||||
itemsPaginationSelector,
|
return {
|
||||||
(itemsPagination) => {
|
...defaultPaginationMeta(),
|
||||||
return {
|
...itemsPagination,
|
||||||
...defaultPaginationMeta(),
|
};
|
||||||
...itemsPagination,
|
});
|
||||||
};
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Retrieve items current view id.
|
// Retrieve items current view id.
|
||||||
export const getItemsCurrentViewIdFactory = () =>
|
export const getItemsCurrentViewIdFactory = () =>
|
||||||
createSelector(
|
createSelector(itemsCurrentViewIdSelector, (currentViewId) => {
|
||||||
customersCurrentViewIdSelector,
|
return currentViewId;
|
||||||
(currentViewId) => {
|
});
|
||||||
return currentViewId;
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ export const fetchManualJournalsTable = ({ query } = {}) => {
|
|||||||
payload: {
|
payload: {
|
||||||
manualJournals: response.data.manual_journals,
|
manualJournals: response.data.manual_journals,
|
||||||
customViewId:
|
customViewId:
|
||||||
response.data.manual_journals?.viewMeta?.customViewId || -1,
|
response.data?.filter_meta?.view?.custom_view_id || -1,
|
||||||
pagination: response.data.pagination,
|
pagination: response.data.pagination,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
@@ -140,23 +140,25 @@ export const fetchManualJournalsTable = ({ query } = {}) => {
|
|||||||
...manualJournal,
|
...manualJournal,
|
||||||
entries: manualJournal.entries.map((entry) => ({
|
entries: manualJournal.entries.map((entry) => ({
|
||||||
...omit(entry, ['account']),
|
...omit(entry, ['account']),
|
||||||
}))
|
})),
|
||||||
})),
|
})),
|
||||||
]
|
],
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.MANUAL_JOURNALS_PAGINATION_SET,
|
type: t.MANUAL_JOURNALS_PAGINATION_SET,
|
||||||
payload: {
|
payload: {
|
||||||
pagination: response.data.pagination,
|
pagination: response.data.pagination,
|
||||||
customViewId:
|
customViewId:
|
||||||
response.data.manual_journals?.viewMeta?.customViewId || -1,
|
response.data?.filter_meta?.view?.custom_view_id || -1,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.ACCOUNTS_ITEMS_SET,
|
type: t.ACCOUNTS_ITEMS_SET,
|
||||||
accounts: flatten(response.data.manual_journals?.map(
|
accounts: flatten(
|
||||||
journal => journal?.entries.map(entry => entry.account),
|
response.data.manual_journals?.map((journal) =>
|
||||||
)),
|
journal?.entries.map((entry) => entry.account),
|
||||||
|
),
|
||||||
|
),
|
||||||
});
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: t.MANUAL_JOURNALS_TABLE_LOADING,
|
type: t.MANUAL_JOURNALS_TABLE_LOADING,
|
||||||
|
|||||||
Reference in New Issue
Block a user