Skip to content

Commit

Permalink
Add debounce of vessel search in pno list
Browse files Browse the repository at this point in the history
  • Loading branch information
louptheron committed Dec 20, 2024
1 parent a0ded4d commit 202b516
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
1 change: 0 additions & 1 deletion frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
"@sentry/vite-plugin": "^2.22.6",
"@tanstack/react-table": "8.20.5",
"@tanstack/react-virtual": "3.11.2",
"@tanstack/virtual-core": "3.11.2",
"comlink": "4.4.2",
"date-fns": "3.6.0",
"dayjs": "1.11.13",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import {
} from '@mtes-mct/monitor-ui'
import { assertNotNullish } from '@utils/assertNotNullish'
import { uniq } from 'lodash'
import { useCallback } from 'react'
import { useCallback, useState } from 'react'
import styled from 'styled-components'
import { useDebouncedCallback } from 'use-debounce'

import {
LAST_CONTROL_PERIODS_AS_OPTIONS,
Expand All @@ -41,6 +42,7 @@ export function FilterBar() {
const dispatch = useMainAppDispatch()
const isSuperUser = useIsSuperUser()
const { newWindowContainerRef } = useNewWindow()
const [searchQuery, setSearchQuery] = useState<string | undefined>(undefined)
const listFilterValues = useMainAppSelector(store => store.priorNotification.listFilterValues)

const { fleetSegmentsAsOptions } = useGetFleetSegmentsAsOptions()
Expand Down Expand Up @@ -104,8 +106,13 @@ export function FilterBar() {
dispatch(priorNotificationActions.setListFilterValues({ priorNotificationTypes: nextPriorNotificationTypes }))
}

const updateSearchQuery = (nextSearchQuery: string | undefined) => {
const updateSliceSearchQuery = useDebouncedCallback((nextSearchQuery: string | undefined) => {
dispatch(priorNotificationActions.setListFilterValues({ searchQuery: nextSearchQuery }))
}, 250)

const updateSearchQuery = (nextSearchQuery: string | undefined) => {
setSearchQuery(nextSearchQuery)
updateSliceSearchQuery(nextSearchQuery)
}

const updateSpecyCodes = (nextSpecyCodes: string[] | undefined) => {
Expand All @@ -132,7 +139,7 @@ export function FilterBar() {
onChange={updateSearchQuery}
placeholder="Rechercher un navire"
size={Size.LARGE}
value={listFilterValues.searchQuery}
value={searchQuery}
/>
</Row>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useTableVirtualizer } from '@hooks/useTableVirtualizer'
import { DisplayedErrorKey } from '@libs/DisplayedError/constants'
import { Icon, IconButton, TableWithSelectableRows, THEME } from '@mtes-mct/monitor-ui'
import { flexRender, getCoreRowModel, getSortedRowModel, useReactTable } from '@tanstack/react-table'
import { notUndefined } from '@tanstack/virtual-core'
import { notUndefined } from '@tanstack/react-virtual'
import { downloadAsCsv } from '@utils/downloadAsCsv'
import { isLegacyFirefox } from '@utils/isLegacyFirefox'
import { pluralize } from '@utils/pluralize'
Expand Down

0 comments on commit 202b516

Please sign in to comment.