diff --git a/x-pack/legacy/plugins/code/public/components/query_bar/components/query_bar.tsx b/x-pack/legacy/plugins/code/public/components/query_bar/components/query_bar.tsx index e192ddb0d5370a..d267d6d73e7fc1 100644 --- a/x-pack/legacy/plugins/code/public/components/query_bar/components/query_bar.tsx +++ b/x-pack/legacy/plugins/code/public/components/query_bar/components/query_bar.tsx @@ -468,7 +468,9 @@ export class CodeQueryBar extends Component { /> { // Update the url and push to history as well. const previousQueries = querystring.parse(history.location.search.replace('?', '')); - const queries: any = - repoScopes.length === 0 - ? { - ...previousQueries, - q: query, - } - : { - ...previousQueries, - q: query, - repoScope: repoScopes, - }; + const queries: any = { + ...previousQueries, + repoScope: repoScopes, + q: query, + }; + if (repoScopes.length === 0) { + delete queries.repoScope; + } history.push( url.format({ pathname: '/search', diff --git a/x-pack/legacy/plugins/code/public/reducers/search.ts b/x-pack/legacy/plugins/code/public/reducers/search.ts index fb1343cb866d6e..6f693e0c430bf1 100644 --- a/x-pack/legacy/plugins/code/public/reducers/search.ts +++ b/x-pack/legacy/plugins/code/public/reducers/search.ts @@ -5,8 +5,9 @@ */ import produce from 'immer'; - +import querystring from 'querystring'; import { Action, handleActions } from 'redux-actions'; +import { history } from '../utils/url'; import { DocumentSearchResult, @@ -33,6 +34,7 @@ import { turnOffDefaultRepoScope, turnOnDefaultRepoScope, } from '../actions'; +import { RepositoryUtils } from '../../common/repository_utils'; export interface SearchState { scope: SearchScope; @@ -51,12 +53,30 @@ export interface SearchState { const repositories: Repository[] = []; +const getRepoScopeFromUrl = () => { + const { repoScope } = querystring.parse(history.location.search.replace('?', '')); + if (repoScope) { + return String(repoScope) + .split(',') + .map(r => ({ + uri: r, + org: RepositoryUtils.orgNameFromUri(r), + name: RepositoryUtils.repoNameFromUri(r), + })) as Repository[]; + } else { + return []; + } +}; + const initialState: SearchState = { query: '', isLoading: false, isScopeSearchLoading: false, scope: SearchScope.DEFAULT, - searchOptions: { repoScope: [], defaultRepoScopeOn: false }, + searchOptions: { + repoScope: getRepoScopeFromUrl(), + defaultRepoScopeOn: false, + }, scopeSearchResults: { repositories, total: 0, took: 0 }, };