From da3129b254666d60adf92cb33ea5125c20d7f722 Mon Sep 17 00:00:00 2001 From: dylan Date: Wed, 12 Jun 2024 12:02:24 -0400 Subject: [PATCH 1/2] updating default filter operation to and --- components/project/traces/traces.tsx | 1 - lib/services/query_builder_service.ts | 12 ++++++------ lib/services/trace_service.ts | 6 +++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/components/project/traces/traces.tsx b/components/project/traces/traces.tsx index 9c56c06f..19e3aeca 100644 --- a/components/project/traces/traces.tsx +++ b/components/project/traces/traces.tsx @@ -29,7 +29,6 @@ export default function Traces({ email }: { email: string }) { const [enableFetch, setEnableFetch] = useState(false); const [utcTime, setUtcTime] = useState(true); const [isFilterDialogOpen, setIsFilterDialogOpen] = useState(false); - const [userId, setUserId] = useState(""); useEffect(() => { setShowLoader(true); diff --git a/lib/services/query_builder_service.ts b/lib/services/query_builder_service.ts index 7927683e..31bb09a1 100644 --- a/lib/services/query_builder_service.ts +++ b/lib/services/query_builder_service.ts @@ -86,7 +86,7 @@ export class QueryBuilderService implements IQueryBuilderService { CountFilteredSpanAttributesQuery( tableName: string, filters: PropertyFilter[], - filterOperation: string = "OR" + filterOperation: string = "AND" ): string { let baseQuery = `COUNT(DISTINCT span_id) AS total_spans FROM ${tableName}`; let whereConditions: string[] = []; @@ -105,7 +105,7 @@ export class QueryBuilderService implements IQueryBuilderService { CountFilteredTraceAttributesQuery( tableName: string, filters: PropertyFilter[], - filterOperation: string = "OR" + filterOperation: string = "AND" ): string { let baseQuery = `COUNT(DISTINCT trace_id) AS total_traces FROM ${tableName}`; let whereConditions: string[] = []; @@ -126,7 +126,7 @@ export class QueryBuilderService implements IQueryBuilderService { filters: PropertyFilter[], pageSize: number = 10, offset: number = 0, - filterOperation: string = "OR", + filterOperation: string = "AND", lastNHours?: number ): string { let baseQuery = `* FROM ${tableName}`; @@ -156,7 +156,7 @@ export class QueryBuilderService implements IQueryBuilderService { filters: PropertyFilter[], pageSize: number, offset: number, - filterOperation: string = "OR" + filterOperation: string = "AND" ): string { let baseQuery = `trace_id, MIN(start_time) AS earliest_start_time FROM ${tableName}`; let whereConditions: string[] = []; @@ -177,7 +177,7 @@ export class QueryBuilderService implements IQueryBuilderService { tableName: string, spanId: string, filters: PropertyFilter[], - filterOperation: string = "OR" + filterOperation: string = "AND" ): string { let baseQuery = `* FROM ${tableName} WHERE span_id = '${spanId}'`; let whereConditions: string[] = []; @@ -197,7 +197,7 @@ export class QueryBuilderService implements IQueryBuilderService { tableName: string, traceId: string, filters: PropertyFilter[], - filterOperation: string = "OR" + filterOperation: string = "AND" ): string { let baseQuery = `* FROM ${tableName} WHERE trace_id = '${traceId}'`; let whereConditions: string[] = []; diff --git a/lib/services/trace_service.ts b/lib/services/trace_service.ts index bb5d4a9a..cfa99cd4 100644 --- a/lib/services/trace_service.ts +++ b/lib/services/trace_service.ts @@ -404,7 +404,7 @@ export class TraceService implements ITraceService { page: number, pageSize: number, filters: PropertyFilter[] = [], - filterOperation: string = "OR" + filterOperation: string = "AND" ): Promise> { try { const tableExists = await this.client.checkTableExists(project_id); @@ -458,7 +458,7 @@ export class TraceService implements ITraceService { project_id: string, lastNHours = 168, filters: PropertyFilter[] = [], - filterOperation: string = "OR" + filterOperation: string = "AND" ): Promise { try { const tableExists = await this.client.checkTableExists(project_id); @@ -488,7 +488,7 @@ export class TraceService implements ITraceService { page: number, pageSize: number, filters: PropertyFilter[] = [], - filterOperation: string = "OR" + filterOperation: string = "AND" ): Promise> { try { const tableExists = await this.client.checkTableExists(project_id); From 05ea863dd90fea756271962ed021986440d2e243 Mon Sep 17 00:00:00 2001 From: dylan Date: Wed, 12 Jun 2024 13:44:33 -0400 Subject: [PATCH 2/2] adding clear all button, cleanup --- app/api/traces/route.ts | 6 ++++-- components/project/traces/trace-filter.tsx | 16 ++++++++++++++++ components/project/traces/traces.tsx | 3 +++ components/shared/user-combobox.tsx | 9 ++++++++- lib/services/query_builder_service.ts | 12 ++++++------ lib/services/trace_service.ts | 6 +++--- 6 files changed, 40 insertions(+), 12 deletions(-) diff --git a/app/api/traces/route.ts b/app/api/traces/route.ts index 64034c71..ffb0c214 100644 --- a/app/api/traces/route.ts +++ b/app/api/traces/route.ts @@ -10,7 +10,8 @@ export async function POST(req: NextRequest) { try { const session = await getServerSession(authOptions); const apiKey = req.headers.get("x-api-key"); - const { page, pageSize, projectId, filters } = await req.json(); + const { page, pageSize, projectId, filters, filterOperation } = + await req.json(); if (!session || !session.user) { if (apiKey) { const project = await prisma.project.findFirst({ @@ -42,7 +43,8 @@ export async function POST(req: NextRequest) { projectId, page, pageSize, - filters + filters, + filterOperation ); return NextResponse.json( diff --git a/components/project/traces/trace-filter.tsx b/components/project/traces/trace-filter.tsx index 27391688..22dc240d 100644 --- a/components/project/traces/trace-filter.tsx +++ b/components/project/traces/trace-filter.tsx @@ -22,6 +22,7 @@ import { PopoverContent, PopoverTrigger, } from "@/components/ui/popover"; +import ClearIcon from "@mui/icons-material/Clear"; import { Check, ChevronsUpDown } from "lucide-react"; import { useEffect, useState } from "react"; @@ -184,6 +185,21 @@ export default function FilterDialog({ + {(selectedFilters.length > 0 || + advancedFilters.length > 0 || + selectedUserId !== "") && ( + + )} diff --git a/components/project/traces/traces.tsx b/components/project/traces/traces.tsx index 19e3aeca..4a41af56 100644 --- a/components/project/traces/traces.tsx +++ b/components/project/traces/traces.tsx @@ -29,6 +29,8 @@ export default function Traces({ email }: { email: string }) { const [enableFetch, setEnableFetch] = useState(false); const [utcTime, setUtcTime] = useState(true); const [isFilterDialogOpen, setIsFilterDialogOpen] = useState(false); + const [clearFilters, setClearFilters] = useState(false); + const [clearFiltersKey, setClearFiltersKey] = useState(0); useEffect(() => { setShowLoader(true); @@ -57,6 +59,7 @@ export default function Traces({ email }: { email: string }) { pageSize: PAGE_SIZE, projectId: project_id, filters: filters, + filterOperation: "AND", }; const response = await fetch(apiEndpoint, { diff --git a/components/shared/user-combobox.tsx b/components/shared/user-combobox.tsx index 19b11a90..6cd74a86 100644 --- a/components/shared/user-combobox.tsx +++ b/components/shared/user-combobox.tsx @@ -16,7 +16,7 @@ import { import { Check, ChevronsUpDown } from "lucide-react"; import { useParams } from "next/navigation"; -import { useState } from "react"; +import { useEffect, useState } from "react"; import { useQuery } from "react-query"; import { toast } from "sonner"; @@ -34,6 +34,8 @@ export function UserCombobox({ const [searchQuery, setSearchQuery] = useState(""); const [userIds, setUserIds] = useState([]); const [showLoader, setShowLoader] = useState(false); + const [internalSelectedUser, setInternalSelectedUser] = + useState(selectedUser); const handleSelectUser = (currentValue: string) => { const newUserId = currentValue === selectedUserId ? "" : currentValue; @@ -43,6 +45,11 @@ export function UserCombobox({ setOpen(false); }; + useEffect(() => { + setSelectedUserIdState(selectedUser || ""); + setInternalSelectedUser(selectedUser || ""); + }, [selectedUser]); + const fetchUserIds = useQuery({ queryKey: ["fetch-user-ids-query", project_id], queryFn: async () => { diff --git a/lib/services/query_builder_service.ts b/lib/services/query_builder_service.ts index 31bb09a1..7927683e 100644 --- a/lib/services/query_builder_service.ts +++ b/lib/services/query_builder_service.ts @@ -86,7 +86,7 @@ export class QueryBuilderService implements IQueryBuilderService { CountFilteredSpanAttributesQuery( tableName: string, filters: PropertyFilter[], - filterOperation: string = "AND" + filterOperation: string = "OR" ): string { let baseQuery = `COUNT(DISTINCT span_id) AS total_spans FROM ${tableName}`; let whereConditions: string[] = []; @@ -105,7 +105,7 @@ export class QueryBuilderService implements IQueryBuilderService { CountFilteredTraceAttributesQuery( tableName: string, filters: PropertyFilter[], - filterOperation: string = "AND" + filterOperation: string = "OR" ): string { let baseQuery = `COUNT(DISTINCT trace_id) AS total_traces FROM ${tableName}`; let whereConditions: string[] = []; @@ -126,7 +126,7 @@ export class QueryBuilderService implements IQueryBuilderService { filters: PropertyFilter[], pageSize: number = 10, offset: number = 0, - filterOperation: string = "AND", + filterOperation: string = "OR", lastNHours?: number ): string { let baseQuery = `* FROM ${tableName}`; @@ -156,7 +156,7 @@ export class QueryBuilderService implements IQueryBuilderService { filters: PropertyFilter[], pageSize: number, offset: number, - filterOperation: string = "AND" + filterOperation: string = "OR" ): string { let baseQuery = `trace_id, MIN(start_time) AS earliest_start_time FROM ${tableName}`; let whereConditions: string[] = []; @@ -177,7 +177,7 @@ export class QueryBuilderService implements IQueryBuilderService { tableName: string, spanId: string, filters: PropertyFilter[], - filterOperation: string = "AND" + filterOperation: string = "OR" ): string { let baseQuery = `* FROM ${tableName} WHERE span_id = '${spanId}'`; let whereConditions: string[] = []; @@ -197,7 +197,7 @@ export class QueryBuilderService implements IQueryBuilderService { tableName: string, traceId: string, filters: PropertyFilter[], - filterOperation: string = "AND" + filterOperation: string = "OR" ): string { let baseQuery = `* FROM ${tableName} WHERE trace_id = '${traceId}'`; let whereConditions: string[] = []; diff --git a/lib/services/trace_service.ts b/lib/services/trace_service.ts index cfa99cd4..bb5d4a9a 100644 --- a/lib/services/trace_service.ts +++ b/lib/services/trace_service.ts @@ -404,7 +404,7 @@ export class TraceService implements ITraceService { page: number, pageSize: number, filters: PropertyFilter[] = [], - filterOperation: string = "AND" + filterOperation: string = "OR" ): Promise> { try { const tableExists = await this.client.checkTableExists(project_id); @@ -458,7 +458,7 @@ export class TraceService implements ITraceService { project_id: string, lastNHours = 168, filters: PropertyFilter[] = [], - filterOperation: string = "AND" + filterOperation: string = "OR" ): Promise { try { const tableExists = await this.client.checkTableExists(project_id); @@ -488,7 +488,7 @@ export class TraceService implements ITraceService { page: number, pageSize: number, filters: PropertyFilter[] = [], - filterOperation: string = "AND" + filterOperation: string = "OR" ): Promise> { try { const tableExists = await this.client.checkTableExists(project_id);