From ed7f6983f93fa8e1f7f487851e86b85cd73c383a Mon Sep 17 00:00:00 2001 From: James Gowdy Date: Fri, 4 May 2018 14:02:43 +0100 Subject: [PATCH] [ML] Data recognizer UI improvements (#18804) * [ML] Data recognizer UI improvements * rolling back accidental change --- .../create_job/create_job_controller.js | 16 +++------ .../models/data_recognizer/data_recognizer.js | 34 +++++++++++-------- 2 files changed, 25 insertions(+), 25 deletions(-) diff --git a/x-pack/plugins/ml/public/jobs/new_job/simple/recognize/create_job/create_job_controller.js b/x-pack/plugins/ml/public/jobs/new_job/simple/recognize/create_job/create_job_controller.js index 9063c2e06e06..72661d8232b7 100644 --- a/x-pack/plugins/ml/public/jobs/new_job/simple/recognize/create_job/create_job_controller.js +++ b/x-pack/plugins/ml/public/jobs/new_job/simple/recognize/create_job/create_job_controller.js @@ -118,11 +118,7 @@ module jobLabel: '', jobGroups: [], jobs: [], - kibanaObjects: { - dashboard: [], - search: [], - visualization: [] - }, + kibanaObjects: {}, start: 0, end: 0, query, @@ -137,9 +133,7 @@ module $scope.overallState = SAVE_STATE.NOT_SAVED; $scope.formConfig.jobs = []; $scope.formConfig.filters = []; - $scope.formConfig.kibanaObjects.dashboard = []; - $scope.formConfig.kibanaObjects.search = []; - $scope.formConfig.kibanaObjects.visualization = []; + $scope.formConfig.kibanaObjects = {}; loadJobConfigs(); }; @@ -188,14 +182,14 @@ module // populate the kibana saved objects if (resp.kibana) { _.each(resp.kibana, (obj, key) => { - obj.forEach((o) => { - $scope.formConfig.kibanaObjects[key].push({ + $scope.formConfig.kibanaObjects[key] = obj.map((o) => { + return { id: o.id, title: o.title, saveState: SAVE_STATE.NOT_SAVED, config: o.config, exists: false - }); + }; }); }); // check to see if any of the saved objects already exist. diff --git a/x-pack/plugins/ml/server/models/data_recognizer/data_recognizer.js b/x-pack/plugins/ml/server/models/data_recognizer/data_recognizer.js index 7ceada426428..61340f40a9f9 100644 --- a/x-pack/plugins/ml/server/models/data_recognizer/data_recognizer.js +++ b/x-pack/plugins/ml/server/models/data_recognizer/data_recognizer.js @@ -105,6 +105,10 @@ export class DataRecognizer { } async searchForFields(moduleConfig, indexPattern) { + if (moduleConfig.query === undefined) { + return false; + } + const index = indexPattern; const size = 0; const body = { @@ -158,21 +162,23 @@ export class DataRecognizer { })); // load all of the kibana saved objects - const kKeys = Object.keys(manifestJSON.kibana); - await Promise.all(kKeys.map(async (key) => { - kibana[key] = []; - await Promise.all(manifestJSON.kibana[key].map(async (obj) => { - const kConfig = await this.readFile(`${this.modulesDir}/${dirName}/${KIBANA_DIR}/${key}/${obj.file}`); - // use the file name for the id - const kId = obj.file.replace('.json', ''); - const config = JSON.parse(kConfig); - kibana[key].push({ - id: kId, - title: config.title, - config - }); + if (manifestJSON.kibana !== undefined) { + const kKeys = Object.keys(manifestJSON.kibana); + await Promise.all(kKeys.map(async (key) => { + kibana[key] = []; + await Promise.all(manifestJSON.kibana[key].map(async (obj) => { + const kConfig = await this.readFile(`${this.modulesDir}/${dirName}/${KIBANA_DIR}/${key}/${obj.file}`); + // use the file name for the id + const kId = obj.file.replace('.json', ''); + const config = JSON.parse(kConfig); + kibana[key].push({ + id: kId, + title: config.title, + config + }); + })); })); - })); + } return { jobs,