Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Code] implement new breadcrumb design #31247

Merged
merged 1 commit into from
Feb 26, 2019
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
25 changes: 4 additions & 21 deletions x-pack/plugins/code/public/components/main/breadcrumb.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,26 @@
import { EuiBreadcrumbs } from '@elastic/eui';
import React from 'react';
import { MainRouteParams } from '../../common/types';
import { VersionDropDown } from './version_dropdown';

interface Props {
routeParams: MainRouteParams;
}
export class Breadcrumb extends React.PureComponent<Props> {
public render() {
const { resource, org, repo, revision, path, pathType } = this.props.routeParams;
const { resource, org, repo, revision, path } = this.props.routeParams;
const repoUri = `${resource}/${org}/${repo}`;

const breadcrumbs = [
{
text: resource,
href: '#',
},
{
text: org,
href: '#',
},
{
text: repo,
href: `#${resource}/${org}/${repo}/tree/master`,
},
{
text: <VersionDropDown head={revision} repoUri={repoUri} path={path} pathType={pathType} />,
},
];
const breadcrumbs: Array<{ text: string; href: string }> = [];
const pathSegments = path ? path.split('/') : [];

pathSegments.forEach((p, index) => {
const paths = pathSegments.slice(0, index + 1);
const href = `#${resource}/${org}/${repo}/tree/master/${paths.join('/')}`;
const href = `#${repoUri}/tree/${revision}/${paths.join('/')}`;
breadcrumbs.push({
text: p,
href,
});
});
return <EuiBreadcrumbs max={Number.MAX_VALUE} truncate={false} breadcrumbs={breadcrumbs} />;
return <EuiBreadcrumbs max={Number.MAX_VALUE} breadcrumbs={breadcrumbs} />;
}
}
8 changes: 7 additions & 1 deletion x-pack/plugins/code/public/components/main/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import styled from 'styled-components';

import { RepositoryUtils } from '../../../common/repository_utils';
import { FileTree, FileTreeItemType, SearchScope, WorkerReservedProgress } from '../../../model';
import { CommitInfo } from '../../../model/commit';
import { CommitInfo, ReferenceInfo } from '../../../model/commit';
import { changeSearchScope, FetchFileResponse, fetchMoreCommits } from '../../actions';
import { MainRouteParams, PathTypes } from '../../common/types';
import { RepoState, RepoStatus, RootState } from '../../reducers';
Expand Down Expand Up @@ -75,6 +75,7 @@ interface Props extends RouteComponentProps<MainRouteParams> {
file: FetchFileResponse | undefined;
currentTree: FileTree | undefined;
commits: CommitInfo[];
branches: ReferenceInfo[];
hasMoreCommits: boolean;
loadingCommits: boolean;
onSearchScopeChanged: (s: SearchScope) => void;
Expand Down Expand Up @@ -180,13 +181,15 @@ class CodeContent extends React.PureComponent<Props> {
return (
<ButtonsContainer>
<EuiButtonGroup
buttonSize="m"
color="primary"
options={this.buttonOptions}
type="single"
idSelected={buttonId}
onChange={this.switchButton}
/>
<EuiButtonGroup
buttonSize="m"
color="primary"
options={this.rawButtonOptions}
type="single"
Expand All @@ -199,6 +202,7 @@ class CodeContent extends React.PureComponent<Props> {
return (
<ButtonsContainer>
<EuiButtonGroup
buttonSize="m"
color="primary"
options={[
{
Expand Down Expand Up @@ -227,6 +231,7 @@ class CodeContent extends React.PureComponent<Props> {
onSearchScopeChanged={this.props.onSearchScopeChanged}
buttons={this.renderButtons()}
repoScope={this.props.repoScope}
branches={this.props.branches}
/>
{this.renderContent()}
</Root>
Expand Down Expand Up @@ -373,6 +378,7 @@ const mapStateToProps = (state: RootState) => ({
tree: state.file.tree,
currentTree: currentTreeSelector(state),
commits: treeCommitsSelector(state),
branches: state.file.branches,
hasMoreCommits: hasMoreCommitsSelector(state),
loadingCommits: state.file.loadingCommits,
repoStatus: statusSelector(state, repoUriSelector(state)),
Expand Down
42 changes: 36 additions & 6 deletions x-pack/plugins/code/public/components/main/top_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,61 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import React from 'react';
import { EuiFlexGroup, EuiFlexItem, EuiSelect } from '@elastic/eui';
import theme from '@elastic/eui/dist/eui_theme_light.json';
import React, { ChangeEvent } from 'react';
import styled from 'styled-components';
import { SearchScope } from '../../../model';
import { ReferenceInfo } from '../../../model/commit';
import { MainRouteParams } from '../../common/types';
import { history } from '../../utils/url';
import { Breadcrumb } from './breadcrumb';
import { SearchBar } from './search_bar';

const SelectContainer = styled(EuiFlexItem)`
margin-right: ${theme.euiSizeS};
`;

interface Props {
routeParams: MainRouteParams;
onSearchScopeChanged: (s: SearchScope) => void;
buttons: React.ReactNode;
repoScope: string[];
branches: ReferenceInfo[];
}

export class TopBar extends React.Component<Props> {
export class TopBar extends React.Component<Props, { value: string }> {
public state = {
value: 'master',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

how should we determine what branch it is by the revision?

Copy link
Contributor

Choose a reason for hiding this comment

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

revision is the branch name

};

public onChange = (e: ChangeEvent<HTMLSelectElement>) => {
const { resource, org, repo, path = '', pathType } = this.props.routeParams;
this.setState({
value: e.target.value,
});
const revision = this.props.branches.find(b => b.name === e.target.value)!.commit.id;
history.push(`/${resource}/${org}/${repo}/${pathType}/${revision}/${path}`);
};

public render() {
return (
<div className="code-top-bar__container">
<SearchBar
onSearchScopeChanged={this.props.onSearchScopeChanged}
repoScope={this.props.repoScope}
/>
<EuiFlexGroup gutterSize="none" justifyContent="spaceBetween" alignItems="center">
<EuiFlexItem grow={false}>
<Breadcrumb routeParams={this.props.routeParams} />
<EuiFlexGroup gutterSize="none" justifyContent="spaceBetween">
<EuiFlexItem>
<EuiFlexGroup gutterSize="none">
<SelectContainer grow={false}>
<EuiSelect
options={this.props.branches.map(b => ({ value: b.name, text: b.name }))}
onChange={this.onChange}
/>
</SelectContainer>
<Breadcrumb routeParams={this.props.routeParams} />
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem grow={false} style={{ marginRight: '-.5rem' }}>
{this.props.buttons}
Expand Down
144 changes: 0 additions & 144 deletions x-pack/plugins/code/public/components/main/version_dropdown.tsx

This file was deleted.

10 changes: 10 additions & 0 deletions x-pack/plugins/code/public/sagas/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import queryString from 'querystring';
import { Action } from 'redux-actions';
import { call, put, select, takeEvery, takeLatest } from 'redux-saga/effects';
import chrome from 'ui/chrome';
import { kfetch } from 'ui/kfetch';
import { TextDocumentPositionParams } from 'vscode-languageserver';
import { parseGoto, parseLspUrl, toCanonicalUrl } from '../../common/uri_util';
Expand All @@ -15,6 +16,7 @@ import {
closeReferences,
fetchFile,
FetchFileResponse,
fetchRepoBranches,
fetchRepoTree,
fetchTreeCommits,
findReferences,
Expand Down Expand Up @@ -144,6 +146,14 @@ function* handleMainRouteChange(action: Action<Match>) {
position = parseGoto(goto);
}
yield put(loadRepo(repoUri));
yield put(fetchRepoBranches({ uri: repoUri }));
chrome.breadcrumbs.set([
{
text: 'Code',
href: '',
},
{ text: `${org} → ${repo}` },
]);
if (file) {
if ([PathTypes.blob, PathTypes.blame].includes(pathType as PathTypes)) {
yield call(handleFile, repoUri, file, revision);
Expand Down