Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(tag-selection): fix tag deselection crash in link editing #1813

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions apps/web/ui/modals/link-builder/tag-select.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,20 @@ export function TagSelect() {
return false;
};

const options = useMemo(
() => availableTags?.map((tag) => getTagOption(tag)),
[availableTags],
);
const options = useMemo(() => {
return (
(availableTags || [])
.filter((tag): tag is TagProps => tag !== null && tag !== undefined)
.map((tag) => getTagOption(tag))
);
}, [availableTags]);

const selectedTags = useMemo(
() => tags.map((tag) => getTagOption(tag)),
[tags],
);
const selectedTags = useMemo(() => {
if (!tags || tags.length === 0) return [];
return tags
.filter((tag): tag is TagProps => tag !== null && tag !== undefined)
.map((tag) => getTagOption(tag));
}, [tags]);

useKeyboardShortcut("t", () => setIsOpen(true), { modal: true });

Expand Down Expand Up @@ -180,7 +185,8 @@ export function TagSelect() {
[...(availableTags || []), ...(tags || [])]?.find(
(t) => t.id === id,
),
),
)
.filter(Boolean),
{ shouldDirty: true },
);
}}
Expand Down