Skip to content

Commit 6f290f6

Browse files
committed
Change substr to substring
Add validate option in routes Change kibana/server path
1 parent 1e91437 commit 6f290f6

File tree

10 files changed

+45
-37
lines changed

10 files changed

+45
-37
lines changed

public/application.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react';
22
import ReactDOM from 'react-dom';
3-
import { AppMountParameters, CoreStart } from '../../../src/core/public';
3+
import { AppMountParameters, CoreStart } from 'kibana/public';
44
import { AppPluginStartDependencies } from './types';
55
import { AnalyzeApiUiApp } from './components/app';
66

public/components/analyze_ui/analyze_ui.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ export class AnalyzeUi extends Component {
7676
this.setState({
7777
"detail": {},
7878
"showResult": false,
79-
"esRequest": ""
79+
"esRequest": "",
80+
"resultAnalyzers": []
8081
});
8182
}
8283
}
@@ -87,7 +88,7 @@ export class AnalyzeUi extends Component {
8788
(response) => {
8889
this.setState({
8990
showResult: true,
90-
detail: response.resultAnalyzers,
91+
resultAnalyzers: response.resultAnalyzers,
9192
resultType: "multi"
9293
});
9394
}
@@ -256,6 +257,7 @@ export class AnalyzeUi extends Component {
256257
detail={this.state.detail}
257258
esRequest={this.state.esRequest}
258259
indexName={indexName}
260+
resultAnalyzers={this.state.resultAnalyzers}
259261
/>
260262
)}
261263
</Fragment>

public/components/result/analyzer_result/tokenizer_and_filters/tokenizer_and_filters.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ export function displayRowsComponent(WrappedComponent) {
7575
return class extends WrappedComponent {
7676

7777
shortenName(name) {
78-
if (name.indexOf('.') > 0) {
79-
return name.substr(name.lastIndexOf('.')+1);
78+
if (name && name.indexOf('.') > 0) {
79+
return name.substring(name.lastIndexOf('.')+1);
8080
}
8181
return name;
8282
}
@@ -110,4 +110,4 @@ export function displayRowsComponent(WrappedComponent) {
110110
);
111111
}
112112
}
113-
}
113+
}

public/components/result/compare_result/compare_result.tsx

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ export class CompareResult extends Component {
2020
super(props);
2121
}
2222

