Skip to content

Commit 34f0389

Browse files
Merge branch 'master' into ml-analytics-progress-fix
2 parents 440b5f8 + e148eb4 commit 34f0389

File tree

12 files changed

+93
-53
lines changed

12 files changed

+93
-53
lines changed

src/plugins/dashboard/public/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export {
3131
} from './application';
3232
export { DashboardConstants, createDashboardEditUrl } from './dashboard_constants';
3333

34-
export { DashboardStart } from './plugin';
34+
export { DashboardStart, DashboardUrlGenerator } from './plugin';
3535
export { DASHBOARD_APP_URL_GENERATOR } from './url_generator';
3636

3737
export function plugin(initializerContext: PluginInitializerContext) {

src/plugins/dashboard/public/plugin.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ import {
4242
DataPublicPluginSetup,
4343
esFilters,
4444
} from '../../../plugins/data/public';
45-
import { SharePluginSetup, SharePluginStart } from '../../../plugins/share/public';
45+
import {
46+
SharePluginSetup,
47+
SharePluginStart,
48+
UrlGeneratorContract,
49+
} from '../../../plugins/share/public';
4650
import { UiActionsSetup, UiActionsStart } from '../../../plugins/ui_actions/public';
4751

4852
import { Start as InspectorStartContract } from '../../../plugins/inspector/public';
@@ -77,7 +81,7 @@ import {
7781
import {
7882
DashboardAppLinkGeneratorState,
7983
DASHBOARD_APP_URL_GENERATOR,
80-
createDirectAccessDashboardLinkGenerator,
84+
createDashboardUrlGenerator,
8185
} from './url_generator';
8286
import { createSavedDashboardLoader } from './saved_dashboards';
8387
import { DashboardConstants } from './dashboard_constants';
@@ -89,6 +93,8 @@ declare module '../../share/public' {
8993
}
9094
}
9195

96+
export type DashboardUrlGenerator = UrlGeneratorContract<typeof DASHBOARD_APP_URL_GENERATOR>;
97+
9298
interface SetupDependencies {
9399
data: DataPublicPluginSetup;
94100
embeddable: EmbeddableSetup;
@@ -111,8 +117,10 @@ interface StartDependencies {
111117
}
112118

113119
export type Setup = void;
120+
114121
export interface DashboardStart {
115122
getSavedDashboardLoader: () => SavedObjectLoader;
123+
dashboardUrlGenerator?: DashboardUrlGenerator;
116124
}
117125

118126
declare module '../../../plugins/ui_actions/public' {
@@ -130,6 +138,8 @@ export class DashboardPlugin
130138
private appStateUpdater = new BehaviorSubject<AngularRenderedAppUpdater>(() => ({}));
131139
private stopUrlTracking: (() => void) | undefined = undefined;
132140

141+
private dashboardUrlGenerator?: DashboardUrlGenerator;
142+
133143
public setup(
134144
core: CoreSetup<StartDependencies, DashboardStart>,
135145
{ share, uiActions, embeddable, home, kibanaLegacy, data, usageCollection }: SetupDependencies
@@ -140,8 +150,8 @@ export class DashboardPlugin
140150
const startServices = core.getStartServices();
141151

142152
if (share) {
143-
share.urlGenerators.registerUrlGenerator(
144-
createDirectAccessDashboardLinkGenerator(async () => {
153+
this.dashboardUrlGenerator = share.urlGenerators.registerUrlGenerator(
154+
createDashboardUrlGenerator(async () => {
145155
const [coreStart, , selfStart] = await startServices;
146156
return {
147157
appBasePath: coreStart.application.getUrlForApp('dashboard'),
@@ -325,6 +335,7 @@ export class DashboardPlugin
325335
});
326336
return {
327337
getSavedDashboardLoader: () => savedDashboardLoader,
338+
dashboardUrlGenerator: this.dashboardUrlGenerator,
328339
};
329340
}
330341

src/plugins/dashboard/public/url_generator.test.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* under the License.
1818
*/
1919

20-
import { createDirectAccessDashboardLinkGenerator } from './url_generator';
20+
import { createDashboardUrlGenerator } from './url_generator';
2121
import { hashedItemStore } from '../../kibana_utils/public';
2222
// eslint-disable-next-line
2323
import { mockStorage } from '../../kibana_utils/public/storage/hashed_item_store/mock';
@@ -55,7 +55,7 @@ describe('dashboard url generator', () => {
5555
});
5656

5757
test('creates a link to a saved dashboard', async () => {
58-
const generator = createDirectAccessDashboardLinkGenerator(() =>
58+
const generator = createDashboardUrlGenerator(() =>
5959
Promise.resolve({
6060
appBasePath: APP_BASE_PATH,
6161
useHashedUrl: false,
@@ -67,7 +67,7 @@ describe('dashboard url generator', () => {
6767
});
6868

6969
test('creates a link with global time range set up', async () => {
70-
const generator = createDirectAccessDashboardLinkGenerator(() =>
70+
const generator = createDashboardUrlGenerator(() =>
7171
Promise.resolve({
7272
appBasePath: APP_BASE_PATH,
7373
useHashedUrl: false,
@@ -83,7 +83,7 @@ describe('dashboard url generator', () => {
8383
});
8484

8585
test('creates a link with filters, time range, refresh interval and query to a saved object', async () => {
86-
const generator = createDirectAccessDashboardLinkGenerator(() =>
86+
const generator = createDashboardUrlGenerator(() =>
8787
Promise.resolve({
8888
appBasePath: APP_BASE_PATH,
8989
useHashedUrl: false,
@@ -123,7 +123,7 @@ describe('dashboard url generator', () => {
123123
});
124124

125125
test('if no useHash setting is given, uses the one was start services', async () => {
126-
const generator = createDirectAccessDashboardLinkGenerator(() =>
126+
const generator = createDashboardUrlGenerator(() =>
127127
Promise.resolve({
128128
appBasePath: APP_BASE_PATH,
129129
useHashedUrl: true,
@@ -137,7 +137,7 @@ describe('dashboard url generator', () => {
137137
});
138138

139139
test('can override a false useHash ui setting', async () => {
140-
const generator = createDirectAccessDashboardLinkGenerator(() =>
140+
const generator = createDashboardUrlGenerator(() =>
141141
Promise.resolve({
142142
appBasePath: APP_BASE_PATH,
143143
useHashedUrl: false,
@@ -152,7 +152,7 @@ describe('dashboard url generator', () => {
152152
});
153153

154154
test('can override a true useHash ui setting', async () => {
155-
const generator = createDirectAccessDashboardLinkGenerator(() =>
155+
const generator = createDashboardUrlGenerator(() =>
156156
Promise.resolve({
157157
appBasePath: APP_BASE_PATH,
158158
useHashedUrl: true,
@@ -195,7 +195,7 @@ describe('dashboard url generator', () => {
195195
};
196196

197197
test('attaches filters from destination dashboard', async () => {
198-
const generator = createDirectAccessDashboardLinkGenerator(() =>
198+
const generator = createDashboardUrlGenerator(() =>
199199
Promise.resolve({
200200
appBasePath: APP_BASE_PATH,
201201
useHashedUrl: false,
@@ -224,7 +224,7 @@ describe('dashboard url generator', () => {
224224
});
225225

226226
test("doesn't fail if can't retrieve filters from destination dashboard", async () => {
227-
const generator = createDirectAccessDashboardLinkGenerator(() =>
227+
const generator = createDashboardUrlGenerator(() =>
228228
Promise.resolve({
229229
appBasePath: APP_BASE_PATH,
230230
useHashedUrl: false,
@@ -246,7 +246,7 @@ describe('dashboard url generator', () => {
246246
});
247247

248248
test('can enforce empty filters', async () => {
249-
const generator = createDirectAccessDashboardLinkGenerator(() =>
249+
const generator = createDashboardUrlGenerator(() =>
250250
Promise.resolve({
251251
appBasePath: APP_BASE_PATH,
252252
useHashedUrl: false,
@@ -270,7 +270,7 @@ describe('dashboard url generator', () => {
270270
});
271271

272272
test('no filters in result url if no filters applied', async () => {
273-
const generator = createDirectAccessDashboardLinkGenerator(() =>
273+
const generator = createDashboardUrlGenerator(() =>
274274
Promise.resolve({
275275
appBasePath: APP_BASE_PATH,
276276
useHashedUrl: false,
@@ -288,7 +288,7 @@ describe('dashboard url generator', () => {
288288
});
289289

290290
test('can turn off preserving filters', async () => {
291-
const generator = createDirectAccessDashboardLinkGenerator(() =>
291+
const generator = createDashboardUrlGenerator(() =>
292292
Promise.resolve({
293293
appBasePath: APP_BASE_PATH,
294294
useHashedUrl: false,

src/plugins/dashboard/public/url_generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ export type DashboardAppLinkGeneratorState = UrlGeneratorState<{
7575
preserveSavedFilters?: boolean;
7676
}>;
7777

78-
export const createDirectAccessDashboardLinkGenerator = (
78+
export const createDashboardUrlGenerator = (
7979
getStartServices: () => Promise<{
8080
appBasePath: string;
8181
useHashedUrl: boolean;

src/plugins/share/public/url_generators/url_generator_service.test.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ test('Asking for a generator that does not exist throws an error', () => {
3030
});
3131

3232
test('Registering and retrieving a generator', async () => {
33-
setup.registerUrlGenerator({
33+
const generator = setup.registerUrlGenerator({
3434
id: 'TEST_GENERATOR',
3535
createUrl: () => Promise.resolve('myurl'),
3636
});
37-
const generator = start.getUrlGenerator('TEST_GENERATOR');
37+
3838
expect(generator).toMatchInlineSnapshot(`
3939
Object {
4040
"createUrl": [Function],
@@ -47,6 +47,20 @@ test('Registering and retrieving a generator', async () => {
4747
new Error('You cannot call migrate on a non-deprecated generator.')
4848
);
4949
expect(await generator.createUrl({})).toBe('myurl');
50+
51+
const retrievedGenerator = start.getUrlGenerator('TEST_GENERATOR');
52+
expect(retrievedGenerator).toMatchInlineSnapshot(`
53+
Object {
54+
"createUrl": [Function],
55+
"id": "TEST_GENERATOR",
56+
"isDeprecated": false,
57+
"migrate": [Function],
58+
}
59+
`);
60+
await expect(generator.migrate({})).rejects.toEqual(
61+
new Error('You cannot call migrate on a non-deprecated generator.')
62+
);
63+
expect(await generator.createUrl({})).toBe('myurl');
5064
});
5165

5266
test('Registering a generator with a createUrl function that is deprecated throws an error', () => {

src/plugins/share/public/url_generators/url_generator_service.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ export interface UrlGeneratorsStart {
2828
}
2929

3030
export interface UrlGeneratorsSetup {
31-
registerUrlGenerator: <Id extends UrlGeneratorId>(generator: UrlGeneratorsDefinition<Id>) => void;
31+
registerUrlGenerator: <Id extends UrlGeneratorId>(
32+
generator: UrlGeneratorsDefinition<Id>
33+
) => UrlGeneratorContract<Id>;
3234
}
3335

3436
export class UrlGeneratorsService implements Plugin<UrlGeneratorsSetup, UrlGeneratorsStart> {
@@ -43,10 +45,9 @@ export class UrlGeneratorsService implements Plugin<UrlGeneratorsSetup, UrlGener
4345
registerUrlGenerator: <Id extends UrlGeneratorId>(
4446
generatorOptions: UrlGeneratorsDefinition<Id>
4547
) => {
46-
this.urlGenerators.set(
47-
generatorOptions.id,
48-
new UrlGeneratorInternal<Id>(generatorOptions, this.getUrlGenerator)
49-
);
48+
const generator = new UrlGeneratorInternal<Id>(generatorOptions, this.getUrlGenerator);
49+
this.urlGenerators.set(generatorOptions.id, generator);
50+
return generator.getPublicContract();
5051
},
5152
};
5253
return setup;

x-pack/plugins/dashboard_enhanced/public/plugin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { DashboardDrilldownsService } from './services';
1111
import { DataPublicPluginStart } from '../../../../src/plugins/data/public';
1212
import { AdvancedUiActionsSetup, AdvancedUiActionsStart } from '../../advanced_ui_actions/public';
1313
import { DrilldownsSetup, DrilldownsStart } from '../../drilldowns/public';
14+
import { DashboardStart } from '../../../../src/plugins/dashboard/public';
1415

1516
export interface SetupDependencies {
1617
advancedUiActions: AdvancedUiActionsSetup;
@@ -25,6 +26,7 @@ export interface StartDependencies {
2526
drilldowns: DrilldownsStart;
2627
embeddable: EmbeddableStart;
2728
share: SharePluginStart;
29+
dashboard: DashboardStart;
2830
}
2931

3032
// eslint-disable-next-line

x-pack/plugins/dashboard_enhanced/public/services/drilldowns/dashboard_drilldowns_services.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,23 @@ export class DashboardDrilldownsService {
4444
{ advancedUiActions: uiActions }: SetupDependencies
4545
) {
4646
const start = createStartServicesGetter(core.getStartServices);
47+
const getDashboardUrlGenerator = () => {
48+
const urlGenerator = start().plugins.dashboard.dashboardUrlGenerator;
49+
if (!urlGenerator)
50+
throw new Error('dashboardUrlGenerator is required for dashboard to dashboard drilldown');
51+
return urlGenerator;
52+
};
4753

4854
const actionFlyoutCreateDrilldown = new FlyoutCreateDrilldownAction({ start });
4955
uiActions.addTriggerAction(CONTEXT_MENU_TRIGGER, actionFlyoutCreateDrilldown);
5056

5157
const actionFlyoutEditDrilldown = new FlyoutEditDrilldownAction({ start });
5258
uiActions.addTriggerAction(CONTEXT_MENU_TRIGGER, actionFlyoutEditDrilldown);
5359

54-
const dashboardToDashboardDrilldown = new DashboardToDashboardDrilldown({ start });
60+
const dashboardToDashboardDrilldown = new DashboardToDashboardDrilldown({
61+
start,
62+
getDashboardUrlGenerator,
63+
});
5564
uiActions.registerDrilldown(dashboardToDashboardDrilldown);
5665
}
5766
}

x-pack/plugins/dashboard_enhanced/public/services/drilldowns/dashboard_to_dashboard_drilldown/drilldown.test.tsx

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
*/
66

77
import { DashboardToDashboardDrilldown } from './drilldown';
8-
import { UrlGeneratorContract } from '../../../../../../../src/plugins/share/public';
9-
import { savedObjectsServiceMock } from '../../../../../../../src/core/public/mocks';
8+
import { savedObjectsServiceMock, coreMock } from '../../../../../../../src/core/public/mocks';
109
import { dataPluginMock } from '../../../../../../../src/plugins/data/public/mocks';
1110
import { ActionContext, Config } from './types';
1211
import {
@@ -19,15 +18,16 @@ import {
1918
import { esFilters } from '../../../../../../../src/plugins/data/public';
2019

2120
// convenient to use real implementation here.
22-
import { createDirectAccessDashboardLinkGenerator } from '../../../../../../../src/plugins/dashboard/public/url_generator';
21+
import { createDashboardUrlGenerator } from '../../../../../../../src/plugins/dashboard/public/url_generator';
22+
import { UrlGeneratorsService } from '../../../../../../../src/plugins/share/public/url_generators';
2323
import { VisualizeEmbeddableContract } from '../../../../../../../src/plugins/visualizations/public';
2424
import {
2525
RangeSelectTriggerContext,
2626
ValueClickTriggerContext,
2727
} from '../../../../../../../src/plugins/embeddable/public';
28+
import { StartDependencies } from '../../../plugin';
2829
import { SavedObjectLoader } from '../../../../../../../src/plugins/saved_objects/public';
2930
import { StartServicesGetter } from '../../../../../../../src/plugins/kibana_utils/public/core';
30-
import { StartDependencies } from '../../../plugin';
3131

3232
describe('.isConfigValid()', () => {
3333
const drilldown = new DashboardToDashboardDrilldown({} as any);
@@ -105,23 +105,19 @@ describe('.execute() & getHref', () => {
105105
data: {
106106
actions: dataPluginActions,
107107
},
108-
share: {
109-
urlGenerators: {
110-
getUrlGenerator: () =>
111-
createDirectAccessDashboardLinkGenerator(() =>
112-
Promise.resolve({
113-
appBasePath: 'test',
114-
useHashedUrl: false,
115-
savedDashboardLoader: ({} as unknown) as SavedObjectLoader,
116-
})
117-
) as UrlGeneratorContract<string>,
118-
},
119-
},
120108
},
121109
self: {},
122-
})) as unknown) as StartServicesGetter<
123-
Pick<StartDependencies, 'data' | 'advancedUiActions' | 'share'>
124-
>,
110+
})) as unknown) as StartServicesGetter<Pick<StartDependencies, 'data' | 'advancedUiActions'>>,
111+
getDashboardUrlGenerator: () =>
112+
new UrlGeneratorsService().setup(coreMock.createSetup()).registerUrlGenerator(
113+
createDashboardUrlGenerator(() =>
114+
Promise.resolve({
115+
appBasePath: 'test',
116+
useHashedUrl: false,
117+
savedDashboardLoader: ({} as unknown) as SavedObjectLoader,
118+
})
119+
)
120+
),
125121
});
126122
const selectRangeFiltersSpy = jest
127123
.spyOn(dataPluginActions, 'createFiltersFromRangeSelectAction')

x-pack/plugins/dashboard_enhanced/public/services/drilldowns/dashboard_to_dashboard_drilldown/drilldown.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import React from 'react';
88
import { reactToUiComponent } from '../../../../../../../src/plugins/kibana_react/public';
9-
import { DASHBOARD_APP_URL_GENERATOR } from '../../../../../../../src/plugins/dashboard/public';
9+
import { DashboardUrlGenerator } from '../../../../../../../src/plugins/dashboard/public';
1010
import { ActionContext, Config } from './types';
1111
import { CollectConfigContainer } from './components';
1212
import { DASHBOARD_TO_DASHBOARD_DRILLDOWN } from './constants';
@@ -22,7 +22,8 @@ import { StartServicesGetter } from '../../../../../../../src/plugins/kibana_uti
2222
import { StartDependencies } from '../../../plugin';
2323

2424
export interface Params {
25-
start: StartServicesGetter<Pick<StartDependencies, 'data' | 'advancedUiActions' | 'share'>>;
25+
start: StartServicesGetter<Pick<StartDependencies, 'data' | 'advancedUiActions'>>;
26+
getDashboardUrlGenerator: () => DashboardUrlGenerator;
2627
}
2728

2829
export class DashboardToDashboardDrilldown
@@ -142,9 +143,7 @@ export class DashboardToDashboardDrilldown
142143
}
143144
}
144145

145-
const { plugins } = this.params.start();
146-
147-
return plugins.share.urlGenerators.getUrlGenerator(DASHBOARD_APP_URL_GENERATOR).createUrl({
146+
return this.params.getDashboardUrlGenerator().createUrl({
148147
dashboardId: config.dashboardId,
149148
query: config.useCurrentFilters ? query : undefined,
150149
timeRange,

0 commit comments

Comments
 (0)