Skip to content

🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.

Add new translation key for "Save filter" in multiple languages and remove unused FilterComponent

Bill Yangd84dd5df8b5a
diff --git a/client/messages/cs.json b/client/messages/cs.json
index 9c2ed2c6b..c8a2675bc 100644
--- a/client/messages/cs.json
+++ b/client/messages/cs.json
@@ -163,6 +163,7 @@
"jHJmjf": "",
"gjBiyj": "Načítám...",
"2/2yg+": "Přidat",
+ "SElbF+": "",
"9Obw6C": "Filtr",
"oZhbMq": "",
"xmcVZ0": "",
diff --git a/client/messages/de.json b/client/messages/de.json
index 116d7cc09..04c3ef6f8 100644
--- a/client/messages/de.json
+++ b/client/messages/de.json
@@ -163,6 +163,7 @@
"jHJmjf": "",
"gjBiyj": "Wird geladen...",
"2/2yg+": "Hinzufügen",
+ "SElbF+": "",
"9Obw6C": "Filter",
"oZhbMq": "",
"xmcVZ0": "",
diff --git a/client/messages/en.json b/client/messages/en.json
index b2fbaa593..a01ad212a 100644
--- a/client/messages/en.json
+++ b/client/messages/en.json
@@ -163,6 +163,7 @@
"jHJmjf": "No results",
"gjBiyj": "Loading...",
"2/2yg+": "Add",
+ "SElbF+": "Save filter",
"9Obw6C": "Filter",
"oZhbMq": "Filter stats by",
"xmcVZ0": "Search",
diff --git a/client/messages/es.json b/client/messages/es.json
index 33201185a..448b0c28d 100644
--- a/client/messages/es.json
+++ b/client/messages/es.json
@@ -163,6 +163,7 @@
"jHJmjf": "",
"gjBiyj": "Cargando...",
"2/2yg+": "Añadir",
+ "SElbF+": "",
"9Obw6C": "Filtro",
"oZhbMq": "",
"xmcVZ0": "",
diff --git a/client/messages/fr.json b/client/messages/fr.json
index 8fa9f5972..42ffce6e3 100644
--- a/client/messages/fr.json
+++ b/client/messages/fr.json
@@ -163,6 +163,7 @@
"jHJmjf": "",
"gjBiyj": "Chargement...",
"2/2yg+": "Ajouter",
+ "SElbF+": "",
"9Obw6C": "Filtre",
"oZhbMq": "",
"xmcVZ0": "",
diff --git a/client/messages/it.json b/client/messages/it.json
index f6388c804..c27150460 100644
--- a/client/messages/it.json
+++ b/client/messages/it.json
@@ -163,6 +163,7 @@
"jHJmjf": "",
"gjBiyj": "Caricamento in corso...",
"2/2yg+": "Aggiungi",
+ "SElbF+": "",
"9Obw6C": "Filtro",
"oZhbMq": "",
"xmcVZ0": "",
diff --git a/client/messages/ja.json b/client/messages/ja.json
index 614e0f3fb..98a789bcb 100644
--- a/client/messages/ja.json
+++ b/client/messages/ja.json
@@ -163,6 +163,7 @@
"jHJmjf": "",
"gjBiyj": "読み込み中...",
"2/2yg+": "追加",
+ "SElbF+": "",
"9Obw6C": "フィルター",
"oZhbMq": "",
"xmcVZ0": "",
diff --git a/client/messages/ko.json b/client/messages/ko.json
index fb3eb2138..3f306d794 100644
--- a/client/messages/ko.json
+++ b/client/messages/ko.json
@@ -163,6 +163,7 @@
"jHJmjf": "",
"gjBiyj": "로딩 중...",
"2/2yg+": "추가",
+ "SElbF+": "",
"9Obw6C": "필터",
"oZhbMq": "",
"xmcVZ0": "",
diff --git a/client/messages/pl.json b/client/messages/pl.json
index 13ee348e6..626e8916a 100644
--- a/client/messages/pl.json
+++ b/client/messages/pl.json
@@ -163,6 +163,7 @@
"jHJmjf": "",
"gjBiyj": "Ładowanie...",
"2/2yg+": "Dodaj",
+ "SElbF+": "",
"9Obw6C": "Filtr",
"oZhbMq": "",
"xmcVZ0": "",
diff --git a/client/messages/pt.json b/client/messages/pt.json
index 5660ac309..e0cb2791d 100644
--- a/client/messages/pt.json
+++ b/client/messages/pt.json
@@ -163,6 +163,7 @@
"jHJmjf": "",
"gjBiyj": "Carregando...",
"2/2yg+": "Adicionar",
+ "SElbF+": "",
"9Obw6C": "Filtro",
"oZhbMq": "",
"xmcVZ0": "",
diff --git a/client/messages/uk.json b/client/messages/uk.json
index 2979b6fdc..06fc93230 100644
--- a/client/messages/uk.json
+++ b/client/messages/uk.json
@@ -163,6 +163,7 @@
"jHJmjf": "",
"gjBiyj": "Завантаження...",
"2/2yg+": "Додати",
+ "SElbF+": "",
"9Obw6C": "Фільтр",
"oZhbMq": "",
"xmcVZ0": "",
diff --git a/client/messages/zh.json b/client/messages/zh.json
index 4ad324ca7..f5507c28b 100644
--- a/client/messages/zh.json
+++ b/client/messages/zh.json
@@ -163,6 +163,7 @@
"jHJmjf": "",
"gjBiyj": "正在加载...",
"2/2yg+": "添加",
+ "SElbF+": "",
"9Obw6C": "过滤",
"oZhbMq": "",
"xmcVZ0": "",
diff --git a/client/src/app/[site]/components/SubHeader/Filters/FilterComponent.tsx b/client/src/app/[site]/components/SubHeader/Filters/FilterComponent.tsx
deleted file mode 100644
index d45d1147a..000000000
--- a/client/src/app/[site]/components/SubHeader/Filters/FilterComponent.tsx
+++ /dev/null
@@ -1,94 +0,0 @@
-"use client";
-
-import { Filter, FilterParameter } from "@rybbit/shared";
-import { Trash } from "lucide-react";
-import { useExtracted } from "next-intl";
-import { Button } from "../../../../../components/ui/button";
-import { useGetRegionName } from "../../../../../lib/geo";
-import { cn } from "../../../../../lib/utils";
-import { isNumericParameter } from "./const";
-import {
- formatDisplayValue,
- getParameterIcon,
- operatorNeedsValue,
- useOperatorLabel,
- useParameterLabel
-} from "./labels";
-import { OperatorPopover } from "./OperatorPopover";
-import { ParameterPopover } from "./ParameterPopover";
-import { ValuePopover } from "./ValuePopover";
-
-export function FilterComponent({
- filter,
- index,
- updateFilter,
- availableFilters,
-}: {
- filter: Filter;
- index: number;
- updateFilter: (filter: Filter | null, index: number) => void;
- availableFilters?: FilterParameter[];
-}) {
- const t = useExtracted();
- const { getRegionName } = useGetRegionName();
-
- const getParameterLabel = useParameterLabel();
- const getOperatorLabel = useOperatorLabel();
-
- const onUpdate = (next: Filter) => updateFilter(next, index);
-
- const isNumeric = isNumericParameter(filter.parameter);
- const displayValue = formatDisplayValue(filter, getRegionName);
- const hasValue = filter.value.length > 0;
- const isNegated =
- filter.type === "not_equals" ||
- filter.type === "not_contains" ||
- filter.type === "not_regex";
-
- return (
- <div className="grid grid-cols-[120px_90px_250px_auto] gap-2">
- <ParameterPopover filter={filter} onUpdate={onUpdate} availableFilters={availableFilters}>
- <Button
- variant="outline"
- size="sm"
- className="font-normal justify-start text-neutral-700 dark:text-neutral-200"
- >
- {getParameterIcon(filter.parameter)}
- {getParameterLabel(filter.parameter)}
- </Button>
- </ParameterPopover>
- <OperatorPopover filter={filter} onUpdate={onUpdate}>
- <Button
- variant="outline"
- size="sm"
- className={cn(
- "font-normal justify-start text-neutral-500 dark:text-neutral-400"
- )}
- >
- {getOperatorLabel(filter.type, isNumeric)}
- </Button>
- </OperatorPopover>
- {operatorNeedsValue(filter.type) ? (
- <ValuePopover filter={filter} onUpdate={onUpdate}>
- <Button
- variant="outline"
- size="sm"
- className={cn(
- "justify-start truncate",
- hasValue
- ? "text-neutral-900 dark:text-neutral-100 font-medium"
- : "text-neutral-500 dark:text-neutral-400 italic font-normal"
- )}
- >
- <span className="truncate">{hasValue ? displayValue : t("pick value")}</span>
- </Button>
- </ValuePopover>
- ) : (
- <div />
- )}
- <Button variant="ghost" className="h-8 w-8" onClick={() => updateFilter(null, index)}>
- <Trash className="w-4 h-4" />
- </Button>
- </div>
- );
-}
diff --git a/client/src/app/[site]/components/SubHeader/Filters/Filters.tsx b/client/src/app/[site]/components/SubHeader/Filters/Filters.tsx
index 2cdf0b31c..e85fb3cce 100644
--- a/client/src/app/[site]/components/SubHeader/Filters/Filters.tsx
+++ b/client/src/app/[site]/components/SubHeader/Filters/Filters.tsx
@@ -35,10 +35,6 @@ export function Filters({ availableFilters }: { availableFilters?: FilterParamet
const isNumeric = isNumericParameter(filter.parameter);
const displayValue = formatDisplayValue(filter, getRegionName);
const hasValue = filter.value.length > 0;
- const isNegated =
- filter.type === "not_equals" ||
- filter.type === "not_contains" ||
- filter.type === "not_regex";
const onUpdate = (next: typeof filter) => updateFilter(next, i);
diff --git a/client/src/app/[site]/components/SubHeader/Filters/NewFilterButton.tsx b/client/src/app/[site]/components/SubHeader/Filters/NewFilterButton.tsx
index 150885734..2be115333 100644
--- a/client/src/app/[site]/components/SubHeader/Filters/NewFilterButton.tsx
+++ b/client/src/app/[site]/components/SubHeader/Filters/NewFilterButton.tsx
@@ -1,7 +1,7 @@
"use client";
import { Filter, FilterParameter, FilterType } from "@rybbit/shared";
-import { ChevronLeft, ChevronRight, ChevronsUpDown, HelpCircle, ListFilterPlus, Plus } from "lucide-react";
+import { Check, ChevronLeft, ChevronRight, ChevronsUpDown, HelpCircle, ListFilterPlus, Plus } from "lucide-react";
import { useExtracted } from "next-intl";
import { useMemo, useRef, useState } from "react";
import { useMetric } from "../../../../../api/analytics/hooks/useGetMetric";
@@ -152,11 +152,13 @@ function ValueStep({
return { parameter, type, value: selected };
};
+ const canSave = buildFilter() !== null;
pendingRef.current = buildFilter;
const commitAndClose = () => {
const f = buildFilter();
- if (f) onCommit(f);
+ if (!f) return;
+ onCommit(f);
onClose();
};
@@ -298,6 +300,21 @@ function ValueStep({
</Command>
)
)}
+ {needsValue && (
+ <div className="border-t border-neutral-200 dark:border-neutral-800 p-2">
+ <Button
+ type="button"
+ size="sm"
+ variant="success"
+ className="w-full"
+ disabled={!canSave}
+ onClick={commitAndClose}
+ >
+ <Check className="h-4 w-4" />
+ {t("Save filter")}
+ </Button>
+ </div>
+ )}
</div>
);
}
diff --git a/client/src/app/[site]/components/SubHeader/Filters/OperatorPopover.tsx b/client/src/app/[site]/components/SubHeader/Filters/OperatorPopover.tsx
index febe27635..c1d30620a 100644
--- a/client/src/app/[site]/components/SubHeader/Filters/OperatorPopover.tsx
+++ b/client/src/app/[site]/components/SubHeader/Filters/OperatorPopover.tsx
@@ -6,7 +6,16 @@ import { useState } from "react";
import { Popover, PopoverContent, PopoverTrigger } from "../../../../../components/ui/popover";
import { cn } from "../../../../../lib/utils";
import { isNumericParameter, NumericOperatorOptions, StringOperatorOptions } from "./const";
-import { useOperatorMenuLabel } from "./labels";
+import { operatorNeedsValue, useOperatorMenuLabel } from "./labels";
+
+const singleValueOperators: FilterType[] = [
+ "regex",
+ "not_regex",
+ "greater_than",
+ "less_than",
+ "greater_than_or_equal",
+ "less_than_or_equal",
+];
export function OperatorPopover({
filter,
@@ -24,7 +33,12 @@ export function OperatorPopover({
const operatorOptions = isNumeric ? NumericOperatorOptions : StringOperatorOptions;
const handleSelect = (newType: FilterType) => {
- onUpdate({ ...filter, type: newType, value: [] });
+ const value =
+ operatorNeedsValue(newType) && singleValueOperators.includes(newType)
+ ? filter.value.slice(0, 1)
+ : filter.value;
+
+ onUpdate({ ...filter, type: newType, value });
setOpen(false);
};
diff --git a/client/src/components/ui/button.tsx b/client/src/components/ui/button.tsx
index 5f4d7f197..b0e2b42a7 100644
--- a/client/src/components/ui/button.tsx
+++ b/client/src/components/ui/button.tsx
@@ -5,7 +5,7 @@ import { cva, type VariantProps } from "class-variance-authority";
import { cn } from "@/lib/utils";
const buttonVariants = cva(
- "inline-flex items-center justify-center gap-2 whitespace-nowrap font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-neutral-950 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 dark:focus-visible:ring-neutral-300",
+ "inline-flex cursor-pointer items-center justify-center gap-2 whitespace-nowrap font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-neutral-950 disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0 dark:focus-visible:ring-neutral-300",
{
variants: {
variant: {
diff --git a/docs/src/components/ui/button.tsx b/docs/src/components/ui/button.tsx
index b427d4e08..2d1a6b9d6 100644
--- a/docs/src/components/ui/button.tsx
+++ b/docs/src/components/ui/button.tsx
@@ -9,7 +9,7 @@ const variants = {
} as const;
export const buttonVariants = cva(
- 'inline-flex items-center justify-center rounded-md p-2 text-sm font-medium transition-colors duration-100 disabled:pointer-events-none disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fd-ring',
+ 'inline-flex cursor-pointer items-center justify-center rounded-md p-2 text-sm font-medium transition-colors duration-100 disabled:pointer-events-none disabled:opacity-50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-fd-ring',
{
variants: {
variant: variants,