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 expand sidebar scrolling #436

Merged
merged 3 commits into from
Jun 14, 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
2 changes: 2 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
(<https://github.com/aws/graph-explorer/pull/434>)
- Added caching and retries to node expansion and neighbor counts
(<https://github.com/aws/graph-explorer/pull/434>)
- Improved scrolling behavior in expand sidebar
(<https://github.com/aws/graph-explorer/pull/436>)

**Bug Fixes and Minor Changes**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const defaultStyles =
height: 100%;
display: flex;
flex-direction: column;
overflow-y: scroll;
background: ${theme.palette.background.default};

.${pfx}-empty-panel-state {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ const defaultStyles =
padding: ${theme.spacing["4x"]};
gap: ${theme.spacing["2x"]};
border-bottom: solid 1px ${theme.palette.divider};
height: 30%;
overflow: auto;

.${pfx}-title {
font-weight: bold;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { cx } from "@emotion/css";
import { Vertex } from "../../../@types/entities";
import { Chip, Tooltip, VertexIcon, VisibleIcon } from "../../../components";
import {
Button,
Chip,
Tooltip,
VertexIcon,
VisibleIcon,
} from "../../../components";
import { useWithTheme, withClassNamePrefix } from "../../../core";
import useNeighborsOptions from "../../../hooks/useNeighborsOptions";
import defaultStyles from "./NeighborsList.styles";
import { useState } from "react";

export type NeighborsListProps = {
classNamePrefix?: string;
Expand All @@ -17,6 +24,10 @@ const NeighborsList = ({
const styleWithTheme = useWithTheme();
const pfx = withClassNamePrefix(classNamePrefix);
const neighborsOptions = useNeighborsOptions(vertex);
const [showMore, setShowMore] = useState(false);
const maxStartingItems = 5;
const hasMore = neighborsOptions.length > maxStartingItems;
const extraCount = hasMore ? neighborsOptions.length - maxStartingItems : 0;

return (
<div
Expand All @@ -28,7 +39,7 @@ const NeighborsList = ({
<div className={pfx("title")}>
Neighbors ({vertex.data.neighborsCount})
</div>
{neighborsOptions.map(op => {
{neighborsOptions.slice(0, showMore ? undefined : 5).map(op => {
const neighborsInView =
vertex.data.neighborsCountByType[op.value] -
(vertex.data.__unfetchedNeighborCounts?.[op.value] ?? 0);
Expand Down Expand Up @@ -62,6 +73,14 @@ const NeighborsList = ({
</div>
);
})}

{hasMore ? (
<Button variant="text" onPress={() => setShowMore(prev => !prev)}>
{showMore
? `Hide ${extraCount} additional neighbors`
: `Show ${extraCount} additional neighbors`}
</Button>
) : null}
</div>
);
};
Expand Down
Loading