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 row selection being removed when clicking off of chart #325

Merged
merged 3 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
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
21 changes: 9 additions & 12 deletions packages/upset/src/components/Root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import { columnsAtom } from '../atoms/columnAtom';
import { itemsAtom } from '../atoms/itemsAtoms';
import { setsAtom } from '../atoms/setsAtoms';
import { dataAtom } from '../atoms/dataAtom';
import { columnHoverAtom, columnSelectAtom } from '../atoms/highlightAtom';
import { columnHoverAtom } from '../atoms/highlightAtom';
import { contextMenuAtom } from '../atoms/contextMenuAtom';
import { upsetConfigAtom } from '../atoms/config/upsetConfigAtoms';
import { currentIntersectionAtom } from '../atoms/config/currentIntersectionAtom';
import {
getActions, initializeProvenanceTracking, UpsetActions, UpsetProvenance,
} from '../provenance';
Expand Down Expand Up @@ -66,12 +65,10 @@ export const Root: FC<Props> = ({

const [sets, setSets] = useRecoilState(setsAtom);
const [items, setItems] = useRecoilState(itemsAtom);
const [columnHover, setColumnHover] = useRecoilState(columnHoverAtom);
const setAttributeColumns = useSetRecoilState(attributeAtom);
const setAllColumns = useSetRecoilState(columnsAtom);
const setData = useSetRecoilState(dataAtom);
const setCurrentIntersection = useSetRecoilState(currentIntersectionAtom);
const setColumnHover = useSetRecoilState(columnHoverAtom);
const setColumnSelect = useSetRecoilState(columnSelectAtom);
const setContextMenu = useSetRecoilState(contextMenuAtom);

useEffect(() => {
Expand Down Expand Up @@ -106,11 +103,11 @@ export const Root: FC<Props> = ({
setData(data);
}, [data]);

// remove all current selections and highlight states
const removeSelections = () => {
setCurrentIntersection(null);
setColumnSelect([]);
setColumnHover([]);
// remove column hover state
const removeHover = () => {
if (columnHover.length > 0) {
setColumnHover([]);
}
};

// close all open context menus
Expand All @@ -119,11 +116,11 @@ export const Root: FC<Props> = ({
};

useEffect(() => {
document.addEventListener('click', removeSelections, false);
document.addEventListener('contextmenu', removeContextMenu, false);
document.addEventListener('mousemove', removeHover, false);

return function removeListeners() {
document.removeEventListener('click', removeSelections, false);
document.removeEventListener('mousemove', removeHover, false);
document.removeEventListener('contextmenu', removeContextMenu, false);
};
}, []);
Expand Down
1 change: 1 addition & 0 deletions packages/upset/src/components/Rows/AggregateRow.tsx
JakeWags marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ export const AggregateRow: FC<Props> = ({ aggregateRow }) => {

return (
<g
onMouseMove={(e) => e.stopPropagation()}
onClick={() => aggregateRow && (setCurrentIntersectionAtom(aggregateRow))}
css={mousePointer}
>
Expand Down
5 changes: 4 additions & 1 deletion packages/upset/src/components/Rows/SubsetRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const SubsetRow: FC<Props> = ({ subset }) => {

return (
<g
onMouseMove={(e) => e.stopPropagation()}
onClick={
() => {
if (currentIntersection !== null && currentIntersection.id === subset.id) { // if the row is already selected, deselect it
Expand All @@ -53,7 +54,9 @@ export const SubsetRow: FC<Props> = ({ subset }) => {
setColumnHighlight(getBelongingSetsFromSetMembership(subset.setMembership));
}
}
onMouseLeave={() => setHover(null)}
onMouseLeave={() => {
setHover(null);
}}
css={mousePointer}
>
<rect
Expand Down
Loading