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.

run prettier

Steven Tey753ef7c65713
diff --git a/apps/web/app/(ee)/api/cron/export/events/workspace/route.ts b/apps/web/app/(ee)/api/cron/export/events/workspace/route.ts
index ac00dd4e1d..d264030b57 100644
--- a/apps/web/app/(ee)/api/cron/export/events/workspace/route.ts
+++ b/apps/web/app/(ee)/api/cron/export/events/workspace/route.ts
@@ -77,8 +77,7 @@ export async function POST(req: Request) {
);
}
- const { linkId, folderIds, dataAvailableFrom, ...eventFilters } =
- filters;
+ const { linkId, folderIds, dataAvailableFrom, ...eventFilters } = filters;
// Fetch events in batches and build CSV
const allEvents: Record<string, any>[] = [];
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/analytics/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/analytics/route.ts
index d71db79463..78e12f299d 100644
--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/analytics/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/analytics/route.ts
@@ -24,8 +24,12 @@ export const GET = withPartnerProfile(
},
});
- let { linkId, domain: domainFilter, key, ...rest } =
- partnerProfileAnalyticsQuerySchema.parse(searchParams);
+ let {
+ linkId,
+ domain: domainFilter,
+ key,
+ ...rest
+ } = partnerProfileAnalyticsQuerySchema.parse(searchParams);
const domain = getFirstFilterValue(domainFilter);
diff --git a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/events/route.ts b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/events/route.ts
index 629b36d826..4e2bf77e13 100644
--- a/apps/web/app/(ee)/api/partner-profile/programs/[programId]/events/route.ts
+++ b/apps/web/app/(ee)/api/partner-profile/programs/[programId]/events/route.ts
@@ -39,8 +39,12 @@ export const GET = withPartnerProfile(
});
}
- let { linkId, domain: domainFilter, key, ...rest } =
- partnerProfileEventsQuerySchema.parse(searchParams);
+ let {
+ linkId,
+ domain: domainFilter,
+ key,
+ ...rest
+ } = partnerProfileEventsQuerySchema.parse(searchParams);
const domain = getFirstFilterValue(domainFilter);
diff --git a/apps/web/app/api/analytics/dashboard/route.ts b/apps/web/app/api/analytics/dashboard/route.ts
index 68a39902e7..f718192b77 100644
--- a/apps/web/app/api/analytics/dashboard/route.ts
+++ b/apps/web/app/api/analytics/dashboard/route.ts
@@ -19,7 +19,14 @@ export const GET = async (req: Request) => {
const searchParams = getSearchParams(req.url);
const parsedParams = parseAnalyticsQuery(searchParams);
- const { domain: domainFilter, key, folderId: folderIdFilter, interval, start, end } = parsedParams;
+ const {
+ domain: domainFilter,
+ key,
+ folderId: folderIdFilter,
+ interval,
+ start,
+ end,
+ } = parsedParams;
// Extract string values for specific link/folder lookup
const domain = getFirstFilterValue(domainFilter);
diff --git a/apps/web/app/api/analytics/export/route.ts b/apps/web/app/api/analytics/export/route.ts
index c0780fb50f..99807b67bc 100644
--- a/apps/web/app/api/analytics/export/route.ts
+++ b/apps/web/app/api/analytics/export/route.ts
@@ -20,8 +20,16 @@ export const GET = withWorkspace(
const parsedParams = parseAnalyticsQuery(searchParams);
- const { interval, start, end, linkId, externalId, domain: domainFilter, key, folderId: folderIdFilter } =
- parsedParams;
+ const {
+ interval,
+ start,
+ end,
+ linkId,
+ externalId,
+ domain: domainFilter,
+ key,
+ folderId: folderIdFilter,
+ } = parsedParams;
// Extract string values for specific link/folder lookup
const domain = getFirstFilterValue(domainFilter);
diff --git a/apps/web/lib/analytics/query-parser.ts b/apps/web/lib/analytics/query-parser.ts
index 7403c9fe15..a4cf010824 100644
--- a/apps/web/lib/analytics/query-parser.ts
+++ b/apps/web/lib/analytics/query-parser.ts
@@ -102,7 +102,8 @@ function parseCondition(condition: string): InternalFilter | null {
// Security: Sanitize value to prevent SQL injection
// Remove potentially dangerous characters from the value
- const sanitizedValue = value.trim()
+ const sanitizedValue = value
+ .trim()
.replace(/^['"`]|['"`]$/g, "")
.replace(/[;\\]|--|\*\/|\/\*/g, "");
diff --git a/apps/web/lib/analytics/types.ts b/apps/web/lib/analytics/types.ts
index 8c4f5d9ab4..91742eb572 100644
--- a/apps/web/lib/analytics/types.ts
+++ b/apps/web/lib/analytics/types.ts
@@ -38,7 +38,9 @@ export type AnalyticsSaleUnit = (typeof ANALYTICS_SALE_UNIT)[number];
export type DeviceTabs = "devices" | "browsers" | "os" | "triggers";
-export type AnalyticsFilters = Partial<Omit<z.infer<typeof analyticsQuerySchema>, 'start' | 'end' | 'partnerId'>> & {
+export type AnalyticsFilters = Partial<
+ Omit<z.infer<typeof analyticsQuerySchema>, "start" | "end" | "partnerId">
+> & {
workspaceId?: string;
dataAvailableFrom?: Date;
isDeprecatedClicksEndpoint?: boolean;
@@ -51,9 +53,17 @@ export type AnalyticsFilters = Partial<Omit<z.infer<typeof analyticsQuerySchema>
};
// Structural fields from eventsQuerySchema that should remain required
-type EventsStructuralFields = Pick<z.infer<typeof eventsQuerySchema>, 'event' | 'page' | 'limit' | 'sortBy'>;
+type EventsStructuralFields = Pick<
+ z.infer<typeof eventsQuerySchema>,
+ "event" | "page" | "limit" | "sortBy"
+>;
-export type EventsFilters = Partial<Omit<z.infer<typeof eventsQuerySchema>, 'start' | 'end' | 'partnerId' | keyof EventsStructuralFields>> &
+export type EventsFilters = Partial<
+ Omit<
+ z.infer<typeof eventsQuerySchema>,
+ "start" | "end" | "partnerId" | keyof EventsStructuralFields
+ >
+> &
EventsStructuralFields & {
workspaceId?: string;
dataAvailableFrom?: Date;
diff --git a/apps/web/lib/partnerstack/import-customers.ts b/apps/web/lib/partnerstack/import-customers.ts
index 70d9ef6833..7be8186366 100644
--- a/apps/web/lib/partnerstack/import-customers.ts
+++ b/apps/web/lib/partnerstack/import-customers.ts
@@ -229,8 +229,7 @@ async function createCustomer({
// Find the customer by email address
const customerFound = existingCustomers.find(
- (c) =>
- c.email === customer.email || c.externalId === customer.customer_key,
+ (c) => c.email === customer.email || c.externalId === customer.customer_key,
);
if (customerFound) {
diff --git a/apps/web/lib/rewardful/import-customers.ts b/apps/web/lib/rewardful/import-customers.ts
index a1bd3a455a..17c5d382c6 100644
--- a/apps/web/lib/rewardful/import-customers.ts
+++ b/apps/web/lib/rewardful/import-customers.ts
@@ -44,8 +44,7 @@ export async function importCustomers(payload: RewardfulImportPayload) {
const stripeCustomerIds = referrals
.filter(
- (r) =>
- r.stripe_customer_id && r.stripe_customer_id.startsWith("cus_"),
+ (r) => r.stripe_customer_id && r.stripe_customer_id.startsWith("cus_"),
)
.map((r) => r.stripe_customer_id!);
const externalIds = referrals.map((r) => r.customer.id);
diff --git a/apps/web/lib/stripe/index.ts b/apps/web/lib/stripe/index.ts
index 8b71428b16..9e01e9a52a 100644
--- a/apps/web/lib/stripe/index.ts
+++ b/apps/web/lib/stripe/index.ts
@@ -26,4 +26,4 @@ export const stripeAppClient = ({ mode }: { mode?: StripeMode }) => {
version: "0.1.0",
},
});
-};
\ No newline at end of file
+};
diff --git a/apps/web/lib/tolt/import-customers.ts b/apps/web/lib/tolt/import-customers.ts
index 4bca9cf88f..d7bc164962 100644
--- a/apps/web/lib/tolt/import-customers.ts
+++ b/apps/web/lib/tolt/import-customers.ts
@@ -108,9 +108,7 @@ export async function importCustomers(payload: ToltImportPayload) {
{} as Record<string, Date>,
);
- const externalIds = customers.map(
- (c) => c.customer_id || c.email || c.id,
- );
+ const externalIds = customers.map((c) => c.customer_id || c.email || c.id);
const existingCustomers = await prisma.customer.findMany({
where: {
diff --git a/apps/web/lib/zod/schemas/analytics.ts b/apps/web/lib/zod/schemas/analytics.ts
index 0fa6bd1348..3c56ba3fe6 100644
--- a/apps/web/lib/zod/schemas/analytics.ts
+++ b/apps/web/lib/zod/schemas/analytics.ts
@@ -3,11 +3,9 @@ import {
EVENT_TYPES,
OLD_ANALYTICS_ENDPOINTS,
OLD_TO_NEW_ANALYTICS_ENDPOINTS,
- TRIGGER_TYPES,
VALID_ANALYTICS_ENDPOINTS,
} from "@/lib/analytics/constants";
import {
- CONTINENT_CODES,
DEFAULT_PAGINATION_LIMIT,
DUB_FOUNDING_DATE,
capitalize,
@@ -55,375 +53,381 @@ export const analyticsPathParamsSchema = z.object({
// Query schema for GET /analytics and GET /events endpoints
export const analyticsQuerySchema = z.object({
- event: analyticsEvents,
- groupBy: analyticsGroupBy,
- domain: z
- .string()
- .optional()
- .transform(parseFilterValue)
- .describe(
- "The domain to filter analytics for. " +
+ event: analyticsEvents,
+ groupBy: analyticsGroupBy,
+ domain: z
+ .string()
+ .optional()
+ .transform(parseFilterValue)
+ .describe(
+ "The domain to filter analytics for. " +
"Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). " +
- "Examples: `dub.co`, `dub.co,google.com`, `-spam.com`."
- )
- .meta({ example: "dub.co" }),
- key: z
- .string()
- .optional()
- .describe(
- "The slug of the short link to retrieve analytics for. Must be used along with the corresponding `domain` of the short link to fetch analytics for a specific short link.",
- ),
- linkId: z
- .string()
- .optional()
- .describe(
- "The unique ID of the short link on Dub to retrieve analytics for.",
- )
- .meta({ deprecated: false }), // Keep for backward compatibility
- linkIds: z
- .union([z.string(), z.array(z.string())])
- .transform((v) => (Array.isArray(v) ? v : v.split(",")))
- .optional()
- .describe(
- "The link IDs to retrieve analytics for. Supports comma-separated values or array format.",
- ),
- externalId: z
- .string()
- .optional()
- .describe(
- "The ID of the link in the your database. Must be prefixed with 'ext_' when passed as a query parameter.",
- ),
- tenantId: z
- .string()
- .optional()
- .transform(parseFilterValue)
- .describe(
- "The ID of the tenant that created the link inside your system. " +
+ "Examples: `dub.co`, `dub.co,google.com`, `-spam.com`.",
+ )
+ .meta({ example: "dub.co" }),
+ key: z
+ .string()
+ .optional()
+ .describe(
+ "The slug of the short link to retrieve analytics for. Must be used along with the corresponding `domain` of the short link to fetch analytics for a specific short link.",
+ ),
+ linkId: z
+ .string()
+ .optional()
+ .describe(
+ "The unique ID of the short link on Dub to retrieve analytics for.",
+ )
+ .meta({ deprecated: false }), // Keep for backward compatibility
+ linkIds: z
+ .union([z.string(), z.array(z.string())])
+ .transform((v) => (Array.isArray(v) ? v : v.split(",")))
+ .optional()
+ .describe(
+ "The link IDs to retrieve analytics for. Supports comma-separated values or array format.",
+ ),
+ externalId: z
+ .string()
+ .optional()
+ .describe(
+ "The ID of the link in the your database. Must be prefixed with 'ext_' when passed as a query parameter.",
+ ),
+ tenantId: z
+ .string()
+ .optional()
+ .transform(parseFilterValue)
+ .describe(
+ "The ID of the tenant that created the link inside your system. " +
"Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). " +
- "Examples: `tenant_123`, `tenant_123,tenant_456`, `-tenant_789`."
- )
- .meta({ example: "tenant_123" }),
- programId: z
- .string()
- .optional()
- .describe("The ID of the program to retrieve analytics for."),
- partnerId: z
- .string()
- .optional()
- .transform(parseFilterValue)
- .describe(
- "The ID of the partner to retrieve analytics for. " +
+ "Examples: `tenant_123`, `tenant_123,tenant_456`, `-tenant_789`.",
+ )
+ .meta({ example: "tenant_123" }),
+ programId: z
+ .string()
+ .optional()
+ .describe("The ID of the program to retrieve analytics for."),
+ partnerId: z
+ .string()
+ .optional()
+ .transform(parseFilterValue)
+ .describe(
+ "The ID of the partner to retrieve analytics for. " +
"Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). " +
- "Examples: `pn_123`, `pn_123,pn_456`, `-pn_789`."
- )
- .meta({ example: "pn_123" }),
- customerId: z
- .string()
- .optional()
- .describe("The ID of the customer to retrieve analytics for."),
- interval: z
- .enum(DATE_RANGE_INTERVAL_PRESETS)
- .optional()
- .describe(
- "The interval to retrieve analytics for. If undefined, defaults to 24h.",
- ),
- start: parseDateSchema
- .refine((value: Date) => value >= DUB_FOUNDING_DATE, {
- message: `The start date cannot be earlier than ${formatDate(DUB_FOUNDING_DATE)}.`,
- })
- .optional()
- .describe(
- "The start date and time when to retrieve analytics from. If set, takes precedence over `interval`.",
- ),
- end: parseDateSchema
- .optional()
- .describe(
- "The end date and time when to retrieve analytics from. If not provided, defaults to the current date. If set along with `start`, takes precedence over `interval`.",
- ),
- timezone: z
- .string()
- .optional()
- .describe(
- "The IANA time zone code for aligning timeseries granularity (e.g. America/New_York). Defaults to UTC.",
- )
- .meta({ example: "America/New_York", default: "UTC" }),
- country: z
- .string()
- .optional()
- .transform(parseFilterValue)
- .describe(
- "The country to retrieve analytics for. Must be passed as a 2-letter ISO 3166-1 country code. " +
+ "Examples: `pn_123`, `pn_123,pn_456`, `-pn_789`.",
+ )
+ .meta({ example: "pn_123" }),
+ customerId: z
+ .string()
+ .optional()
+ .describe("The ID of the customer to retrieve analytics for."),
+ interval: z
+ .enum(DATE_RANGE_INTERVAL_PRESETS)
+ .optional()
+ .describe(
+ "The interval to retrieve analytics for. If undefined, defaults to 24h.",
+ ),
+ start: parseDateSchema
+ .refine((value: Date) => value >= DUB_FOUNDING_DATE, {
+ message: `The start date cannot be earlier than ${formatDate(DUB_FOUNDING_DATE)}.`,
+ })
+ .optional()
+ .describe(
+ "The start date and time when to retrieve analytics from. If set, takes precedence over `interval`.",
+ ),
+ end: parseDateSchema
+ .optional()
+ .describe(
+ "The end date and time when to retrieve analytics from. If not provided, defaults to the current date. If set along with `start`, takes precedence over `interval`.",
+ ),
+ timezone: z
+ .string()
+ .optional()
+ .describe(
+ "The IANA time zone code for aligning timeseries granularity (e.g. America/New_York). Defaults to UTC.",
+ )
+ .meta({ example: "America/New_York", default: "UTC" }),
+ country: z
+ .string()
+ .optional()
+ .transform(parseFilterValue)
+ .describe(
+ "The country to retrieve analytics for. Must be passed as a 2-letter ISO 3166-1 country code. " +
"Supports advanced filtering: " +
"• Single value: `US` (IS US) " +
"• Multiple values: `US,BR,FR` (IS ONE OF) " +
"• Exclude single: `-US` (IS NOT US) " +
"• Exclude multiple: `-US,BR` (IS NOT ONE OF). " +
"See https://d.to/geo for country codes.",
- )
- .meta({
- example: "US",
- }),
- city: z
- .string()
- .optional()
- .transform(parseFilterValue)
- .describe(
- "The city to retrieve analytics for. " +
+ )
+ .meta({
+ example: "US",
+ }),
+ city: z
+ .string()
+ .optional()
+ .transform(parseFilterValue)
+ .describe(
+ "The city to retrieve analytics for. " +
"Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). " +
- "Examples: `New York`, `New York,London`, `-New York`."
- )
- .meta({ example: "New York" }),
- region: z
- .string()
- .optional()
- .describe("The ISO 3166-2 region code to retrieve analytics for."),
- continent: z
- .string()
- .optional()
- .transform(parseFilterValue)
- .describe(
- "The continent to retrieve analytics for. " +
+ "Examples: `New York`, `New York,London`, `-New York`.",
+ )
+ .meta({ example: "New York" }),
+ region: z
+ .string()
+ .optional()
+ .describe("The ISO 3166-2 region code to retrieve analytics for."),
+ continent: z
+ .string()
+ .optional()
+ .transform(parseFilterValue)
+ .describe(
+ "The continent to retrieve analytics for. " +
"Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). " +
"Valid values: AF, AN, AS, EU, NA, OC, SA. " +
- "Examples: `NA`, `NA,EU`, `-AS`."
- )
- .meta({ example: "NA" }),
- device: z
- .string()
- .optional()
- .transform((v) => {
- if (!v) return undefined;
- // Capitalize each value
- const parsed = parseFilterValue(v);
- if (!parsed) return undefined;
- return {
- ...parsed,
- values: parsed.values.map((val) => capitalize(val)).filter(Boolean) as string[],
- };
- })
- .describe(
- "The device to retrieve analytics for. " +
+ "Examples: `NA`, `NA,EU`, `-AS`.",
+ )
+ .meta({ example: "NA" }),
+ device: z
+ .string()
+ .optional()
+ .transform((v) => {
+ if (!v) return undefined;
+ // Capitalize each value
+ const parsed = parseFilterValue(v);
+ if (!parsed) return undefined;
+ return {
+ ...parsed,
+ values: parsed.values
+ .map((val) => capitalize(val))
+ .filter(Boolean) as string[],
+ };
+ })
+ .describe(
+ "The device to retrieve analytics for. " +
"Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). " +
- "Examples: `Desktop`, `Mobile,Tablet`, `-Mobile`."
- )
- .meta({ example: "Desktop" }),
- browser: z
- .string()
- .optional()
- .transform((v) => {
- if (!v) return undefined;
- const parsed = parseFilterValue(v);
- if (!parsed) return undefined;
- return {
- ...parsed,
- values: parsed.values.map((val) => capitalize(val)).filter(Boolean) as string[],
- };
- })
- .describe(
- "The browser to retrieve analytics for. " +
+ "Examples: `Desktop`, `Mobile,Tablet`, `-Mobile`.",
+ )
+ .meta({ example: "Desktop" }),
+ browser: z
+ .string()
+ .optional()
+ .transform((v) => {
+ if (!v) return undefined;
+ const parsed = parseFilterValue(v);
+ if (!parsed) return undefined;
+ return {
+ ...parsed,
+ values: parsed.values
+ .map((val) => capitalize(val))
+ .filter(Boolean) as string[],
+ };
+ })
+ .describe(
+ "The browser to retrieve analytics for. " +
"Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). " +
- "Examples: `Chrome`, `Chrome,Firefox,Safari`, `-IE`."
- )
- .meta({ example: "Chrome" }),
- os: z
- .string()
- .optional()
- .transform((v) => {
- if (!v) return undefined;
- const parsed = parseFilterValue(v);
- if (!parsed) return undefined;
- return {
- ...parsed,
- values: parsed.values.map((val) => (val === "iOS" ? "iOS" : capitalize(val))).filter(Boolean) as string[],
- };
- })
- .describe(
- "The OS to retrieve analytics for. " +
+ "Examples: `Chrome`, `Chrome,Firefox,Safari`, `-IE`.",
+ )
+ .meta({ example: "Chrome" }),
+ os: z
+ .string()
+ .optional()
+ .transform((v) => {
+ if (!v) return undefined;
+ const parsed = parseFilterValue(v);
+ if (!parsed) return undefined;
+ return {
+ ...parsed,
+ values: parsed.values
+ .map((val) => (val === "iOS" ? "iOS" : capitalize(val)))
+ .filter(Boolean) as string[],
+ };
+ })
+ .describe(
+ "The OS to retrieve analytics for. " +
"Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). " +
- "Examples: `Windows`, `Mac,Windows,Linux`, `-Windows`."
- )
- .meta({ example: "Windows" }),
- trigger: z
- .string()
- .optional()
- .transform(parseFilterValue)
- .describe(
- "The trigger to retrieve analytics for. " +
+ "Examples: `Windows`, `Mac,Windows,Linux`, `-Windows`.",
+ )
+ .meta({ example: "Windows" }),
+ trigger: z
+ .string()
+ .optional()
+ .transform(parseFilterValue)
+ .describe(
+ "The trigger to retrieve analytics for. " +
"Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). " +
"Valid values: qr, link. " +
"Examples: `qr`, `qr,link`, `-qr`. " +
- "If undefined, returns all trigger types."
- )
- .meta({ example: "qr" }),
- referer: z
- .string()
- .optional()
- .transform(parseFilterValue)
- .describe(
- "The referer hostname to retrieve analytics for. " +
+ "If undefined, returns all trigger types.",
+ )
+ .meta({ example: "qr" }),
+ referer: z
+ .string()
+ .optional()
+ .transform(parseFilterValue)
+ .describe(
+ "The referer hostname to retrieve analytics for. " +
"Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). " +
- "Examples: `google.com`, `google.com,twitter.com`, `-facebook.com`."
- )
- .meta({ example: "google.com" }),
- refererUrl: z
- .string()
- .optional()
- .transform(parseFilterValue)
- .describe(
- "The full referer URL to retrieve analytics for. " +
- "Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`)."
- )
- .meta({ example: "https://dub.co/blog" }),
- url: z
- .string()
- .optional()
- .transform(parseFilterValue)
- .describe(
- "The destination URL to retrieve analytics for. " +
+ "Examples: `google.com`, `google.com,twitter.com`, `-facebook.com`.",
+ )
+ .meta({ example: "google.com" }),
+ refererUrl: z
+ .string()
+ .optional()
+ .transform(parseFilterValue)
+ .describe(
+ "The full referer URL to retrieve analytics for. " +
+ "Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`).",
+ )
+ .meta({ example: "https://dub.co/blog" }),
+ url: z
+ .string()
+ .optional()
+ .transform(parseFilterValue)
+ .describe(
+ "The destination URL to retrieve analytics for. " +
"Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). " +
- "Examples: `https://example.com`, `https://example.com,https://other.com`, `-https://spam.com`."
- )
- .meta({ example: "https://example.com" }),
- tagIds: z
- .string()
- .optional()
- .transform(parseFilterValue)
- .describe(
- "The tag IDs to retrieve analytics for. " +
+ "Examples: `https://example.com`, `https://example.com,https://other.com`, `-https://spam.com`.",
+ )
+ .meta({ example: "https://example.com" }),
+ tagIds: z
+ .string()
+ .optional()
+ .transform(parseFilterValue)
+ .describe(
+ "The tag IDs to retrieve analytics for. " +
"Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). " +
- "Examples: `tag_123`, `tag_123,tag_456`, `-tag_789`."
- )
- .meta({ example: "tag_123" }),
- folderId: z
- .string()
- .optional()
- .transform(parseFilterValue)
- .describe(
- "The folder ID to retrieve analytics for. " +
+ "Examples: `tag_123`, `tag_123,tag_456`, `-tag_789`.",
+ )
+ .meta({ example: "tag_123" }),
+ folderId: z
+ .string()
+ .optional()
+ .transform(parseFilterValue)
+ .describe(
+ "The folder ID to retrieve analytics for. " +
"Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). " +
"Examples: `folder_123`, `folder_123,folder_456`, `-folder_789`. " +
- "If not provided, return analytics for all links."
- )
- .meta({ example: "folder_123" }),
- groupId: z
- .string()
- .optional()
- .transform(parseFilterValue)
- .describe(
- "The group ID to retrieve analytics for. " +
+ "If not provided, return analytics for all links.",
+ )
+ .meta({ example: "folder_123" }),
+ groupId: z
+ .string()
+ .optional()
+ .transform(parseFilterValue)
+ .describe(
+ "The group ID to retrieve analytics for. " +
"Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). " +
- "Examples: `grp_123`, `grp_123,grp_456`, `-grp_789`."
- )
- .meta({ example: "grp_123" }),
- root: z
- .string()
- .optional()
- .transform((v) => {
- if (!v) return undefined;
- // Normalize boolean values to "true" or "false" strings for consistency
- const parsed = parseFilterValue(v);
- if (!parsed) return undefined;
- return {
- ...parsed,
- values: parsed.values.map((val) => {
- // Normalize various truthy/falsy values to "true"/"false"
- if (val === "true" || val === "1" || val === "yes") return "true";
- if (val === "false" || val === "0" || val === "no") return "false";
- return val;
- }),
- };
- })
- .describe(
- "Filter for root domains. " +
+ "Examples: `grp_123`, `grp_123,grp_456`, `-grp_789`.",
+ )
+ .meta({ example: "grp_123" }),
+ root: z
+ .string()
+ .optional()
+ .transform((v) => {
+ if (!v) return undefined;
+ // Normalize boolean values to "true" or "false" strings for consistency
+ const parsed = parseFilterValue(v);
+ if (!parsed) return undefined;
+ return {
+ ...parsed,
+ values: parsed.values.map((val) => {
+ // Normalize various truthy/falsy values to "true"/"false"
+ if (val === "true" || val === "1" || val === "yes") return "true";
+ if (val === "false" || val === "0" || val === "no") return "false";
+ return val;
+ }),
+ };
+ })
+ .describe(
+ "Filter for root domains. " +
"Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). " +
"Examples: `true` (root domains only), `false` (regular links only), `true,false` (both). " +
- "If undefined, return both."
- )
- .meta({ example: "true" }),
- saleType: z
- .string()
- .optional()
- .transform(parseFilterValue)
- .describe(
- "Filter sales by type. " +
+ "If undefined, return both.",
+ )
+ .meta({ example: "true" }),
+ saleType: z
+ .string()
+ .optional()
+ .transform(parseFilterValue)
+ .describe(
+ "Filter sales by type. " +
"Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). " +
"Valid values: `new` (first-time purchases), `recurring` (repeat purchases). " +
"Examples: `new`, `new,recurring`, `-recurring`. " +
- "If undefined, returns both."
- )
- .meta({ example: "new" }),
- query: z
- .string()
- .max(10000)
- .optional()
- .describe(
- "Search the events by a custom metadata value. Only available for lead and sale events.",
- )
- .meta({
- example: "metadata['key']:'value'",
- }),
- // deprecated fields
- tagId: z
- .string()
- .optional()
- .describe(
- "Deprecated: Use `tagIds` instead. The tag ID to retrieve analytics for.",
- )
- .meta({ deprecated: true }),
- qr: booleanQuerySchema
- .optional()
- .describe(
- "Deprecated: Use the `trigger` field instead. Filter for QR code scans. If true, filter for QR codes only. If false, filter for links only. If undefined, return both.",
- )
- .meta({ deprecated: true }),
- utm_source: z
- .string()
- .optional()
- .transform(parseFilterValue)
- .describe(
- "The UTM source to retrieve analytics for. " +
+ "If undefined, returns both.",
+ )
+ .meta({ example: "new" }),
+ query: z
+ .string()
+ .max(10000)
+ .optional()
+ .describe(
+ "Search the events by a custom metadata value. Only available for lead and sale events.",
+ )
+ .meta({
+ example: "metadata['key']:'value'",
+ }),
+ // deprecated fields
+ tagId: z
+ .string()
+ .optional()
+ .describe(
+ "Deprecated: Use `tagIds` instead. The tag ID to retrieve analytics for.",
+ )
+ .meta({ deprecated: true }),
+ qr: booleanQuerySchema
+ .optional()
+ .describe(
+ "Deprecated: Use the `trigger` field instead. Filter for QR code scans. If true, filter for QR codes only. If false, filter for links only. If undefined, return both.",
+ )
+ .meta({ deprecated: true }),
+ utm_source: z
+ .string()
+ .optional()
+ .transform(parseFilterValue)
+ .describe(
+ "The UTM source to retrieve analytics for. " +
"Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). " +
- "Examples: `google`, `google,twitter`, `-spam`."
- )
- .meta({ example: "google" }),
- utm_medium: z
- .string()
- .optional()
- .transform(parseFilterValue)
- .describe(
- "The UTM medium to retrieve analytics for. " +
+ "Examples: `google`, `google,twitter`, `-spam`.",
+ )
+ .meta({ example: "google" }),
+ utm_medium: z
+ .string()
+ .optional()
+ .transform(parseFilterValue)
+ .describe(
+ "The UTM medium to retrieve analytics for. " +
"Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). " +
- "Examples: `cpc`, `cpc,social`, `-email`."
- )
- .meta({ example: "cpc" }),
- utm_campaign: z
- .string()
- .optional()
- .transform(parseFilterValue)
- .describe(
- "The UTM campaign to retrieve analytics for. " +
+ "Examples: `cpc`, `cpc,social`, `-email`.",
+ )
+ .meta({ example: "cpc" }),
+ utm_campaign: z
+ .string()
+ .optional()
+ .transform(parseFilterValue)
+ .describe(
+ "The UTM campaign to retrieve analytics for. " +
"Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`). " +
- "Examples: `summer_sale`, `summer_sale,winter_sale`, `-old_campaign`."
- )
- .meta({ example: "summer_sale" }),
- utm_term: z
- .string()
- .optional()
- .transform(parseFilterValue)
- .describe(
- "The UTM term to retrieve analytics for. " +
- "Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`)."
- )
- .meta({ example: "keyword" }),
- utm_content: z
- .string()
- .optional()
- .transform(parseFilterValue)
- .describe(
- "The UTM content to retrieve analytics for. " +
- "Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`)."
- )
- .meta({ example: "banner" }),
+ "Examples: `summer_sale`, `summer_sale,winter_sale`, `-old_campaign`.",
+ )
+ .meta({ example: "summer_sale" }),
+ utm_term: z
+ .string()
+ .optional()
+ .transform(parseFilterValue)
+ .describe(
+ "The UTM term to retrieve analytics for. " +
+ "Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`).",
+ )
+ .meta({ example: "keyword" }),
+ utm_content: z
+ .string()
+ .optional()
+ .transform(parseFilterValue)
+ .describe(
+ "The UTM content to retrieve analytics for. " +
+ "Supports advanced filtering: single value, multiple values (comma-separated), or exclusion (prefix with `-`).",
+ )
+ .meta({ example: "banner" }),
});
/**
@@ -432,18 +436,22 @@ export const analyticsQuerySchema = z.object({
*/
export function parseAnalyticsQuery(searchParams: unknown) {
const data = analyticsQuerySchema.parse(searchParams);
-
+
// Backward compatibility: convert linkId to linkIds
if (data.linkId && !data.linkIds) {
data.linkIds = [data.linkId];
}
-
+
// Backward compatibility: convert tagId to tagIds
if (data.tagId && !data.tagIds) {
// Convert single tagId to the multi-value format
- data.tagIds = { operator: "IS" as const, sqlOperator: "IN" as const, values: [data.tagId] };
+ data.tagIds = {
+ operator: "IS" as const,
+ sqlOperator: "IN" as const,
+ values: [data.tagId],
+ };
}
-
+
return data;
}
@@ -473,7 +481,9 @@ export const analyticsFilterTB = z.object({
.union([z.string(), z.array(z.string())])
.transform((v) => (Array.isArray(v) ? v : v.split(",")))
.optional()
- .describe("The folder ID(s) to retrieve analytics for (with operator support)."),
+ .describe(
+ "The folder ID(s) to retrieve analytics for (with operator support).",
+ ),
domain: z
.union([z.string(), z.array(z.string())])
.transform((v) => (Array.isArray(v) ? v : v.split(",")))
@@ -488,11 +498,15 @@ export const analyticsFilterTB = z.object({
tagIdsOperator: z.enum(["IN", "NOT IN"]).optional(),
folderIdOperator: z.enum(["IN", "NOT IN"]).optional(),
root: z
- .union([z.string(), z.boolean(), z.array(z.union([z.string(), z.boolean()]))])
+ .union([
+ z.string(),
+ z.boolean(),
+ z.array(z.union([z.string(), z.boolean()])),
+ ])
.transform((v) => {
const normalize = (val: string | boolean): boolean => {
- if (typeof val === 'boolean') return val;
- return val === 'true' || val === '1' || val === 'yes';
+ if (typeof val === "boolean") return val;
+ return val === "true" || val === "1" || val === "yes";
};
if (Array.isArray(v)) return v.map(normalize);
return [normalize(v)];
@@ -506,19 +520,25 @@ export const analyticsFilterTB = z.object({
.union([z.string(), z.array(z.string())])
.transform((v) => (Array.isArray(v) ? v : v.split(",")))
.optional()
- .describe("The partner ID(s) to retrieve analytics for (with operator support)."),
+ .describe(
+ "The partner ID(s) to retrieve analytics for (with operator support).",
+ ),
partnerIdOperator: z.enum(["IN", "NOT IN"]).optional(),
tenantId: z
.union([z.string(), z.array(z.string())])
.transform((v) => (Array.isArray(v) ? v : v.split(",")))
.optional()
- .describe("The tenant ID(s) to retrieve analytics for (with operator support)."),
+ .describe(
+ "The tenant ID(s) to retrieve analytics for (with operator support).",
+ ),
tenantIdOperator: z.enum(["IN", "NOT IN"]).optional(),
groupId: z
.union([z.string(), z.array(z.string())])
.transform((v) => (Array.isArray(v) ? v : v.split(",")))
.optional()
- .describe("The group ID(s) to retrieve analytics for (with operator support)."),
+ .describe(
+ "The group ID(s) to retrieve analytics for (with operator support).",
+ ),
groupIdOperator: z.enum(["IN", "NOT IN"]).optional(),
// Region is a special case - it's the subdivision part of a region code
region: z.string().optional(),
@@ -577,17 +597,21 @@ export const eventsQuerySchema = analyticsQuerySchema
*/
export function parseEventsQuery(searchParams: unknown) {
const data = eventsQuerySchema.parse(searchParams);
-
+
// Backward compatibility: convert linkId to linkIds
if (data.linkId && !data.linkIds) {
data.linkIds = [data.linkId];
}
-
+
// Backward compatibility: convert tagId to tagIds
if (data.tagId && !data.tagIds) {
// Convert single tagId to the multi-value format
- data.tagIds = { operator: "IS" as const, sqlOperator: "IN" as const, values: [data.tagId] };
+ data.tagIds = {
+ operator: "IS" as const,
+ sqlOperator: "IN" as const,
+ values: [data.tagId],
+ };
}
-
+
return data;
}
diff --git a/apps/web/tests/analytics/advanced-filters.test.ts b/apps/web/tests/analytics/advanced-filters.test.ts
index 42c71bcd18..d21c45f7a8 100644
--- a/apps/web/tests/analytics/advanced-filters.test.ts
+++ b/apps/web/tests/analytics/advanced-filters.test.ts
@@ -1,9 +1,9 @@
-import { parseFilterValue, buildFilterValue } from "@dub/utils";
import {
buildAdvancedFilters,
ensureParsedFilter,
extractWorkspaceLinkFilters,
} from "@/lib/analytics/filter-helpers";
+import { buildFilterValue, parseFilterValue } from "@dub/utils";
import { describe, expect, test } from "vitest";
describe("Advanced Filters - Unit Tests", () => {
@@ -464,7 +464,11 @@ describe("Advanced Filters - Unit Tests", () => {
values: ["grp_abc123", "grp_def456", "grp_ghi789"],
},
});
- expect(result.groupId).toEqual(["grp_abc123", "grp_def456", "grp_ghi789"]);
+ expect(result.groupId).toEqual([
+ "grp_abc123",
+ "grp_def456",
+ "grp_ghi789",
+ ]);
expect(result.groupIdOperator).toBe("IN");
});
@@ -546,7 +550,11 @@ describe("Advanced Filters - Unit Tests", () => {
values: ["tenant_abc", "tenant_def", "tenant_ghi"],
},
});
- expect(result.tenantId).toEqual(["tenant_abc", "tenant_def", "tenant_ghi"]);
+ expect(result.tenantId).toEqual([
+ "tenant_abc",
+ "tenant_def",
+ "tenant_ghi",
+ ]);
expect(result.tenantIdOperator).toBe("IN");
});
@@ -573,8 +581,16 @@ describe("Advanced Filters - Unit Tests", () => {
domain: { operator: "IS", sqlOperator: "IN", values: ["dub.sh"] },
partnerId: { operator: "IS", sqlOperator: "IN", values: ["pn_abc"] },
groupId: { operator: "IS", sqlOperator: "IN", values: ["grp_abc"] },
- tenantId: { operator: "IS_ONE_OF", sqlOperator: "IN", values: ["t1", "t2"] },
- folderId: { operator: "IS_NOT", sqlOperator: "NOT IN", values: ["fold_x"] },
+ tenantId: {
+ operator: "IS_ONE_OF",
+ sqlOperator: "IN",
+ values: ["t1", "t2"],
+ },
+ folderId: {
+ operator: "IS_NOT",
+ sqlOperator: "NOT IN",
+ values: ["fold_x"],
+ },
});
expect(result.domain).toEqual(["dub.sh"]);
expect(result.partnerId).toEqual(["pn_abc"]);
diff --git a/apps/web/tests/analytics/index.test.ts b/apps/web/tests/analytics/index.test.ts
index 360733200e..765b834029 100644
--- a/apps/web/tests/analytics/index.test.ts
+++ b/apps/web/tests/analytics/index.test.ts
@@ -4,7 +4,11 @@ import { describe, expect, test } from "vitest";
import * as z from "zod/v4";
import { env } from "../utils/env";
import { IntegrationHarness } from "../utils/integration";
-import { E2E_PARTNER, E2E_PARTNERS, E2E_PARTNER_GROUP } from "../utils/resource";
+import {
+ E2E_PARTNER,
+ E2E_PARTNERS,
+ E2E_PARTNER_GROUP,
+} from "../utils/resource";
describe.runIf(env.CI).sequential("GET /analytics", async () => {
const h = new IntegrationHarness();
@@ -95,7 +99,7 @@ describe.runIf(env.CI).sequential("GET /analytics", async () => {
expect(status).toEqual(200);
expect(Array.isArray(data)).toBe(true);
-
+
// All returned countries should be in the filter
data.forEach((item: any) => {
expect(["US", "CA", "GB"]).toContain(item.country);
@@ -118,7 +122,7 @@ describe.runIf(env.CI).sequential("GET /analytics", async () => {
expect(status).toEqual(200);
expect(Array.isArray(data)).toBe(true);
-
+
// No country should be US
data.forEach((item: any) => {
expect(item.country).not.toBe("US");
@@ -141,7 +145,7 @@ describe.runIf(env.CI).sequential("GET /analytics", async () => {
expect(status).toEqual(200);
expect(Array.isArray(data)).toBe(true);
-
+
// No country should be US or GB
data.forEach((item: any) => {
expect(["US", "GB"]).not.toContain(item.country);
@@ -164,7 +168,7 @@ describe.runIf(env.CI).sequential("GET /analytics", async () => {
expect(status).toEqual(200);
expect(Array.isArray(data)).toBe(true);
-
+
// All returned devices should be in the filter
data.forEach((item: any) => {
expect(["Mobile", "Desktop"]).toContain(item.device);
diff --git a/apps/web/tests/events/index.test.ts b/apps/web/tests/events/index.test.ts
index 802da8417c..599b16562f 100644
--- a/apps/web/tests/events/index.test.ts
+++ b/apps/web/tests/events/index.test.ts
@@ -5,7 +5,11 @@ import { describe, expect, test } from "vitest";
import * as z from "zod/v4";
import { env } from "../utils/env";
import { IntegrationHarness } from "../utils/integration";
-import { E2E_PARTNER, E2E_PARTNERS, E2E_PARTNER_GROUP } from "../utils/resource";
+import {
+ E2E_PARTNER,
+ E2E_PARTNERS,
+ E2E_PARTNER_GROUP,
+} from "../utils/resource";
describe.runIf(env.CI).sequential("GET /events", async () => {
const h = new IntegrationHarness();
diff --git a/apps/web/ui/analytics/use-analytics-filters.tsx b/apps/web/ui/analytics/use-analytics-filters.tsx
index aa371795ed..6a09cd189d 100644
--- a/apps/web/ui/analytics/use-analytics-filters.tsx
+++ b/apps/web/ui/analytics/use-analytics-filters.tsx
@@ -118,15 +118,22 @@ export function useAnalyticsFilters({
const [requestedFilters, setRequestedFilters] = useState<string[]>([]);
- const parseFilterParam = useCallback((value: string): ParsedFilter | undefined => {
- return parseFilterValue(value);
- }, []);
+ const parseFilterParam = useCallback(
+ (value: string): ParsedFilter | undefined => {
+ return parseFilterValue(value);
+ },
+ [],
+ );
const activeFilters = useMemo(() => {
const { domain, key, tagIds, root, folderId, ...params } = searchParamsObj;
// Handle special cases first
- const filters: Array<{ key: string; operator: FilterOperator; values: any[] }> = [
+ const filters: Array<{
+ key: string;
+ operator: FilterOperator;
+ values: any[];
+ }> = [
// Handle domain/key special case for links
...(domain && key
? [
@@ -145,8 +152,8 @@ export function useAnalyticsFilters({
operator: "IS" as FilterOperator,
values: [
selectedCustomer.email ||
- selectedCustomer["name"] ||
- selectedCustomer["externalId"],
+ selectedCustomer["name"] ||
+ selectedCustomer["externalId"],
],
},
]
@@ -162,11 +169,25 @@ export function useAnalyticsFilters({
// Skip domain if we're showing a specific link (domain + key)
if (filter === "domain" && domain && key) return;
- const value = params[filter] || (filter === "domain" ? domain : filter === "tagIds" ? tagIds : filter === "root" ? root : filter === "folderId" ? folderId : undefined);
+ const value =
+ params[filter] ||
+ (filter === "domain"
+ ? domain
+ : filter === "tagIds"
+ ? tagIds
+ : filter === "root"
+ ? root
+ : filter === "folderId"
+ ? folderId
+ : undefined);
if (value) {
const parsed = parseFilterParam(value);
if (parsed) {
- filters.push({ key: filter, operator: parsed.operator, values: parsed.values });
+ filters.push({
+ key: filter,
+ operator: parsed.operator,
+ values: parsed.values,
+ });
}
}
});
@@ -545,7 +566,7 @@ export function useAnalyticsFilters({
icon: FlagWavy,
label: "Country",
getOptionIcon: (value) => {
- if (typeof value !== 'string') return null;
+ if (typeof value !== "string") return null;
return (
<img
@@ -556,7 +577,7 @@ export function useAnalyticsFilters({
);
},
getOptionLabel: (value) => {
- if (typeof value !== 'string') return String(value);
+ if (typeof value !== "string") return String(value);
return COUNTRIES[value] || value;
},
options:
@@ -607,11 +628,11 @@ export function useAnalyticsFilters({
icon: MapPosition,
label: "Continent",
getOptionIcon: (value) => {
- if (typeof value !== 'string') return null;
+ if (typeof value !== "string") return null;
return <ContinentIcon display={value} className="size-2.5" />;
},
getOptionLabel: (value) => {
- if (typeof value !== 'string') return String(value);
+ if (typeof value !== "string") return String(value);
return CONTINENTS[value] || value;
},
options:
@@ -626,7 +647,7 @@ export function useAnalyticsFilters({
icon: MobilePhone,
label: "Device",
getOptionIcon: (value) => {
- if (typeof value !== 'string') return null;
+ if (typeof value !== "string") return null;
return (
<DeviceIcon
display={capitalize(value) ?? value}
@@ -647,8 +668,10 @@ export function useAnalyticsFilters({
icon: Window,
label: "Browser",
getOptionIcon: (value) => {
- if (typeof value !== 'string') return null;
- return <DeviceIcon display={value} tab="browsers" className="h-4 w-4" />;
+ if (typeof value !== "string") return null;
+ return (
+ <DeviceIcon display={value} tab="browsers" className="h-4 w-4" />
+ );
},
options:
browsers?.map(({ browser, ...rest }) => ({
@@ -662,7 +685,7 @@ export function useAnalyticsFilters({
icon: Cube,
label: "OS",
getOptionIcon: (value) => {
- if (typeof value !== 'string') return null;
+ if (typeof value !== "string") return null;
return <DeviceIcon display={value} tab="os" className="h-4 w-4" />;
},
options:
@@ -697,7 +720,7 @@ export function useAnalyticsFilters({
icon: ReferredVia,
label: "Referrer",
getOptionIcon: (value, _props) => {
- if (typeof value !== 'string') return null;
+ if (typeof value !== "string") return null;
return <ReferrerIcon display={value} className="h-4 w-4" />;
},
options:
@@ -715,7 +738,7 @@ export function useAnalyticsFilters({
icon: ReferredVia,
label: "Referrer URL",
getOptionIcon: (value, props) => {
- if (typeof value !== 'string') return null;
+ if (typeof value !== "string") return null;
return <ReferrerIcon display={value} className="h-4 w-4" />;
},
options:
@@ -748,7 +771,7 @@ export function useAnalyticsFilters({
icon: Icon,
label: `UTM ${label}`,
getOptionIcon: (value) => {
- if (typeof value !== 'string') return null;
+ if (typeof value !== "string") return null;
return <Icon display={value} className="h-4 w-4" />;
},
options:
@@ -844,9 +867,7 @@ export function useAnalyticsFilters({
const currentParam = searchParamsObj[key];
const isNegated = currentParam?.startsWith("-") ?? false;
- const newParam = isNegated
- ? `-${value.join(",")}`
- : value.join(",");
+ const newParam = isNegated ? `-${value.join(",")}` : value.join(",");
queryParams({
set: { [key]: newParam },
@@ -964,12 +985,9 @@ export function useAnalyticsFilters({
[queryParams],
);
- const onOpenFilter = useCallback(
- (key) => {
- setRequestedFilters((rf) => (rf.includes(key) ? rf : [...rf, key]));
- },
- [],
- );
+ const onOpenFilter = useCallback((key) => {
+ setRequestedFilters((rf) => (rf.includes(key) ? rf : [...rf, key]));
+ }, []);
const onToggleOperator = useCallback(
(key) => {
@@ -1001,21 +1019,18 @@ export function useAnalyticsFilters({
[queryParams],
);
- const activeFiltersWithStreaming = useMemo(
- () => {
- return [
- ...activeFilters,
- ...(streaming && !activeFilters.length
- ? Array.from({ length: 2 }, (_, i) => i).map((i) => ({
+ const activeFiltersWithStreaming = useMemo(() => {
+ return [
+ ...activeFilters,
+ ...(streaming && !activeFilters.length
+ ? Array.from({ length: 2 }, (_, i) => i).map((i) => ({
key: "loader",
values: [i],
operator: "IS" as const,
}))
- : []),
- ];
- },
- [activeFilters, streaming],
- );
+ : []),
+ ];
+ }, [activeFilters, streaming]);
return {
filters,
diff --git a/apps/web/ui/partners/program-marketplace/program-marketplace-banner.tsx b/apps/web/ui/partners/program-marketplace/program-marketplace-banner.tsx
index e280b0763c..ffb454c375 100644
--- a/apps/web/ui/partners/program-marketplace/program-marketplace-banner.tsx
+++ b/apps/web/ui/partners/program-marketplace/program-marketplace-banner.tsx
@@ -16,87 +16,87 @@ export function ProgramMarketplaceBanner() {
return (
<AnimatePresence>
{partner && status === "banner" && (
- <motion.div
- initial={{ opacity: 0, height: 0 }}
- animate={{ opacity: 1, height: "auto" }}
- exit={{ opacity: 0, height: 0 }}
- transition={{ duration: 0.2 }}
- className="overflow-hidden"
+ <motion.div
+ initial={{ opacity: 0, height: 0 }}
+ animate={{ opacity: 1, height: "auto" }}
+ exit={{ opacity: 0, height: 0 }}
+ transition={{ duration: 0.2 }}
+ className="overflow-hidden"
+ >
+ <div
+ className={cn(
+ "border-border-subtle relative mb-4 gap-x-2 overflow-hidden rounded-xl border bg-white sm:h-12 lg:mb-6",
+ )}
>
- <div
- className={cn(
- "border-border-subtle relative mb-4 gap-x-2 overflow-hidden rounded-xl border bg-white sm:h-12 lg:mb-6",
- )}
- >
- <div className="absolute inset-0">
- <div
- className={cn(
- "absolute inset-0 opacity-10 blur-xl sm:-scale-x-100 sm:opacity-20",
- "[background-image:radial-gradient(140%_146%_at_93%_14%,#72FE7D,rgba(114,254,125,0)_50%),radial-gradient(126%_82%_at_56%_100%,#FD3A4E,rgba(253,58,78,0)_50%),radial-gradient(131%_124%_at_11%_35%,#855AFC,rgba(133,90,252,0)_50%),radial-gradient(117%_77%_at_100%_100%,#E4C795,rgba(228,199,149,0)_50%),radial-gradient(86%_74%_at_40%_59%,#3A8BFD,rgba(58,139,253,0)_50%),radial-gradient(115%_96%_at_42%_69%,#EEA5BA,rgba(238,165,186,0)_50%)]",
- )}
- />
- <Grid
- cellSize={32}
- strokeWidth={2}
- patternOffset={[-8, -12]}
- className="text-border-subtle/40 [mask-image:linear-gradient(90deg,black_50%,#0003_100%)]"
- />
- </div>
+ <div className="absolute inset-0">
+ <div
+ className={cn(
+ "absolute inset-0 opacity-10 blur-xl sm:-scale-x-100 sm:opacity-20",
+ "[background-image:radial-gradient(140%_146%_at_93%_14%,#72FE7D,rgba(114,254,125,0)_50%),radial-gradient(126%_82%_at_56%_100%,#FD3A4E,rgba(253,58,78,0)_50%),radial-gradient(131%_124%_at_11%_35%,#855AFC,rgba(133,90,252,0)_50%),radial-gradient(117%_77%_at_100%_100%,#E4C795,rgba(228,199,149,0)_50%),radial-gradient(86%_74%_at_40%_59%,#3A8BFD,rgba(58,139,253,0)_50%),radial-gradient(115%_96%_at_42%_69%,#EEA5BA,rgba(238,165,186,0)_50%)]",
+ )}
+ />
+ <Grid
+ cellSize={32}
+ strokeWidth={2}
+ patternOffset={[-8, -12]}
+ className="text-border-subtle/40 [mask-image:linear-gradient(90deg,black_50%,#0003_100%)]"
+ />
+ </div>
- <div className="relative flex h-full flex-col justify-between sm:flex-row">
- <div className="flex h-full min-w-0 flex-col gap-x-2 sm:flex-row sm:items-center">
- <div className="h-full shrink-0 overflow-hidden p-3 sm:p-0">
- <div className="relative h-24 w-40 sm:h-full sm:w-24">
- <div className="absolute left-2 right-0 top-1/2 h-full -translate-y-1/2">
- <ProgramMarketplaceLogos className="[--logo-size:32px] sm:[--logo-size:18px]" />
- </div>
+ <div className="relative flex h-full flex-col justify-between sm:flex-row">
+ <div className="flex h-full min-w-0 flex-col gap-x-2 sm:flex-row sm:items-center">
+ <div className="h-full shrink-0 overflow-hidden p-3 sm:p-0">
+ <div className="relative h-24 w-40 sm:h-full sm:w-24">
+ <div className="absolute left-2 right-0 top-1/2 h-full -translate-y-1/2">
+ <ProgramMarketplaceLogos className="[--logo-size:32px] sm:[--logo-size:18px]" />
</div>
</div>
-
- <p
- className="text-content-subtle flex min-w-0 flex-col px-3 text-base sm:block sm:truncate sm:px-0 sm:text-sm xl:text-base"
- title="Program Marketplace is here. Discover and apply to more programs on Dub."
- >
- <span className="text-content-emphasis font-semibold">
- Program Marketplace is here.
- </span>{" "}
- <span className="font-medium">
- Discover and apply to more programs on Dub.
- </span>
- </p>
</div>
- <div className="flex items-center gap-2 p-3 sm:px-2 sm:py-0">
- <Link
- href="/programs/marketplace"
- className={cn(
- buttonVariants({ variant: "primary" }),
- "flex h-8 w-fit items-center justify-center whitespace-nowrap rounded-lg border px-3 text-sm",
- )}
- >
- View the marketplace
- </Link>
-
- {/* > mobile close button */}
- <Button
- variant="outline"
- icon={<X className="size-4" />}
- className="hidden size-8 rounded-lg bg-black/5 p-0 hover:bg-black/10 sm:flex"
- onClick={() => setStatus("card")}
- />
- </div>
+ <p
+ className="text-content-subtle flex min-w-0 flex-col px-3 text-base sm:block sm:truncate sm:px-0 sm:text-sm xl:text-base"
+ title="Program Marketplace is here. Discover and apply to more programs on Dub."
+ >
+ <span className="text-content-emphasis font-semibold">
+ Program Marketplace is here.
+ </span>{" "}
+ <span className="font-medium">
+ Discover and apply to more programs on Dub.
+ </span>
+ </p>
</div>
- {/* Mobile close button */}
- <Button
- variant="outline"
- icon={<X className="size-4" />}
- className="absolute right-2 top-2 size-8 rounded-lg bg-black/5 p-0 hover:bg-black/10 sm:hidden"
- onClick={() => setStatus("card")}
- />
+ <div className="flex items-center gap-2 p-3 sm:px-2 sm:py-0">
+ <Link
+ href="/programs/marketplace"
+ className={cn(
+ buttonVariants({ variant: "primary" }),
+ "flex h-8 w-fit items-center justify-center whitespace-nowrap rounded-lg border px-3 text-sm",
+ )}
+ >
+ View the marketplace
+ </Link>
+
+ {/* > mobile close button */}
+ <Button
+ variant="outline"
+ icon={<X className="size-4" />}
+ className="hidden size-8 rounded-lg bg-black/5 p-0 hover:bg-black/10 sm:flex"
+ onClick={() => setStatus("card")}
+ />
+ </div>
</div>
- </motion.div>
- )}
+
+ {/* Mobile close button */}
+ <Button
+ variant="outline"
+ icon={<X className="size-4" />}
+ className="absolute right-2 top-2 size-8 rounded-lg bg-black/5 p-0 hover:bg-black/10 sm:hidden"
+ onClick={() => setStatus("card")}
+ />
+ </div>
+ </motion.div>
+ )}
</AnimatePresence>
);
}
diff --git a/apps/web/ui/partners/program-marketplace/program-marketplace-card.tsx b/apps/web/ui/partners/program-marketplace/program-marketplace-card.tsx
index a649b4f136..619173164d 100644
--- a/apps/web/ui/partners/program-marketplace/program-marketplace-card.tsx
+++ b/apps/web/ui/partners/program-marketplace/program-marketplace-card.tsx
@@ -16,8 +16,7 @@ export function ProgramMarketplaceCard() {
const { status } = useProgramMarketplacePromo();
- if (!partner || status !== "card")
- return null;
+ if (!partner || status !== "card") return null;
return (
<AnimatePresence>
diff --git a/packages/ui/src/filter/filter-list.tsx b/packages/ui/src/filter/filter-list.tsx
index 1ee95f9395..5b6cc333ec 100644
--- a/packages/ui/src/filter/filter-list.tsx
+++ b/packages/ui/src/filter/filter-list.tsx
@@ -2,14 +2,20 @@ import { cn, truncate } from "@dub/utils";
import { Command } from "cmdk";
import { X } from "lucide-react";
import { AnimatePresence, motion } from "motion/react";
-import { ReactNode, isValidElement, useState, useCallback } from "react";
+import { ReactNode, isValidElement, useCallback, useState } from "react";
import { AnimatedSizeContainer } from "../animated-size-container";
import { Combobox, ComboboxOption } from "../combobox";
import { useKeyboardShortcut } from "../hooks";
import { Check, Icon } from "../icons";
import { Popover } from "../popover";
import { Tooltip } from "../tooltip";
-import { Filter, FilterOption, ActiveFilterInput, FilterOperator, normalizeActiveFilter } from "./types";
+import {
+ ActiveFilterInput,
+ Filter,
+ FilterOperator,
+ FilterOption,
+ normalizeActiveFilter,
+} from "./types";
type FilterListProps = {
filters: Filter[];
@@ -17,7 +23,10 @@ type FilterListProps = {
onRemove: (key: string, value: FilterOption["value"]) => void;
onRemoveFilter?: (key: string) => void;
onRemoveAll: () => void;
- onSelect?: (key: string, value: FilterOption["value"] | FilterOption["value"][]) => void;
+ onSelect?: (
+ key: string,
+ value: FilterOption["value"] | FilterOption["value"][],
+ ) => void;
onToggleOperator?: (key: string) => void;
isAdvancedFilter?: boolean;
className?: string;
@@ -42,10 +51,10 @@ function pluralize(word: string, count: number): string {
if (count === 1) return word.toLowerCase();
const irregularPlurals: Record<string, string> = {
- 'country': 'countries',
- 'city': 'cities',
- 'category': 'categories',
- 'os': 'OS',
+ country: "countries",
+ city: "cities",
+ category: "categories",
+ os: "OS",
};
const lowerWord = word.toLowerCase();
@@ -53,11 +62,14 @@ function pluralize(word: string, count: number): string {
return irregularPlurals[lowerWord];
}
- if (lowerWord.endsWith('y') && !['ay', 'ey', 'iy', 'oy', 'uy'].some(ending => lowerWord.endsWith(ending))) {
- return lowerWord.slice(0, -1) + 'ies';
+ if (
+ lowerWord.endsWith("y") &&
+ !["ay", "ey", "iy", "oy", "uy"].some((ending) => lowerWord.endsWith(ending))
+ ) {
+ return lowerWord.slice(0, -1) + "ies";
}
- return lowerWord + 's';
+ return lowerWord + "s";
}
export function FilterList({
@@ -113,25 +125,26 @@ export function FilterList({
const displayLabel = isSingleValue
? (() => {
- const value = values[0];
- const option = filter.options?.find((o) =>
- typeof o.value === "string" && typeof value === "string"
- ? o.value.toLowerCase() === value.toLowerCase()
- : o.value === value,
- );
- return option?.label ??
- filter.getOptionLabel?.(value, { key: filter.key, option }) ??
- String(value);
- })()
+ const value = values[0];
+ const option = filter.options?.find((o) =>
+ typeof o.value === "string" && typeof value === "string"
+ ? o.value.toLowerCase() === value.toLowerCase()
+ : o.value === value,
+ );
+ return (
+ option?.label ??
+ filter.getOptionLabel?.(value, {
+ key: filter.key,
+ option,
+ }) ??
+ String(value)
+ );
+ })()
: `${values.length} ${pluralize(filter.label, values.length)}`;
const showMultipleIcons = ["country", "city"].includes(key);
- const OptionDisplay = ({
- className,
- }: {
- className?: string;
- }) => {
+ const OptionDisplay = ({ className }: { className?: string }) => {
let iconDisplay;
if (isSingleValue) {
@@ -164,7 +177,8 @@ export function FilterList({
<div className="flex shrink-0 -space-x-1">
{displayValues.map((value, idx) => {
const option = filter.options?.find((o) =>
- typeof o.value === "string" && typeof value === "string"
+ typeof o.value === "string" &&
+ typeof value === "string"
? o.value.toLowerCase() === value.toLowerCase()
: o.value === value,
);
@@ -380,30 +394,38 @@ function OperatorFilterPill({
OptionDisplay: ({ className }: { className?: string }) => ReactNode;
onRemove: (key: string, value: FilterOption["value"]) => void;
onRemoveFilter?: (key: string) => void;
- onSelect?: (key: string, value: FilterOption["value"] | FilterOption["value"][]) => void;
+ onSelect?: (
+ key: string,
+ value: FilterOption["value"] | FilterOption["value"][],
+ ) => void;
onToggleOperator?: (key: string) => void;
isAdvancedFilter?: boolean;
}) {
const [operatorDropdownOpen, setOperatorDropdownOpen] = useState(false);
const [valueDropdownOpen, setValueDropdownOpen] = useState(false);
const [search, setSearch] = useState("");
- const [initialSelectedValues, setInitialSelectedValues] = useState<Set<FilterOption["value"]>>(new Set());
+ const [initialSelectedValues, setInitialSelectedValues] = useState<
+ Set<FilterOption["value"]>
+ >(new Set());
const openValueDropdown = useCallback(() => {
setInitialSelectedValues(new Set(values));
setValueDropdownOpen(true);
}, [values]);
- const toggleValue = useCallback((value: FilterOption["value"]) => {
- const isSelected = values.includes(value);
- if (isSelected) {
- onRemove(filterKey, value);
- } else {
- onSelect?.(filterKey, value);
- }
+ const toggleValue = useCallback(
+ (value: FilterOption["value"]) => {
+ const isSelected = values.includes(value);
+ if (isSelected) {
+ onRemove(filterKey, value);
+ } else {
+ onSelect?.(filterKey, value);
+ }
- if (!isAdvancedFilter && !filter.multiple) setValueDropdownOpen(false);
- }, [filterKey, values, onSelect, onRemove, isAdvancedFilter, filter.multiple]);
+ if (!isAdvancedFilter && !filter.multiple) setValueDropdownOpen(false);
+ },
+ [filterKey, values, onSelect, onRemove, isAdvancedFilter, filter.multiple],
+ );
return (
<motion.div
@@ -432,7 +454,7 @@ function OperatorFilterPill({
type="button"
className={cn(
"flex w-full items-center rounded-md px-3 py-2 text-left text-sm transition-colors hover:bg-neutral-100",
- !operator.includes("NOT") && "bg-neutral-50"
+ !operator.includes("NOT") && "bg-neutral-50",
)}
onClick={() => {
if (operator.includes("NOT")) {
@@ -447,7 +469,7 @@ function OperatorFilterPill({
type="button"
className={cn(
"flex w-full items-center rounded-md px-3 py-2 text-left text-sm transition-colors hover:bg-neutral-100",
- operator.includes("NOT") && "bg-neutral-50"
+ operator.includes("NOT") && "bg-neutral-50",
)}
onClick={() => {
if (!operator.includes("NOT")) {
@@ -470,9 +492,7 @@ function OperatorFilterPill({
</button>
</Popover>
) : (
- <div className="px-3 py-2 text-neutral-500">
- is
- </div>
+ <div className="px-3 py-2 text-neutral-500">is</div>
)}
<Popover
@@ -486,11 +506,7 @@ function OperatorFilterPill({
}}
content={
<div>
- <AnimatedSizeContainer
- width
- height
- className="rounded-[inherit]"
- >
+ <AnimatedSizeContainer width height className="rounded-[inherit]">
<Command loop shouldFilter={false}>
<div className="flex items-center overflow-hidden rounded-t-lg border-b border-neutral-200">
<Command.Input
@@ -502,23 +518,27 @@ function OperatorFilterPill({
/>
</div>
<div className="scrollbar-hide max-h-[50vh] w-screen overflow-y-scroll sm:w-auto">
- <Command.List className="flex w-full flex-col gap-1 p-1 min-w-[180px]">
+ <Command.List className="flex w-full min-w-[180px] flex-col gap-1 p-1">
{(() => {
- const filteredOptions = filter.options?.filter(option => {
- if (!search) return true;
- const optionLabel = (
- option.label ??
- filter.getOptionLabel?.(option.value, { key: filter.key, option }) ??
- String(option.value)
- ).toLowerCase();
- return optionLabel.includes(search.toLowerCase());
- }) ?? [];
-
- const selectedOptions = filteredOptions.filter(option =>
- initialSelectedValues.has(option.value)
+ const filteredOptions =
+ filter.options?.filter((option) => {
+ if (!search) return true;
+ const optionLabel = (
+ option.label ??
+ filter.getOptionLabel?.(option.value, {
+ key: filter.key,
+ option,
+ }) ??
+ String(option.value)
+ ).toLowerCase();
+ return optionLabel.includes(search.toLowerCase());
+ }) ?? [];
+
+ const selectedOptions = filteredOptions.filter((option) =>
+ initialSelectedValues.has(option.value),
);
- const unselectedOptions = filteredOptions.filter(option =>
- !initialSelectedValues.has(option.value)
+ const unselectedOptions = filteredOptions.filter(
+ (option) => !initialSelectedValues.has(option.value),
);
const renderOption = (option: FilterOption) => {
@@ -533,7 +553,10 @@ function OperatorFilterPill({
const optionLabel =
option.label ??
- filter.getOptionLabel?.(option.value, { key: filter.key, option }) ??
+ filter.getOptionLabel?.(option.value, {
+ key: filter.key,
+ option,
+ }) ??
String(option.value);
return (
@@ -552,26 +575,36 @@ function OperatorFilterPill({
value={optionLabel + option.value}
>
{(isAdvancedFilter || filter.multiple) && (
- <div className={cn(
- "flex h-4 w-4 items-center justify-center rounded border",
- isSelected ? "border-neutral-900 bg-neutral-900" : "border-neutral-300"
- )}>
- {isSelected && <Check className="h-3 w-3 text-white" />}
+ <div
+ className={cn(
+ "flex h-4 w-4 items-center justify-center rounded border",
+ isSelected
+ ? "border-neutral-900 bg-neutral-900"
+ : "border-neutral-300",
+ )}
+ >
+ {isSelected && (
+ <Check className="h-3 w-3 text-white" />
+ )}
</div>
)}
<span className="shrink-0 text-neutral-600">
- {isReactNode(OptionIcon) ? OptionIcon : <OptionIcon className="h-4 w-4" />}
+ {isReactNode(OptionIcon) ? (
+ OptionIcon
+ ) : (
+ <OptionIcon className="h-4 w-4" />
+ )}
+ </span>
+ <span className="flex-1">
+ {truncate(optionLabel, 48)}
</span>
- <span className="flex-1">{truncate(optionLabel, 48)}</span>
<div className="ml-1 flex shrink-0 justify-end text-neutral-500">
- {(isAdvancedFilter || filter.multiple) ? (
+ {isAdvancedFilter || filter.multiple ? (
option.right
+ ) : isSelected ? (
+ <Check className="h-4 w-4" />
) : (
- isSelected ? (
- <Check className="h-4 w-4" />
- ) : (
- option.right
- )
+ option.right
)}
</div>
</Command.Item>
@@ -582,9 +615,11 @@ function OperatorFilterPill({
<>
{selectedOptions.map(renderOption)}
- {(isAdvancedFilter || filter.multiple) && selectedOptions.length > 0 && unselectedOptions.length > 0 && (
- <Command.Separator className="-mx-1 my-1 border-b border-neutral-200" />
- )}
+ {(isAdvancedFilter || filter.multiple) &&
+ selectedOptions.length > 0 &&
+ unselectedOptions.length > 0 && (
+ <Command.Separator className="-mx-1 my-1 border-b border-neutral-200" />
+ )}
{unselectedOptions.map(renderOption)}
</>
@@ -620,7 +655,9 @@ function OperatorFilterPill({
if (onRemoveFilter) {
onRemoveFilter(filterKey);
} else {
- values.forEach((value) => { onRemove(filterKey, value); });
+ values.forEach((value) => {
+ onRemove(filterKey, value);
+ });
}
}}
>
diff --git a/packages/ui/src/filter/filter-select.tsx b/packages/ui/src/filter/filter-select.tsx
index 299175e089..6a985731e5 100644
--- a/packages/ui/src/filter/filter-select.tsx
+++ b/packages/ui/src/filter/filter-select.tsx
@@ -18,11 +18,19 @@ import { useKeyboardShortcut, useMediaQuery } from "../hooks";
import { useScrollProgress } from "../hooks/use-scroll-progress";
import { Check, LoadingSpinner, Magic } from "../icons";
import { Popover } from "../popover";
-import { Filter, FilterOption, ActiveFilterInput, normalizeActiveFilter } from "./types";
+import {
+ ActiveFilterInput,
+ Filter,
+ FilterOption,
+ normalizeActiveFilter,
+} from "./types";
type FilterSelectProps = {
filters: Filter[];
- onSelect: (key: string, value: FilterOption["value"] | FilterOption["value"][]) => void;
+ onSelect: (
+ key: string,
+ value: FilterOption["value"] | FilterOption["value"][],
+ ) => void;
onRemove: (key: string, value: FilterOption["value"]) => void;
onOpenFilter?: (key: string) => void;
onSearchChange?: (search: string) => void;
@@ -84,39 +92,45 @@ export function FilterSelect({
? filters.find(({ key }) => key === selectedFilterKey)
: null;
- const openFilter = useCallback((key: Filter["key"]) => {
- // Maintain dimensions for loading options
- if (listContainer.current) {
- listDimensions.current = {
- width: listContainer.current.clientWidth,
- height: listContainer.current.clientHeight,
- };
- }
+ const openFilter = useCallback(
+ (key: Filter["key"]) => {
+ // Maintain dimensions for loading options
+ if (listContainer.current) {
+ listDimensions.current = {
+ width: listContainer.current.clientWidth,
+ height: listContainer.current.clientHeight,
+ };
+ }
- setSearch("");
- setSelectedFilterKey(key);
+ setSearch("");
+ setSelectedFilterKey(key);
- onOpenFilter?.(key);
- }, [onOpenFilter]);
+ onOpenFilter?.(key);
+ },
+ [onOpenFilter],
+ );
const isOptionSelected = useCallback(
(value: FilterOption["value"]) => {
if (!selectedFilter || !activeFilters) return false;
- const rawActiveFilter = activeFilters.find((filter) => filter.key === selectedFilterKey);
+ const rawActiveFilter = activeFilters.find(
+ (filter) => filter.key === selectedFilterKey,
+ );
if (!rawActiveFilter) return false;
-
+
const normalizedFilter = normalizeActiveFilter(rawActiveFilter);
return normalizedFilter.values.includes(value);
},
[selectedFilter, activeFilters, selectedFilterKey],
);
-
const selectOption = useCallback(
(value: FilterOption["value"]) => {
if (selectedFilter) {
- const isSingleSelect = selectedFilter?.singleSelect || (!isAdvancedFilter && !selectedFilter?.multiple);
+ const isSingleSelect =
+ selectedFilter?.singleSelect ||
+ (!isAdvancedFilter && !selectedFilter?.multiple);
if (isSingleSelect) {
const isSelected = isOptionSelected(value);
@@ -137,7 +151,6 @@ export function FilterSelect({
[selectedFilter, isOptionSelected, onSelect, onRemove, isAdvancedFilter],
);
-
useEffect(() => {
onSearchChange?.(search);
}, [search]);
@@ -241,7 +254,9 @@ export function FilterSelect({
selectedFilter.options
?.filter((option) => !search || !option.hideDuringSearch)
?.map((option) => {
- const isSingleSelect = selectedFilter?.singleSelect || (!isAdvancedFilter && !selectedFilter?.multiple);
+ const isSingleSelect =
+ selectedFilter?.singleSelect ||
+ (!isAdvancedFilter && !selectedFilter?.multiple);
const isSelected = isOptionSelected(option.value);
return (
@@ -249,7 +264,10 @@ export function FilterSelect({
key={option.value}
filter={selectedFilter}
option={option}
- showCheckbox={!isSingleSelect && (isAdvancedFilter || selectedFilter?.multiple)}
+ showCheckbox={
+ !isSingleSelect &&
+ (isAdvancedFilter || selectedFilter?.multiple)
+ }
isChecked={isSelected}
right={
isSingleSelect ? (
@@ -433,10 +451,14 @@ function FilterButton({
value={label + option?.value}
>
{showCheckbox && (
- <div className={cn(
- "flex h-4 w-4 items-center justify-center rounded border",
- isChecked ? "border-neutral-900 bg-neutral-900" : "border-neutral-300"
- )}>
+ <div
+ className={cn(
+ "flex h-4 w-4 items-center justify-center rounded border",
+ isChecked
+ ? "border-neutral-900 bg-neutral-900"
+ : "border-neutral-300",
+ )}
+ >
{isChecked && <Check className="h-3 w-3 text-white" />}
</div>
)}
diff --git a/packages/ui/src/filter/index.ts b/packages/ui/src/filter/index.ts
index 5182f46c56..24017ca2ed 100644
--- a/packages/ui/src/filter/index.ts
+++ b/packages/ui/src/filter/index.ts
@@ -3,14 +3,14 @@ import { FilterSelect } from "./filter-select";
const Filter = { Select: FilterSelect, List: FilterList };
-export { Filter };
-export type {
- FilterOperator,
- ActiveFilter,
+export { normalizeActiveFilter } from "./types";
+export type {
+ ActiveFilter,
ActiveFilterInput,
- LegacyActiveFilterSingular,
+ FilterOperator,
+ FilterOption,
+ Filter as FilterType,
LegacyActiveFilterPlural,
- Filter as FilterType,
- FilterOption
+ LegacyActiveFilterSingular,
} from "./types";
-export { normalizeActiveFilter } from "./types";
+export { Filter };
diff --git a/packages/ui/src/filter/types.ts b/packages/ui/src/filter/types.ts
index d9dd751574..70b3954bb4 100644
--- a/packages/ui/src/filter/types.ts
+++ b/packages/ui/src/filter/types.ts
@@ -70,30 +70,33 @@ export type ActiveFilterInput =
* - { key, values, operator } → unchanged (already correct)
*/
export function normalizeActiveFilter(filter: ActiveFilterInput): ActiveFilter {
- if ('operator' in filter && filter.operator && Array.isArray(filter.values)) {
+ if ("operator" in filter && filter.operator && Array.isArray(filter.values)) {
return filter as ActiveFilter;
}
- if ('value' in filter && !('values' in filter)) {
+ if ("value" in filter && !("values" in filter)) {
return {
key: filter.key,
- operator: 'IS' as FilterOperator,
+ operator: "IS" as FilterOperator,
values: [filter.value],
};
}
- if (Array.isArray((filter as any).values) && (!('operator' in filter) || !filter.operator)) {
+ if (
+ Array.isArray((filter as any).values) &&
+ (!("operator" in filter) || !filter.operator)
+ ) {
const values = (filter as LegacyActiveFilterPlural).values;
return {
key: filter.key,
- operator: values.length > 1 ? 'IS_ONE_OF' : 'IS',
+ operator: values.length > 1 ? "IS_ONE_OF" : "IS",
values: values,
};
}
return {
key: filter.key,
- operator: 'IS',
+ operator: "IS",
values: [],
};
}
diff --git a/packages/ui/src/index.tsx b/packages/ui/src/index.tsx
index eb468c27f0..32f94f4db6 100644
--- a/packages/ui/src/index.tsx
+++ b/packages/ui/src/index.tsx
@@ -23,10 +23,10 @@ export * from "./form";
export * from "./grid";
export * from "./input";
export * from "./label";
-export * from "./multi-value-input";
export * from "./menu-item";
export * from "./mini-area-chart";
export * from "./modal";
+export * from "./multi-value-input";
export * from "./number-stepper";
export * from "./pagination-controls";
export * from "./popover";
diff --git a/packages/utils/src/functions/parse-filter-value.ts b/packages/utils/src/functions/parse-filter-value.ts
index 9aea182679..735cf0a1bc 100644
--- a/packages/utils/src/functions/parse-filter-value.ts
+++ b/packages/utils/src/functions/parse-filter-value.ts
@@ -9,16 +9,16 @@ export interface ParsedFilter {
/**
* Parse filter value from URL format to structured filter
- *
+ *
* Formats supported:
* - "US" → IS, values: ["US"], SQL: IN
* - "US,BR,FR" → IS_ONE_OF, values: ["US", "BR", "FR"], SQL: IN
* - "-US" → IS_NOT, values: ["US"], SQL: NOT IN
* - "-US,BR" → IS_NOT_ONE_OF, values: ["US", "BR"], SQL: NOT IN
- *
+ *
* Note: All filters now use IN/NOT IN operators for consistency,
* even for single values. This simplifies SQL query generation.
- *
+ *
* @param value - The filter value string (can include "-" prefix for negation)
* @returns Parsed filter with operator and values array
*/
@@ -56,7 +56,7 @@ export function parseFilterValue(
/**
* Build filter value string from parsed filter
- *
+ *
* @param parsed - The parsed filter object
* @returns URL-formatted filter string
*/