Skip to content
This repository has been archived by the owner on Jan 11, 2023. It is now read-only.

Commit

Permalink
limit resultCount in QuickOpenModal to 100 sources (#8134)
Browse files Browse the repository at this point in the history
  • Loading branch information
arosenfeld2003 authored and darkwing committed Apr 4, 2019
1 parent 5aaaf1a commit 62c8117
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
35 changes: 20 additions & 15 deletions src/components/QuickOpenModal.js
Expand Up @@ -69,10 +69,12 @@ type GotoLocationType = {
column?: number
};

const maxResults = 100;

function filter(values, query) {
return fuzzyAldrin.filter(values, query, {
key: "value",
maxResults: 1000
maxResults: maxResults
});
}

Expand All @@ -82,6 +84,13 @@ export class QuickOpenModal extends Component<Props, State> {
this.state = { results: null, selectedIndex: 0 };
}

setResults(results: ?Array<QuickOpenResult>) {
if (results) {
results = results.slice(0, maxResults);
}
this.setState({ results });
}

componentDidMount() {
const { query, shortcutsModalEnabled, toggleShortcutsModal } = this.props;

Expand Down Expand Up @@ -121,7 +130,7 @@ export class QuickOpenModal extends Component<Props, State> {
const { sources } = this.props;
const results =
query == "" ? sources : filter(sources, this.dropGoto(query));
return this.setState({ results });
return this.setResults(results);
};

searchSymbols = (query: string) => {
Expand All @@ -133,31 +142,28 @@ export class QuickOpenModal extends Component<Props, State> {
results = results.filter(result => result.title !== "anonymous");

if (query === "@" || query === "#") {
return this.setState({ results });
return this.setResults(results);
}

this.setState({ results: filter(results, query.slice(1)) });
results = filter(results, query.slice(1));
return this.setResults(results);
};

searchShortcuts = (query: string) => {
const results = formatShortcutResults();
if (query == "?") {
this.setState({ results });
this.setResults(results);
} else {
this.setState({ results: filter(results, query.slice(1)) });
this.setResults(filter(results, query.slice(1)));
}
};

showTopSources = () => {
const { tabs, sources } = this.props;
if (tabs.length > 0) {
const tabUrls = tabs.map((tab: Tab) => tab.url);

this.setState({
results: sources.filter(source => tabUrls.includes(source.url))
});
this.setResults(sources.filter(source => tabUrls.includes(source.url)));
} else {
this.setState({ results: sources.slice(0, 100) });
this.setResults(sources);
}
};

Expand Down Expand Up @@ -374,8 +380,7 @@ export class QuickOpenModal extends Component<Props, State> {
if (!enabled) {
return null;
}
const newResults = results && results.slice(0, 100);
const items = this.highlightMatching(query, newResults || []);
const items = this.highlightMatching(query, results || []);
const expanded = !!items && items.length > 0;

return (
Expand All @@ -398,7 +403,7 @@ export class QuickOpenModal extends Component<Props, State> {
}
{...(this.isSourceSearch() ? { size: "big" } : {})}
/>
{newResults && (
{results && (
<ResultList
key="results"
items={items}
Expand Down
6 changes: 3 additions & 3 deletions src/components/test/QuickOpenModal.spec.js
Expand Up @@ -209,7 +209,7 @@ describe("QuickOpenModal", () => {
wrapper.find("input").simulate("change", { target: { value: "somefil" } });
expect(filter).toHaveBeenCalledWith([], "somefil", {
key: "value",
maxResults: 1000
maxResults: 100
});
});

Expand All @@ -230,7 +230,7 @@ describe("QuickOpenModal", () => {
.simulate("change", { target: { value: "somefil:33" } });
expect(filter).toHaveBeenCalledWith([], "somefil", {
key: "value",
maxResults: 1000
maxResults: 100
});
});

Expand All @@ -257,7 +257,7 @@ describe("QuickOpenModal", () => {

expect(filter).toHaveBeenCalledWith([], "someFunc", {
key: "value",
maxResults: 1000
maxResults: 100
});
});

Expand Down

0 comments on commit 62c8117

Please sign in to comment.