feat: WIP advanced filter.

This commit is contained in:
a.bouhuolia
2021-08-10 19:38:36 +02:00
parent aefb89e1c0
commit 23e8e251a1
97 changed files with 2008 additions and 1937 deletions

View File

@@ -1,25 +1,27 @@
import React, { useState } from 'react';
import React from 'react';
import Icon from 'components/Icon';
import {
Button,
Classes,
Popover,
NavbarDivider,
NavbarGroup,
PopoverInteractionKind,
Position,
Intent,
Alignment,
} from '@blueprintjs/core';
import classNames from 'classnames';
import { useHistory } from 'react-router-dom';
import { FormattedMessage as T } from 'components';
import intl from 'react-intl-universal';
import { If, DashboardActionViewsList } from 'components';
import {
AdvancedFilterPopover,
If,
DashboardActionViewsList,
DashboardFilterButton,
} from 'components';
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
import withEstimatesActions from './withEstimatesActions';
import withEstimates from './withEstimates';
import { useEstimatesListContext } from './EstimatesListProvider';
import { useRefreshEstimates } from 'hooks/query/estimates';
@@ -31,13 +33,14 @@ import { compose } from 'utils';
function EstimateActionsBar({
// #withEstimateActions
setEstimatesTableState,
// #withEstimates
estimatesFilterRoles
}) {
const history = useHistory();
const [filterCount, setFilterCount] = useState(0);
// Estimates list context.
const { estimatesViews } = useEstimatesListContext();
const { estimatesViews, fields } = useEstimatesListContext();
// Handle click a new sale estimate.
const onClickNewEstimate = () => {
@@ -55,9 +58,7 @@ function EstimateActionsBar({
};
// Handle click a refresh sale estimates
const handleRefreshBtnClick = () => {
refresh();
};
const handleRefreshBtnClick = () => { refresh(); };
return (
<DashboardActionsBar>
@@ -74,23 +75,21 @@ function EstimateActionsBar({
text={<T id={'new_estimate'} />}
onClick={onClickNewEstimate}
/>
<Popover
minimal={true}
interactionKind={PopoverInteractionKind.CLICK}
position={Position.BOTTOM_LEFT}
<AdvancedFilterPopover
advancedFilterProps={{
conditions: estimatesFilterRoles,
defaultFieldKey: 'estimate_number',
fields: fields,
onFilterChange: (filterConditions) => {
setEstimatesTableState({ filterRoles: filterConditions });
},
}}
>
<Button
className={classNames(Classes.MINIMAL, 'button--filter')}
text={
filterCount <= 0 ? (
<T id={'filter'} />
) : (
`${filterCount} ${intl.get('filters_applied')}`
)
}
icon={<Icon icon={'filter-16'} iconSize={16} />}
<DashboardFilterButton
conditionsCount={estimatesFilterRoles.length}
/>
</Popover>
</AdvancedFilterPopover>
<If condition={false}>
<Button
className={Classes.MINIMAL}
@@ -128,4 +127,9 @@ function EstimateActionsBar({
);
}
export default compose(withEstimatesActions)(EstimateActionsBar);
export default compose(
withEstimatesActions,
withEstimates(({ estimatesTableState }) => ({
estimatesFilterRoles: estimatesTableState.filterRoles,
})),
)(EstimateActionsBar);

View File

@@ -9,6 +9,7 @@ import EstimatesViewTabs from './EstimatesViewTabs';
import EstimatesDataTable from './EstimatesDataTable';
import withEstimates from './withEstimates';
import withEstimatesActions from './withEstimatesActions';
import { EstimatesListProvider } from './EstimatesListProvider';
import { compose, transformTableStateToQuery } from 'utils';
@@ -19,7 +20,22 @@ import { compose, transformTableStateToQuery } from 'utils';
function EstimatesList({
// #withEstimate
estimatesTableState,
// #withEstimatesActions
setEstimatesTableState
}) {
// Resets the estimates table state once the page unmount.
React.useEffect(
() => () => {
setEstimatesTableState({
filterRoles: [],
viewSlug: '',
pageIndex: 0,
});
},
[setEstimatesTableState],
);
return (
<EstimatesListProvider
query={transformTableStateToQuery(estimatesTableState)}
@@ -41,4 +57,5 @@ function EstimatesList({
export default compose(
withEstimates(({ estimatesTableState }) => ({ estimatesTableState })),
withEstimatesActions
)(EstimatesList);

View File

@@ -1,7 +1,9 @@
import React, { createContext } from 'react';
import DashboardInsider from 'components/Dashboard/DashboardInsider';
import { useResourceViews, useResourceFields, useEstimates } from 'hooks/query';
import { isTableEmptyStatus } from 'utils';
import { useResourceViews, useResourceMeta, useEstimates } from 'hooks/query';
import { isTableEmptyStatus, getFieldsFromResourceMeta } from 'utils';
const EstimatesListContext = createContext();
@@ -10,17 +12,17 @@ const EstimatesListContext = createContext();
*/
function EstimatesListProvider({ query, ...props }) {
// Fetches estimates resource views and fields.
const { data: estimatesViews, isLoading: isViewsLoading } = useResourceViews(
'sale_estimates',
);
const { data: estimatesViews, isLoading: isViewsLoading } =
useResourceViews('sale_estimates');
// Fetches the estimates resource fields.
const {
data: estimatesFields,
isLoading: isFieldsLoading,
} = useResourceFields('sale_estimates');
data: resourceMeta,
isLoading: isResourceLoading,
isFetching: isResourceFetching,
} = useResourceMeta('sale_estimates');
// Fetch estimates list according to the given custom view id.
// Fetches estimates list according to the given custom view id.
const {
data: { estimates, pagination, filterMeta },
isLoading: isEstimatesLoading,
@@ -39,12 +41,15 @@ function EstimatesListProvider({ query, ...props }) {
const provider = {
estimates,
pagination,
estimatesFields,
fields: getFieldsFromResourceMeta(resourceMeta.fields),
estimatesViews,
isResourceLoading,
isResourceFetching,
isEstimatesLoading,
isEstimatesFetching,
isFieldsLoading,
isViewsLoading,
isEmptyStatus,
@@ -52,7 +57,7 @@ function EstimatesListProvider({ query, ...props }) {
return (
<DashboardInsider
loading={isViewsLoading || isFieldsLoading}
loading={isViewsLoading || isResourceLoading}
name={'sale_estimate'}
>
<EstimatesListContext.Provider value={provider} {...props} />