mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-07-26 04:04:29 +08:00
fix: empty filters field (#3290)
This commit is contained in:
parent
3b22698e35
commit
c35f2ec0aa
@ -1,3 +1,4 @@
|
|||||||
|
import { initialFilters } from 'constants/queryBuilder';
|
||||||
import { getPaginationQueryData } from 'lib/newQueryBuilder/getPaginationQueryData';
|
import { getPaginationQueryData } from 'lib/newQueryBuilder/getPaginationQueryData';
|
||||||
import { ILog } from 'types/api/logs/log';
|
import { ILog } from 'types/api/logs/log';
|
||||||
import {
|
import {
|
||||||
@ -28,7 +29,7 @@ export const getRequestData = ({
|
|||||||
if (!query) return null;
|
if (!query) return null;
|
||||||
|
|
||||||
const paginateData = getPaginationQueryData({
|
const paginateData = getPaginationQueryData({
|
||||||
currentStagedQueryData: stagedQueryData,
|
filters: stagedQueryData?.filters || initialFilters,
|
||||||
listItemId: log ? log.id : null,
|
listItemId: log ? log.id : null,
|
||||||
orderByTimestamp,
|
orderByTimestamp,
|
||||||
page,
|
page,
|
||||||
|
@ -3,7 +3,9 @@ import TabLabel from 'components/TabLabel';
|
|||||||
import { QueryParams } from 'constants/query';
|
import { QueryParams } from 'constants/query';
|
||||||
import {
|
import {
|
||||||
initialAutocompleteData,
|
initialAutocompleteData,
|
||||||
|
initialFilters,
|
||||||
initialQueriesMap,
|
initialQueriesMap,
|
||||||
|
initialQueryBuilderFormValues,
|
||||||
PANEL_TYPES,
|
PANEL_TYPES,
|
||||||
} from 'constants/queryBuilder';
|
} from 'constants/queryBuilder';
|
||||||
import { queryParamNamesMap } from 'constants/queryBuilderQueryNames';
|
import { queryParamNamesMap } from 'constants/queryBuilderQueryNames';
|
||||||
@ -36,6 +38,7 @@ import {
|
|||||||
IBuilderQuery,
|
IBuilderQuery,
|
||||||
OrderByPayload,
|
OrderByPayload,
|
||||||
Query,
|
Query,
|
||||||
|
TagFilter,
|
||||||
} from 'types/api/queryBuilder/queryBuilderData';
|
} from 'types/api/queryBuilder/queryBuilderData';
|
||||||
import { DataSource, StringOperators } from 'types/common/queryBuilder';
|
import { DataSource, StringOperators } from 'types/common/queryBuilder';
|
||||||
import { GlobalReducer } from 'types/reducer/globalTime';
|
import { GlobalReducer } from 'types/reducer/globalTime';
|
||||||
@ -75,19 +78,19 @@ function LogsExplorerViews(): JSX.Element {
|
|||||||
|
|
||||||
const handleAxisError = useAxiosError();
|
const handleAxisError = useAxiosError();
|
||||||
|
|
||||||
const currentStagedQueryData = useMemo(() => {
|
const listQuery = useMemo(() => {
|
||||||
if (!stagedQuery || stagedQuery.builder.queryData.length !== 1) return null;
|
if (!stagedQuery || stagedQuery.builder.queryData.length < 1) return null;
|
||||||
|
|
||||||
return stagedQuery.builder.queryData[0];
|
return stagedQuery.builder.queryData.find((item) => !item.disabled) || null;
|
||||||
}, [stagedQuery]);
|
}, [stagedQuery]);
|
||||||
|
|
||||||
const orderByTimestamp: OrderByPayload | null = useMemo(() => {
|
const orderByTimestamp: OrderByPayload | null = useMemo(() => {
|
||||||
const timestampOrderBy = currentStagedQueryData?.orderBy.find(
|
const timestampOrderBy = listQuery?.orderBy.find(
|
||||||
(item) => item.columnName === 'timestamp',
|
(item) => item.columnName === 'timestamp',
|
||||||
);
|
);
|
||||||
|
|
||||||
return timestampOrderBy || null;
|
return timestampOrderBy || null;
|
||||||
}, [currentStagedQueryData]);
|
}, [listQuery]);
|
||||||
|
|
||||||
const isMultipleQueries = useMemo(
|
const isMultipleQueries = useMemo(
|
||||||
() =>
|
() =>
|
||||||
@ -106,17 +109,17 @@ function LogsExplorerViews(): JSX.Element {
|
|||||||
}, [currentQuery]);
|
}, [currentQuery]);
|
||||||
|
|
||||||
const isLimit: boolean = useMemo(() => {
|
const isLimit: boolean = useMemo(() => {
|
||||||
if (!currentStagedQueryData) return false;
|
if (!listQuery) return false;
|
||||||
if (!currentStagedQueryData.limit) return false;
|
if (!listQuery.limit) return false;
|
||||||
|
|
||||||
return logs.length >= currentStagedQueryData.limit;
|
return logs.length >= listQuery.limit;
|
||||||
}, [logs.length, currentStagedQueryData]);
|
}, [logs.length, listQuery]);
|
||||||
|
|
||||||
const listChartQuery = useMemo(() => {
|
const listChartQuery = useMemo(() => {
|
||||||
if (!stagedQuery || !currentStagedQueryData) return null;
|
if (!stagedQuery || !listQuery) return null;
|
||||||
|
|
||||||
const modifiedQueryData: IBuilderQuery = {
|
const modifiedQueryData: IBuilderQuery = {
|
||||||
...currentStagedQueryData,
|
...listQuery,
|
||||||
aggregateOperator: StringOperators.COUNT,
|
aggregateOperator: StringOperators.COUNT,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -132,7 +135,7 @@ function LogsExplorerViews(): JSX.Element {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return modifiedQuery;
|
return modifiedQuery;
|
||||||
}, [stagedQuery, currentStagedQueryData]);
|
}, [stagedQuery, listQuery]);
|
||||||
|
|
||||||
const exportDefaultQuery = useMemo(
|
const exportDefaultQuery = useMemo(
|
||||||
() =>
|
() =>
|
||||||
@ -147,6 +150,9 @@ function LogsExplorerViews(): JSX.Element {
|
|||||||
const listChartData = useGetExplorerQueryRange(
|
const listChartData = useGetExplorerQueryRange(
|
||||||
listChartQuery,
|
listChartQuery,
|
||||||
PANEL_TYPES.TIME_SERIES,
|
PANEL_TYPES.TIME_SERIES,
|
||||||
|
{
|
||||||
|
enabled: !!listChartQuery && panelType === PANEL_TYPES.LIST,
|
||||||
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
const { data, isFetching, isError } = useGetExplorerQueryRange(
|
const { data, isFetching, isError } = useGetExplorerQueryRange(
|
||||||
@ -205,52 +211,66 @@ function LogsExplorerViews(): JSX.Element {
|
|||||||
const getRequestData = useCallback(
|
const getRequestData = useCallback(
|
||||||
(
|
(
|
||||||
query: Query | null,
|
query: Query | null,
|
||||||
params: { page: number; log: ILog | null; pageSize: number },
|
params: {
|
||||||
|
page: number;
|
||||||
|
log: ILog | null;
|
||||||
|
pageSize: number;
|
||||||
|
filters: TagFilter;
|
||||||
|
},
|
||||||
): Query | null => {
|
): Query | null => {
|
||||||
if (!query) return null;
|
if (!query) return null;
|
||||||
|
|
||||||
const paginateData = getPaginationQueryData({
|
const paginateData = getPaginationQueryData({
|
||||||
currentStagedQueryData,
|
filters: params.filters,
|
||||||
listItemId: params.log ? params.log.id : null,
|
listItemId: params.log ? params.log.id : null,
|
||||||
orderByTimestamp,
|
orderByTimestamp,
|
||||||
page: params.page,
|
page: params.page,
|
||||||
pageSize: params.pageSize,
|
pageSize: params.pageSize,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const queryData: IBuilderQuery[] =
|
||||||
|
query.builder.queryData.length > 1
|
||||||
|
? query.builder.queryData
|
||||||
|
: [
|
||||||
|
{
|
||||||
|
...(listQuery || initialQueryBuilderFormValues),
|
||||||
|
...paginateData,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const data: Query = {
|
const data: Query = {
|
||||||
...query,
|
...query,
|
||||||
builder: {
|
builder: {
|
||||||
...query.builder,
|
...query.builder,
|
||||||
queryData: query.builder.queryData.map((item) => ({
|
queryData,
|
||||||
...item,
|
|
||||||
...paginateData,
|
|
||||||
pageSize: params.pageSize,
|
|
||||||
})),
|
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
},
|
},
|
||||||
[currentStagedQueryData, orderByTimestamp],
|
[orderByTimestamp, listQuery],
|
||||||
);
|
);
|
||||||
|
|
||||||
const handleEndReached = useCallback(
|
const handleEndReached = useCallback(
|
||||||
(index: number) => {
|
(index: number) => {
|
||||||
|
if (!listQuery) return;
|
||||||
|
|
||||||
if (isLimit) return;
|
if (isLimit) return;
|
||||||
if (logs.length < pageSize) return;
|
if (logs.length < pageSize) return;
|
||||||
|
|
||||||
|
const { limit, filters } = listQuery;
|
||||||
|
|
||||||
const lastLog = logs[index];
|
const lastLog = logs[index];
|
||||||
|
|
||||||
const limit = currentStagedQueryData?.limit;
|
const nextLogsLength = logs.length + pageSize;
|
||||||
|
|
||||||
const nextLogsLenth = logs.length + pageSize;
|
|
||||||
|
|
||||||
const nextPageSize =
|
const nextPageSize =
|
||||||
limit && nextLogsLenth >= limit ? limit - logs.length : pageSize;
|
limit && nextLogsLength >= limit ? limit - logs.length : pageSize;
|
||||||
|
|
||||||
if (!stagedQuery) return;
|
if (!stagedQuery) return;
|
||||||
|
|
||||||
const newRequestData = getRequestData(stagedQuery, {
|
const newRequestData = getRequestData(stagedQuery, {
|
||||||
|
filters,
|
||||||
page: page + 1,
|
page: page + 1,
|
||||||
log: orderByTimestamp ? lastLog : null,
|
log: orderByTimestamp ? lastLog : null,
|
||||||
pageSize: nextPageSize,
|
pageSize: nextPageSize,
|
||||||
@ -263,7 +283,7 @@ function LogsExplorerViews(): JSX.Element {
|
|||||||
[
|
[
|
||||||
isLimit,
|
isLimit,
|
||||||
logs,
|
logs,
|
||||||
currentStagedQueryData?.limit,
|
listQuery,
|
||||||
pageSize,
|
pageSize,
|
||||||
stagedQuery,
|
stagedQuery,
|
||||||
getRequestData,
|
getRequestData,
|
||||||
@ -367,11 +387,13 @@ function LogsExplorerViews(): JSX.Element {
|
|||||||
currentMinTimeRef.current !== minTime
|
currentMinTimeRef.current !== minTime
|
||||||
) {
|
) {
|
||||||
const newRequestData = getRequestData(stagedQuery, {
|
const newRequestData = getRequestData(stagedQuery, {
|
||||||
|
filters: listQuery?.filters || initialFilters,
|
||||||
page: 1,
|
page: 1,
|
||||||
log: null,
|
log: null,
|
||||||
pageSize:
|
pageSize:
|
||||||
timeRange?.pageSize && activeLogId ? timeRange?.pageSize : pageSize,
|
timeRange?.pageSize && activeLogId ? timeRange?.pageSize : pageSize,
|
||||||
});
|
});
|
||||||
|
|
||||||
setLogs([]);
|
setLogs([]);
|
||||||
setPage(1);
|
setPage(1);
|
||||||
setRequestData(newRequestData);
|
setRequestData(newRequestData);
|
||||||
@ -385,11 +407,13 @@ function LogsExplorerViews(): JSX.Element {
|
|||||||
stagedQuery,
|
stagedQuery,
|
||||||
requestData,
|
requestData,
|
||||||
getRequestData,
|
getRequestData,
|
||||||
|
listQuery,
|
||||||
pageSize,
|
pageSize,
|
||||||
minTime,
|
minTime,
|
||||||
timeRange,
|
timeRange,
|
||||||
activeLogId,
|
activeLogId,
|
||||||
onTimeRangeChange,
|
onTimeRangeChange,
|
||||||
|
panelType,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const tabsItems: TabsProps['items'] = useMemo(
|
const tabsItems: TabsProps['items'] = useMemo(
|
||||||
@ -407,7 +431,7 @@ function LogsExplorerViews(): JSX.Element {
|
|||||||
children: (
|
children: (
|
||||||
<LogsExplorerList
|
<LogsExplorerList
|
||||||
isLoading={isFetching}
|
isLoading={isFetching}
|
||||||
currentStagedQueryData={currentStagedQueryData}
|
currentStagedQueryData={listQuery}
|
||||||
logs={logs}
|
logs={logs}
|
||||||
onEndReached={handleEndReached}
|
onEndReached={handleEndReached}
|
||||||
/>
|
/>
|
||||||
@ -435,7 +459,7 @@ function LogsExplorerViews(): JSX.Element {
|
|||||||
isMultipleQueries,
|
isMultipleQueries,
|
||||||
isGroupByExist,
|
isGroupByExist,
|
||||||
isFetching,
|
isFetching,
|
||||||
currentStagedQueryData,
|
listQuery,
|
||||||
logs,
|
logs,
|
||||||
handleEndReached,
|
handleEndReached,
|
||||||
data,
|
data,
|
||||||
@ -463,18 +487,14 @@ function LogsExplorerViews(): JSX.Element {
|
|||||||
(queryData) => queryData.groupBy.length > 0,
|
(queryData) => queryData.groupBy.length > 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
const firstEnabledQuery = stagedQuery.builder.queryData.find(
|
|
||||||
(item) => !item.disabled,
|
|
||||||
);
|
|
||||||
|
|
||||||
const firstPayloadQuery = data.payload.data.result.find(
|
const firstPayloadQuery = data.payload.data.result.find(
|
||||||
(item) => item.queryName === firstEnabledQuery?.queryName,
|
(item) => item.queryName === listQuery?.queryName,
|
||||||
);
|
);
|
||||||
|
|
||||||
const firstPayloadQueryArray = firstPayloadQuery ? [firstPayloadQuery] : [];
|
const firstPayloadQueryArray = firstPayloadQuery ? [firstPayloadQuery] : [];
|
||||||
|
|
||||||
return isGroupByExist ? data.payload.data.result : firstPayloadQueryArray;
|
return isGroupByExist ? data.payload.data.result : firstPayloadQueryArray;
|
||||||
}, [stagedQuery, data, panelType, listChartData]);
|
}, [stagedQuery, panelType, data, listChartData, listQuery]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import { initialFilters } from 'constants/queryBuilder';
|
|
||||||
import { FILTERS } from 'container/QueryBuilder/filters/OrderByFilter/config';
|
import { FILTERS } from 'container/QueryBuilder/filters/OrderByFilter/config';
|
||||||
import {
|
import {
|
||||||
IBuilderQuery,
|
IBuilderQuery,
|
||||||
@ -8,7 +7,7 @@ import {
|
|||||||
import { v4 as uuid } from 'uuid';
|
import { v4 as uuid } from 'uuid';
|
||||||
|
|
||||||
type SetupPaginationQueryDataParams = {
|
type SetupPaginationQueryDataParams = {
|
||||||
currentStagedQueryData: IBuilderQuery | null;
|
filters: IBuilderQuery['filters'];
|
||||||
listItemId: string | null;
|
listItemId: string | null;
|
||||||
orderByTimestamp: OrderByPayload | null;
|
orderByTimestamp: OrderByPayload | null;
|
||||||
page: number;
|
page: number;
|
||||||
@ -17,20 +16,15 @@ type SetupPaginationQueryDataParams = {
|
|||||||
|
|
||||||
type SetupPaginationQueryData = (
|
type SetupPaginationQueryData = (
|
||||||
params: SetupPaginationQueryDataParams,
|
params: SetupPaginationQueryDataParams,
|
||||||
) => Pick<IBuilderQuery, 'filters' | 'offset'>;
|
) => Partial<IBuilderQuery>;
|
||||||
|
|
||||||
export const getPaginationQueryData: SetupPaginationQueryData = ({
|
export const getPaginationQueryData: SetupPaginationQueryData = ({
|
||||||
currentStagedQueryData,
|
filters,
|
||||||
listItemId,
|
listItemId,
|
||||||
orderByTimestamp,
|
orderByTimestamp,
|
||||||
page,
|
page,
|
||||||
pageSize,
|
pageSize,
|
||||||
}) => {
|
}) => {
|
||||||
if (!currentStagedQueryData) {
|
|
||||||
return { limit: null, filters: initialFilters };
|
|
||||||
}
|
|
||||||
|
|
||||||
const filters = currentStagedQueryData.filters || initialFilters;
|
|
||||||
const offset = (page - 1) * pageSize;
|
const offset = (page - 1) * pageSize;
|
||||||
|
|
||||||
const queryProps = {
|
const queryProps = {
|
||||||
@ -69,5 +63,5 @@ export const getPaginationQueryData: SetupPaginationQueryData = ({
|
|||||||
...queryProps,
|
...queryProps,
|
||||||
};
|
};
|
||||||
|
|
||||||
return { ...currentStagedQueryData, ...chunkOfQueryData };
|
return chunkOfQueryData;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user