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.

Link selector fixes

Tim Wilson5ff73a4af065
diff --git a/apps/web/app/api/links/route.ts b/apps/web/app/api/links/route.ts
index c63a8c0ca1..15426b8e36 100644
--- a/apps/web/app/api/links/route.ts
+++ b/apps/web/app/api/links/route.ts
@@ -22,8 +22,16 @@ import { NextResponse } from "next/server";
export const GET = withWorkspace(
async ({ headers, searchParams, workspace, session }) => {
const params = getLinksQuerySchemaExtended.parse(searchParams);
- const { domain, folderId, search, tagId, tagIds, tagNames, tenantId } =
- params;
+ const {
+ domain,
+ folderId,
+ search,
+ tagId,
+ tagIds,
+ tagNames,
+ tenantId,
+ linkIds,
+ } = params;
if (domain) {
await getDomainOrThrow({ workspace, domain });
@@ -44,7 +52,8 @@ export const GET = withWorkspace(
- filtering by search, domain, tags, or tenantId
*/
let folderIds =
- !folderId && (search || domain || tagId || tagIds || tagNames || tenantId)
+ !folderId &&
+ (search || domain || tagId || tagIds || tagNames || tenantId || linkIds)
? await getFolderIdsToFilter({
workspace,
userId: session.user.id,
diff --git a/apps/web/ui/webhooks/link-selector.tsx b/apps/web/ui/webhooks/link-selector.tsx
index a43709c06f..93a8a39860 100644
--- a/apps/web/ui/webhooks/link-selector.tsx
+++ b/apps/web/ui/webhooks/link-selector.tsx
@@ -7,6 +7,8 @@ import { cn, getApexDomain, linkConstructor, truncate } from "@dub/utils";
import { useMemo, useState } from "react";
import { useDebounce } from "use-debounce";
+const MAX_DISPLAYED_LINKS = 10;
+
const getLinkOption = (link: LinkProps) => ({
value: link.id,
label: linkConstructor({ ...link, pretty: true }),
@@ -62,6 +64,12 @@ export function LinksSelector({
[selectedLinkIds, links, selectedLinks],
);
+ const plusCount =
+ selectedLinkIds.length > selectedOptions.length
+ ? selectedLinkIds.length -
+ Math.min(selectedOptions.length, MAX_DISPLAYED_LINKS)
+ : Math.max(0, selectedOptions.length - MAX_DISPLAYED_LINKS);
+
return (
<Combobox
multiple
@@ -70,9 +78,13 @@ export function LinksSelector({
side="top" // Since this control is near the bottom of the page, prefer top to avoid jumping
options={options}
selected={selectedOptions ?? []}
- setSelected={(selected) => {
- setSelectedLinkIds(selected.map(({ value: id }) => id));
- }}
+ onSelect={({ value: id }) =>
+ setSelectedLinkIds(
+ selectedLinkIds.includes(id)
+ ? selectedLinkIds.filter((sid) => sid !== id)
+ : [...selectedLinkIds, id],
+ )
+ }
shouldFilter={false}
onSearchChange={setSearch}
buttonProps={{
@@ -86,7 +98,7 @@ export function LinksSelector({
<div className="py-0.5">Select links...</div>
) : selectedLinks && selectedOptions ? (
<div className="flex flex-wrap gap-2">
- {selectedOptions.slice(0, 10).map((option) => (
+ {selectedOptions.slice(0, MAX_DISPLAYED_LINKS).map((option) => (
<span
key={option.value}
className="animate-fade-in flex min-w-0 items-center gap-1 rounded-md bg-neutral-100 px-1.5 py-1 text-xs text-neutral-600"
@@ -100,6 +112,11 @@ export function LinksSelector({
</span>
</span>
))}
+ {plusCount > 0 && (
+ <span className="animate-fade-in flex rounded-md bg-neutral-100 px-1.5 py-1 text-xs font-medium text-neutral-600">
+ + {plusCount} more
+ </span>
+ )}
</div>
) : (
<div className="my-0.5 h-5 w-1/3 animate-pulse rounded bg-neutral-200" />
diff --git a/packages/ui/src/combobox/index.tsx b/packages/ui/src/combobox/index.tsx
index 62f2ca26f4..1e74482f61 100644
--- a/packages/ui/src/combobox/index.tsx
+++ b/packages/ui/src/combobox/index.tsx
@@ -44,9 +44,10 @@ export type ComboboxProps<
selected: TMultiple extends true
? ComboboxOption<TMeta>[]
: ComboboxOption<TMeta> | null;
- setSelected: TMultiple extends true
+ setSelected?: TMultiple extends true
? (options: ComboboxOption<TMeta>[]) => void
: (option: ComboboxOption<TMeta> | null) => void;
+ onSelect?: (option: ComboboxOption<TMeta>) => void;
options?: ComboboxOption<TMeta>[];
icon?: Icon | ReactNode;
placeholder?: ReactNode;
@@ -81,6 +82,7 @@ export function Combobox({
multiple,
selected: selectedProp,
setSelected,
+ onSelect,
options,
icon: Icon,
placeholder = "Select...",
@@ -127,6 +129,10 @@ export function Combobox({
const [isCreating, setIsCreating] = useState(false);
const handleSelect = (option: ComboboxOption) => {
+ onSelect?.(option);
+
+ if (!setSelected) return;
+
if (isMultiple) {
const isAlreadySelected = selected.some(
({ value }) => value === option.value,