Skip to content

Commit

Permalink
Bugfix: clicking the bookmark star unbookmarks an intersection
Browse files Browse the repository at this point in the history
  • Loading branch information
NateLanza committed Feb 19, 2025
1 parent d1fd4ba commit 18b7b3e
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions packages/upset/src/components/Columns/BookmarkStar.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Row } from '@visdesignlab/upset2-core';
import StarIcon from '@mui/icons-material/Star';
import { FC, MouseEvent, useContext, useMemo, useState } from 'react';
import {
FC, MouseEvent, useContext, useMemo, useState,
} from 'react';
import { useRecoilValue } from 'recoil';
import { ProvenanceContext } from '../Root';
import { dimensionsSelector } from '../../atoms/dimensionsAtom';
Expand All @@ -9,6 +11,7 @@ import {
bookmarkedColorSelector,
isRowBookmarkedSelector,
} from '../../atoms/config/currentIntersectionAtom';
import { UpsetActions } from '../../provenance';

type Props = {
row: Row;
Expand All @@ -34,7 +37,7 @@ export const BookmarkStar: FC<Props> = ({ row }) => {
const dimensions = useRecoilValue(dimensionsSelector);
const bookmarked = useRecoilValue(isRowBookmarkedSelector(row));
const color = useRecoilValue(bookmarkedColorSelector(row));
const { actions } = useContext(ProvenanceContext);
const { actions }: {actions: UpsetActions} = useContext(ProvenanceContext);

const rowDisplayName = row.elementName.replaceAll('~&~', ' & ') || '';

Expand Down Expand Up @@ -79,15 +82,17 @@ export const BookmarkStar: FC<Props> = ({ row }) => {
*/
const handleClick = (event: MouseEvent<SVGGElement, MouseEvent>) => {
event.stopPropagation();
const bookmark = {
id: row.id,
label: rowDisplayName,
size: row.size,
// Without 'as const' it complains that 'type' is a string instead of 'intersection' lol
type: 'intersection' as const,
};
if (bookmarked) {
actions.removeBookmark(bookmarked);
actions.removeBookmark(bookmark);
} else {
actions.addBookmark({
id: row.id,
label: rowDisplayName,
size: row.size,
type: 'intersection',
});
actions.addBookmark(bookmark);
}
};

Expand Down

0 comments on commit 18b7b3e

Please sign in to comment.