Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Immediate filter on row click (#3654)

Pedro Ladeiraf3c8a181030d
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/analytics/analytics-partners-table.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/analytics/analytics-partners-table.tsx
index 89adaceab8..028a7a6f8e 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/analytics/analytics-partners-table.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/analytics/analytics-partners-table.tsx
@@ -115,6 +115,10 @@ export function AnalyticsPartnersTable() {
isStaged={stagedPartnerIds?.includes(partnerId) ?? false}
isApplied={activePartnerIdsFromUrl.includes(partnerId)}
onToggle={() => toggleStagePartner(partnerId)}
+ onApplyImmediate={() => {
+ queryParams({ set: { partnerId }, del: "page" });
+ setStagedPartnerIds(null);
+ }}
/>
);
},
diff --git a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/analytics/partner-analytics-filter-cell.tsx b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/analytics/partner-analytics-filter-cell.tsx
index 037e8ed255..b9bf739872 100644
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/analytics/partner-analytics-filter-cell.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/analytics/partner-analytics-filter-cell.tsx
@@ -16,6 +16,7 @@ interface PartnerAnalyticsFilterCellProps {
isStaged: boolean;
isApplied: boolean;
onToggle: () => void;
+ onApplyImmediate: () => void;
}
export function PartnerAnalyticsFilterCell({
@@ -24,30 +25,17 @@ export function PartnerAnalyticsFilterCell({
isStaged,
isApplied,
onToggle,
+ onApplyImmediate,
}: PartnerAnalyticsFilterCellProps) {
const { slug } = useParams() as { slug: string };
return (
<div
- role={!isApplied ? "button" : undefined}
- tabIndex={!isApplied ? 0 : -1}
- aria-disabled={isApplied}
className={cn(
"flex select-none items-center gap-2",
!isApplied && "cursor-pointer",
- "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-neutral-400 focus-visible:ring-offset-1",
)}
- onClick={isApplied ? undefined : onToggle}
- onKeyDown={
- !isApplied
- ? (e) => {
- if (e.key === "Enter" || e.key === " ") {
- e.preventDefault();
- onToggle();
- }
- }
- : undefined
- }
+ onClick={isApplied ? undefined : onApplyImmediate}
>
<div className="relative size-6 shrink-0">
<div
@@ -62,19 +50,35 @@ export function PartnerAnalyticsFilterCell({
</div>
<div className="absolute inset-0 flex items-center justify-center">
- <div
+ <button
+ type="button"
+ onClick={(e) => {
+ e.stopPropagation();
+ if (isApplied) return;
+ if (isStaged) {
+ onToggle();
+ } else {
+ onApplyImmediate();
+ }
+ }}
className={cn(
"flex size-6 shrink-0 items-center justify-center rounded-lg transition-all duration-200",
+ "focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-neutral-400 focus-visible:ring-offset-1",
isStaged
- ? "pointer-events-none translate-x-0 opacity-100"
+ ? "pointer-events-auto translate-x-0 opacity-100"
: cn(
"-translate-x-3 opacity-0 group-hover:translate-x-0 group-hover:opacity-100",
- "pointer-events-none",
+ "pointer-events-none group-hover:pointer-events-auto",
+ "focus-visible:pointer-events-auto focus-visible:translate-x-0 focus-visible:opacity-100",
),
isStaged || isApplied
? "bg-neutral-900"
: "border border-neutral-200 bg-white",
)}
+ aria-label={
+ isStaged ? "Remove from multi-select" : "Filter by this partner"
+ }
+ aria-pressed={isStaged}
>
<FilterBars
className={cn(
@@ -82,7 +86,7 @@ export function PartnerAnalyticsFilterCell({
isStaged || isApplied ? "text-white" : "text-neutral-500",
)}
/>
- </div>
+ </button>
</div>
</div>
diff --git a/apps/web/ui/analytics/bar-list.tsx b/apps/web/ui/analytics/bar-list.tsx
index f0a050e1f1..67421d3b5f 100644
--- a/apps/web/ui/analytics/bar-list.tsx
+++ b/apps/web/ui/analytics/bar-list.tsx
@@ -44,6 +44,7 @@ export function BarList({
onClearFilter,
onClearSelection,
onApplyFilterValues,
+ onImmediateFilter,
}: {
tab: string;
unit: string;
@@ -78,6 +79,7 @@ export function BarList({
onClearFilter?: () => void;
onClearSelection?: () => void;
onApplyFilterValues?: (values: string[]) => void;
+ onImmediateFilter?: (value: string) => void;
}) {
const [search, setSearch] = useState("");
const [modalSelectedValues, setModalSelectedValues] = useState<string[]>(
@@ -161,6 +163,15 @@ export function BarList({
? () => onToggleFilter(data.filterValue!)
: undefined
: undefined,
+ onRowClick:
+ data.filterValue && onImmediateFilter
+ ? !limit
+ ? () => {
+ onImmediateFilter(data.filterValue!);
+ setShowModal(false);
+ }
+ : () => onImmediateFilter(data.filterValue!)
+ : undefined,
}));
const filterButtons = hasSelection &&
@@ -291,6 +302,7 @@ export function LineItem({
isSelected,
isActivelyFiltered,
onFilterClick,
+ onRowClick,
href,
}: {
icon: ReactNode;
@@ -310,6 +322,7 @@ export function LineItem({
isSelected?: boolean;
isActivelyFiltered?: boolean;
onFilterClick?: () => void;
+ onRowClick?: () => void;
href?: string;
}) {
const [isHovered, setIsHovered] = useState(false);
@@ -414,16 +427,19 @@ export function LineItem({
);
const rowClickable =
- (onFilterClick && !isActivelyFiltered) || (!!href && !onFilterClick);
+ (!isActivelyFiltered && (!!onRowClick || !!onFilterClick)) ||
+ (!!href && !onFilterClick && !onRowClick);
return (
<div
onMouseEnter={() => setIsHovered(true)}
onMouseLeave={() => setIsHovered(false)}
onClick={() => {
- if (onFilterClick && !isActivelyFiltered) {
+ if (onRowClick && !isActivelyFiltered) {
+ onRowClick();
+ } else if (onFilterClick && !isActivelyFiltered) {
onFilterClick();
- } else if (href && !onFilterClick) {
+ } else if (href && !onFilterClick && !onRowClick) {
router.push(href);
setShowModal(false);
}
diff --git a/apps/web/ui/analytics/device-section.tsx b/apps/web/ui/analytics/device-section.tsx
index fd613b4dae..6a33a075c0 100644
--- a/apps/web/ui/analytics/device-section.tsx
+++ b/apps/web/ui/analytics/device-section.tsx
@@ -129,6 +129,7 @@ export function DeviceSection() {
onClearFilter={onClearFilter}
onClearSelection={() => setSelectedItems([])}
onApplyFilterValues={onApplyFilterValues}
+ onImmediateFilter={(val) => onApplyFilterValues([val])}
{...(limit && { limit })}
/>
) : (
diff --git a/apps/web/ui/analytics/location-section.tsx b/apps/web/ui/analytics/location-section.tsx
index e29da4b3d2..a0139727b0 100644
--- a/apps/web/ui/analytics/location-section.tsx
+++ b/apps/web/ui/analytics/location-section.tsx
@@ -162,6 +162,7 @@ export function LocationSection() {
onClearFilter={onClearFilter}
onClearSelection={() => setSelectedItems([])}
onApplyFilterValues={onApplyFilterValues}
+ onImmediateFilter={(val) => onApplyFilterValues([val])}
{...(limit && { limit })}
/>
) : (
diff --git a/apps/web/ui/analytics/partner-section.tsx b/apps/web/ui/analytics/partner-section.tsx
index 78aabef2c5..9a4666713f 100644
--- a/apps/web/ui/analytics/partner-section.tsx
+++ b/apps/web/ui/analytics/partner-section.tsx
@@ -258,6 +258,11 @@ export function PartnerSection() {
onApplyFilterValues={
filterParamKey ? onApplyFilterValues : undefined
}
+ onImmediateFilter={
+ filterParamKey
+ ? (val) => onApplyFilterValues([val])
+ : undefined
+ }
{...(limit && { limit })}
/>
) : (
diff --git a/apps/web/ui/analytics/referrers-utms.tsx b/apps/web/ui/analytics/referrers-utms.tsx
index 6677c8bcb1..3747e75eea 100644
--- a/apps/web/ui/analytics/referrers-utms.tsx
+++ b/apps/web/ui/analytics/referrers-utms.tsx
@@ -216,6 +216,7 @@ export function ReferrersUTMs() {
onClearFilter={onClearFilter}
onClearSelection={() => setSelectedItems([])}
onApplyFilterValues={onApplyFilterValues}
+ onImmediateFilter={(val) => onApplyFilterValues([val])}
{...(limit && { limit })}
/>
) : (
diff --git a/apps/web/ui/analytics/top-links.tsx b/apps/web/ui/analytics/top-links.tsx
index 34525ec0d2..1fd3f92f63 100644
--- a/apps/web/ui/analytics/top-links.tsx
+++ b/apps/web/ui/analytics/top-links.tsx
@@ -251,6 +251,11 @@ export function TopLinks() {
onApplyFilterValues={
filterParamKey ? onApplyFilterValues : undefined
}
+ onImmediateFilter={
+ filterParamKey
+ ? (val) => onApplyFilterValues([val])
+ : undefined
+ }
{...(limit && { limit })}
/>
) : (