Skip to content

Commit

Permalink
user default filter fix
Browse files Browse the repository at this point in the history
added total to logistic
  • Loading branch information
nsylwa committed Oct 19, 2023
1 parent 3c3030f commit fa43d30
Show file tree
Hide file tree
Showing 5 changed files with 2,802 additions and 2,870 deletions.
13 changes: 11 additions & 2 deletions components/logistic/Logistic.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ const Logistic = () => {

const groupByType = groupByOneKey(shippingList, x => x.contentType)

groupByType.set('ВСЕ ТИПЫ', shippingList)

const tableData: LogisticDataType[] = [...groupByType.entries()].map(([type, shippings]) => {
const row: LogisticDataType = {
contentType: type,
Expand Down Expand Up @@ -75,9 +77,16 @@ const Logistic = () => {
return row
})

console.log(tableData)
const sorted = tableData.sort((a, b) => a.contentType.localeCompare(b.contentType))

const x = sorted.findIndex(x => x.contentType === 'ВСЕ ТИПЫ')

const a = [
sorted[x],
...sorted.slice(0, x),
...sorted.slice(x + 1)]

setTableData(tableData.sort((a, b) => a.contentType.localeCompare(b.contentType)))
setTableData(a)
}
}, [data, dateRange])

Expand Down
1 change: 1 addition & 0 deletions components/shippingTable/ShippingTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ export default function ShippingTable(props: ShippintTableProps) {


useEffect(() => {
console.log('data', filtered)
setTableData(shippigDataToTableData(filtered))
}, [filtered])

Expand Down
16 changes: 11 additions & 5 deletions components/shippingTable/filters/Filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export function TableFilters(props: TableFiltersProps) {
const [searchId, setSearchId] = useState<number | undefined>(undefined)
const [filters, setFilters] = useState<Filters>(new Map(initialColumns.map((x) => ([x.key! as string, undefined]))))


const [privateFiltered, setPrivateFiltered] = useState<Shipping[]>([])

useEffect(() => {
let filtered = shippings;

Expand All @@ -54,20 +57,22 @@ export function TableFilters(props: TableFiltersProps) {
})
}
})
setFiltered(filtered)
}, [shippings, filters, setFiltered, userFilters])

setPrivateFiltered(filtered)
}, [shippings, filters, setFiltered, userFilters, user])


useEffect(() => {
let filtered = shippings;
let filtered = privateFiltered

if (searchId) {
filtered = shippings.filter(shipping =>
filtered = filtered.filter(shipping =>
shipping.number.toString().startsWith(searchId.toString())
)
}

setFiltered(filtered)
}, [searchId, setFiltered, shippings])
}, [privateFiltered, searchId, setFiltered, shippings])


const clearColumnFilters = () => {
Expand All @@ -77,6 +82,7 @@ export function TableFilters(props: TableFiltersProps) {

return <>
{user.role !== 'admin' && <UserFilter
user={user}
userFilters={userFilters}
setUserFilters={setUserFilters}
/>}
Expand Down
33 changes: 21 additions & 12 deletions components/shippingTable/filters/UserFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
import { Shipping } from "@/interfaces/Shipping"
import { User } from "@/interfaces/UserInterface"
import { UserFilterFunction, userFilterList, userFilterMap, UserFilterOption } from "@/utils/filterUtils"
import { FilterFilled } from "@ant-design/icons"
import { Select } from "antd"
import { useState } from "react"
import { useEffect, useMemo, useState } from "react"


interface UserFilterProps {
user: User,
userFilters: UserFilterFunction[],
setUserFilters: (e: UserFilterFunction[]) => void
}


export function UserFilter(props: UserFilterProps) {

const { setUserFilters } = props
const { setUserFilters, user } = props
const [state, setState] = useState('all')

const handleOnChangeFilter = (option: UserFilterOption) => {
setState(option.value)
setUserFilters([
(shipping: Shipping, userId: string) => {
return shipping.toId === userId || shipping.fromId === userId
},
userFilterMap.get(option.value)!
])
useEffect(() => {
const defaultUserFilter = (shipping: Shipping, userId: string) => shipping.toId === userId || shipping.fromId === userId

}
const filters = []
if (user.role !== 'admin') {
console.log('def filter')
filters.push(defaultUserFilter)
}
filters.push(userFilterMap.get(state)!)
setUserFilters(filters)

}, [setUserFilters, state, user])






return <>
<Select
suffixIcon={<FilterFilled />}
defaultValue="all"
style={{ width: 200 }}
onChange={(_, option) => handleOnChangeFilter(option as UserFilterOption)}
onChange={(_, option) => setState((option as UserFilterOption).value)}
options={userFilterList}
value={state}
/>
Expand Down
Loading

0 comments on commit fa43d30

Please sign in to comment.