in packages/graph-explorer/src/modules/NodeExpand/NodeExpandContent.tsx [75:143]
function ExpansionOptions({
vertexId,
neighborsOptions,
}: {
vertexId: VertexId;
neighborsOptions: NeighborOption[];
}) {
const t = useTranslations();
const neighbors = useNeighbors(vertexId);
const [selectedType, setSelectedType] = useState<string>(
firstNeighborAvailableForExpansion(neighborsOptions)?.value ?? ""
);
const [filters, setFilters] = useState<Array<NodeExpandFilter>>([]);
const [limit, setLimit] = useState<number | null>(null);
const hasSelectedType = Boolean(selectedType);
const hasUnfetchedNeighbors = (neighbors?.unfetched ?? 0) > 0;
const expandOffset =
limit !== null && neighbors ? neighbors.fetched : undefined;
// Reset filters when selected type changes
const [prevSelectedType, setPrevSelectedType] = useState(selectedType);
if (prevSelectedType !== selectedType) {
setPrevSelectedType(selectedType);
setFilters([]);
}
if (!hasUnfetchedNeighbors) {
return (
<PanelEmptyState
className="empty-panel-state"
icon={<GraphIcon />}
title={t("node-expand.no-unfetched-title")}
subtitle={t("node-expand.no-unfetched-subtitle")}
/>
);
}
return (
<>
<NodeExpandFilters
neighborsOptions={neighborsOptions}
selectedType={selectedType}
onSelectedTypeChange={setSelectedType}
filters={filters}
onFiltersChange={setFilters}
limit={limit}
onLimitChange={setLimit}
/>
<PanelFooter className="flex flex-row justify-end">
<ExpandButton
isDisabled={!hasUnfetchedNeighbors || !hasSelectedType}
vertexId={vertexId}
filters={{
filterByVertexTypes: [selectedType],
filterCriteria: filters.map(filter => ({
name: filter.name,
operator: "LIKE",
value: filter.value,
})),
limit: limit || undefined,
offset: expandOffset,
}}
/>
</PanelFooter>
</>
);
}