Merge pull request #1018 from chaotixkilla/fix-customers-page-filters
Fix customers page filter deletion
This commit is contained in:
commit
48496b3e18
1 changed files with 38 additions and 11 deletions
|
|
@ -51,6 +51,9 @@ const GET_CUSTOMERS = gql`
|
||||||
|
|
||||||
const useBaseStyles = makeStyles(baseStyles)
|
const useBaseStyles = makeStyles(baseStyles)
|
||||||
|
|
||||||
|
const getFiltersObj = filters =>
|
||||||
|
R.reduce((s, f) => ({ ...s, [f.type]: f.value }), {}, filters)
|
||||||
|
|
||||||
const Customers = () => {
|
const Customers = () => {
|
||||||
const baseStyles = useBaseStyles()
|
const baseStyles = useBaseStyles()
|
||||||
const history = useHistory()
|
const history = useHistory()
|
||||||
|
|
@ -82,12 +85,7 @@ const Customers = () => {
|
||||||
)
|
)
|
||||||
|
|
||||||
const onFilterChange = filters => {
|
const onFilterChange = filters => {
|
||||||
const filtersObject = R.compose(
|
const filtersObject = getFiltersObj(filters)
|
||||||
R.mergeAll,
|
|
||||||
R.map(f => ({
|
|
||||||
[f.type]: f.value
|
|
||||||
}))
|
|
||||||
)(filters)
|
|
||||||
|
|
||||||
setFilters(filters)
|
setFilters(filters)
|
||||||
|
|
||||||
|
|
@ -101,10 +99,38 @@ const Customers = () => {
|
||||||
refetch && refetch()
|
refetch && refetch()
|
||||||
}
|
}
|
||||||
|
|
||||||
const onFilterDelete = filter =>
|
const onFilterDelete = filter => {
|
||||||
setFilters(
|
const newFilters = R.filter(
|
||||||
R.filter(f => !R.whereEq(R.pick(['type', 'value'], f), filter))(filters)
|
f => !R.whereEq(R.pick(['type', 'value'], f), filter)
|
||||||
)
|
)(filters)
|
||||||
|
|
||||||
|
setFilters(newFilters)
|
||||||
|
|
||||||
|
const filtersObject = getFiltersObj(newFilters)
|
||||||
|
|
||||||
|
setVariables({
|
||||||
|
phone: filtersObject.phone,
|
||||||
|
name: filtersObject.name,
|
||||||
|
address: filtersObject.address,
|
||||||
|
id: filtersObject.id
|
||||||
|
})
|
||||||
|
|
||||||
|
refetch && refetch()
|
||||||
|
}
|
||||||
|
|
||||||
|
const deleteAllFilters = () => {
|
||||||
|
setFilters([])
|
||||||
|
const filtersObject = getFiltersObj([])
|
||||||
|
|
||||||
|
setVariables({
|
||||||
|
phone: filtersObject.phone,
|
||||||
|
name: filtersObject.name,
|
||||||
|
address: filtersObject.address,
|
||||||
|
id: filtersObject.id
|
||||||
|
})
|
||||||
|
|
||||||
|
refetch && refetch()
|
||||||
|
}
|
||||||
|
|
||||||
const filterOptions = R.path(['customerFilters'])(filtersResponse)
|
const filterOptions = R.path(['customerFilters'])(filtersResponse)
|
||||||
|
|
||||||
|
|
@ -131,9 +157,10 @@ const Customers = () => {
|
||||||
/>
|
/>
|
||||||
{filters.length > 0 && (
|
{filters.length > 0 && (
|
||||||
<SearchFilter
|
<SearchFilter
|
||||||
|
entries={customersData.length}
|
||||||
filters={filters}
|
filters={filters}
|
||||||
onFilterDelete={onFilterDelete}
|
onFilterDelete={onFilterDelete}
|
||||||
setFilters={setFilters}
|
deleteAllFilters={deleteAllFilters}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<CustomersList
|
<CustomersList
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue