Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const Icon = styled(EuiIcon)`
interface State {
isFlyoutOpen: boolean;
repoScope: Repository[];
query: string;
}

interface Props {
Expand All @@ -47,10 +48,12 @@ interface Props {
repoSearchResults: any[];
searchLoading: boolean;
searchOptions: ISearchOptions;
defaultRepoOptions: Repository[];
}

export class SearchOptions extends Component<Props, State> {
public state: State = {
query: '',
isFlyoutOpen: false,
repoScope: this.props.searchOptions.repoScope,
};
Expand Down Expand Up @@ -109,9 +112,15 @@ export class SearchOptions extends Component<Props, State> {
<EuiComboBox
placeholder="Search to add repos"
async={true}
options={this.props.repoSearchResults.map(repo => ({
label: repo.name,
}))}
options={
this.state.query
? this.props.repoSearchResults.map(repo => ({
label: repo.name,
}))
: this.props.defaultRepoOptions.map(repo => ({
label: repo.name,
}))
}
selectedOptions={[]}
isLoading={this.props.searchLoading}
onChange={this.onRepoChange}
Expand Down Expand Up @@ -144,6 +153,7 @@ export class SearchOptions extends Component<Props, State> {
}

private onRepoSearchChange = (searchValue: string) => {
this.setState({ query: searchValue });
if (searchValue) {
this.props.repositorySearch({ query: searchValue });
}
Expand All @@ -153,7 +163,11 @@ export class SearchOptions extends Component<Props, State> {
this.setState(prevState => ({
repoScope: unique([
...prevState.repoScope,
...repos.map((r: any) => this.props.repoSearchResults.find(rs => rs.name === r.label)),
...repos.map((r: any) =>
[...this.props.repoSearchResults, ...this.props.defaultRepoOptions].find(
rs => rs.name === r.label
)
),
]),
}));
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ test('render correctly with empty query string', () => {
onSelect={emptyFn}
onSearchScopeChanged={emptyFn}
searchScope={SearchScope.DEFAULT}
defaultRepoOptions={[]}
/>
);
expect(toJson(queryBarComp)).toMatchSnapshot();
Expand Down Expand Up @@ -100,6 +101,7 @@ test('render correctly with input query string changed', done => {
onSelect={emptyFn}
onSearchScopeChanged={emptyFn}
searchScope={SearchScope.DEFAULT}
defaultRepoOptions={[]}
/>
</MemoryRouter>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
import { matchPairs } from '../lib/match_pairs';
import { SuggestionsComponent } from './typeahead/suggestions_component';

import { SearchScope } from '../../../../model';
import { SearchScope, Repository } from '../../../../model';
import { SearchScopePlaceholderText } from '../../../common/types';
import { RootState } from '../../../reducers';
import {
Expand Down Expand Up @@ -55,6 +55,7 @@ interface Props {
searchLoading: boolean;
searchScope: SearchScope;
searchOptions: ISearchOptions;
defaultRepoOptions: Repository[];
}

interface State {
Expand Down Expand Up @@ -460,6 +461,7 @@ export class CodeQueryBar extends Component<Props, State> {
role="textbox"
/>
<SearchOptions
defaultRepoOptions={this.props.defaultRepoOptions}
repositorySearch={this.props.repositorySearch}
saveSearchOptions={this.props.saveSearchOptions}
repoSearchResults={this.props.repoSearchResults}
Expand Down Expand Up @@ -494,6 +496,7 @@ const mapStateToProps = (state: RootState) => ({
searchLoading: state.search.isScopeSearchLoading,
searchScope: state.search.scope,
searchOptions: state.search.searchOptions,
defaultRepoOptions: state.repository.repositories.slice(0, 5),
});

const mapDispatchToProps = {
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/code/public/sagas/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
Match,
resetRepoTree,
revealPosition,
fetchRepos,
} from '../actions';
import { loadRepo, loadRepoFailed, loadRepoSuccess } from '../actions/status';
import { PathTypes } from '../common/types';
Expand Down Expand Up @@ -137,6 +138,8 @@ export function* watchLoadRepo() {
}

function* handleMainRouteChange(action: Action<Match>) {
// in source view page, we need repos as default repo scope options when no query input
yield put(fetchRepos());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please elaborate on why do we need to issue this action.

const { location } = action.payload!;
const search = location.search.startsWith('?') ? location.search.substring(1) : location.search;
const queryParams = queryString.parse(search);
Expand Down