Skip to content

Commit

Permalink
[dagit] Truncate global search result list (#7569)
Browse files Browse the repository at this point in the history
## Summary

I noticed that with the giant asset graph loaded, typing even `a` in the global search input makes it super cruncy because it tries to render hundreds of results.

Truncate at 50.

## Test Plan

Load Dagit, open global search. Type "a", verify that only fifty results render. Navigate up/down with keyboard, verify correct highlighting, wraparound, scrolling.
  • Loading branch information
hellendag committed Apr 26, 2022
1 parent 65f15cd commit 36e7e6a
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions js_modules/dagit/packages/core/src/search/SearchDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import {SearchResults} from './SearchResults';
import {SearchResult} from './types';
import {useRepoSearch} from './useRepoSearch';

const MAX_DISPLAYED_RESULTS = 50;

type State = {
shown: boolean;
queryString: string;
Expand Down Expand Up @@ -62,7 +64,8 @@ export const SearchDialog: React.FC<{searchPlaceholder: string}> = ({searchPlace
const [state, dispatch] = React.useReducer(reducer, initialState);
const {shown, queryString, results, highlight, loaded} = state;

const numResults = results.length;
const renderedResults = results.slice(0, MAX_DISPLAYED_RESULTS);
const numRenderedResults = renderedResults.length;

const openSearch = React.useCallback(() => dispatch({type: 'show-dialog'}), []);
const onChange = React.useCallback((e) => {
Expand All @@ -86,7 +89,7 @@ export const SearchDialog: React.FC<{searchPlaceholder: string}> = ({searchPlace
[history],
);

const highlightedResult = results[highlight] || null;
const highlightedResult = renderedResults[highlight] || null;

const onKeyDown = (e: React.KeyboardEvent) => {
const {key} = e;
Expand All @@ -95,11 +98,11 @@ export const SearchDialog: React.FC<{searchPlaceholder: string}> = ({searchPlace
return;
}

if (!numResults) {
if (!numRenderedResults) {
return;
}

const lastResult = numResults - 1;
const lastResult = numRenderedResults - 1;

switch (key) {
case 'ArrowUp':
Expand Down Expand Up @@ -179,7 +182,7 @@ export const SearchDialog: React.FC<{searchPlaceholder: string}> = ({searchPlace
<SearchResults
highlight={highlight}
queryString={queryString}
results={results}
results={renderedResults}
onClickResult={onClickResult}
/>
</Container>
Expand Down

0 comments on commit 36e7e6a

Please sign in to comment.