Skip to content

Commit

Permalink
Préavis - Limite la fréquence des appels API après changement de filt…
Browse files Browse the repository at this point in the history
…re dans la liste (#3780)

## Linked issues

- Resolve #3773

----

- [ ] Tests E2E (Cypress)
  • Loading branch information
ivangabriele authored Oct 18, 2024
2 parents ea0324b + 697d707 commit 8fdc5c1
Showing 1 changed file with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import { isLegacyFirefox } from '@utils/isLegacyFirefox'
import { useIsSuperUser } from 'auth/hooks/useIsSuperUser'
import { useCallback, useEffect, useRef, useState } from 'react'
import styled, { css } from 'styled-components'
import { useDebounce } from 'use-debounce'

import { getTableColumns } from './columns'
import { DEFAULT_PAGE_SIZE, SUB_MENUS_AS_OPTIONS } from './constants'
import { DEFAULT_PAGE_SIZE, ExpectedArrivalPeriod, SUB_MENUS_AS_OPTIONS } from './constants'
import { FilterBar } from './FilterBar'
import { FilterTags } from './FilterTags'
import { Row } from './Row'
Expand Down Expand Up @@ -68,16 +69,26 @@ export function PriorNotificationList({ isFromUrl }: PriorNotificationListProps)
BackendApi.SortDirection.DESC
)

const rtkQueryParams = {
apiPaginationParams,
apiSortingParams,
listFilter
}
const [rtkQueryParams] = useDebounce(
{
apiPaginationParams,
apiSortingParams,
listFilter
},
1000
)
const areRtkQueryParamsValid = !(
rtkQueryParams.listFilter.expectedArrivalPeriod === ExpectedArrivalPeriod.CUSTOM &&
!rtkQueryParams.listFilter.expectedArrivalCustomPeriod
)
// `!!error` !== `isError` because `isError` is `false` when the query is fetching.
const { data, error, isError, isFetching } = useGetPriorNotificationsQuery(rtkQueryParams, {
...RTK_ONE_MINUTE_POLLING_QUERY_OPTIONS,
...RTK_FORCE_REFETCH_QUERY_OPTIONS
})
const { data, error, isError, isFetching } = useGetPriorNotificationsQuery(
areRtkQueryParamsValid ? rtkQueryParams : skipToken,
{
...RTK_ONE_MINUTE_POLLING_QUERY_OPTIONS,
...RTK_FORCE_REFETCH_QUERY_OPTIONS
}
)
useHandleFrontendApiError(
DisplayedErrorKey.SIDE_WINDOW_PRIOR_NOTIFICATION_LIST_ERROR,
error,
Expand Down

0 comments on commit 8fdc5c1

Please sign in to comment.