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:
parent
8137de0be7
commit
8c2a502ead
@ -1,9 +1,4 @@
|
|||||||
import {
|
import { encodeQueryParams, StringParam, withDefault } from 'use-query-params';
|
||||||
encodeQueryParams,
|
|
||||||
NumberParam,
|
|
||||||
StringParam,
|
|
||||||
withDefault,
|
|
||||||
} from 'use-query-params';
|
|
||||||
import { FilterItemParam } from 'utils/serializeQueryParams';
|
import { FilterItemParam } from 'utils/serializeQueryParams';
|
||||||
import { usePersistentTableState } from 'hooks/usePersistentTableState';
|
import { usePersistentTableState } from 'hooks/usePersistentTableState';
|
||||||
import mapValues from 'lodash.mapvalues';
|
import mapValues from 'lodash.mapvalues';
|
||||||
@ -11,6 +6,7 @@ import { useEventSearch } from 'hooks/api/getters/useEventSearch/useEventSearch'
|
|||||||
import type { SearchEventsParams } from 'openapi';
|
import type { SearchEventsParams } from 'openapi';
|
||||||
import type { FilterItemParamHolder } from 'component/filter/Filters/Filters';
|
import type { FilterItemParamHolder } from 'component/filter/Filters/Filters';
|
||||||
import { format, subYears } from 'date-fns';
|
import { format, subYears } from 'date-fns';
|
||||||
|
import { SafeNumberParam } from 'utils/safeNumberParam';
|
||||||
|
|
||||||
type Log =
|
type Log =
|
||||||
| { type: 'global' }
|
| { type: 'global' }
|
||||||
@ -58,8 +54,8 @@ export const useEventLogSearch = (
|
|||||||
refreshInterval = 15 * 1000,
|
refreshInterval = 15 * 1000,
|
||||||
) => {
|
) => {
|
||||||
const stateConfig = {
|
const stateConfig = {
|
||||||
offset: withDefault(NumberParam, 0),
|
offset: withDefault(SafeNumberParam, 0),
|
||||||
limit: withDefault(NumberParam, DEFAULT_PAGE_SIZE),
|
limit: withDefault(SafeNumberParam, DEFAULT_PAGE_SIZE),
|
||||||
query: StringParam,
|
query: StringParam,
|
||||||
from: withDefault(FilterItemParam, {
|
from: withDefault(FilterItemParam, {
|
||||||
values: [format(subYears(new Date(), 1), 'yyyy-MM-dd')],
|
values: [format(subYears(new Date(), 1), 'yyyy-MM-dd')],
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
import { useCallback } from 'react';
|
import { useCallback } from 'react';
|
||||||
import {
|
import { encodeQueryParams, StringParam, withDefault } from 'use-query-params';
|
||||||
encodeQueryParams,
|
|
||||||
NumberParam,
|
|
||||||
StringParam,
|
|
||||||
withDefault,
|
|
||||||
} from 'use-query-params';
|
|
||||||
import {
|
import {
|
||||||
DEFAULT_PAGE_LIMIT,
|
DEFAULT_PAGE_LIMIT,
|
||||||
useFeatureSearch,
|
useFeatureSearch,
|
||||||
@ -16,12 +11,13 @@ import {
|
|||||||
import { usePersistentTableState } from 'hooks/usePersistentTableState';
|
import { usePersistentTableState } from 'hooks/usePersistentTableState';
|
||||||
import mapValues from 'lodash.mapvalues';
|
import mapValues from 'lodash.mapvalues';
|
||||||
import type { SearchFeaturesParams } from 'openapi';
|
import type { SearchFeaturesParams } from 'openapi';
|
||||||
|
import { SafeNumberParam } from 'utils/safeNumberParam';
|
||||||
|
|
||||||
export const useGlobalFeatureSearch = (pageLimit = DEFAULT_PAGE_LIMIT) => {
|
export const useGlobalFeatureSearch = (pageLimit = DEFAULT_PAGE_LIMIT) => {
|
||||||
const storageKey = 'features-list-table';
|
const storageKey = 'features-list-table';
|
||||||
const stateConfig = {
|
const stateConfig = {
|
||||||
offset: withDefault(NumberParam, 0),
|
offset: withDefault(SafeNumberParam, 0),
|
||||||
limit: withDefault(NumberParam, pageLimit),
|
limit: withDefault(SafeNumberParam, pageLimit),
|
||||||
query: StringParam,
|
query: StringParam,
|
||||||
favoritesFirst: withDefault(BooleansStringParam, true),
|
favoritesFirst: withDefault(BooleansStringParam, true),
|
||||||
sortBy: withDefault(StringParam, 'createdAt'),
|
sortBy: withDefault(StringParam, 'createdAt'),
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import {
|
import {
|
||||||
ArrayParam,
|
ArrayParam,
|
||||||
encodeQueryParams,
|
encodeQueryParams,
|
||||||
NumberParam,
|
|
||||||
StringParam,
|
StringParam,
|
||||||
withDefault,
|
withDefault,
|
||||||
} from 'use-query-params';
|
} from 'use-query-params';
|
||||||
@ -16,6 +15,7 @@ import {
|
|||||||
import { usePersistentTableState } from 'hooks/usePersistentTableState';
|
import { usePersistentTableState } from 'hooks/usePersistentTableState';
|
||||||
import mapValues from 'lodash.mapvalues';
|
import mapValues from 'lodash.mapvalues';
|
||||||
import type { SearchFeaturesParams } from 'openapi';
|
import type { SearchFeaturesParams } from 'openapi';
|
||||||
|
import { SafeNumberParam } from 'utils/safeNumberParam';
|
||||||
|
|
||||||
type Attribute =
|
type Attribute =
|
||||||
| { key: 'tag'; operator: 'INCLUDE' }
|
| { key: 'tag'; operator: 'INCLUDE' }
|
||||||
@ -28,8 +28,8 @@ export const useProjectFeatureSearch = (
|
|||||||
refreshInterval = 15 * 1000,
|
refreshInterval = 15 * 1000,
|
||||||
) => {
|
) => {
|
||||||
const stateConfig = {
|
const stateConfig = {
|
||||||
offset: withDefault(NumberParam, 0),
|
offset: withDefault(SafeNumberParam, 0),
|
||||||
limit: withDefault(NumberParam, DEFAULT_PAGE_LIMIT),
|
limit: withDefault(SafeNumberParam, DEFAULT_PAGE_LIMIT),
|
||||||
query: StringParam,
|
query: StringParam,
|
||||||
favoritesFirst: withDefault(BooleansStringParam, true),
|
favoritesFirst: withDefault(BooleansStringParam, true),
|
||||||
sortBy: withDefault(StringParam, 'createdAt'),
|
sortBy: withDefault(StringParam, 'createdAt'),
|
||||||
|
9
frontend/src/utils/safeNumberParam.ts
Normal file
9
frontend/src/utils/safeNumberParam.ts
Normal 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;
|
||||||
|
},
|
||||||
|
};
|
Loading…
Reference in New Issue
Block a user