fix(code/frontend): should update search results if search options change (#41232)

This commit is contained in:
WangQianliang 2019-07-21 18:45:06 +08:00 committed by GitHub
parent 376240d81b
commit 59297beb17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 14 deletions

View file

@ -468,7 +468,9 @@ export class CodeQueryBar extends Component<Props, State> {
/>
<SearchOptions
defaultRepoOptions={this.props.defaultRepoOptions}
defaultSearchScope={this.props.currentRepository}
defaultSearchScope={
this.props.currentRepository || this.props.searchOptions.defaultRepoScope
}
repositorySearch={this.props.repositorySearch}
saveSearchOptions={this.props.saveSearchOptions}
repoSearchResults={this.props.repoSearchResults}

View file

@ -40,17 +40,14 @@ export class SearchBar extends React.PureComponent<Props> {
// 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',

View file

@ -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 },
};