Skip to content

Commit

Permalink
fix(code/frontend): fix button group not match path type (#38530)
Browse files Browse the repository at this point in the history
  • Loading branch information
WangQianliang authored Jun 11, 2019
1 parent 9d31076 commit c7349fe
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
3 changes: 0 additions & 3 deletions x-pack/plugins/code/public/reducers/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export interface FileState {
opendir?: FileTree;
isNotFound: boolean;
treeCommits: { [path: string]: CommitInfo[] };
currentPath: string;
loadingCommits: boolean;
commitsFullyLoaded: { [path: string]: boolean };
fileTreeLoadingPaths: string[];
Expand All @@ -67,7 +66,6 @@ const initialState: FileState = {
commits: [],
treeCommits: {},
isNotFound: false,
currentPath: '',
loadingCommits: false,
commitsFullyLoaded: {},
};
Expand Down Expand Up @@ -112,7 +110,6 @@ export const file = handleActions(
{
[String(fetchRepoTree)]: (state: FileState, action: any) =>
produce(state, draft => {
draft.currentPath = action.payload.path;
draft.fileTreeLoadingPaths.push(action.payload!.path);
}),
[String(fetchRepoTreeSuccess)]: (state: FileState, action: Action<RepoTreePayload>) =>
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/code/public/sagas/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ function* handleMainRouteChange(action: Action<Match>) {
yield put(fetchRepoBranches({ uri: repoUri }));
if (file) {
if ([PathTypes.blob, PathTypes.blame].includes(pathType as PathTypes)) {
yield call(handleFile, repoUri, file, revision);
yield put(revealPosition(position));
const { tab, refUrl } = queryParams;
if (tab === 'references' && refUrl) {
Expand All @@ -182,6 +181,7 @@ function* handleMainRouteChange(action: Action<Match>) {
yield put(closeReferences(false));
}
}
yield call(handleFile, repoUri, file, revision);
const commits = yield select((state: RootState) => state.file.treeCommits[file]);
if (commits === undefined) {
yield put(fetchTreeCommits({ revision, uri: repoUri, path: file }));
Expand Down
5 changes: 2 additions & 3 deletions x-pack/plugins/code/public/sagas/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@ import {
fetchRootRepoTreeFailed,
dirNotFound,
} from '../actions';
import { RootState } from '../reducers';
import { treeCommitsSelector } from '../selectors';
import { treeCommitsSelector, currentPathSelector } from '../selectors';
import { repoRoutePattern } from './patterns';
import { FileTree } from '../../model';

Expand Down Expand Up @@ -143,7 +142,7 @@ function* handleFetchCommits(action: Action<FetchRepoPayloadWithRevision>) {

function* handleFetchMoreCommits(action: Action<string>) {
try {
const path = yield select((state: RootState) => state.file.currentPath);
const path = yield select(currentPathSelector);
const commits = yield select(treeCommitsSelector);
const revision = commits.length > 0 ? commits[commits.length - 1].id : 'head';
const uri = action.payload;
Expand Down
8 changes: 5 additions & 3 deletions x-pack/plugins/code/public/selectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ export const statusSelector = (state: RootState, repoUri: RepositoryUri) => {

export const allStatusSelector = (state: RootState) => state.status.status;

export const currentPathSelector = (state: RootState) => state.route.match.params.path;

export const treeCommitsSelector = (state: RootState) => {
const path = state.file.currentPath;
const path = currentPathSelector(state);
if (path === '') {
return state.file.commits;
} else {
Expand All @@ -53,7 +55,7 @@ export const treeCommitsSelector = (state: RootState) => {
};

export const hasMoreCommitsSelector = (state: RootState) => {
const path = state.file.currentPath;
const path = currentPathSelector(state);
const isLoading = state.file.loadingCommits;
if (isLoading) {
return false;
Expand Down Expand Up @@ -86,7 +88,7 @@ function find(tree: FileTree, paths: string[]): FileTree | null {

export const currentTreeSelector = (state: RootState) => {
const tree = getTree(state);
const path = state.file.currentPath;
const path = currentPathSelector(state) || '';
return find(tree, path.split('/'));
};

Expand Down

0 comments on commit c7349fe

Please sign in to comment.