mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
* Allow overwriting of query in recognizer jobs * adding query overwrite warning * adding null check
This commit is contained in:
parent
c00bfe535a
commit
a80c669490
9 changed files with 68 additions and 15 deletions
|
@ -22,6 +22,7 @@ export function dataRecognizerProvider(ml) {
|
|||
};
|
||||
|
||||
this.indexPattern = props.indexPattern;
|
||||
this.savedSearch = props.savedSearch;
|
||||
this.className = props.className;
|
||||
this.results = props.results;
|
||||
}
|
||||
|
@ -35,6 +36,7 @@ export function dataRecognizerProvider(ml) {
|
|||
key={r.id}
|
||||
config={r}
|
||||
indexPattern={this.indexPattern}
|
||||
savedSearch={this.savedSearch}
|
||||
/>
|
||||
));
|
||||
if (typeof this.results === 'object') {
|
||||
|
@ -58,6 +60,7 @@ export function dataRecognizerProvider(ml) {
|
|||
|
||||
DataRecognizer.propTypes = {
|
||||
indexPattern: PropTypes.object,
|
||||
savedSearch: PropTypes.object,
|
||||
className: PropTypes.string,
|
||||
results: PropTypes.object,
|
||||
};
|
||||
|
|
|
@ -12,8 +12,14 @@ import PropTypes from 'prop-types';
|
|||
export const RecognizedResult = ({
|
||||
config,
|
||||
indexPattern,
|
||||
savedSearch
|
||||
}) => {
|
||||
const href = `#/jobs/new_job/simple/recognize?id=${config.id}&index=${indexPattern.id}`;
|
||||
const id = (savedSearch.id === undefined) ?
|
||||
`index=${indexPattern.id}` :
|
||||
`savedSearchId=${savedSearch.id}`;
|
||||
|
||||
const href = `#/jobs/new_job/simple/recognize?id=${config.id}&${id}`;
|
||||
|
||||
let logo = null;
|
||||
// if a logo is available, use that, otherwise display the id
|
||||
// the logo should be a base64 encoded image
|
||||
|
@ -51,4 +57,5 @@ export const RecognizedResult = ({
|
|||
RecognizedResult.propTypes = {
|
||||
config: PropTypes.object,
|
||||
indexPattern: PropTypes.object,
|
||||
savedSearch: PropTypes.object,
|
||||
};
|
||||
|
|
|
@ -3,8 +3,27 @@
|
|||
<ml-message-bar></ml-message-bar>
|
||||
<div ng-controller="MlCreateRecognizerJobs" class="recognizer-job-container">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="col-md-12">
|
||||
<h3 class="euiTitle euiTitle--large">New job from {{ui.pageTitle}}</h3>
|
||||
|
||||
<div ng-if="displayQueryWarning === true" class="euiCallOut euiCallOut--warning">
|
||||
<div class="euiCallOutHeader">
|
||||
<svg class="euiIcon euiCallOutHeader__icon euiIcon--medium" xmlns="http://www.w3.org/2000/svg"
|
||||
width="16" height="16" viewBox="0 0 16 16">
|
||||
<g fill-rule="evenodd">
|
||||
<path d="M7.5 2.236L1.618 14h11.764L7.5 2.236zm.894-.447l5.882 11.764A1 1 0 0 1 13.382 15H1.618a1 1 0 0 1-.894-1.447L6.606 1.789a1 1 0 0 1 1.788 0z"
|
||||
/>
|
||||
<path d="M7 6h1v5H7zM7 12h1v1H7z" />
|
||||
</g>
|
||||
</svg>
|
||||
<span class="euiCallOutHeader__title">Search will be overwritten</span>
|
||||
</div>
|
||||
<div class="euiText euiText--small">
|
||||
<p>
|
||||
Using a saved search will mean the query used in the datafeeds will be different from the default ones we supply in the {{moduleId}} module.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -77,9 +77,19 @@ module
|
|||
|
||||
$scope.overallState = SAVE_STATE.NOT_SAVED;
|
||||
|
||||
const { indexPattern, query } = createSearchItems($route);
|
||||
const moduleId = $route.current.params.id;
|
||||
$scope.moduleId = moduleId;
|
||||
|
||||
const pageTitle = `index pattern ${indexPattern.title}`;
|
||||
const {
|
||||
indexPattern,
|
||||
savedSearch,
|
||||
query,
|
||||
combinedQuery } = createSearchItems($route);
|
||||
|
||||
const pageTitle = (savedSearch.id !== undefined) ?
|
||||
`saved search ${savedSearch.title}` : `index pattern ${indexPattern.title}`;
|
||||
|
||||
$scope.displayQueryWarning = (savedSearch.id !== undefined);
|
||||
|
||||
$scope.ui = {
|
||||
formValid: true,
|
||||
|
@ -120,8 +130,6 @@ module
|
|||
|
||||
$scope.resultsUrl = '';
|
||||
|
||||
const moduleId = $route.current.params.id;
|
||||
|
||||
$scope.resetJob = function () {
|
||||
$scope.overallState = SAVE_STATE.NOT_SAVED;
|
||||
$scope.formConfig.jobs = [];
|
||||
|
@ -259,7 +267,10 @@ module
|
|||
const prefix = $scope.formConfig.jobLabel;
|
||||
const indexPatternName = $scope.formConfig.indexPattern.title;
|
||||
const groups = $scope.formConfig.jobGroups;
|
||||
ml.setupDataRecognizerConfig({ moduleId, prefix, groups, indexPatternName })
|
||||
const tempQuery = (savedSearch.id === undefined) ?
|
||||
undefined : combinedQuery;
|
||||
|
||||
ml.setupDataRecognizerConfig({ moduleId, prefix, groups, query: tempQuery, indexPatternName })
|
||||
.then((resp) => {
|
||||
if (resp.jobs) {
|
||||
$scope.formConfig.jobs.forEach((job) => {
|
||||
|
|
|
@ -44,6 +44,7 @@
|
|||
class-name='"euiFlexGrid euiFlexGrid--gutterLarge euiFlexGrid--fourths"'
|
||||
item-class-name='""'
|
||||
index-pattern='indexPattern'
|
||||
saved-search='savedSearch'
|
||||
results=recognizerResults/>
|
||||
<div class="euiSpacer euiSpacer--xxl"></div>
|
||||
</div>
|
||||
|
|
|
@ -60,6 +60,7 @@ module.controller('MlNewJobStepJobType',
|
|||
}
|
||||
|
||||
$scope.indexPattern = indexPattern;
|
||||
$scope.savedSearch = savedSearch;
|
||||
$scope.recognizerResults = { count: 0 };
|
||||
|
||||
$scope.pageTitleLabel = (savedSearch.id !== undefined) ?
|
||||
|
|
|
@ -254,7 +254,8 @@ module.service('ml', function (prlHttpService) {
|
|||
const data = pick(obj, [
|
||||
'prefix',
|
||||
'groups',
|
||||
'indexPatternName'
|
||||
'indexPatternName',
|
||||
'query'
|
||||
]);
|
||||
|
||||
return http.request({
|
||||
|
|
|
@ -185,7 +185,7 @@ export class DataRecognizer {
|
|||
// takes a module config id, an optional jobPrefix and the request object
|
||||
// creates all of the jobs, datafeeds and savedObjects listed in the module config.
|
||||
// if any of the savedObjects already exist, they will not be overwritten.
|
||||
async setupModuleItems(moduleId, jobPrefix, groups, indexPatternName, request) {
|
||||
async setupModuleItems(moduleId, jobPrefix, groups, indexPatternName, query, request) {
|
||||
this.savedObjectsClient = request.getSavedObjectsClient();
|
||||
this.indexPatterns = await this.loadIndexPatterns();
|
||||
|
||||
|
@ -223,6 +223,11 @@ export class DataRecognizer {
|
|||
|
||||
// create the datafeeds
|
||||
if (moduleConfig.datafeeds && moduleConfig.datafeeds.length) {
|
||||
if (typeof query === 'object' && query !== null) {
|
||||
moduleConfig.datafeeds.forEach((df) => {
|
||||
df.config.query = query;
|
||||
});
|
||||
}
|
||||
saveResults.datafeeds = await this.saveDatafeeds(moduleConfig.datafeeds);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,9 +21,9 @@ function getModule(callWithRequest, moduleId) {
|
|||
return dr.getModule(moduleId);
|
||||
}
|
||||
|
||||
function saveModuleItems(callWithRequest, moduleId, prefix, groups, indexPatternName, request) {
|
||||
function saveModuleItems(callWithRequest, moduleId, prefix, groups, indexPatternName, query, request) {
|
||||
const dr = new DataRecognizer(callWithRequest);
|
||||
return dr.setupModuleItems(moduleId, prefix, groups, indexPatternName, request);
|
||||
return dr.setupModuleItems(moduleId, prefix, groups, indexPatternName, query, request);
|
||||
}
|
||||
|
||||
export function dataRecognizer(server, commonRouteConfig) {
|
||||
|
@ -64,10 +64,15 @@ export function dataRecognizer(server, commonRouteConfig) {
|
|||
handler(request, reply) {
|
||||
const callWithRequest = callWithRequestFactory(server, request);
|
||||
const moduleId = request.params.moduleId;
|
||||
const prefix = (request.payload) ? request.payload.prefix : undefined;
|
||||
const groups = (request.payload) ? request.payload.groups : undefined;
|
||||
const indexPatternName = (request.payload) ? request.payload.indexPatternName : undefined;
|
||||
return saveModuleItems(callWithRequest, moduleId, prefix, groups, indexPatternName, request)
|
||||
|
||||
const {
|
||||
prefix,
|
||||
groups,
|
||||
indexPatternName,
|
||||
query
|
||||
} = request.payload;
|
||||
|
||||
return saveModuleItems(callWithRequest, moduleId, prefix, groups, indexPatternName, query, request)
|
||||
.then(resp => reply(resp))
|
||||
.catch(resp => reply(wrapError(resp)));
|
||||
},
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue