🐸 Rybbit - open-source and privacy-friendly alternative to Google Analytics that is 10x more intuitive.
Enhance filter functionality and layout improvements
Bill Yangc4512d3c17a5
diff --git a/client/src/api/analytics/useSingleCol.ts b/client/src/api/analytics/useSingleCol.tsindex 494c3ed20..371463dfd 100644--- a/client/src/api/analytics/useSingleCol.ts+++ b/client/src/api/analytics/useSingleCol.ts@@ -30,7 +30,7 @@ export function useSingleCol({const { startDate, endDate } = getStartAndEndDate(timeToUse);return useQuery({- queryKey: [parameter, timeToUse, site, filters, limit],+ queryKey: [parameter, timeToUse, site, filters, limit, useFilters],queryFn: () => {const timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;return authedFetch(`${BACKEND_URL}/single-col`, {diff --git a/client/src/app/[site]/components/SubHeader/Filters/NewFilterButton.tsx b/client/src/app/[site]/components/SubHeader/Filters/NewFilterButton.tsxindex 8ac3dc001..471ae29e3 100644--- a/client/src/app/[site]/components/SubHeader/Filters/NewFilterButton.tsx+++ b/client/src/app/[site]/components/SubHeader/Filters/NewFilterButton.tsx@@ -1,130 +1,52 @@"use client";import { ListFilterPlus, Plus } from "lucide-react";+import { useState } from "react";import { Button } from "../../../../../components/ui/button";import {DropdownMenu,DropdownMenuContent,- DropdownMenuItem,DropdownMenuTrigger,} from "../../../../../components/ui/dropdown-menu";-import { FilterParameter, FilterType } from "../../../../../lib/store";-import { useMemo, useState } from "react";+import { Filter, useStore } from "../../../../../lib/store";import { sleep } from "../../../../../lib/utils";-import { cn } from "../../../../../lib/utils";-import { ValueFilter } from "./ValueFilter";--const FilterOptions: { label: string; value: FilterParameter }[] = [- {- label: "Path",- value: "pathname",- },- {- label: "Page Title",- value: "page_title",- },- {- label: "Query",- value: "querystring",- },- {- label: "Referrer",- value: "referrer",- },- {- label: "Channel",- value: "channel",- },- {- label: "Country",- value: "country",- },- {- label: "Region",- value: "iso_3166_2",- },- {- label: "City",- value: "city",- },- {- label: "Device Type",- value: "device_type",- },- {- label: "Operating System",- value: "operating_system",- },- {- label: "Browser",- value: "browser",- },- {- label: "Language",- value: "language",- },- {- label: "Entry Page",- value: "entry_page",- },- {- label: "Exit Page",- value: "exit_page",- },- {- label: "Screen Dimensions",- value: "dimensions",- },- {- label: "Event Name",- value: "event_name",- },-];+import { FilterComponent } from "../../shared/Filters/FilterComponent";export function NewFilterButton() {- const [selectedFilter, setSelectedFilter] = useState<{- label: string;- value: FilterParameter;- } | null>(null);+ const { filters, setFilters } = useStore();++ const [localFilters, setLocalFilters] = useState<Filter[]>(filters);- const [selectedOperator, setSelectedOperator] =- useState<FilterType>("equals");+ const updateLocalFilters = (filter: Filter | null, index: number) => {+ if (filter === null) {+ const newFilters = [...localFilters];+ newFilters.splice(index, 1);+ setLocalFilters(newFilters);+ return;+ }+ const newFilters = [...localFilters];+ newFilters[index] = filter;+ setLocalFilters(newFilters);+ };++ const addLocalFilter = () => {+ setLocalFilters([+ ...localFilters,+ {+ parameter: "pathname",+ type: "equals",+ value: [],+ },+ ]);+ };const [open, setOpen] = useState(false);const onClose = async () => {setOpen(false);+ setLocalFilters(filters);await sleep(100);- setSelectedFilter(null);- setSelectedOperator("equals");};- const operatorOptions: { label: string; value: FilterType }[] =- useMemo(() => {- if (- selectedFilter?.value === "referrer" ||- selectedFilter?.value === "page_title" ||- selectedFilter?.value === "language" ||- selectedFilter?.value === "country" ||- selectedFilter?.value === "region" ||- selectedFilter?.value === "city" ||- selectedFilter?.value === "iso_3166_2" ||- selectedFilter?.value === "entry_page" ||- selectedFilter?.value === "exit_page" ||- selectedFilter?.value === "querystring"- ) {- return [- { label: "Is", value: "equals" },- { label: "Is not", value: "not_equals" },- { label: "Contains", value: "contains" },- { label: "Not contains", value: "not_contains" },- ];- }- return [- { label: "Is", value: "equals" },- { label: "Is not", value: "not_equals" },- ];- }, []);-return (<DropdownMenuonOpenChange={(isOpen) => {@@ -144,50 +66,38 @@ export function NewFilterButton() {Filter</Button></DropdownMenuTrigger>- <DropdownMenuContent align="start">- {selectedFilter ? (- <div className="flex flex-col gap-2 p-2">- <div>{selectedFilter.label}</div>- <div className="flex flex-col items-center gap-2 text-sm">- <div className="flex w-full rounded-md overflow-hidden">- {operatorOptions.map((option) => (- <Button- key={option.value}- type="button"- variant={"default"}- className={cn(- "flex-1 rounded-none text-xs h-8 border-neutral-700 transition-[background-color,color]",- selectedOperator === option.value- ? "bg-neutral-900 text-white dark:bg-neutral-750"- : "bg-white text-neutral-700 hover:bg-neutral-100 dark:bg-neutral-850 dark:text-neutral-300 dark:hover:text-neutral-100"- )}- onClick={() => setSelectedOperator(option.value)}- >- {option.label}- </Button>- ))}- </div>-- <ValueFilter- parameter={selectedFilter.value}- type={selectedOperator}- onComplete={() => onClose()}- />- </div>- </div>- ) : (- FilterOptions.map((option) => (- <DropdownMenuItem- key={option.value}- onClick={(e) => {- e.preventDefault();- setSelectedFilter(option);- }}- >- {option.label}- </DropdownMenuItem>- ))- )}+ <DropdownMenuContent align="start" className="flex flex-col p-0">+ <div className="flex flex-col gap-2 p-3">+ {localFilters.map((filter, index) => (+ <FilterComponent+ key={index}+ filter={filter}+ index={index}+ updateFilter={updateLocalFilters}+ />+ ))}+ </div>+ <div className="flex justify-between border-t border-neutral-750 p-3">+ <Button+ variant={"ghost"}+ onClick={() => addLocalFilter()}+ size={"sm"}+ className="gap-1"+ >+ <Plus className="w-3 h-3" />+ Add Filter+ </Button>+ <Button+ variant={"outline"}+ size={"sm"}+ onClick={() => {+ setFilters(localFilters);+ setOpen(false);+ }}+ >+ Save Filters+ </Button>+ </div></DropdownMenuContent></DropdownMenu>);diff --git a/client/src/app/[site]/components/shared/Filters/FilterComponent.tsx b/client/src/app/[site]/components/shared/Filters/FilterComponent.tsxnew file mode 100644index 000000000..9e71b7509--- /dev/null+++ b/client/src/app/[site]/components/shared/Filters/FilterComponent.tsx@@ -0,0 +1,95 @@+import { Trash } from "lucide-react";+import { Button } from "../../../../../components/ui/button";+import {+ Select,+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue,+} from "../../../../../components/ui/select";+import {+ Filter,+ FilterParameter,+ FilterType,+ updateFilter,+} from "../../../../../lib/store";+import { FilterOptions, OperatorOptions } from "./const";+import { ValueSelect } from "./ValueSelect";++export function FilterComponent({+ filter,+ index,+ updateFilter,+}: {+ filter: Filter;+ index: number;+ updateFilter: (filter: Filter | null, index: number) => void;+}) {+ return (+ <div className="flex gap-2">+ <Select+ onValueChange={(value) => {+ updateFilter(+ {+ ...filter,+ value: [],+ parameter: value as FilterParameter,+ },+ index+ );+ }}+ value={filter.parameter}+ >+ <SelectTrigger>+ <SelectValue placeholder="Filter" />+ </SelectTrigger>+ <SelectContent>+ {FilterOptions.map((option) => (+ <SelectItem key={option.value} value={option.value}>+ {option.label}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ <Select+ value={filter.type}+ onValueChange={(value) => {+ updateFilter(+ {+ ...filter,+ type: value as FilterType,+ },+ index+ );+ }}+ >+ <SelectTrigger>+ <SelectValue placeholder="Operator" />+ </SelectTrigger>+ <SelectContent>+ {OperatorOptions.map((option) => (+ <SelectItem key={option.value} value={option.value}>+ {option.label}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ <ValueSelect+ onChange={(value) => {+ updateFilter({ ...filter, value: value }, index);+ }}+ parameter={filter.parameter}+ value={filter.value}+ />+ <Button+ variant={"ghost"}+ size={"icon"}+ onClick={() => {+ updateFilter(null, index);+ }}+ >+ <Trash className="w-4 h-4" />+ </Button>+ </div>+ );+}diff --git a/client/src/app/[site]/components/SubHeader/Filters/ValueFilter.tsx b/client/src/app/[site]/components/shared/Filters/ValueSelect.tsxsimilarity index 51%rename from client/src/app/[site]/components/SubHeader/Filters/ValueFilter.tsxrename to client/src/app/[site]/components/shared/Filters/ValueSelect.tsxindex e95fa3b25..f8743274b 100644--- a/client/src/app/[site]/components/SubHeader/Filters/ValueFilter.tsx+++ b/client/src/app/[site]/components/shared/Filters/ValueSelect.tsx@@ -1,26 +1,24 @@"use client";-import { useMemo, useState } from "react";--import { Button } from "../../../../../components/ui/button";+import { useMemo } from "react";import { getCountryName } from "../../../../../lib/utils";-import { FilterParameter, addFilter } from "../../../../../lib/store";+import { FilterParameter } from "../../../../../lib/store";-import { MultiSelect } from "../../../../../components/MultiSelect";import { useSingleCol } from "../../../../../api/analytics/useSingleCol";+import { MultiSelect } from "../../../../../components/MultiSelect";import { useGetRegionName } from "../../../../../lib/geo";-interface ValueFilterProps {+export function ValueSelect({+ parameter,+ value,+ onChange,+}: {parameter: FilterParameter;-- type: "equals" | "not_equals" | "contains" | "not_contains";-- onComplete?: () => void;-}--export function ValueFilter({ parameter, type, onComplete }: ValueFilterProps) {+ value: string[];+ onChange: (values: string[]) => void;+}) {const { data, isLoading } = useSingleCol({parameter,limit: 1000,@@ -28,7 +26,6 @@ export function ValueFilter({ parameter, type, onComplete }: ValueFilterProps) {});const { getRegionName } = useGetRegionName();- const [selectedValues, setSelectedValues] = useState<string[]>([]);const suggestions = useMemo(() => {return (@@ -58,38 +55,24 @@ export function ValueFilter({ parameter, type, onComplete }: ValueFilterProps) {const handleChange = (selected: any) => {const values = selected.map((item: { value: string }) => item.value);- setSelectedValues(values);- };-- const handleApply = () => {- if (parameter && type && selectedValues.length > 0) {- addFilter({- parameter,- type,- value: selectedValues,- });- setSelectedValues([]);- if (onComplete) {- onComplete();- }- }+ onChange(values);};return (- <div className="flex flex-col gap-2">- <MultiSelect- options={suggestions}- onChange={handleChange}- placeholder="Select values..."- isLoading={isLoading}- />- <Button- onClick={handleApply}- disabled={selectedValues.length === 0}- className="mt-2"- >- Apply Filter- </Button>- </div>+ <MultiSelect+ value={value.map((val) => {+ if (parameter === "country") {+ return { value: val, label: getCountryName(val) };+ }+ if (parameter === "iso_3166_2") {+ return { value: val, label: getRegionName(val) };+ }+ return { value: val, label: val };+ })}+ options={suggestions}+ onChange={handleChange}+ placeholder="Select values..."+ isLoading={isLoading}+ />);}diff --git a/client/src/app/[site]/components/shared/Filters/const.ts b/client/src/app/[site]/components/shared/Filters/const.tsnew file mode 100644index 000000000..ee49de4e7--- /dev/null+++ b/client/src/app/[site]/components/shared/Filters/const.ts@@ -0,0 +1,75 @@+import { FilterParameter } from "../../../../../lib/store";++export const FilterOptions: { label: string; value: FilterParameter }[] = [+ {+ label: "Path",+ value: "pathname",+ },+ {+ label: "Page Title",+ value: "page_title",+ },+ {+ label: "Query",+ value: "querystring",+ },+ {+ label: "Referrer",+ value: "referrer",+ },+ {+ label: "Channel",+ value: "channel",+ },+ {+ label: "Country",+ value: "country",+ },+ {+ label: "Region",+ value: "iso_3166_2",+ },+ {+ label: "City",+ value: "city",+ },+ {+ label: "Device Type",+ value: "device_type",+ },+ {+ label: "Operating System",+ value: "operating_system",+ },+ {+ label: "Browser",+ value: "browser",+ },+ {+ label: "Language",+ value: "language",+ },+ {+ label: "Entry Page",+ value: "entry_page",+ },+ {+ label: "Exit Page",+ value: "exit_page",+ },+ {+ label: "Screen Dimensions",+ value: "dimensions",+ },+ {+ label: "Event Name",+ value: "event_name",+ },+];++export const OperatorOptions = [+ { label: "Is", value: "equals" },+ { label: "Is not", value: "not_equals" },+ { label: "Contains", value: "contains" },+ { label: "Not contains", value: "not_contains" },+];diff --git a/client/src/app/[site]/components/shared/StandardSection/BaseStandardSection.tsx b/client/src/app/[site]/components/shared/StandardSection/BaseStandardSection.tsxnew file mode 100644index 000000000..81df1dc13--- /dev/null+++ b/client/src/app/[site]/components/shared/StandardSection/BaseStandardSection.tsx@@ -0,0 +1,229 @@+import { Button } from "@/components/ui/button";+import {+ Dialog,+ DialogContent,+ DialogHeader,+ DialogTitle,+ DialogTrigger,+} from "@/components/ui/dialog";+import { round } from "lodash";+import { AlertCircle, RefreshCcw, SquareArrowOutUpRight } from "lucide-react";+import { ReactNode } from "react";+import { SingleColResponse } from "../../../../../api/analytics/useSingleCol";+import { addFilter, FilterParameter } from "../../../../../lib/store";+import { formatter } from "../../../../../lib/utils";+import { Skeleton } from "./Skeleton";++export const Row = ({+ e,+ ratio,+ getKey,+ getLabel,+ getValue,+ getLink,+ filterParameter,+}: {+ e: SingleColResponse;+ ratio: number;+ getKey: (item: SingleColResponse) => string;+ getLabel: (item: SingleColResponse) => ReactNode;+ getValue: (item: SingleColResponse) => string;+ getLink?: (item: SingleColResponse) => string;+ filterParameter: FilterParameter;+}) => {+ return (+ <div+ key={getKey(e)}+ className="relative h-6 flex items-center cursor-pointer hover:bg-neutral-850 group"+ onClick={() =>+ addFilter({+ parameter: filterParameter,+ value: [getValue(e)],+ type: "equals",+ })+ }+ >+ <div+ className="absolute inset-0 bg-accent-400 py-2 opacity-25 rounded-md"+ style={{ width: `${e.percentage * ratio}%` }}+ ></div>+ <div className="z-10 mx-2 flex justify-between items-center text-xs w-full">+ <div className="flex items-center gap-1">+ {getLabel(e)}+ {getLink && (+ <a+ href={getLink(e)}+ target="_blank"+ onClick={(e) => e.stopPropagation()}+ >+ <SquareArrowOutUpRight+ className="w-3 h-3 text-neutral-300 hover:text-neutral-100"+ strokeWidth={3}+ />+ </a>+ )}+ </div>+ <div className="text-xs flex gap-2">+ <div className="hidden group-hover:block text-neutral-400">+ {round(e.percentage, 1)}%+ </div>+ <div>{formatter(e.count)}</div>+ </div>+ </div>+ </div>+ );+};++interface BaseStandardSectionProps {+ title: string;+ data: { data?: SingleColResponse[] } | undefined;+ isFetching: boolean;+ error: Error | null;+ refetch: () => void;+ getKey: (item: SingleColResponse) => string;+ getLabel: (item: SingleColResponse) => ReactNode;+ getValue: (item: SingleColResponse) => string;+ getLink?: (item: SingleColResponse) => string;+ countLabel?: string;+ filterParameter: FilterParameter;+}++export function BaseStandardSection({+ title,+ data,+ isFetching,+ error,+ refetch,+ getKey,+ getLabel,+ getValue,+ getLink,+ countLabel,+ filterParameter,+}: BaseStandardSectionProps) {+ // Determine if we're in a loading state+ const isLoading = isFetching;++ const ratio = data?.data?.[0]?.percentage+ ? 100 / data?.data?.[0]?.percentage+ : 1;++ // Check for errors+ const hasError = error;+ const errorMessage =+ error?.message || "An error occurred while fetching data";++ return (+ <div className="flex flex-col gap-2">+ {isLoading ? (+ <Skeleton />+ ) : hasError ? (+ <div className="py-6 flex-1 flex flex-col items-center justify-center gap-3 transition-all">+ <AlertCircle className="text-amber-400 w-8 h-8" />+ <div className="text-center">+ <div className="text-neutral-100 font-medium mb-1">+ Failed to load data+ </div>+ <div className="text-sm text-neutral-400 max-w-md mx-auto mb-3">+ {errorMessage}+ </div>+ </div>+ <Button+ variant="outline"+ size="sm"+ className="bg-transparent hover:bg-neutral-800 border-neutral-700 text-neutral-300 hover:text-neutral-100"+ onClick={() => refetch()}+ >+ <RefreshCcw className="w-3 h-3" /> Try Again+ </Button>+ </div>+ ) : (+ <>+ <div className="flex flex-row gap-2 justify-between pr-1 text-xs text-neutral-400">+ <div>{title}</div>+ <div>{countLabel || "Sessions"}</div>+ </div>+ {data?.data?.slice(0, 10).map((e) => (+ <Row+ key={getKey(e)}+ e={e}+ ratio={ratio}+ getKey={getKey}+ getLabel={getLabel}+ getValue={getValue}+ getLink={getLink}+ filterParameter={filterParameter}+ />+ ))}+ </>+ )}+ {isLoading ? (+ // Skeleton for "View All" button when loading+ <Button variant="outline" disabled className="opacity-50">+ View All+ </Button>+ ) : !hasError && data?.data?.length && data?.data?.length > 10 ? (+ <Dialog>+ <DialogTrigger asChild>+ <Button variant="outline">View All</Button>+ </DialogTrigger>+ <DialogContent className="max-w-[90vw] w-[1000px]">+ <DialogHeader>+ <DialogTitle>{title}</DialogTitle>+ </DialogHeader>+ <div className="flex flex-col gap-2">+ <div className="flex flex-row gap-2 justify-between pr-20 text-sm text-neutral-400">+ <div>{title}</div>+ <div>{countLabel || "Sessions"}</div>+ </div>+ <div className="flex flex-col gap-2 max-h-[85vh] overflow-x-hidden">+ {data?.data?.map((e) => (+ <div+ key={getKey(e)}+ className="relative flex items-center mr-3 cursor-pointer hover:bg-neutral-850"+ onClick={() =>+ addFilter({+ parameter: filterParameter,+ value: [getValue(e)],+ type: "equals",+ })+ }+ >+ <div+ className="absolute inset-0 bg-accent-400 py-2 opacity-30 rounded-md"+ style={{ width: `${e.percentage * ratio}%` }}+ ></div>+ <div className="z-10 ml-2 mr-4 flex justify-between items-center text-xs w-full h-6">+ <div className="flex items-center gap-1">+ {getLabel(e)}+ {getLink && (+ <a+ href={getLink(e)}+ target="_blank"+ onClick={(e) => e.stopPropagation()}+ >+ <SquareArrowOutUpRight+ className="w-3 h-3 text-neutral-300 hover:text-neutral-100"+ strokeWidth={3}+ />+ </a>+ )}+ </div>+ <div className="flex">+ <div>{e.count.toLocaleString()}</div>+ <div className="mx-2 bg-neutral-400 w-[1px] rounded-full h-5"></div>+ <div className="w-10 text-neutral-400">+ {round(e.percentage, 2)}%+ </div>+ </div>+ </div>+ </div>+ ))}+ </div>+ </div>+ </DialogContent>+ </Dialog>+ ) : null}+ </div>+ );+}diff --git a/client/src/app/[site]/components/shared/StandardSection/StandardSection.tsx b/client/src/app/[site]/components/shared/StandardSection/StandardSection.tsxindex e30e53d01..766372490 100644--- a/client/src/app/[site]/components/shared/StandardSection/StandardSection.tsx+++ b/client/src/app/[site]/components/shared/StandardSection/StandardSection.tsx@@ -1,97 +1,12 @@"use client";-import { Button } from "@/components/ui/button";-import {- Dialog,- DialogContent,- DialogHeader,- DialogTitle,- DialogTrigger,-} from "@/components/ui/dialog";-import { round } from "lodash";-import { AlertCircle, RefreshCcw, SquareArrowOutUpRight } from "lucide-react";import { ReactNode, useMemo } from "react";import {SingleColResponse,useSingleCol,} from "../../../../../api/analytics/useSingleCol";-import { addFilter, FilterParameter } from "../../../../../lib/store";-import { formatter } from "../../../../../lib/utils";-import { Skeleton } from "./Skeleton";--const Row = ({- e,- ratio,- getKey,- getLabel,- getValue,- getLink,- filterParameter,-}: {- e: SingleColResponse;- ratio: number;- getKey: (item: SingleColResponse) => string;- getLabel: (item: SingleColResponse) => ReactNode;- getValue: (item: SingleColResponse) => string;- getLink?: (item: SingleColResponse) => string;- filterParameter: FilterParameter;-}) => {- return (- <div- key={getKey(e)}- className="relative h-7 flex items-center cursor-pointer hover:bg-neutral-850 group"- onClick={() =>- addFilter({- parameter: filterParameter,- value: [getValue(e)],- type: "equals",- })- }- >- <div- className="absolute inset-0 bg-accent-400 py-2 opacity-30 rounded-md"- style={{ width: `${e.percentage * ratio}%` }}- ></div>- <div className="z-10 mx-2 flex justify-between items-center text-sm w-full">- <div className="flex items-center gap-1">- {getLabel(e)}- {getLink && (- <a- href={getLink(e)}- target="_blank"- onClick={(e) => e.stopPropagation()}- >- <SquareArrowOutUpRight- className="w-3 h-3 text-neutral-300 hover:text-neutral-100"- strokeWidth={3}- />- </a>- )}- </div>- <div className="text-sm flex gap-2">- <div className="hidden group-hover:block text-neutral-400">- {round(e.percentage, 1)}%- </div>- <div>{formatter(e.count)}</div>- {/* <div>- {previousDataMap?.[getKey(e)]?.percentage ? (- <div className="text-sm flex gap-2">- <div>- {round(- e.percentage -- (previousDataMap?.[getKey(e)]?.percentage || 0),- 1- )}- %- </div>- </div>- ) : null}- </div> */}- </div>- </div>- </div>- );-};+import { FilterParameter } from "../../../../../lib/store";+import { BaseStandardSection } from "./BaseStandardSection";export function StandardSection({title,@@ -120,136 +35,30 @@ export function StandardSection({periodTime: "previous",});- // Determine if we're in a loading state+ // Create combined loading stateconst isLoading = isFetching || previousIsFetching;+ // For potential additional features that use previous dataconst previousDataMap = useMemo(() => {return previousData?.data?.reduce((acc, curr) => {acc[getKey(curr)] = curr;return acc;}, {} as Record<string, SingleColResponse>);- }, [previousData]);-- const ratio = data?.data?.[0]?.percentage- ? 100 / data?.data?.[0]?.percentage- : 1;-- // Check for errors from either query- const hasError = error || previousData?.error;- const errorMessage =- error?.message || "An error occurred while fetching data";+ }, [previousData, getKey]);return (- <div className="flex flex-col gap-2">- {isLoading ? (- <Skeleton />- ) : hasError ? (- <div className="py-6 flex-1 flex flex-col items-center justify-center gap-3 transition-all">- <AlertCircle className="text-amber-400 w-8 h-8" />- <div className="text-center">- <div className="text-neutral-100 font-medium mb-1">- Failed to load data- </div>- <div className="text-sm text-neutral-400 max-w-md mx-auto mb-3">- {errorMessage}- </div>- </div>- <Button- variant="outline"- size="sm"- className="bg-transparent hover:bg-neutral-800 border-neutral-700 text-neutral-300 hover:text-neutral-100"- onClick={() => refetch()}- >- <RefreshCcw className="w-3 h-3" /> Try Again- </Button>- </div>- ) : (- <>- <div className="flex flex-row gap-2 justify-between pr-1 text-xs text-neutral-400">- <div>{title}</div>- <div>{countLabel || "Sessions"}</div>- </div>- {data?.data?.slice(0, 10).map((e) => (- <Row- key={getKey(e)}- e={e}- ratio={ratio}- getKey={getKey}- getLabel={getLabel}- getValue={getValue}- getLink={getLink}- filterParameter={filterParameter}- />- ))}- </>- )}- {isLoading ? (- // Skeleton for "View All" button when loading- <Button variant="outline" disabled className="opacity-50">- View All- </Button>- ) : !hasError && data?.data?.length && data?.data?.length > 10 ? (- <Dialog>- <DialogTrigger asChild>- <Button variant="outline">View All</Button>- </DialogTrigger>- <DialogContent className="max-w-[90vw] w-[1000px]">- <DialogHeader>- <DialogTitle>{title}</DialogTitle>- </DialogHeader>- <div className="flex flex-col gap-2">- <div className="flex flex-row gap-2 justify-between pr-20 text-sm text-neutral-400">- <div>{title}</div>- <div>{countLabel || "Sessions"}</div>- </div>- <div className="flex flex-col gap-2 max-h-[85vh] overflow-x-hidden">- {data?.data?.map((e) => (- <div- key={getKey(e)}- className="relative flex items-center mr-3 cursor-pointer hover:bg-neutral-850"- onClick={() =>- addFilter({- parameter: filterParameter,- value: [getValue(e)],- type: "equals",- })- }- >- <div- className="absolute inset-0 bg-accent-400 py-2 opacity-30 rounded-md"- style={{ width: `${e.percentage * ratio}%` }}- ></div>- <div className="z-10 ml-2 mr-4 flex justify-between items-center text-sm w-full h-7">- <div className="flex items-center gap-1">- {getLabel(e)}- {getLink && (- <a- href={getLink(e)}- target="_blank"- onClick={(e) => e.stopPropagation()}- >- <SquareArrowOutUpRight- className="w-3 h-3 text-neutral-300 hover:text-neutral-100"- strokeWidth={3}- />- </a>- )}- </div>- <div className="text-sm flex">- <div>{e.count.toLocaleString()}</div>- <div className="mx-2 bg-neutral-400 w-[1px] rounded-full h-5"></div>- <div className="w-10 text-neutral-400">- {round(e.percentage, 2)}%- </div>- </div>- </div>- </div>- ))}- </div>- </div>- </DialogContent>- </Dialog>- ) : null}- </div>+ <BaseStandardSection+ title={title}+ data={data}+ isFetching={isLoading}+ error={error}+ refetch={refetch}+ getKey={getKey}+ getLabel={getLabel}+ getValue={getValue}+ getLink={getLink}+ countLabel={countLabel}+ filterParameter={filterParameter}+ />);}diff --git a/client/src/app/[site]/components/shared/StandardSection/StandardSectionRealtime.tsx b/client/src/app/[site]/components/shared/StandardSection/StandardSectionRealtime.tsxindex 3489d503f..bc1e4444a 100644--- a/client/src/app/[site]/components/shared/StandardSection/StandardSectionRealtime.tsx+++ b/client/src/app/[site]/components/shared/StandardSection/StandardSectionRealtime.tsx@@ -1,84 +1,12 @@"use client";-import { Button } from "@/components/ui/button";-import {- Dialog,- DialogContent,- DialogHeader,- DialogTitle,- DialogTrigger,-} from "@/components/ui/dialog";-import { round } from "lodash";-import { AlertCircle, RefreshCcw, SquareArrowOutUpRight } from "lucide-react";-import { ReactNode, useMemo } from "react";+import { ReactNode } from "react";import {SingleColResponse,- useSingleCol,useSingleColRealtime,} from "../../../../../api/analytics/useSingleCol";-import { addFilter, FilterParameter } from "../../../../../lib/store";-import { formatter } from "../../../../../lib/utils";-import { Skeleton } from "./Skeleton";--const Row = ({- e,- ratio,- getKey,- getLabel,- getValue,- getLink,- filterParameter,-}: {- e: SingleColResponse;- ratio: number;- getKey: (item: SingleColResponse) => string;- getLabel: (item: SingleColResponse) => ReactNode;- getValue: (item: SingleColResponse) => string;- getLink?: (item: SingleColResponse) => string;- filterParameter: FilterParameter;-}) => {- return (- <div- key={getKey(e)}- className="relative h-7 flex items-center cursor-pointer hover:bg-neutral-850 group"- onClick={() =>- addFilter({- parameter: filterParameter,- value: [getValue(e)],- type: "equals",- })- }- >- <div- className="absolute inset-0 bg-accent-400 py-2 opacity-30 rounded-md"- style={{ width: `${e.percentage * ratio}%` }}- ></div>- <div className="z-10 mx-2 flex justify-between items-center text-sm w-full">- <div className="flex items-center gap-1">- {getLabel(e)}- {getLink && (- <a- href={getLink(e)}- target="_blank"- onClick={(e) => e.stopPropagation()}- >- <SquareArrowOutUpRight- className="w-3 h-3 text-neutral-300 hover:text-neutral-100"- strokeWidth={3}- />- </a>- )}- </div>- <div className="text-sm flex gap-2">- <div className="hidden group-hover:block text-neutral-400">- {round(e.percentage, 1)}%- </div>- <div>{formatter(e.count)}</div>- </div>- </div>- </div>- );-};+import { FilterParameter } from "../../../../../lib/store";+import { BaseStandardSection } from "./BaseStandardSection";export function StandardSectionRealtime({title,@@ -102,128 +30,19 @@ export function StandardSectionRealtime({parameter: filterParameter,});- // Determine if we're in a loading state- const isLoading = isFetching;-- const ratio = data?.data?.[0]?.percentage- ? 100 / data?.data?.[0]?.percentage- : 1;-- const hasError = error;- const errorMessage =- error?.message || "An error occurred while fetching data";-return (- <div className="flex flex-col gap-2">- {isLoading ? (- <Skeleton />- ) : hasError ? (- <div className="py-6 flex-1 flex flex-col items-center justify-center gap-3 transition-all">- <AlertCircle className="text-amber-400 w-8 h-8" />- <div className="text-center">- <div className="text-neutral-100 font-medium mb-1">- Failed to load data- </div>- <div className="text-sm text-neutral-400 max-w-md mx-auto mb-3">- {errorMessage}- </div>- </div>- <Button- variant="outline"- size="sm"- className="bg-transparent hover:bg-neutral-800 border-neutral-700 text-neutral-300 hover:text-neutral-100"- onClick={() => refetch()}- >- <RefreshCcw className="w-3 h-3" /> Try Again- </Button>- </div>- ) : (- <>- <div className="flex flex-row gap-2 justify-between pr-1 text-xs text-neutral-400">- <div>{title}</div>- <div>{countLabel || "Sessions"}</div>- </div>- {data?.data?.slice(0, 10).map((e) => (- <Row- key={getKey(e)}- e={e}- ratio={ratio}- getKey={getKey}- getLabel={getLabel}- getValue={getValue}- getLink={getLink}- filterParameter={filterParameter}- />- ))}- </>- )}- {isLoading ? (- // Skeleton for "View All" button when loading- <Button variant="outline" disabled className="opacity-50">- View All- </Button>- ) : !hasError && data?.data?.length && data?.data?.length > 10 ? (- <Dialog>- <DialogTrigger asChild>- <Button variant="outline">View All</Button>- </DialogTrigger>- <DialogContent className="max-w-[90vw] w-[1000px]">- <DialogHeader>- <DialogTitle>{title}</DialogTitle>- </DialogHeader>- <div className="flex flex-col gap-2">- <div className="flex flex-row gap-2 justify-between pr-20 text-sm text-neutral-400">- <div>{title}</div>- <div>{countLabel || "Sessions"}</div>- </div>- <div className="flex flex-col gap-2 max-h-[85vh] overflow-x-hidden">- {data?.data?.map((e) => (- <div- key={getKey(e)}- className="relative flex items-center mr-3 cursor-pointer hover:bg-neutral-850"- onClick={() =>- addFilter({- parameter: filterParameter,- value: [getValue(e)],- type: "equals",- })- }- >- <div- className="absolute inset-0 bg-accent-400 py-2 opacity-30 rounded-md"- style={{ width: `${e.percentage * ratio}%` }}- ></div>- <div className="z-10 ml-2 mr-4 flex justify-between items-center text-sm w-full h-7">- <div className="flex items-center gap-1">- {getLabel(e)}- {getLink && (- <a- href={getLink(e)}- target="_blank"- onClick={(e) => e.stopPropagation()}- >- <SquareArrowOutUpRight- className="w-3 h-3 text-neutral-300 hover:text-neutral-100"- strokeWidth={3}- />- </a>- )}- </div>- <div className="text-sm flex">- <div>{e.count.toLocaleString()}</div>- <div className="mx-2 bg-neutral-400 w-[1px] rounded-full h-5"></div>- <div className="w-10 text-neutral-400">- {round(e.percentage, 2)}%- </div>- </div>- </div>- </div>- ))}- </div>- </div>- </DialogContent>- </Dialog>- ) : null}- </div>+ <BaseStandardSection+ title={title}+ data={data}+ isFetching={isFetching}+ error={error}+ refetch={refetch}+ getKey={getKey}+ getLabel={getLabel}+ getValue={getValue}+ getLink={getLink}+ countLabel={countLabel}+ filterParameter={filterParameter}+ />);}diff --git a/client/src/app/[site]/layout.tsx b/client/src/app/[site]/layout.tsxindex 6ec847452..de011d612 100644--- a/client/src/app/[site]/layout.tsx+++ b/client/src/app/[site]/layout.tsx@@ -48,7 +48,7 @@ export default function SiteLayout({<div className="flex flex-1 overflow-hidden"><Sidebar /><div className="flex-1 overflow-auto">- <div className="px-4 py-2 max-w-[1400px] mx-auto w-full">+ <div className="px-4 py-2 max-w-[1400px] mx-auto w-full mb-4"><Header /><div>{children}</div></div>diff --git a/client/src/app/[site]/main/components/MainSection/MainSection.tsx b/client/src/app/[site]/main/components/MainSection/MainSection.tsxindex 0ea126508..9d1e45242 100644--- a/client/src/app/[site]/main/components/MainSection/MainSection.tsx+++ b/client/src/app/[site]/main/components/MainSection/MainSection.tsx@@ -39,7 +39,7 @@ export function MainSection() {<Overview /><BucketSelection /></div>- <div className="h-[350px] relative">+ <div className="h-[310px] relative"><div className="absolute top-0 left-0 w-full h-full"><PreviousChart data={previousData} max={maxOfDataAndPreviousData} /></div>diff --git a/client/src/app/[site]/main/components/sections/Devices.tsx b/client/src/app/[site]/main/components/sections/Devices.tsxindex f52668825..9a6cac1c9 100644--- a/client/src/app/[site]/main/components/sections/Devices.tsx+++ b/client/src/app/[site]/main/components/sections/Devices.tsx@@ -18,7 +18,7 @@ type Tab = "devices" | "browsers" | "os" | "dimensions";export function Devices() {const [tab, setTab] = useState<Tab>("devices");return (- <Card className="h-[493px]">+ <Card className="h-[445px]"><CardContent className="mt-2"><TabsdefaultValue="devices"diff --git a/client/src/app/[site]/main/components/sections/Pages.tsx b/client/src/app/[site]/main/components/sections/Pages.tsxindex b06088408..5f2862d6e 100644--- a/client/src/app/[site]/main/components/sections/Pages.tsx+++ b/client/src/app/[site]/main/components/sections/Pages.tsx@@ -24,7 +24,7 @@ export function Pages({ isRealtime = false }: { isRealtime?: boolean }) {const ComponentToUse = isRealtime ? StandardSectionRealtime : StandardSection;return (- <Card className="h-[493px]">+ <Card className="h-[445px]"><CardContent className="mt-2"><TabsdefaultValue="pages"diff --git a/client/src/app/[site]/main/components/sections/Referrers.tsx b/client/src/app/[site]/main/components/sections/Referrers.tsxindex 15df31f3a..ca690049c 100644--- a/client/src/app/[site]/main/components/sections/Referrers.tsx+++ b/client/src/app/[site]/main/components/sections/Referrers.tsx@@ -18,7 +18,7 @@ export function Referrers({ isRealtime = false }: { isRealtime?: boolean }) {const ComponentToUse = isRealtime ? StandardSectionRealtime : StandardSection;return (- <Card className="h-[493px]">+ <Card className="h-[445px]"><CardContent className="mt-2"><TabsdefaultValue="referrers"diff --git a/client/src/components/MultiSelect.tsx b/client/src/components/MultiSelect.tsxindex 6353b62c5..778bd44cf 100644--- a/client/src/components/MultiSelect.tsx+++ b/client/src/components/MultiSelect.tsx@@ -25,7 +25,7 @@ export const MultiSelect = forwardRef<any, MultiSelectProps<any>>(classNames={{control: ({ isFocused }) =>cn(- "flex w-[300px] min-h-[36px] rounded-md bg-neutral-900 px-3 py-[3px] text-sm shadow-sm transition-colors ",+ "flex w-[300px] min-h-[36px] rounded-md px-3 py-[3px] text-sm shadow-sm transition-colors ","placeholder:text-muted-foreground ","disabled:cursor-not-allowed disabled:opacity-50",isFocused && "ring-1 ring-ring",@@ -46,7 +46,7 @@ export const MultiSelect = forwardRef<any, MultiSelectProps<any>>("text-popover-foreground hover:bg-accent hover:text-accent-foreground"),multiValue: () =>- "inline-flex items-center bg-secondary text-secondary-foreground mr-1",+ "inline-flex items-center bg-neutral-750 rounded-md text-secondary-foreground mr-1",multiValueLabel: () => "px-2 text-xs leading-none",multiValueRemove: () =>cn(@@ -64,7 +64,7 @@ export const MultiSelect = forwardRef<any, MultiSelectProps<any>>(styles={{control: (base) => ({...base,- border: "1px solid hsl(var(--neutral-800))",+ border: "1px solid hsl(var(--neutral-750))",}),}}{...props}diff --git a/client/src/components/Sessions/SessionsList.tsx b/client/src/components/Sessions/SessionsList.tsxindex faab2168d..e843073c0 100644--- a/client/src/components/Sessions/SessionsList.tsx+++ b/client/src/components/Sessions/SessionsList.tsx@@ -57,7 +57,7 @@ export default function SessionsList({ userId }: { userId?: string }) {<divref={containerRef}className="overflow-auto pr-2"- style={{ height: "calc(100vh - 200px)" }}+ style={{ height: "calc(100vh - 130px)" }}>{isLoading ? (// Show skeleton cards while loadingdiff --git a/client/src/components/TopBar.tsx b/client/src/components/TopBar.tsxindex 4820e4709..4f1ecbd7c 100644--- a/client/src/components/TopBar.tsx+++ b/client/src/components/TopBar.tsx@@ -1,6 +1,5 @@"use client";-import { User } from "@phosphor-icons/react";import { useQueryClient } from "@tanstack/react-query";import Link from "next/link";import { useRouter } from "next/navigation";@@ -11,6 +10,7 @@ import {DropdownMenuItem,DropdownMenuTrigger,} from "./ui/dropdown-menu";+import { User } from "lucide-react";export function TopBar() {const session = authClient.useSession();@@ -18,16 +18,19 @@ export function TopBar() {const queryClient = useQueryClient();return (- <div className="flex pt-2 pb-2 px-3 items-center w-full bg-neutral-900 justify-center">+ <div className="flex py-1 px-3 items-center w-full bg-neutral-900 justify-center"><div className="flex items-center justify-between flex-1"><div className="flex items-center space-x-4">- <Link href="/" className="font-bold text-lg">+ <Link href="/" className="font-semibold text-base">🐸 Frogstats</Link></div><DropdownMenu>- <DropdownMenuTrigger className="flex items-center gap-1 text-sm font-medium">- <User size={16} weight="bold" />+ <DropdownMenuTrigger+ className="flex items-center gap-1 text-xs font-medium px-2 py-0"+ variant="ghost"+ >+ <User className="w-4 h-4" />{session.data?.user.name}</DropdownMenuTrigger><DropdownMenuContent align="end">diff --git a/client/src/components/ui/button.tsx b/client/src/components/ui/button.tsxindex 7ab1c7144..6c57b47a3 100644--- a/client/src/components/ui/button.tsx+++ b/client/src/components/ui/button.tsx@@ -22,7 +22,7 @@ const buttonVariants = cva(warning:"bg-yellow-500 text-neutral-900 shadow-sm hover:bg-yellow-500/90 dark:bg-yellow-600 dark:text-neutral-50 dark:hover:bg-yellow-600/90",outline:- "border border-neutral-200 bg-white shadow-sm hover:bg-neutral-100 hover:text-neutral-900 dark:border-neutral-700 dark:bg-neutral-900 dark:hover:bg-neutral-800 dark:hover:text-neutral-50",+ "border border-neutral-200 shadow-sm hover:bg-neutral-100 hover:text-neutral-900 dark:border-neutral-700 dark:hover:bg-neutral-800 dark:hover:text-neutral-50",ghost:"hover:bg-neutral-100 hover:text-neutral-900 dark:hover:bg-neutral-800 dark:hover:text-neutral-50",link: "text-neutral-900 underline-offset-4 hover:underline dark:text-neutral-50",diff --git a/client/src/components/ui/dropdown-menu.tsx b/client/src/components/ui/dropdown-menu.tsxindex 16121d8cf..e0063688d 100644--- a/client/src/components/ui/dropdown-menu.tsx+++ b/client/src/components/ui/dropdown-menu.tsx@@ -80,7 +80,7 @@ const DropdownMenuContent = React.forwardRef<ref={ref}sideOffset={sideOffset}className={cn(- "z-50 min-w-[8rem] rounded-md border border-neutral-200 bg-white p-1 text-neutral-950 shadow-md dark:border-neutral-850 dark:bg-neutral-900 dark:text-neutral-50",+ "z-50 min-w-[8rem] rounded-lg border border-neutral-200 bg-white p-1 text-neutral-950 shadow-2xl dark:border-neutral-750 dark:bg-neutral-850 dark:text-neutral-50","data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",className)}diff --git a/client/src/components/ui/select.tsx b/client/src/components/ui/select.tsxindex 50864a2a0..64acd61c4 100644--- a/client/src/components/ui/select.tsx+++ b/client/src/components/ui/select.tsx@@ -21,7 +21,7 @@ const SelectTrigger = React.forwardRef<<SelectPrimitive.Triggerref={ref}className={cn(- "flex w-full items-center justify-between whitespace-nowrap rounded-md border border-neutral-200 bg-transparent px-3 text-sm shadow-sm ring-offset-white placeholder:text-neutral-500 focus:outline-none focus:ring-1 focus:ring-neutral-950 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1 dark:border-neutral-800 dark:ring-offset-neutral-950 dark:placeholder:text-neutral-400 dark:focus:ring-neutral-300",+ "flex w-full items-center justify-between whitespace-nowrap rounded-md border border-neutral-200 bg-transparent px-3 text-sm shadow-sm ring-offset-white placeholder:text-neutral-500 focus:outline-none focus:ring-1 focus:ring-neutral-950 disabled:cursor-not-allowed disabled:opacity-50 [&>span]:line-clamp-1 dark:border-neutral-750 dark:ring-offset-neutral-950 dark:placeholder:text-neutral-400 dark:focus:ring-neutral-300",size === "default" && "h-9 py-2",size === "sm" && "h-7 py-1 text-xs",classNamediff --git a/server/src/api/getOverviewBucketed.ts b/server/src/api/getOverviewBucketed.tsindex c971aba15..5fadb07d3 100644--- a/server/src/api/getOverviewBucketed.ts+++ b/server/src/api/getOverviewBucketed.ts@@ -208,8 +208,6 @@ export async function getOverviewBucketed(pastMinutes,});- console.info(query);-try {const result = await clickhouse.query({query,