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.

Refactor TagIds

Steven Tey6148c72ae2b2
diff --git a/apps/web/app/api/links/route.ts b/apps/web/app/api/links/route.ts
index ab38bfaac3..77df0e6165 100644
--- a/apps/web/app/api/links/route.ts
+++ b/apps/web/app/api/links/route.ts
@@ -13,13 +13,23 @@ import { NextResponse } from "next/server";
// GET /api/links – get all user links
export const GET = withAuth(async ({ headers, searchParams, project }) => {
- const { domain, tagId, search, sort, page, userId, showArchived, withTags } =
- getLinksQuerySchema.parse(searchParams);
+ const {
+ domain,
+ tagId,
+ tagIds,
+ search,
+ sort,
+ page,
+ userId,
+ showArchived,
+ withTags,
+ } = getLinksQuerySchema.parse(searchParams);
const response = await getLinksForProject({
projectId: project.id,
domain,
tagId,
+ tagIds,
search,
sort,
page,
diff --git a/apps/web/lib/api/links.ts b/apps/web/lib/api/links.ts
index 62b27a998a..839641de19 100644
--- a/apps/web/lib/api/links.ts
+++ b/apps/web/lib/api/links.ts
@@ -38,6 +38,7 @@ export async function getLinksForProject({
projectId,
domain,
tagId,
+ tagIds,
search,
sort = "createdAt",
page,
@@ -47,7 +48,7 @@ export async function getLinksForProject({
}: Omit<z.infer<typeof getLinksQuerySchema>, "projectSlug"> & {
projectId: string;
}): Promise<LinkProps[]> {
- const tagIds = tagId ? tagId.split(",") : [];
+ const finalTagIds = combineTagIds({ tagId, tagIds });
const links = await prisma.link.findMany({
where: {
@@ -69,8 +70,8 @@ export async function getLinksForProject({
some: {},
},
}),
- ...(tagIds.length > 0 && {
- tags: { some: { tagId: { in: tagIds } } },
+ ...(finalTagIds.length > 0 && {
+ tags: { some: { tagId: { in: finalTagIds } } },
}),
...(userId && { userId }),
},
diff --git a/apps/web/lib/zod/schemas/links.ts b/apps/web/lib/zod/schemas/links.ts
index 8726758a7f..6111e39ad7 100644
--- a/apps/web/lib/zod/schemas/links.ts
+++ b/apps/web/lib/zod/schemas/links.ts
@@ -17,10 +17,13 @@ const LinksQuerySchema = {
tagId: z
.string()
.optional()
- .describe("The tag ID to filter the links by.")
+ .describe(
+ "[DEPRECATED (use tagIds instead)]: The tag ID to filter the links by.",
+ )
.openapi({ deprecated: true }),
tagIds: z
- .array(z.string())
+ .string()
+ .transform((v) => v.split(",").filter(Boolean))
.optional()
.describe("The tag IDs to filter the links by."),
search: z
@@ -190,7 +193,9 @@ export const createLinkBodySchema = z.object({
tagId: z
.string()
.nullish()
- .describe("The unique ID of the tag assigned to the short link.")
+ .describe(
+ "[DEPRECATED (use tagIds instead)]: The unique ID of the tag assigned to the short link.",
+ )
.openapi({ deprecated: true }),
tagIds: z
.array(z.string())
diff --git a/apps/web/ui/links/link-filters.tsx b/apps/web/ui/links/link-filters.tsx
index 8322cf5742..29cab72e66 100644
--- a/apps/web/ui/links/link-filters.tsx
+++ b/apps/web/ui/links/link-filters.tsx
@@ -63,7 +63,7 @@ export default function LinkFilters() {
"search",
"domain",
"userId",
- "tagId",
+ "tagIds",
"showArchived",
"page",
"withTags",
@@ -304,7 +304,7 @@ const TagsFilter = ({
const { AddEditTagModal, AddTagButton } = useAddEditTagModal();
const selectedTagIds =
- searchParams?.get("tagId")?.split(",")?.filter(Boolean) ?? [];
+ searchParams?.get("tagIds")?.split(",")?.filter(Boolean) ?? [];
const onCheckboxChange = useCallback(
(e: React.ChangeEvent<HTMLInputElement>) => {
@@ -313,12 +313,12 @@ const TagsFilter = ({
: selectedTagIds.filter((tagId) => tagId !== e.target.id) ?? [];
queryParams({
set: {
- tagId: newTags,
+ tagIds: newTags,
},
del: [
"page",
// Remove tagId from params if empty
- ...(newTags.length ? [] : ["tagId"]),
+ ...(newTags.length ? [] : ["tagIds"]),
],
});
},
@@ -442,7 +442,7 @@ const TagPopover = ({ tag, count }: { tag: TagProps; count: number }) => {
method: "DELETE",
}).then(async (res) => {
if (res.ok) {
- queryParams({ del: "tagId" });
+ queryParams({ del: "tagIds" });
await Promise.all([
mutate(`/api/tags?projectSlug=${slug}`),
mutate(