Skip to content

Commit

Permalink
pathfinding bug fix (#284)
Browse files Browse the repository at this point in the history
fixes BED-3973
  • Loading branch information
brandonshearin authored Jan 5, 2024
1 parent 8dfa6c7 commit d0f1946
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
6 changes: 5 additions & 1 deletion cmd/ui/src/ducks/searchbar/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,14 @@ export const sourceNodeEdited = (searchTerm: string): types.SourceNodeEditedActi
};
};

export const sourceNodeSelected = (node: types.SearchNodeType | null): types.SourceNodeSelectedAction => {
export const sourceNodeSelected = (
node: types.SearchNodeType | null,
doPathfindSearch: boolean = false // sometimes, selecting a source node should trigger a pathfinding search, and other times it should only trigger a single node search
): types.SourceNodeSelectedAction => {
return {
type: types.SOURCE_NODE_SELECTED,
node,
doPathfindSearch,
};
};

Expand Down
12 changes: 8 additions & 4 deletions cmd/ui/src/ducks/searchbar/saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ function* primarySearchWatcher(): SagaIterator {
yield takeLatest(types.PRIMARY_SEARCH, primarySearchWorker);
}

function* primarySearchWorker() {
function* primarySearchWorker(payload: types.SourceNodeSelectedAction) {
const { primary, secondary, pathFilters }: types.SearchState = yield select((state: AppState) => state.search);

const edges = pathFilters.filter((pathFilter) => pathFilter.checked).map((pathFilter) => pathFilter.edgeType);

// attempt a pathfinding search first
if (primary.value !== null && secondary.value !== null) {
yield put(startPathfindingQuery(primary.value.objectid, secondary.value.objectid, edges));
// try a pathfinding search first if flag is true
if (payload.doPathfindSearch) {
if (primary.value !== null && secondary.value !== null) {
yield put(startPathfindingQuery(primary.value.objectid, secondary.value.objectid, edges));
} else if (primary.value !== null) {
yield put(startSearchQuery(primary.value.objectid, types.SEARCH_TYPE_EXACT));
}
} else if (primary.value !== null) {
yield put(startSearchQuery(primary.value.objectid, types.SEARCH_TYPE_EXACT));
}
Expand Down
1 change: 1 addition & 0 deletions cmd/ui/src/ducks/searchbar/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export interface CypherQueryEditedAction {
export interface SourceNodeSelectedAction {
type: typeof SOURCE_NODE_SELECTED;
node: SearchNodeType | null;
doPathfindSearch: boolean;
}

export interface SourceNodeEditedAction {
Expand Down
13 changes: 8 additions & 5 deletions cmd/ui/src/views/Explore/ContextMenu/ContextMenu.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,14 @@ describe('ContextMenu', async () => {
await user.click(startNodeOption);

expect(sourceNodeSelectedSpy).toBeCalledTimes(1);
expect(sourceNodeSelectedSpy).toHaveBeenCalledWith({
name: 'foo',
objectid: '1234',
type: 'User',
});
expect(sourceNodeSelectedSpy).toHaveBeenCalledWith(
{
name: 'foo',
objectid: '1234',
type: 'User',
},
true
);
});

it('handles setting an end node', async () => {
Expand Down
13 changes: 8 additions & 5 deletions cmd/ui/src/views/Explore/ContextMenu/ContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,14 @@ const ContextMenu: FC<{ contextMenu: { mouseX: number; mouseY: number } | null;
if (selectedNode) {
dispatch(tabChanged('secondary'));
dispatch(
sourceNodeSelected({
name: selectedNode.name,
objectid: selectedNode.id,
type: selectedNode.type,
})
sourceNodeSelected(
{
name: selectedNode.name,
objectid: selectedNode.id,
type: selectedNode.type,
},
true
)
);
}
};
Expand Down

0 comments on commit d0f1946

Please sign in to comment.