Skip to content
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
1 change: 0 additions & 1 deletion x-pack/plugins/code/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ export const code = (kibana: any) =>
uiExports: {
app: {
title: 'Code',
description: 'Code Search Plugin',
main: 'plugins/code/app',
euiIconType: 'codeApp',
},
Expand Down
8 changes: 3 additions & 5 deletions x-pack/plugins/code/public/components/admin_page/admin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { EuiTab, EuiTabs } from '@elastic/eui';
import React from 'react';

import { connect } from 'react-redux';

import { EuiTab, EuiTabs } from '@elastic/eui';

import styled from 'styled-components';
import url from 'url';

import theme from '@elastic/eui/dist/eui_theme_light.json';
import { parse as parseQuery } from 'querystring';
Expand Down Expand Up @@ -91,7 +89,7 @@ class AdminPage extends React.PureComponent<Props, State> {

public getAdminTabClickHandler = (tab: AdminTabs) => () => {
this.setState({ tab });
this.props.history.push(`/admin?tab=${tab}`);
this.props.history.push(url.format({ pathname: '/admin', query: { tab } }));
};

public renderTabs() {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/code/public/components/diff_page/diff.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import React, { MouseEvent } from 'react';
import { connect } from 'react-redux';
import { Link, RouteComponentProps, withRouter } from 'react-router-dom';
import styled from 'styled-components';
import { SearchScope } from 'x-pack/plugins/code/model';
import { CommitDiff, FileDiff } from '../../../common/git_diff';
import { SearchScope } from '../../../model';
import { changeSearchScope } from '../../actions';
import { RootState } from '../../reducers';
import { SearchBar } from '../search_page/search_bar';
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/code/public/components/main/content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { connect } from 'react-redux';
import { RouteComponentProps } from 'react-router-dom';
import { withRouter } from 'react-router-dom';
import styled from 'styled-components';
import chrome from 'ui/chrome';

import { RepositoryUtils } from '../../../common/repository_utils';
import { FileTree, FileTreeItemType, SearchScope, WorkerReservedProgress } from '../../../model';
Expand Down Expand Up @@ -157,7 +158,7 @@ class CodeContent extends React.PureComponent<Props> {
public openRawFile = () => {
const { path, resource, org, repo, revision } = this.props.match.params;
const repoUri = `${resource}/${org}/${repo}`;
window.open(`../api/code/repo/${repoUri}/blob/${revision}/${path}`);
window.open(chrome.addBasePath(`/app/code/repo/${repoUri}/raw/${revision}/${path}`));
};

public renderButtons = () => {
Expand Down
18 changes: 11 additions & 7 deletions x-pack/plugins/code/public/components/main/search_bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { ParsedUrlQuery } from 'querystring';
import React from 'react';
import { RouteComponentProps, withRouter } from 'react-router-dom';
import styled from 'styled-components';
import url from 'url';

import { SearchScope } from '../../../model';
import { MainRouteParams, SearchScopeText } from '../../common/types';
import {
Expand Down Expand Up @@ -40,20 +43,21 @@ export class CodeSearchBar extends React.Component<Props> {
new RepositorySuggestionsProvider(),
];

public onSubmit = (query: string) => {
public onSubmit = (queryString: string) => {
const { history } = this.props;
if (query.trim().length === 0) {
if (queryString.trim().length === 0) {
return;
}
let qs = '';
const query: ParsedUrlQuery = {
q: queryString,
};
if (this.props.repoScope) {
qs = `&repoScope=${this.props.repoScope.join(',')}`;
query.repoScope = this.props.repoScope.join(',');
}
if (this.state.searchScope === SearchScope.REPOSITORY) {
history.push(`/search?q=${query}&scope=${SearchScope.REPOSITORY}${qs}`);
} else {
history.push(`/search?q=${query}${qs}`);
query.scope = SearchScope.REPOSITORY;
}
history.push(url.format({ pathname: '/search', query }));
};

public onSelect = (item: AutocompleteSuggestion) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { EuiFlexGroup, EuiText, EuiToken, IconType } from '@elastic/eui';
import { isEmpty } from 'lodash';
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
import Url from 'url';
import url from 'url';

import {
AutocompleteSuggestion,
Expand Down Expand Up @@ -102,7 +102,7 @@ export class SuggestionsComponent extends Component<Props> {
</EuiFlexGroup>
);

const viewMoreUrl = Url.format({
const viewMoreUrl = url.format({
pathname: '/search',
query: {
q: this.props.query,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class FileSuggestionsProvider extends AbstractSuggestionsProvider {
queryParams.repoScope = repoScope.join(',');
}
const res = await kfetch({
pathname: `../api/code/suggestions/doc`,
pathname: `/api/code/suggestions/doc`,
method: 'get',
query: queryParams,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class RepositorySuggestionsProvider extends AbstractSuggestionsProvider {
queryParams.repoScope = repoScope.join(',');
}
const res = await kfetch({
pathname: `../api/code/suggestions/repo`,
pathname: `/api/code/suggestions/repo`,
method: 'get',
query: queryParams,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class SymbolSuggestionsProvider extends AbstractSuggestionsProvider {
queryParams.repoScope = repoScope.join(',');
}
const res = await kfetch({
pathname: `../api/code/suggestions/symbol`,
pathname: `/api/code/suggestions/symbol`,
method: 'get',
query: queryParams,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { EuiFlexGroup, EuiFlexItem, EuiPagination } from '@elastic/eui';
import querystring from 'querystring';
import React from 'react';
import Url from 'url';
import url from 'url';

import { history } from '../../utils/url';

Expand All @@ -22,7 +22,7 @@ export class Pagination extends React.PureComponent<Props> {
const { query } = this.props;
const queries = querystring.parse(history.location.search.replace('?', ''));
history.push(
Url.format({
url.format({
pathname: '/search',
query: {
...queries,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { EuiTab, EuiTabs } from '@elastic/eui';
import querystring from 'querystring';
import React from 'react';
import styled from 'styled-components';
import Url from 'url';
import url from 'url';

import { SearchScope } from '../../../model';
import { history } from '../../utils/url';
Expand All @@ -32,7 +32,7 @@ export class ScopeTabs extends React.PureComponent<Props> {
const { query } = this.props;
const queries = querystring.parse(history.location.search.replace('?', ''));
history.push(
Url.format({
url.format({
pathname: '/search',
query: {
...queries,
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/code/public/components/search_page/search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React from 'react';
import { connect } from 'react-redux';
import styled from 'styled-components';
import chrome from 'ui/chrome';
import Url from 'url';
import url from 'url';

import theme from '@elastic/eui/dist/eui_theme_light.json';
import { DocumentSearchResult, SearchScope } from '../../../model';
Expand Down Expand Up @@ -92,7 +92,7 @@ class SearchPage extends React.PureComponent<Props, State> {
const queries = querystring.parse(history.location.search.replace('?', ''));
return () => {
history.push(
Url.format({
url.format({
pathname: '/search',
query: {
...queries,
Expand Down Expand Up @@ -121,7 +121,7 @@ class SearchPage extends React.PureComponent<Props, State> {
const queries = querystring.parse(history.location.search.replace('?', ''));
return () => {
history.push(
Url.format({
url.format({
pathname: '/search',
query: {
...queries,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import querystring from 'querystring';
import React from 'react';
import Url from 'url';
import url from 'url';

import { SearchScope } from '../../../model';
import { SearchScopeText } from '../../common/types';
Expand Down Expand Up @@ -34,7 +34,7 @@ export class SearchBar extends React.PureComponent<Props> {
// Update the url and push to history as well.
const queries = querystring.parse(history.location.search.replace('?', ''));
history.push(
Url.format({
url.format({
pathname: '/search',
query: {
...queries,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import theme from '@elastic/eui/dist/eui_theme_light.json';
import React from 'react';
import { Link } from 'react-router-dom';
import styled from 'styled-components';
import url from 'url';
import { Location, SymbolKind } from 'vscode-languageserver-types/lib/umd/main';

import { RepositoryUtils } from '../../../common/repository_utils';
import { EuiSideNavItem } from '../../common/types';
import { SymbolWithMembers } from '../../reducers/symbol';
Expand Down Expand Up @@ -100,7 +102,10 @@ export class CodeSymbolTree extends React.PureComponent<Props, { activePath?: st
))}
<EuiFlexItem grow={1}>
<Link
to={`${RepositoryUtils.locationToUrl(location)}?tab=structure`}
to={url.format({
pathname: RepositoryUtils.locationToUrl(location),
query: { tab: 'structure' },
})}
className="code-link"
onClick={this.getClickHandler(path)}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Location } from 'vscode-languageserver-types';
import { LspRestClient, TextDocumentMethods } from '../../../common/lsp_client';

export function provideDefinition(monaco: any, model: editor.ITextModel, position: any) {
const lspClient = new LspRestClient('../api/lsp');
const lspClient = new LspRestClient('/api/code/lsp');
Copy link
Contributor

Choose a reason for hiding this comment

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

so this should fix an existing bug. or the /api/lsp route is also a valid endpoint?

const lspMethods = new TextDocumentMethods(lspClient);
function handleLocation(location: Location): languages.Location {
return {
Expand All @@ -27,7 +27,7 @@ export function provideDefinition(monaco: any, model: editor.ITextModel, positio
}

async function handleQname(qname: string) {
const res: any = await kfetch({ pathname: `/api/lsp/symbol/${qname}` });
const res: any = await kfetch({ pathname: `/api/code/lsp/symbol/${qname}` });
if (res.symbols) {
return res.symbols.map((s: DetailSymbolInformation) =>
handleLocation(s.symbolInformation.location)
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/code/public/monaco/editor_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export class EditorService extends StandaloneCodeEditorServiceImpl {
public static async findSymbolByQname(qname: string) {
try {
const response = await kfetch({
pathname: `/api/lsp/symbol/${qname}`,
pathname: `/api/code/lsp/symbol/${qname}`,
method: 'GET',
});
return response as SymbolSearchResult;
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/code/public/monaco/hover/hover_computer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export class HoverComputer implements Computer<Hover> {
private uri: string | null = null;

constructor() {
const lspClient = new LspRestClient('../api/lsp');
const lspClient = new LspRestClient('/api/code/lsp');
this.lspMethods = new TextDocumentMethods(lspClient);
}

Expand Down
6 changes: 5 additions & 1 deletion x-pack/plugins/code/public/monaco/textmodel_resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/

import { editor, IDisposable, Uri } from 'monaco-editor';
import chrome from 'ui/chrome';

import { ImmortalReference } from './immortal_reference';

export interface IReference<T> extends IDisposable {
Expand Down Expand Up @@ -52,7 +54,9 @@ export class TextModelResolverService implements ITextModelService {
const repo = `${resource.authority}${resource.path}`;
const revision = resource.query;
const file = resource.fragment;
const response = await fetch(`../api/code/repo/${repo}/blob/${revision}/${file}`);
const response = await fetch(
chrome.addBasePath(`/api/code/repo/${repo}/blob/${revision}/${file}`)
Copy link
Contributor

Choose a reason for hiding this comment

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

just to confirm. it's required to add chrome.addBasePath for fetch, and not required for kfetch.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

kfetch return the body of the request using body.asJson

the problem is that our request doesn't return json, so response will be null unfornately.

);
if (response.status === 200) {
const contentType = response.headers.get('Content-Type');

Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/code/public/sagas/blame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { loadBlame, loadBlameFailed, LoadBlamePayload, loadBlameSuccess } from '
import { blamePattern } from './patterns';

function requestBlame(repoUri: string, revision: string, path: string) {
return kfetch({ pathname: `../api/code/repo/${repoUri}/blame/${revision}/${path}` });
return kfetch({ pathname: `/api/code/repo/${repoUri}/blame/${revision}/${path}` });
}

function* handleFetchBlame(action: Action<LoadBlamePayload>) {
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/code/public/sagas/commit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { commitRoutePattern } from './patterns';

function requestCommit(repo: string, commitId: string) {
return kfetch({
pathname: `../api/code/repo/${repo}/diff/${commitId}`,
pathname: `/api/code/repo/${repo}/diff/${commitId}`,
});
}

Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/code/public/sagas/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function* handleReferences(action: Action<TextDocumentPositionParams>) {

function requestFindReferences(params: TextDocumentPositionParams) {
return kfetch({
pathname: `../api/lsp/findReferences`,
pathname: `/api/code/lsp/findReferences`,
method: 'POST',
body: JSON.stringify(params),
});
Expand Down Expand Up @@ -120,7 +120,7 @@ function* handleFile(repoUri: string, file: string, revision: string) {
}

function fetchRepo(repoUri: string) {
return kfetch({ pathname: `../api/code/repo/${repoUri}` });
return kfetch({ pathname: `/api/code/repo/${repoUri}` });
}

function* loadRepoSaga(action: any) {
Expand Down
17 changes: 11 additions & 6 deletions x-pack/plugins/code/public/sagas/file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

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 Url from 'url';

import { FileTree } from '../../model';
import {
fetchDirectory,
Expand Down Expand Up @@ -90,7 +93,7 @@ function requestRepoTree({
query.parents = true;
}
return kfetch({
pathname: `../api/code/repo/${uri}/tree/${revision}/${path}`,
pathname: `/api/code/repo/${uri}/tree/${revision}/${path}`,
query,
});
}
Expand All @@ -110,7 +113,7 @@ function* handleFetchBranches(action: Action<FetchRepoPayload>) {

function requestBranches({ uri }: FetchRepoPayload) {
return kfetch({
pathname: `../api/code/repo/${uri}/references`,
pathname: `/api/code/repo/${uri}/references`,
});
}

Expand Down Expand Up @@ -155,7 +158,7 @@ function requestCommits(
) {
const pathStr = path ? `/${path}` : '';
const options: any = {
pathname: `../api/code/repo/${uri}/history/${revision}${pathStr}`,
pathname: `/api/code/repo/${uri}/history/${revision}${pathStr}`,
};
if (loadMore) {
options.query = { after: 1 };
Expand All @@ -171,11 +174,13 @@ export async function requestFile(
line?: string
): Promise<FetchFileResponse> {
const { uri, revision, path } = payload;
let url = `../api/code/repo/${uri}/blob/${revision}/${path}`;
const url = `/api/code/repo/${uri}/blob/${revision}/${path}`;
const query: any = {};
if (line) {
url += '?line=' + line;
query.line = line;
}
const response: Response = await fetch(url);
const response: Response = await fetch(chrome.addBasePath(Url.format({ pathname: url, query })));

if (response.status >= 200 && response.status < 300) {
const contentType = response.headers.get('Content-Type');

Expand Down
Loading