Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Préavis - Limite la fréquence des appels API après changement de filtre dans la liste #3780

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading