mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-07-31 21:41:59 +08:00
fix Logs contains issue (#1708)
* chore: logs is updated * chore: contains is updated
This commit is contained in:
parent
65af8c1b98
commit
0480197914
@ -6,24 +6,17 @@ import LogsAggregate from 'container/LogsAggregate';
|
|||||||
import LogsFilters from 'container/LogsFilters';
|
import LogsFilters from 'container/LogsFilters';
|
||||||
import SearchFilter from 'container/LogsSearchFilter';
|
import SearchFilter from 'container/LogsSearchFilter';
|
||||||
import LogsTable from 'container/LogsTable';
|
import LogsTable from 'container/LogsTable';
|
||||||
import React, { memo, useEffect, useMemo } from 'react';
|
import useUrlQuery from 'hooks/useUrlQuery';
|
||||||
|
import React, { memo, useEffect } from 'react';
|
||||||
import { connect, useDispatch } from 'react-redux';
|
import { connect, useDispatch } from 'react-redux';
|
||||||
import { useLocation } from 'react-router-dom';
|
|
||||||
import { bindActionCreators, Dispatch } from 'redux';
|
import { bindActionCreators, Dispatch } from 'redux';
|
||||||
import { ThunkDispatch } from 'redux-thunk';
|
import { ThunkDispatch } from 'redux-thunk';
|
||||||
import { GetLogsFields } from 'store/actions/logs/getFields';
|
import { GetLogsFields } from 'store/actions/logs/getFields';
|
||||||
import AppActions from 'types/actions';
|
import AppActions from 'types/actions';
|
||||||
import { SET_SEARCH_QUERY_STRING } from 'types/actions/logs';
|
import { SET_SEARCH_QUERY_STRING } from 'types/actions/logs';
|
||||||
|
|
||||||
interface LogsProps {
|
|
||||||
getLogsFields: VoidFunction;
|
|
||||||
}
|
|
||||||
function Logs({ getLogsFields }: LogsProps): JSX.Element {
|
function Logs({ getLogsFields }: LogsProps): JSX.Element {
|
||||||
const { search } = useLocation();
|
const urlQuery = useUrlQuery();
|
||||||
|
|
||||||
const urlQuery = useMemo(() => {
|
|
||||||
return new URLSearchParams(search);
|
|
||||||
}, [search]);
|
|
||||||
|
|
||||||
const dispatch = useDispatch();
|
const dispatch = useDispatch();
|
||||||
|
|
||||||
@ -58,6 +51,8 @@ function Logs({ getLogsFields }: LogsProps): JSX.Element {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type LogsProps = DispatchProps;
|
||||||
|
|
||||||
interface DispatchProps {
|
interface DispatchProps {
|
||||||
getLogsFields: () => (dispatch: Dispatch<AppActions>) => void;
|
getLogsFields: () => (dispatch: Dispatch<AppActions>) => void;
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,11 @@ import { v4 } from 'uuid';
|
|||||||
import FieldKey from '../FieldKey';
|
import FieldKey from '../FieldKey';
|
||||||
import { QueryConditionContainer, QueryFieldContainer } from '../styles';
|
import { QueryConditionContainer, QueryFieldContainer } from '../styles';
|
||||||
import { createParsedQueryStructure } from '../utils';
|
import { createParsedQueryStructure } from '../utils';
|
||||||
|
import { hashCode, parseQuery } from './utils';
|
||||||
|
|
||||||
const { Option } = Select;
|
const { Option } = Select;
|
||||||
interface QueryFieldProps {
|
interface QueryFieldProps {
|
||||||
query: { value: string | string[]; type: string }[];
|
query: Query;
|
||||||
queryIndex: number;
|
queryIndex: number;
|
||||||
onUpdate: (query: unknown, queryIndex: number) => void;
|
onUpdate: (query: unknown, queryIndex: number) => void;
|
||||||
onDelete: (queryIndex: number) => void;
|
onDelete: (queryIndex: number) => void;
|
||||||
@ -49,12 +50,12 @@ function QueryField({
|
|||||||
}
|
}
|
||||||
return '';
|
return '';
|
||||||
};
|
};
|
||||||
|
|
||||||
const fieldType = useMemo(() => getFieldType(query[0].value as string), [
|
const fieldType = useMemo(() => getFieldType(query[0].value as string), [
|
||||||
query,
|
query,
|
||||||
]);
|
]);
|
||||||
const handleChange = (qIdx: number, value: string): void => {
|
const handleChange = (qIdx: number, value: string): void => {
|
||||||
query[qIdx].value = value || '';
|
query[qIdx].value = value || '';
|
||||||
|
|
||||||
if (qIdx === 1) {
|
if (qIdx === 1) {
|
||||||
if (Object.values(QueryOperatorsMultiVal).includes(value)) {
|
if (Object.values(QueryOperatorsMultiVal).includes(value)) {
|
||||||
if (!Array.isArray(query[2].value)) {
|
if (!Array.isArray(query[2].value)) {
|
||||||
@ -166,17 +167,8 @@ function QueryConditionField({
|
|||||||
</QueryConditionContainer>
|
</QueryConditionContainer>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const hashCode = (s: string): string => {
|
|
||||||
if (!s) {
|
export type Query = { value: string | string[]; type: string }[];
|
||||||
return '0';
|
|
||||||
}
|
|
||||||
return `${Math.abs(
|
|
||||||
s.split('').reduce((a, b) => {
|
|
||||||
a = (a << 5) - a + b.charCodeAt(0);
|
|
||||||
return a & a;
|
|
||||||
}, 0),
|
|
||||||
)}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
function QueryBuilder({
|
function QueryBuilder({
|
||||||
updateParsedQuery,
|
updateParsedQuery,
|
||||||
@ -201,12 +193,9 @@ function QueryBuilder({
|
|||||||
}
|
}
|
||||||
}, [parsedQuery]);
|
}, [parsedQuery]);
|
||||||
|
|
||||||
const handleUpdate = (
|
const handleUpdate = (query: Query, queryIndex: number): void => {
|
||||||
query: { value: string | string[]; type: string }[],
|
|
||||||
queryIndex: number,
|
|
||||||
): void => {
|
|
||||||
const updatedParsedQuery = generatedQueryStructure;
|
const updatedParsedQuery = generatedQueryStructure;
|
||||||
updatedParsedQuery[queryIndex] = query as never;
|
updatedParsedQuery[queryIndex] = parseQuery(query) as never;
|
||||||
|
|
||||||
const flatParsedQuery = flatten(updatedParsedQuery).filter((q) => q.value);
|
const flatParsedQuery = flatten(updatedParsedQuery).filter((q) => q.value);
|
||||||
keyPrefixRef.current = hashCode(JSON.stringify(flatParsedQuery));
|
keyPrefixRef.current = hashCode(JSON.stringify(flatParsedQuery));
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
import _set from 'lodash-es/set';
|
||||||
|
|
||||||
|
import { Query } from './QueryBuilder';
|
||||||
|
|
||||||
|
export const parseQuery = (queries: Query): Query => {
|
||||||
|
if (Array.isArray(queries)) {
|
||||||
|
const isContainsPresent = queries.find((e) => e.value === 'CONTAINS');
|
||||||
|
if (isContainsPresent) {
|
||||||
|
// find the index of VALUE to update
|
||||||
|
const valueIndex = queries.findIndex((e) => e.type === 'QUERY_VALUE');
|
||||||
|
if (valueIndex > -1) {
|
||||||
|
// update the value to wrap with ""
|
||||||
|
_set(
|
||||||
|
queries,
|
||||||
|
[valueIndex, 'value'],
|
||||||
|
`'${queries[valueIndex].value || ''}'`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return queries;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return queries;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const hashCode = (s: string): string => {
|
||||||
|
if (!s) {
|
||||||
|
return '0';
|
||||||
|
}
|
||||||
|
return `${Math.abs(
|
||||||
|
s.split('').reduce((a, b) => {
|
||||||
|
// eslint-disable-next-line no-bitwise, no-param-reassign
|
||||||
|
a = (a << 5) - a + b.charCodeAt(0);
|
||||||
|
// eslint-disable-next-line no-bitwise
|
||||||
|
return a & a;
|
||||||
|
}, 0),
|
||||||
|
)}`;
|
||||||
|
};
|
@ -2,9 +2,14 @@
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
|
|
||||||
import { QueryTypes } from 'lib/logql/tokens';
|
import { QueryTypes, QueryOperatorsSingleVal } from 'lib/logql/tokens';
|
||||||
|
|
||||||
export const queryKOVPair = () => [
|
export interface QueryFields {
|
||||||
|
type: keyof typeof QueryTypes;
|
||||||
|
value: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const queryKOVPair = (): QueryFields[] => [
|
||||||
{
|
{
|
||||||
type: QueryTypes.QUERY_KEY,
|
type: QueryTypes.QUERY_KEY,
|
||||||
value: null,
|
value: null,
|
||||||
|
@ -15,9 +15,6 @@ import { ILogsReducer } from 'types/reducer/logs';
|
|||||||
|
|
||||||
import { Container, Heading } from './styles';
|
import { Container, Heading } from './styles';
|
||||||
|
|
||||||
interface LogsTableProps {
|
|
||||||
getLogs: (props: Parameters<typeof getLogs>[0]) => ReturnType<typeof getLogs>;
|
|
||||||
}
|
|
||||||
function LogsTable({ getLogs }: LogsTableProps): JSX.Element {
|
function LogsTable({ getLogs }: LogsTableProps): JSX.Element {
|
||||||
const {
|
const {
|
||||||
searchFilter: { queryString },
|
searchFilter: { queryString },
|
||||||
@ -51,6 +48,7 @@ function LogsTable({ getLogs }: LogsTableProps): JSX.Element {
|
|||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return <Spinner height={20} tip="Getting Logs" />;
|
return <Spinner height={20} tip="Getting Logs" />;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Container flex="auto">
|
<Container flex="auto">
|
||||||
<Heading>
|
<Heading>
|
||||||
@ -86,4 +84,8 @@ const mapDispatchToProps = (
|
|||||||
getLogs: bindActionCreators(getLogs, dispatch),
|
getLogs: bindActionCreators(getLogs, dispatch),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
interface LogsTableProps {
|
||||||
|
getLogs: (props: Parameters<typeof getLogs>[0]) => ReturnType<typeof getLogs>;
|
||||||
|
}
|
||||||
|
|
||||||
export default connect(null, mapDispatchToProps)(memo(LogsTable));
|
export default connect(null, mapDispatchToProps)(memo(LogsTable));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user