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 selected type #501

Merged
merged 2 commits into from
Jul 19, 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 @@ -15,6 +15,8 @@

**Bug Fixes and Minor Changes**

- Fix default selection of expand type to be the first available type for
expansion (<https://github.com/aws/graph-explorer/pull/501>)
- Use `application/sparql-results+json` accept header for SPARQL requests
(<https://github.com/aws/graph-explorer/pull/499>)
- Fix text wrapping for labels in edge styling sidebar
Expand Down
16 changes: 11 additions & 5 deletions packages/graph-explorer/src/hooks/useNeighborsOptions.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { useMemo } from "react";
import { Vertex } from "../@types/entities";
import { useConfiguration } from "../core/ConfigurationProvider";
import {
useConfiguration,
VertexTypeConfig,
} from "../core/ConfigurationProvider";
import useTextTransform from "./useTextTransform";
import { SelectOption } from "../components";

const useNeighborsOptions = (vertex: Vertex) => {
export type NeighborOption = SelectOption & {
config?: VertexTypeConfig;
};

export default function useNeighborsOptions(vertex: Vertex): NeighborOption[] {
const config = useConfiguration();
const textTransform = useTextTransform();

Expand All @@ -26,6 +34,4 @@ const useNeighborsOptions = (vertex: Vertex) => {
vertex.data.neighborsCountByType,
vertex.data.__unfetchedNeighborCounts,
]);
};

export default useNeighborsOptions;
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ import LoadingSpinner from "../../components/LoadingSpinner";
import PanelEmptyState from "../../components/PanelEmptyState/PanelEmptyState";
import { useWithTheme } from "../../core";
import { useExpandNode } from "../../hooks";
import useNeighborsOptions from "../../hooks/useNeighborsOptions";
import useNeighborsOptions, {
NeighborOption,
} from "../../hooks/useNeighborsOptions";
import useTranslations from "../../hooks/useTranslations";
import NeighborsList from "../common/NeighborsList/NeighborsList";
import defaultStyles from "./NodeExpandContent.styles";
Expand Down Expand Up @@ -69,13 +71,15 @@ function ExpansionOptions({ vertex }: { vertex: Vertex }) {
const neighborsOptions = useNeighborsOptions(vertex);

const [selectedType, setSelectedType] = useState<string>(
neighborsOptions[0]?.value
firstNeighborAvailableForExpansion(neighborsOptions)?.value ?? ""
);
const [filters, setFilters] = useState<Array<NodeExpandFilter>>([]);
const [limit, setLimit] = useState<number | null>(null);

useEffect(() => {
setSelectedType(neighborsOptions[0]?.value);
setSelectedType(
firstNeighborAvailableForExpansion(neighborsOptions)?.value ?? ""
);
}, [neighborsOptions]);

const hasUnfetchedNeighbors = Boolean(vertex.data.__unfetchedNeighborCount);
Expand Down Expand Up @@ -151,3 +155,9 @@ function ExpandButton({
</Button>
);
}

function firstNeighborAvailableForExpansion(
vkagamlyk marked this conversation as resolved.
Show resolved Hide resolved
neighborsOptions: NeighborOption[]
) {
return neighborsOptions.find(x => !x.isDisabled) ?? neighborsOptions[0];
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
InfoTooltip,
Input,
Select,
SelectOption,
} from "../../components";
import { useConfiguration } from "../../core";
import useTextTransform from "../../hooks/useTextTransform";
Expand All @@ -17,7 +18,7 @@ export type NodeExpandFilter = {
value: string;
};
export type NodeExpandFiltersProps = {
neighborsOptions: Array<{ label: string; value: string }>;
neighborsOptions: SelectOption[];
selectedType: string;
onSelectedTypeChange(type: string): void;
filters: Array<NodeExpandFilter>;
Expand Down
Loading