Skip to content

Commit 0f46b6b

Browse files
authored
[Code]: use absolute path for api path (#34582)
* [Code]: use absolute path for api path * [Code]: always use url.format to construct url with queries that have variables * [Code]: prefix lsp api with code * [Code]: Add chrome.addBasePath call for raw fetch argument
1 parent 812a2c6 commit 0f46b6b

32 files changed

+84
-68
lines changed

x-pack/plugins/code/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ export const code = (kibana: any) =>
2121
uiExports: {
2222
app: {
2323
title: 'Code',
24-
description: 'Code Search Plugin',
2524
main: 'plugins/code/app',
2625
euiIconType: 'codeApp',
2726
},

x-pack/plugins/code/public/components/admin_page/admin.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7+
import { EuiTab, EuiTabs } from '@elastic/eui';
78
import React from 'react';
8-
99
import { connect } from 'react-redux';
10-
11-
import { EuiTab, EuiTabs } from '@elastic/eui';
12-
1310
import styled from 'styled-components';
11+
import url from 'url';
1412

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

9290
public getAdminTabClickHandler = (tab: AdminTabs) => () => {
9391
this.setState({ tab });
94-
this.props.history.push(`/admin?tab=${tab}`);
92+
this.props.history.push(url.format({ pathname: '/admin', query: { tab } }));
9593
};
9694

9795
public renderTabs() {

x-pack/plugins/code/public/components/diff_page/diff.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import React, { MouseEvent } from 'react';
1010
import { connect } from 'react-redux';
1111
import { Link, RouteComponentProps, withRouter } from 'react-router-dom';
1212
import styled from 'styled-components';
13-
import { SearchScope } from 'x-pack/plugins/code/model';
1413
import { CommitDiff, FileDiff } from '../../../common/git_diff';
14+
import { SearchScope } from '../../../model';
1515
import { changeSearchScope } from '../../actions';
1616
import { RootState } from '../../reducers';
1717
import { SearchBar } from '../search_page/search_bar';

x-pack/plugins/code/public/components/main/content.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { connect } from 'react-redux';
1414
import { RouteComponentProps } from 'react-router-dom';
1515
import { withRouter } from 'react-router-dom';
1616
import styled from 'styled-components';
17+
import chrome from 'ui/chrome';
1718

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

163164
public renderButtons = () => {

x-pack/plugins/code/public/components/main/search_bar.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7+
import { ParsedUrlQuery } from 'querystring';
78
import React from 'react';
89
import { RouteComponentProps, withRouter } from 'react-router-dom';
910
import styled from 'styled-components';
11+
import url from 'url';
12+
1013
import { SearchScope } from '../../../model';
1114
import { MainRouteParams, SearchScopeText } from '../../common/types';
1215
import {
@@ -40,20 +43,21 @@ export class CodeSearchBar extends React.Component<Props> {
4043
new RepositorySuggestionsProvider(),
4144
];
4245

43-
public onSubmit = (query: string) => {
46+
public onSubmit = (queryString: string) => {
4447
const { history } = this.props;
45-
if (query.trim().length === 0) {
48+
if (queryString.trim().length === 0) {
4649
return;
4750
}
48-
let qs = '';
51+
const query: ParsedUrlQuery = {
52+
q: queryString,
53+
};
4954
if (this.props.repoScope) {
50-
qs = `&repoScope=${this.props.repoScope.join(',')}`;
55+
query.repoScope = this.props.repoScope.join(',');
5156
}
5257
if (this.state.searchScope === SearchScope.REPOSITORY) {
53-
history.push(`/search?q=${query}&scope=${SearchScope.REPOSITORY}${qs}`);
54-
} else {
55-
history.push(`/search?q=${query}${qs}`);
58+
query.scope = SearchScope.REPOSITORY;
5659
}
60+
history.push(url.format({ pathname: '/search', query }));
5761
};
5862

5963
public onSelect = (item: AutocompleteSuggestion) => {

x-pack/plugins/code/public/components/query_bar/components/typeahead/suggestions_component.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { EuiFlexGroup, EuiText, EuiToken, IconType } from '@elastic/eui';
88
import { isEmpty } from 'lodash';
99
import React, { Component } from 'react';
1010
import { Link } from 'react-router-dom';
11-
import Url from 'url';
11+
import url from 'url';
1212

1313
import {
1414
AutocompleteSuggestion,
@@ -102,7 +102,7 @@ export class SuggestionsComponent extends Component<Props> {
102102
</EuiFlexGroup>
103103
);
104104

105-
const viewMoreUrl = Url.format({
105+
const viewMoreUrl = url.format({
106106
pathname: '/search',
107107
query: {
108108
q: this.props.query,

x-pack/plugins/code/public/components/query_bar/suggestions/file_suggestions_provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class FileSuggestionsProvider extends AbstractSuggestionsProvider {
2828
queryParams.repoScope = repoScope.join(',');
2929
}
3030
const res = await kfetch({
31-
pathname: `../api/code/suggestions/doc`,
31+
pathname: `/api/code/suggestions/doc`,
3232
method: 'get',
3333
query: queryParams,
3434
});

x-pack/plugins/code/public/components/query_bar/suggestions/repository_suggestions_provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class RepositorySuggestionsProvider extends AbstractSuggestionsProvider {
2929
queryParams.repoScope = repoScope.join(',');
3030
}
3131
const res = await kfetch({
32-
pathname: `../api/code/suggestions/repo`,
32+
pathname: `/api/code/suggestions/repo`,
3333
method: 'get',
3434
query: queryParams,
3535
});

x-pack/plugins/code/public/components/query_bar/suggestions/symbol_suggestions_provider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export class SymbolSuggestionsProvider extends AbstractSuggestionsProvider {
3333
queryParams.repoScope = repoScope.join(',');
3434
}
3535
const res = await kfetch({
36-
pathname: `../api/code/suggestions/symbol`,
36+
pathname: `/api/code/suggestions/symbol`,
3737
method: 'get',
3838
query: queryParams,
3939
});

x-pack/plugins/code/public/components/search_page/pagination.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import { EuiFlexGroup, EuiFlexItem, EuiPagination } from '@elastic/eui';
88
import querystring from 'querystring';
99
import React from 'react';
10-
import Url from 'url';
10+
import url from 'url';
1111

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

@@ -22,7 +22,7 @@ export class Pagination extends React.PureComponent<Props> {
2222
const { query } = this.props;
2323
const queries = querystring.parse(history.location.search.replace('?', ''));
2424
history.push(
25-
Url.format({
25+
url.format({
2626
pathname: '/search',
2727
query: {
2828
...queries,

0 commit comments

Comments
 (0)