23-
countTokenStreamLength(analyzerResults) {
23+
countTokenStreamLength(resultAnalyzers) {
2424
let tokenStreamLength = 0;
25-
analyzerResults.forEach((detail) => {
25+
resultAnalyzers.forEach((detail) => {
2626
tokenStreamLength = getLength(tokenStreamLength, detail.tokens);
2727
});
2828
return createTokenIndices(tokenStreamLength);
@@ -56,8 +56,8 @@ export class CompareResult extends Component {
5656
return tokenCells;
5757
}
5858

59-
renderRows(tokenIndices, detail) {
60-
const rows = detail.map(
59+
renderRows(tokenIndices, resultAnalyzers) {
60+
const rows = resultAnalyzers.map(
6161
(result) =>
6262
<EuiTableRow
6363
className="analyzeApiTableRowTop"
@@ -75,9 +75,9 @@ export class CompareResult extends Component {
7575

7676
render() {
7777
const {
78-
detail
78+
resultAnalyzers
7979
} = this.props;
80-
const tokenIndices = this.countTokenStreamLength(detail);
80+
const tokenIndices = this.countTokenStreamLength(resultAnalyzers);
8181

8282
return (
8383
<EuiPanel
@@ -86,6 +86,7 @@ export class CompareResult extends Component {
8686
>
8787
There are only tokens and positions. If you know analyzer details, use analyzer/custom_analyzer tab.
8888
<div class="analyzeApiTableScroll">
89+
8990
<EuiTable className="analyzeApiTableLayout">
9091
<EuiTableHeader>
9192
<EuiTableHeaderCell
@@ -97,11 +98,11 @@ export class CompareResult extends Component {
9798
{this.renderHeaderTokensCells(tokenIndices)}
9899
</EuiTableHeader>
99100
<EuiTableBody>
100-
{this.renderRows(tokenIndices, detail)}
101+
{this.renderRows(tokenIndices, resultAnalyzers)}
101102
</EuiTableBody>
102103
</EuiTable>
103104
</div>
104105
</EuiPanel>
105106
);
106107
}
107-
}
108+
}

public/components/result/result.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export class Result extends Component {
1717
const {esRequest} = this.props;
1818
const {indexName} = this.props;
1919
const {showAllTokenAttr} = this.props;
20+
const {resultAnalyzers} = this.props;
2021
if (type === RESULT_TYPE.SINGLE) {
2122
return (
2223
<AnalyzerResult
@@ -29,9 +30,9 @@ export class Result extends Component {
2930
} else {
3031
return (
3132
<CompareResult
32-
detail={detail}
33+
resultAnalyzers={resultAnalyzers}
3334
/>
3435
);
3536
}
3637
}
37-
}
38+
}

public/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { AppMountParameters, CoreSetup, CoreStart, Plugin } from '../../../src/core/public';
1+
import { AppMountParameters, CoreSetup, CoreStart, Plugin } from 'kibana/public';
22
import {
33
AnalyzeApiUiPluginSetup,
44
AnalyzeApiUiPluginStart,

public/services/validator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@ function parseCustom(target, label, validatedParams) {
9292
} else {
9393
return target;
9494
}
95-
};
95+
};

server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PluginInitializerContext } from '../../../src/core/server';
1+
import { PluginInitializerContext } from 'kibana/server';
22
import { AnalyzeApiUiPlugin } from './plugin';
33

44
// This exports static code and TypeScript types,

server/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
CoreStart,
55
Plugin,
66
Logger,
7-
} from '../../../src/core/server';
7+
} from 'kibana/server';
88

99
import { AnalyzeApiUiPluginSetup, AnalyzeApiUiPluginStart } from './types';
1010
import { defineRoutes } from './routes';
@@ -23,7 +23,7 @@ export class AnalyzeApiUiPlugin
2323
const router = core.http.createRouter();
2424

2525
// Register server side APIs
26-
defineRoutes(router);
26+
defineRoutes(router, this.logger);
2727

2828
return {};
2929
}

server/routes/index.ts

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { IRouter } from '../../../../src/core/server';
1+
import { IRouter, Logger } from 'kibana/server';
22
import { schema } from '@kbn/config-schema';
33
import { convertEsError } from "./handle_es_error";
44

5-
export function defineRoutes(router: IRouter) {
5+
export function defineRoutes(router: IRouter, logger: logger) {
66
router.post(
77
{
88
path: '/api/analyze_api_ui/analyze',
@@ -11,10 +11,10 @@ export function defineRoutes(router: IRouter) {
1111
text: schema.string(),
1212
indexName: schema.maybe(schema.nullable(schema.string())),
1313
analyzer: schema.maybe(schema.nullable(schema.string())),
14-
tokenizer: schema.maybe(schema.oneOf([schema.nullable(schema.string()), schema.object({})])),
14+
tokenizer: schema.maybe(schema.oneOf([schema.nullable(schema.string()), schema.object({}, { unknowns: 'allow' })])),
1515
field: schema.maybe(schema.nullable(schema.string())),
16-
filters: schema.maybe(schema.arrayOf(schema.nullable(schema.oneOf([schema.string(), schema.object({})])))),
17-
charfilters: schema.maybe(schema.arrayOf(schema.nullable(schema.oneOf([schema.string(), schema.object({})]))))
16+
filters: schema.maybe(schema.arrayOf(schema.nullable(schema.oneOf([schema.string(), schema.object({}, { unknowns: 'allow' })])))),
17+
charfilters: schema.maybe(schema.arrayOf(schema.nullable(schema.oneOf([schema.string(), schema.object({}, { unknowns: 'allow' })]))))
1818
})
1919
}
2020
},
@@ -65,39 +65,43 @@ export function defineRoutes(router: IRouter) {
6565
};
6666
if (request.body.indexName) param.index = request.body.indexName;
6767
const res = {
68-
resultAnalyzers: []
68+
body: {
69+
resultAnalyzers: []
70+
}
6971
};
7072

7173
function getAnalyzerResult(analyzer, id) {
7274
return new Promise(function (resolve, reject) {
7375
param.body.analyzer = analyzer;
74-
context.core.elasticsearch.client.asCurrentUser.indices.analyze(param)
75-
.then(function (response) {
76-
res.resultAnalyzers.push({analyzer: analyzer, id: id, tokens: response.tokens});
77-
resolve(res);
78-
})
79-
.catch(error => {
76+
const results = context.core.elasticsearch.client.asCurrentUser.indices.analyze(param)
77+
results.then(
78+
(x) => {
79+
res.body.resultAnalyzers.push({analyzer: analyzer, id: id, tokens: x.body.tokens});
80+
resolve(res);
81+
}
82+
);
83+
results.catch(error => {
8084
reject(convertEsError(response, error));
8185
});
8286
});
8387
};
8488

8589
if (Array.isArray(request.body.analyzers) && request.body.analyzers.length >= 1) {
8690
try {
87-
const response = await Promise.all(request.body.analyzers.map(getAnalyzerResult));
88-
res.resultAnalyzers.sort(
91+
const res_promise = await Promise.all(request.body.analyzers.map(getAnalyzerResult));
92+
res.body.resultAnalyzers.sort(
8993
function (a, b) {
9094
if (a.id < b.id) return -1;
9195
if (a.id > b.id) return 1;
9296
return 0;
9397
}
9498
);
95-
return res;
99+
return response.ok(res);
96100
} catch (error) {
97101
return convertEsError(response, error);
98102
}
99103
} else {
100-
return res;
104+
return response.ok(res);
101105
}
102106
}
103107
);

0 commit comments

Comments
 (0)