+ {filters.filter((filter) => filter.field === id).length > 0 && (
+
+ {filters.filter((filter) => filter.field === id).length}
+
+ )}
+
diff --git a/apps/dashboard/app/(app)/logs-v2/components/controls/components/logs-filters/components/methods-filter.tsx b/apps/dashboard/app/(app)/logs-v2/components/controls/components/logs-filters/components/methods-filter.tsx
index 2faf897976..a082642193 100644
--- a/apps/dashboard/app/(app)/logs-v2/components/controls/components/logs-filters/components/methods-filter.tsx
+++ b/apps/dashboard/app/(app)/logs-v2/components/controls/components/logs-filters/components/methods-filter.tsx
@@ -1,44 +1,40 @@
+import { type FilterValue, type HttpMethod, useFilters } from "@/app/(app)/logs-v2/query-state";
import { Checkbox } from "@/components/ui/checkbox";
import { Button } from "@unkey/ui";
-import { useState } from "react";
+import { useCallback, useEffect, useState } from "react";
interface CheckboxOption {
id: number;
- method: string;
+ method: HttpMethod;
checked: boolean;
}
const options: CheckboxOption[] = [
- {
- id: 1,
- method: "GET",
- checked: false,
- },
- {
- id: 2,
- method: "POST",
- checked: false,
- },
- {
- id: 3,
- method: "PUT",
- checked: false,
- },
- {
- id: 4,
- method: "DELETE",
- checked: false,
- },
- {
- id: 5,
- method: "PATCH",
- checked: false,
- },
+ { id: 1, method: "GET", checked: false },
+ { id: 2, method: "POST", checked: false },
+ { id: 3, method: "PUT", checked: false },
+ { id: 4, method: "DELETE", checked: false },
+ { id: 5, method: "PATCH", checked: false },
] as const;
export const MethodsFilter = () => {
+ const { filters, updateFilters } = useFilters();
const [checkboxes, setCheckboxes] = useState
(options);
+ // Sync checkboxes with filters on mount and when filters change
+ useEffect(() => {
+ const methodFilters = filters
+ .filter((f) => f.field === "methods")
+ .map((f) => f.value as HttpMethod);
+
+ setCheckboxes((prev) =>
+ prev.map((checkbox) => ({
+ ...checkbox,
+ checked: methodFilters.includes(checkbox.method),
+ })),
+ );
+ }, [filters]);
+
const handleCheckboxChange = (index: number): void => {
setCheckboxes((prevCheckboxes) => {
const newCheckboxes = [...prevCheckboxes];
@@ -60,17 +56,36 @@ export const MethodsFilter = () => {
});
};
+ const handleApplyFilter = useCallback(() => {
+ const selectedMethods = checkboxes.filter((c) => c.checked).map((c) => c.method);
+
+ // Keep all non-method filters and add new method filters
+ const otherFilters = filters.filter((f) => f.field !== "methods");
+ const methodFilters: FilterValue[] = selectedMethods.map((method) => ({
+ id: crypto.randomUUID(),
+ field: "methods",
+ operator: "is",
+ value: method,
+ }));
+
+ updateFilters([...otherFilters, ...methodFilters]);
+ }, [checkboxes, filters, updateFilters]);
+
return (
-
+
+
+
{checkboxes.map((checkbox, index) => (