-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Lens] Fixes the transition to a dashboard when originatingApp is not…
… given (#172543) ## Summary Closes #172410 This is a regression caused by #167019. The originatingApp on the navigateToPrefilledEditor defaults to "" (empty string) and not undefined. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
- Loading branch information
Showing
3 changed files
with
122 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
76 changes: 76 additions & 0 deletions
76
x-pack/plugins/lens/public/app_plugin/save_modal_container_helpers.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
import { makeDefaultServices } from '../mocks'; | ||
import type { LensEmbeddableInput } from '../embeddable'; | ||
import type { LensAppServices } from './types'; | ||
import { redirectToDashboard } from './save_modal_container_helpers'; | ||
|
||
describe('redirectToDashboard', () => { | ||
const embeddableInput = { | ||
test: 'test', | ||
} as unknown as LensEmbeddableInput; | ||
const mockServices = makeDefaultServices(); | ||
|
||
it('should return error in case of allowByValueEmbeddables false', () => { | ||
expect(() => { | ||
redirectToDashboard({ | ||
embeddableInput, | ||
dashboardFeatureFlag: { | ||
allowByValueEmbeddables: false, | ||
}, | ||
dashboardId: 'id', | ||
originatingApp: '', | ||
getOriginatingPath: jest.fn(), | ||
stateTransfer: mockServices.stateTransfer, | ||
}); | ||
}).toThrow('redirectToDashboard called with by-value embeddables disabled'); | ||
}); | ||
|
||
it('should call the navigateToWithEmbeddablePackage with the correct args if originatingApp is given', () => { | ||
const navigateToWithEmbeddablePackageSpy = jest.fn(); | ||
const transferService = { | ||
...mockServices.stateTransfer, | ||
navigateToWithEmbeddablePackage: navigateToWithEmbeddablePackageSpy, | ||
} as unknown as LensAppServices['stateTransfer']; | ||
redirectToDashboard({ | ||
embeddableInput, | ||
dashboardFeatureFlag: { | ||
allowByValueEmbeddables: true, | ||
}, | ||
dashboardId: 'id', | ||
originatingApp: 'security', | ||
getOriginatingPath: jest.fn(), | ||
stateTransfer: transferService, | ||
}); | ||
expect(navigateToWithEmbeddablePackageSpy).toHaveBeenCalledWith('security', { | ||
path: '#/view/id', | ||
state: { input: { test: 'test' }, type: 'lens' }, | ||
}); | ||
}); | ||
|
||
it('should call the navigateToWithEmbeddablePackage with the correct args if originatingApp is an empty string', () => { | ||
const navigateToWithEmbeddablePackageSpy = jest.fn(); | ||
const transferService = { | ||
...mockServices.stateTransfer, | ||
navigateToWithEmbeddablePackage: navigateToWithEmbeddablePackageSpy, | ||
} as unknown as LensAppServices['stateTransfer']; | ||
redirectToDashboard({ | ||
embeddableInput, | ||
dashboardFeatureFlag: { | ||
allowByValueEmbeddables: true, | ||
}, | ||
dashboardId: 'id', | ||
originatingApp: '', | ||
getOriginatingPath: jest.fn(), | ||
stateTransfer: transferService, | ||
}); | ||
expect(navigateToWithEmbeddablePackageSpy).toHaveBeenCalledWith('dashboards', { | ||
path: '#/view/id', | ||
state: { input: { test: 'test' }, type: 'lens' }, | ||
}); | ||
}); | ||
}); |
44 changes: 44 additions & 0 deletions
44
x-pack/plugins/lens/public/app_plugin/save_modal_container_helpers.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import type { LensAppServices } from './types'; | ||
import type { LensEmbeddableInput } from '../embeddable'; | ||
import { LENS_EMBEDDABLE_TYPE } from '../../common/constants'; | ||
|
||
export const redirectToDashboard = ({ | ||
embeddableInput, | ||
dashboardFeatureFlag, | ||
dashboardId, | ||
originatingApp, | ||
getOriginatingPath, | ||
stateTransfer, | ||
}: { | ||
embeddableInput: LensEmbeddableInput; | ||
dashboardId: string; | ||
dashboardFeatureFlag: LensAppServices['dashboardFeatureFlag']; | ||
originatingApp?: string; | ||
getOriginatingPath?: (dashboardId: string) => string | undefined; | ||
stateTransfer: LensAppServices['stateTransfer']; | ||
}) => { | ||
if (!dashboardFeatureFlag.allowByValueEmbeddables) { | ||
throw new Error('redirectToDashboard called with by-value embeddables disabled'); | ||
} | ||
|
||
const state = { | ||
input: embeddableInput, | ||
type: LENS_EMBEDDABLE_TYPE, | ||
}; | ||
|
||
const path = | ||
getOriginatingPath?.(dashboardId) ?? | ||
(dashboardId === 'new' ? '#/create' : `#/view/${dashboardId}`); | ||
const appId = originatingApp || 'dashboards'; | ||
stateTransfer.navigateToWithEmbeddablePackage(appId, { | ||
state, | ||
path, | ||
}); | ||
}; |