77import { TIME_RANGE_TYPE , URL_TYPE } from './constants' ;
88
99import rison from 'rison-node' ;
10- // import url from 'url';
10+ import url from 'url' ;
1111
12- // import { npStart } from 'ui/new_platform';
13- // import { DASHBOARD_APP_URL_GENERATOR } from '../../../../../../../../src/plugins/dashboard_embeddable_container/public';
12+ import { DASHBOARD_APP_URL_GENERATOR } from '../../../../../../../../src/plugins/dashboard/public' ;
1413
1514import { ML_RESULTS_INDEX_PATTERN } from '../../../../../common/constants/index_patterns' ;
1615import { getPartitioningFieldNames } from '../../../../../common/util/job_utils' ;
@@ -19,7 +18,7 @@ import { replaceTokensInUrlValue, isValidLabel } from '../../../util/custom_url_
1918import { ml } from '../../../services/ml_api_service' ;
2019import { mlJobService } from '../../../services/job_service' ;
2120import { escapeForElasticsearchQuery } from '../../../util/string_utils' ;
22- // import { getSavedObjectsClient } from '../../../util/dependency_cache';
21+ import { getSavedObjectsClient , getGetUrlGenerator } from '../../../util/dependency_cache' ;
2322
2423export function getNewCustomUrlDefaults ( job , dashboards , indexPatterns ) {
2524 // Returns the settings object in the format used by the custom URL editor
@@ -119,7 +118,7 @@ export function buildCustomUrlFromSettings(settings) {
119118 // Dashboard URL returns a Promise as a query is made to obtain the full dashboard config.
120119 // So wrap the other two return types in a Promise for consistent return type.
121120 if ( settings . type === URL_TYPE . KIBANA_DASHBOARD ) {
122- // return buildDashboardUrlFromSettings(settings);
121+ return buildDashboardUrlFromSettings ( settings ) ;
123122 } else if ( settings . type === URL_TYPE . KIBANA_DISCOVER ) {
124123 return Promise . resolve ( buildDiscoverUrlFromSettings ( settings ) ) ;
125124 } else {
@@ -132,72 +131,70 @@ export function buildCustomUrlFromSettings(settings) {
132131 }
133132}
134133
135- // function buildDashboardUrlFromSettings(settings) {
136- // // Get the complete list of attributes for the selected dashboard (query, filters).
137- // return new Promise((resolve, reject) => {
138- // const { dashboardId, queryFieldNames } = settings.kibanaSettings;
139-
140- // const savedObjectsClient = getSavedObjectsClient();
141- // savedObjectsClient
142- // .get('dashboard', dashboardId)
143- // .then(response => {
144- // // Use the filters from the saved dashboard if there are any.
145- // // let filters = [];
146-
147- // // Use the query from the dashboard only if no job entities are selected.
148- // let query = undefined;
149-
150- // const searchSourceJSON = response.get('kibanaSavedObjectMeta.searchSourceJSON');
151- // if (searchSourceJSON !== undefined) {
152- // const searchSourceData = JSON.parse(searchSourceJSON);
153- // if (searchSourceData.filter !== undefined) {
154- // filters = searchSourceData.filter;
155- // }
156- // query = searchSourceData.query;
157- // }
158-
159- // const queryFromEntityFieldNames = buildAppStateQueryParam(queryFieldNames);
160- // if (queryFromEntityFieldNames !== undefined) {
161- // query = queryFromEntityFieldNames;
162- // }
163-
164- // const generator = npStart.plugins.share.urlGenerators.getUrlGenerator(
165- // DASHBOARD_APP_URL_GENERATOR
166- // );
167-
168- // return generator
169- // .createUrl({
170- // dashboardId,
171- // timeRange: {
172- // from: '$earliest$',
173- // to: '$latest$',
174- // mode: 'absolute',
175- // },
176- // filters,
177- // query,
178- // // Don't hash the URL since this string will be 1. shown to the user and 2. used as a
179- // // template to inject the time parameters.
180- // useHash: false,
181- // })
182- // .then(urlValue => {
183- // const urlToAdd = {
184- // url_name: settings.label,
185- // url_value: decodeURIComponent(`kibana${url.parse(urlValue).hash}`),
186- // time_range: TIME_RANGE_TYPE.AUTO,
187- // };
188-
189- // if (settings.timeRange.type === TIME_RANGE_TYPE.INTERVAL) {
190- // urlToAdd.time_range = settings.timeRange.interval;
191- // }
192-
193- // resolve(urlToAdd);
194- // });
195- // })
196- // .catch(resp => {
197- // reject(resp);
198- // });
199- // });
200- // }
134+ function buildDashboardUrlFromSettings ( settings ) {
135+ // Get the complete list of attributes for the selected dashboard (query, filters).
136+ return new Promise ( ( resolve , reject ) => {
137+ const { dashboardId, queryFieldNames } = settings . kibanaSettings ;
138+
139+ const savedObjectsClient = getSavedObjectsClient ( ) ;
140+ savedObjectsClient
141+ . get ( 'dashboard' , dashboardId )
142+ . then ( response => {
143+ // Use the filters from the saved dashboard if there are any.
144+ let filters = [ ] ;
145+
146+ // Use the query from the dashboard only if no job entities are selected.
147+ let query = undefined ;
148+
149+ const searchSourceJSON = response . get ( 'kibanaSavedObjectMeta.searchSourceJSON' ) ;
150+ if ( searchSourceJSON !== undefined ) {
151+ const searchSourceData = JSON . parse ( searchSourceJSON ) ;
152+ if ( searchSourceData . filter !== undefined ) {
153+ filters = searchSourceData . filter ;
154+ }
155+ query = searchSourceData . query ;
156+ }
157+
158+ const queryFromEntityFieldNames = buildAppStateQueryParam ( queryFieldNames ) ;
159+ if ( queryFromEntityFieldNames !== undefined ) {
160+ query = queryFromEntityFieldNames ;
161+ }
162+
163+ const getUrlGenerator = getGetUrlGenerator ( ) ;
164+ const generator = getUrlGenerator ( DASHBOARD_APP_URL_GENERATOR ) ;
165+ return generator
166+ . createUrl ( {
167+ dashboardId,
168+ timeRange : {
169+ from : '$earliest$' ,
170+ to : '$latest$' ,
171+ mode : 'absolute' ,
172+ } ,
173+ filters,
174+ query,
175+ // Don't hash the URL since this string will be 1. shown to the user and 2. used as a
176+ // template to inject the time parameters.
177+ useHash : false ,
178+ } )
179+ . then ( urlValue => {
180+ const urlToAdd = {
181+ url_name : settings . label ,
182+ url_value : decodeURIComponent ( `kibana${ url . parse ( urlValue ) . hash } ` ) ,
183+ time_range : TIME_RANGE_TYPE . AUTO ,
184+ } ;
185+
186+ if ( settings . timeRange . type === TIME_RANGE_TYPE . INTERVAL ) {
187+ urlToAdd . time_range = settings . timeRange . interval ;
188+ }
189+
190+ resolve ( urlToAdd ) ;
191+ } ) ;
192+ } )
193+ . catch ( resp => {
194+ reject ( resp ) ;
195+ } ) ;
196+ } ) ;
197+ }
201198
202199function buildDiscoverUrlFromSettings ( settings ) {
203200 const { discoverIndexPatternId, queryFieldNames } = settings . kibanaSettings ;
0 commit comments