[Code] Reset the default search scope (#37014) (#37169)

This commit is contained in:
Mengwei Ding 2019-05-26 22:16:14 -07:00 committed by GitHub
parent f71384e9f9
commit 677b102f7d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 3 deletions

View file

@ -41,6 +41,7 @@ export const repositoryTypeaheadSearchFailed = createAction<string>('REPOSITORY
export const saveSearchOptions = createAction<SearchOptions>('SAVE SEARCH OPTIONS');
export const turnOnDefaultRepoScope = createAction<Repository>('TURN ON DEFAULT REPO SCOPE');
export const turnOffDefaultRepoScope = createAction('TURN OFF DEFAULT REPO SCOPE');
export const searchReposForScope = createAction<RepositorySearchPayload>('SEARCH REPOS FOR SCOPE');
export const searchReposForScopeSuccess = createAction<any>('SEARCH REPOS FOR SCOPE SUCCESS');

View file

@ -51,8 +51,7 @@ export class SearchOptions extends Component<Props, State> {
componentDidUpdate(prevProps: Props) {
if (
this.props.searchOptions.defaultRepoScopeOn &&
!prevProps.searchOptions.defaultRepoScopeOn
this.props.searchOptions.defaultRepoScopeOn !== prevProps.searchOptions.defaultRepoScopeOn
) {
this.setState({ defaultRepoScopeOn: this.props.searchOptions.defaultRepoScopeOn });
}

View file

@ -22,6 +22,7 @@ import {
saveSearchOptions,
searchReposForScope,
searchReposForScopeSuccess,
turnOffDefaultRepoScope,
turnOnDefaultRepoScope,
} from '../actions';
@ -179,6 +180,11 @@ export const search = handleActions<SearchState, any>(
draft.searchOptions.defaultRepoScope = action.payload;
draft.searchOptions.defaultRepoScopeOn = true;
}),
[String(turnOffDefaultRepoScope)]: (state: SearchState, action: Action<any>) =>
produce<SearchState>(state, draft => {
delete draft.searchOptions.defaultRepoScope;
draft.searchOptions.defaultRepoScopeOn = false;
}),
},
initialState
);

View file

@ -25,8 +25,9 @@ import {
searchReposForScope,
searchReposForScopeFailed,
searchReposForScopeSuccess,
turnOffDefaultRepoScope,
} from '../actions';
import { searchRoutePattern } from './patterns';
import { adminRoutePattern, searchRoutePattern } from './patterns';
function requestDocumentSearch(payload: DocumentSearchPayload) {
const { query, page, languages, repositories, repoScope } = payload;
@ -123,8 +124,14 @@ function* handleSearchRouteChange(action: Action<Match>) {
}
}
function* resetDefaultRepoScope() {
yield put(turnOffDefaultRepoScope());
}
export function* watchSearchRouteChange() {
yield takeLatest(searchRoutePattern, handleSearchRouteChange);
// Reset the default search scope if enters the admin page.
yield takeLatest(adminRoutePattern, resetDefaultRepoScope);
}
function* handleReposSearchForScope(action: Action<RepositorySearchPayload>) {