Skip to content

Commit

Permalink
Fix graph builder crash when plugins are involved in project
Browse files Browse the repository at this point in the history
  • Loading branch information
abrenneke committed Oct 17, 2023
1 parent 88dbf70 commit 9982a97
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions packages/app/src/hooks/useSearchGraph.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
import { useRecoilValue, useSetRecoilState } from 'recoil';
import { useViewportBounds } from './useViewportBounds';
import { nodesState } from '../state/graph';
import { useEffect, useMemo } from 'react';
import { entries } from '../../../core/src/utils/typeSafety';
import { searchMatchingNodeIdsState, searchingGraphState } from '../state/graphBuilder';
import { useFuseSearch } from './useFuseSearch';
import { globalRivetNodeRegistry } from '@ironclad/rivet-core';
import { useFocusOnNodes } from './useFocusOnNodes';
import { useNodeTypes } from './useNodeTypes';
import { useDependsOnPlugins } from './useDependsOnPlugins';

export function useSearchGraph() {
const graphNodes = useRecoilValue(nodesState);
const setSearchMatchingNodes = useSetRecoilState(searchMatchingNodeIdsState);

useDependsOnPlugins();
const focusOnNodes = useFocusOnNodes();
const nodeTypes = useNodeTypes();

const searchableNodes = useMemo(() => {
return graphNodes.map((node) => {
const joinedData = entries(node.data as object).map(([key, value]) => {
return `${value}`;
});

const isKnownNodeType = node.type in nodeTypes;

const searchableNode = {
title: node.title,
description: node.description,
id: node.id,
joinedData: joinedData.join(' '),
nodeType: globalRivetNodeRegistry.getDisplayName(node.type as any),
nodeType: isKnownNodeType ? globalRivetNodeRegistry.getDisplayName(node.type as any) : '',
};

return searchableNode;
Expand All @@ -34,10 +39,15 @@ export function useSearchGraph() {

const searchState = useRecoilValue(searchingGraphState);

const searchedNodes = useFuseSearch(searchableNodes, searchState.query, ['title', 'description', 'joinedData'], {
enabled: searchState.searching,
noInputEmptyList: true,
});
const searchedNodes = useFuseSearch(
searchableNodes,
searchState.query,
['title', 'description', 'joinedData', 'nodeType'],
{
enabled: searchState.searching,
noInputEmptyList: true,
},
);

useEffect(() => {
setSearchMatchingNodes(searchedNodes.map((n) => n.item.id));
Expand Down

0 comments on commit 9982a97

Please sign in to comment.