mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-01 02:22:00 +08:00
fix: handled value as string from queryParams for trace filters (#5274)
* fix: handled value as string from queryParams for trace filters * fix: added isArray check
This commit is contained in:
parent
afcee9cd02
commit
b59d9c7b90
@ -4,7 +4,7 @@ import { Button, Card, Checkbox, Input, Tooltip } from 'antd';
|
|||||||
import { CheckboxChangeEvent } from 'antd/es/checkbox';
|
import { CheckboxChangeEvent } from 'antd/es/checkbox';
|
||||||
import { ParaGraph } from 'container/Trace/Filters/Panel/PanelBody/Common/styles';
|
import { ParaGraph } from 'container/Trace/Filters/Panel/PanelBody/Common/styles';
|
||||||
import useDebouncedFn from 'hooks/useDebouncedFunction';
|
import useDebouncedFn from 'hooks/useDebouncedFunction';
|
||||||
import { defaultTo, isEmpty } from 'lodash-es';
|
import { isArray, isEmpty } from 'lodash-es';
|
||||||
import {
|
import {
|
||||||
ChangeEvent,
|
ChangeEvent,
|
||||||
Dispatch,
|
Dispatch,
|
||||||
@ -17,6 +17,7 @@ import {
|
|||||||
import {
|
import {
|
||||||
addFilter,
|
addFilter,
|
||||||
AllTraceFilterKeys,
|
AllTraceFilterKeys,
|
||||||
|
convertToStringArr,
|
||||||
FilterType,
|
FilterType,
|
||||||
HandleRunProps,
|
HandleRunProps,
|
||||||
removeFilter,
|
removeFilter,
|
||||||
@ -37,15 +38,14 @@ export function SectionBody(props: SectionBodyProps): JSX.Element {
|
|||||||
const [searchFilter, setSearchFilter] = useState<string>('');
|
const [searchFilter, setSearchFilter] = useState<string>('');
|
||||||
const [searchText, setSearchText] = useState<string>('');
|
const [searchText, setSearchText] = useState<string>('');
|
||||||
const [checkedItems, setCheckedItems] = useState<string[]>(
|
const [checkedItems, setCheckedItems] = useState<string[]>(
|
||||||
defaultTo(selectedFilters?.[type]?.values as string[], []),
|
convertToStringArr(selectedFilters?.[type]?.values),
|
||||||
);
|
);
|
||||||
|
|
||||||
const [results, setResults] = useState<string[]>([]);
|
const [results, setResults] = useState<string[]>([]);
|
||||||
const [isFetching, setFetching] = useState<boolean>(false);
|
const [isFetching, setFetching] = useState<boolean>(false);
|
||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
() =>
|
() => setCheckedItems(convertToStringArr(selectedFilters?.[type]?.values)),
|
||||||
setCheckedItems(defaultTo(selectedFilters?.[type]?.values as string[], [])),
|
|
||||||
[selectedFilters, type],
|
[selectedFilters, type],
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -92,17 +92,21 @@ export function SectionBody(props: SectionBodyProps): JSX.Element {
|
|||||||
if (checked) {
|
if (checked) {
|
||||||
addFilter(type, newValue, setSelectedFilters, keys);
|
addFilter(type, newValue, setSelectedFilters, keys);
|
||||||
setCheckedItems((prev) => {
|
setCheckedItems((prev) => {
|
||||||
if (!prev.includes(newValue)) {
|
const arr = prev || [];
|
||||||
prev.push(newValue);
|
if (isArray(arr) && !arr.includes(newValue)) {
|
||||||
|
arr.push(newValue);
|
||||||
}
|
}
|
||||||
return prev;
|
return convertToStringArr(arr);
|
||||||
});
|
});
|
||||||
} else if (checkedItems.length === 1) {
|
} else if (checkedItems.length === 1) {
|
||||||
handleRun({ clearByType: type });
|
handleRun({ clearByType: type });
|
||||||
setCheckedItems([]);
|
setCheckedItems([]);
|
||||||
} else {
|
} else {
|
||||||
removeFilter(type, newValue, setSelectedFilters, keys);
|
removeFilter(type, newValue, setSelectedFilters, keys);
|
||||||
setCheckedItems((prev) => prev.filter((item) => item !== newValue));
|
setCheckedItems((prev) => {
|
||||||
|
const prevValue = convertToStringArr(prev);
|
||||||
|
return prevValue.filter((item) => item !== newValue);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
/* eslint-disable react-hooks/exhaustive-deps */
|
/* eslint-disable react-hooks/exhaustive-deps */
|
||||||
import { getAttributesValues } from 'api/queryBuilder/getAttributesValues';
|
import { getAttributesValues } from 'api/queryBuilder/getAttributesValues';
|
||||||
import { isArray } from 'lodash-es';
|
|
||||||
import { Dispatch, SetStateAction, useEffect, useState } from 'react';
|
import { Dispatch, SetStateAction, useEffect, useState } from 'react';
|
||||||
import {
|
import {
|
||||||
BaseAutocompleteData,
|
BaseAutocompleteData,
|
||||||
@ -41,6 +40,18 @@ export type FilterType = Record<
|
|||||||
{ values: string[] | string; keys: BaseAutocompleteData }
|
{ values: string[] | string; keys: BaseAutocompleteData }
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
export function convertToStringArr(
|
||||||
|
value: string | string[] | undefined,
|
||||||
|
): string[] {
|
||||||
|
if (value) {
|
||||||
|
if (typeof value === 'string') {
|
||||||
|
return [value];
|
||||||
|
}
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
export const addFilter = (
|
export const addFilter = (
|
||||||
filterType: AllTraceFilterKeys,
|
filterType: AllTraceFilterKeys,
|
||||||
value: string,
|
value: string,
|
||||||
@ -62,28 +73,36 @@ export const addFilter = (
|
|||||||
'durationNano',
|
'durationNano',
|
||||||
].includes(filterType);
|
].includes(filterType);
|
||||||
|
|
||||||
|
// Convert value to string array
|
||||||
|
const valueArray = convertToStringArr(value);
|
||||||
|
|
||||||
// If previous filters are undefined, initialize them
|
// If previous filters are undefined, initialize them
|
||||||
if (!prevFilters) {
|
if (!prevFilters) {
|
||||||
return ({
|
return ({
|
||||||
[filterType]: { values: isDuration ? value : [value], keys },
|
[filterType]: { values: isDuration ? value : valueArray, keys },
|
||||||
} as unknown) as FilterType;
|
} as unknown) as FilterType;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the filter type doesn't exist, initialize it
|
// If the filter type doesn't exist, initialize it
|
||||||
if (!prevFilters[filterType]?.values.length) {
|
if (!prevFilters[filterType]?.values.length) {
|
||||||
return {
|
return {
|
||||||
...prevFilters,
|
...prevFilters,
|
||||||
[filterType]: { values: isDuration ? value : [value], keys },
|
[filterType]: { values: isDuration ? value : valueArray, keys },
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
// If the value already exists, don't add it again
|
// If the value already exists, don't add it again
|
||||||
if (prevFilters[filterType].values.includes(value)) {
|
if (convertToStringArr(prevFilters[filterType].values).includes(value)) {
|
||||||
return prevFilters;
|
return prevFilters;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, add the value to the existing array
|
// Otherwise, add the value to the existing array
|
||||||
return {
|
return {
|
||||||
...prevFilters,
|
...prevFilters,
|
||||||
[filterType]: {
|
[filterType]: {
|
||||||
values: isDuration ? value : [...prevFilters[filterType].values, value],
|
values: isDuration
|
||||||
|
? value
|
||||||
|
: [...convertToStringArr(prevFilters[filterType].values), value],
|
||||||
keys,
|
keys,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -110,10 +129,8 @@ export const removeFilter = (
|
|||||||
return prevFilters;
|
return prevFilters;
|
||||||
}
|
}
|
||||||
|
|
||||||
const prevValue = prevFilters[filterType]?.values;
|
const prevValue = convertToStringArr(prevFilters[filterType]?.values);
|
||||||
const updatedValues = !isArray(prevValue)
|
const updatedValues = prevValue.filter((item: any) => item !== value);
|
||||||
? prevValue
|
|
||||||
: prevValue?.filter((item: any) => item !== value);
|
|
||||||
|
|
||||||
if (updatedValues.length === 0) {
|
if (updatedValues.length === 0) {
|
||||||
const { [filterType]: item, ...remainingFilters } = prevFilters;
|
const { [filterType]: item, ...remainingFilters } = prevFilters;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user