mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-17 23:35:34 +00:00
Bug 1523386 - [release 121] strict flow and remove some unused code in project search (#7669). r=dwalsh
This commit is contained in:
parent
9376828bbe
commit
0d6e63e879
@ -16,7 +16,6 @@ import { highlightMatches } from "../utils/project-search";
|
||||
import { statusType } from "../reducers/project-text-search";
|
||||
import { getRelativePath } from "../utils/sources-tree";
|
||||
import {
|
||||
getSources,
|
||||
getActiveSearch,
|
||||
getTextSearchResults,
|
||||
getTextSearchStatus,
|
||||
@ -59,7 +58,6 @@ type State = {
|
||||
};
|
||||
|
||||
type Props = {
|
||||
sources: Object,
|
||||
query: string,
|
||||
results: List<Result>,
|
||||
status: StatusType,
|
||||
@ -83,13 +81,18 @@ function sanitizeQuery(query: string): string {
|
||||
return query.replace(/\\$/, "");
|
||||
}
|
||||
|
||||
type FileItem = {
|
||||
setExpanded: (Result, boolean) => mixed,
|
||||
file: Result,
|
||||
expanded: boolean
|
||||
};
|
||||
type MatchItem = {
|
||||
expanded: null,
|
||||
match: Match
|
||||
};
|
||||
|
||||
export class ProjectSearch extends Component<Props, State> {
|
||||
focusedItem: ?{
|
||||
setExpanded?: any,
|
||||
file?: any,
|
||||
expanded?: any,
|
||||
match?: Match
|
||||
};
|
||||
focusedItem: ?(FileItem | MatchItem);
|
||||
constructor(props: Props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
@ -182,13 +185,16 @@ export class ProjectSearch extends Component<Props, State> {
|
||||
};
|
||||
|
||||
onEnterPress = () => {
|
||||
if (this.focusedItem && !this.state.inputFocused) {
|
||||
const { setExpanded, file, expanded, match } = this.focusedItem;
|
||||
if (setExpanded) {
|
||||
setExpanded(file, !expanded);
|
||||
} else if (match) {
|
||||
this.selectMatchItem(match);
|
||||
}
|
||||
if (!this.focusedItem || this.state.inputFocused) {
|
||||
return;
|
||||
}
|
||||
if (this.focusedItem.expanded !== null) {
|
||||
// expanded is not null implies this is a `FileItem`
|
||||
const { setExpanded, file, expanded } = this.focusedItem;
|
||||
setExpanded(file, !expanded);
|
||||
} else {
|
||||
const { match } = this.focusedItem;
|
||||
this.selectMatchItem(match);
|
||||
}
|
||||
};
|
||||
|
||||
@ -229,7 +235,7 @@ export class ProjectSearch extends Component<Props, State> {
|
||||
|
||||
renderMatch = (match: Match, focused: boolean) => {
|
||||
if (focused) {
|
||||
this.focusedItem = { match };
|
||||
this.focusedItem = { match, expanded: null };
|
||||
}
|
||||
return (
|
||||
<div
|
||||
@ -340,7 +346,6 @@ ProjectSearch.contextTypes = {
|
||||
};
|
||||
|
||||
const mapStateToProps = state => ({
|
||||
sources: getSources(state),
|
||||
activeSearch: getActiveSearch(state),
|
||||
results: getTextSearchResults(state),
|
||||
query: getTextSearchQuery(state),
|
||||
|
@ -195,7 +195,7 @@ describe("ProjectSearch", () => {
|
||||
},
|
||||
true
|
||||
);
|
||||
component.instance().focusedItem = {};
|
||||
component.instance().focusedItem = null;
|
||||
shortcuts.dispatch("Enter");
|
||||
expect(selectSpecificLocation).not.toHaveBeenCalled();
|
||||
});
|
||||
@ -209,7 +209,7 @@ describe("ProjectSearch", () => {
|
||||
},
|
||||
true
|
||||
);
|
||||
component.instance().focusedItem = { match: testMatch };
|
||||
component.instance().focusedItem = { match: testMatch, expanded: null };
|
||||
shortcuts.dispatch("Enter");
|
||||
expect(selectSpecificLocation).toHaveBeenCalledWith({
|
||||
sourceId: "some-target/source42",
|
||||
|
Loading…
Reference in New Issue
Block a user