-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Enterprise Search] Remove all instances of KibanaContext to Kea store #78513
Changes from 1 commit
dde8773
2cbb9a0
b29ccd9
742ecf9
167bf07
90bb26b
1f6f4e4
aec8adf
f951152
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export const mockKibanaValues = { | ||
config: { host: 'http://localhost:3002' }, | ||
navigateToUrl: jest.fn(), | ||
setBreadcrumbs: jest.fn(), | ||
setDocTitle: jest.fn(), | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
export { KibanaLogic, mountKibanaLogic } from './kibana_logic'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { resetContext } from 'kea'; | ||
|
||
import { mockKibanaValues } from '../../__mocks__'; | ||
|
||
import { KibanaLogic, mountKibanaLogic } from './kibana_logic'; | ||
|
||
describe('KibanaLogic', () => { | ||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
resetContext({}); | ||
}); | ||
|
||
describe('mounts', () => { | ||
it('sets values from props', () => { | ||
mountKibanaLogic(mockKibanaValues); | ||
|
||
expect(KibanaLogic.values).toEqual(mockKibanaValues); | ||
}); | ||
|
||
it('gracefully handles missing configs', () => { | ||
mountKibanaLogic({ ...mockKibanaValues, config: undefined } as any); | ||
|
||
expect(KibanaLogic.values.config).toEqual({}); | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { kea, MakeLogicType } from 'kea'; | ||
|
||
import { ApplicationStart, ChromeBreadcrumb } from 'src/core/public'; | ||
|
||
export interface IKibanaValues { | ||
config: { host?: string }; | ||
navigateToUrl: ApplicationStart['navigateToUrl']; | ||
setBreadcrumbs(crumbs: ChromeBreadcrumb[]): void; | ||
setDocTitle(title: string): void; | ||
} | ||
|
||
export const KibanaLogic = kea<MakeLogicType<IKibanaValues>>({ | ||
path: ['enterprise_search', 'kibana_logic'], | ||
reducers: ({ props }) => ({ | ||
config: [props.config || {}, {}], | ||
navigateToUrl: [props.navigateToUrl, {}], | ||
setBreadcrumbs: [props.setBreadcrumbs, {}], | ||
setDocTitle: [props.setDocTitle, {}], | ||
}), | ||
}); | ||
Comment on lines
+18
to
+26
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the previous externalUrl PR, I also felt kinda weird that this store essentially just holds some variables that never update or require state, but in the end I decided to stay with a Kea logic file here because:
Admittedly those aren't like, super strong reasons heh, so if I'm definitely open to better paradigms if we think of them or if they come up down the road. |
||
|
||
export const mountKibanaLogic = (props: IKibanaValues) => { | ||
KibanaLogic(props); | ||
const unmount = KibanaLogic.mount(); | ||
return unmount; | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. I didn't realize you could initialize logic with props like this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah! https://kea.js.org/docs/guide/additional/#props
Although as a warning (I think I mentioned this a few PRs back, but repeating it just as an fyi) if you set a value default to a passed prop without any fallbacks (e.g.
someVar: [props.someVar, {}],
), if you ever mount without passing asomeVar
prop the entire Kea/redux instance will error/crash. It's a good way of making sure you always have the data you need I guess? 😄