1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-24 17:51:14 +02:00

fix: limit and offset with non numbers

This commit is contained in:
kwasniew 2025-09-09 12:58:51 +02:00
parent 8137de0be7
commit 8c2a502ead
No known key found for this signature in database
GPG Key ID: 43A7CBC24C119560
4 changed files with 20 additions and 19 deletions

View File

@ -1,9 +1,4 @@
import {
encodeQueryParams,
NumberParam,
StringParam,
withDefault,
} from 'use-query-params';
import { encodeQueryParams, StringParam, withDefault } from 'use-query-params';
import { FilterItemParam } from 'utils/serializeQueryParams';
import { usePersistentTableState } from 'hooks/usePersistentTableState';
import mapValues from 'lodash.mapvalues';
@ -11,6 +6,7 @@ import { useEventSearch } from 'hooks/api/getters/useEventSearch/useEventSearch'
import type { SearchEventsParams } from 'openapi';
import type { FilterItemParamHolder } from 'component/filter/Filters/Filters';
import { format, subYears } from 'date-fns';
import { SafeNumberParam } from 'utils/safeNumberParam';
type Log =
| { type: 'global' }
@ -58,8 +54,8 @@ export const useEventLogSearch = (
refreshInterval = 15 * 1000,
) => {
const stateConfig = {
offset: withDefault(NumberParam, 0),
limit: withDefault(NumberParam, DEFAULT_PAGE_SIZE),
offset: withDefault(SafeNumberParam, 0),
limit: withDefault(SafeNumberParam, DEFAULT_PAGE_SIZE),
query: StringParam,
from: withDefault(FilterItemParam, {
values: [format(subYears(new Date(), 1), 'yyyy-MM-dd')],

View File

@ -1,10 +1,5 @@
import { useCallback } from 'react';
import {
encodeQueryParams,
NumberParam,
StringParam,
withDefault,
} from 'use-query-params';
import { encodeQueryParams, StringParam, withDefault } from 'use-query-params';
import {
DEFAULT_PAGE_LIMIT,
useFeatureSearch,
@ -16,12 +11,13 @@ import {
import { usePersistentTableState } from 'hooks/usePersistentTableState';
import mapValues from 'lodash.mapvalues';
import type { SearchFeaturesParams } from 'openapi';
import { SafeNumberParam } from 'utils/safeNumberParam';
export const useGlobalFeatureSearch = (pageLimit = DEFAULT_PAGE_LIMIT) => {
const storageKey = 'features-list-table';
const stateConfig = {
offset: withDefault(NumberParam, 0),
limit: withDefault(NumberParam, pageLimit),
offset: withDefault(SafeNumberParam, 0),
limit: withDefault(SafeNumberParam, pageLimit),
query: StringParam,
favoritesFirst: withDefault(BooleansStringParam, true),
sortBy: withDefault(StringParam, 'createdAt'),

View File

@ -1,7 +1,6 @@
import {
ArrayParam,
encodeQueryParams,
NumberParam,
StringParam,
withDefault,
} from 'use-query-params';
@ -16,6 +15,7 @@ import {
import { usePersistentTableState } from 'hooks/usePersistentTableState';
import mapValues from 'lodash.mapvalues';
import type { SearchFeaturesParams } from 'openapi';
import { SafeNumberParam } from 'utils/safeNumberParam';
type Attribute =
| { key: 'tag'; operator: 'INCLUDE' }
@ -28,8 +28,8 @@ export const useProjectFeatureSearch = (
refreshInterval = 15 * 1000,
) => {
const stateConfig = {
offset: withDefault(NumberParam, 0),
limit: withDefault(NumberParam, DEFAULT_PAGE_LIMIT),
offset: withDefault(SafeNumberParam, 0),
limit: withDefault(SafeNumberParam, DEFAULT_PAGE_LIMIT),
query: StringParam,
favoritesFirst: withDefault(BooleansStringParam, true),
sortBy: withDefault(StringParam, 'createdAt'),

View File

@ -0,0 +1,9 @@
import { encodeNumber, decodeNumber } from 'serialize-query-params';
export const SafeNumberParam = {
encode: encodeNumber,
decode: (input: any) => {
const result = decodeNumber(input);
return result == null ? result : Number.isNaN(result) ? null : result;
},
};