-
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.
Browse files
Browse the repository at this point in the history
## Summary This reverts commit cf942f2. It also moves the `appId` and `appTitle` outside the cases context. The `useApplication` hook is used when needed to get the `appId` and `appTitle`. Lastly, a new hook called `useCasesLocalStorage` was created to be used when interacting with the local storage. It will use the `owner` to namespace the keys of the local storage and fallback to the `appId` if the `owner` is empty. Fixes #175204 Fixes #175570 ### Checklist Delete any items that are not applicable to this PR. - [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 ### For maintainers - [x] This was checked for breaking API changes and was [labeled appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process) --------- Co-authored-by: Kibana Machine <[email protected]>
- Loading branch information
1 parent
f60b448
commit 48d8230
Showing
68 changed files
with
892 additions
and
551 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
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
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
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
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
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
10 changes: 10 additions & 0 deletions
10
x-pack/plugins/cases/public/common/lib/kibana/__mocks__/use_application.tsx
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,10 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
export const useApplication = jest | ||
.fn() | ||
.mockReturnValue({ appId: 'testAppId', appTitle: 'test-title' }); |
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
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
108 changes: 108 additions & 0 deletions
108
x-pack/plugins/cases/public/common/lib/kibana/use_application.test.tsx
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,108 @@ | ||
/* | ||
* 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 { PublicAppInfo } from '@kbn/core-application-browser'; | ||
import { AppStatus } from '@kbn/core-application-browser'; | ||
import { renderHook } from '@testing-library/react-hooks'; | ||
import { BehaviorSubject, Subject } from 'rxjs'; | ||
import type { AppMockRenderer } from '../../mock'; | ||
import { createAppMockRenderer } from '../../mock'; | ||
import { useApplication } from './use_application'; | ||
|
||
describe('useApplication', () => { | ||
let appMockRender: AppMockRenderer; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
appMockRender = createAppMockRenderer(); | ||
}); | ||
|
||
const getApp = (props: Partial<PublicAppInfo> = {}): PublicAppInfo => ({ | ||
id: 'testAppId', | ||
title: 'Test title', | ||
status: AppStatus.accessible, | ||
visibleIn: ['globalSearch'], | ||
appRoute: `/app/some-id`, | ||
keywords: [], | ||
deepLinks: [], | ||
...props, | ||
}); | ||
|
||
it('returns the appId and the appTitle correctly', () => { | ||
const { result } = renderHook(() => useApplication(), { | ||
wrapper: appMockRender.AppWrapper, | ||
}); | ||
|
||
expect(result.current).toEqual({ | ||
appId: 'testAppId', | ||
appTitle: 'Test', | ||
}); | ||
}); | ||
|
||
it('returns undefined appId and appTitle if the currentAppId observable is not defined', () => { | ||
appMockRender.coreStart.application.currentAppId$ = new Subject(); | ||
|
||
const { result } = renderHook(() => useApplication(), { | ||
wrapper: appMockRender.AppWrapper, | ||
}); | ||
|
||
expect(result.current).toEqual({}); | ||
}); | ||
|
||
it('returns undefined appTitle if the applications observable is not defined', () => { | ||
appMockRender.coreStart.application.applications$ = new Subject(); | ||
|
||
const { result } = renderHook(() => useApplication(), { | ||
wrapper: appMockRender.AppWrapper, | ||
}); | ||
|
||
expect(result.current).toEqual({ | ||
appId: 'testAppId', | ||
appTitle: undefined, | ||
}); | ||
}); | ||
|
||
it('returns the label as appTitle', () => { | ||
appMockRender.coreStart.application.applications$ = new BehaviorSubject( | ||
new Map([['testAppId', getApp({ category: { id: 'test-label-id', label: 'Test label' } })]]) | ||
); | ||
|
||
const { result } = renderHook(() => useApplication(), { | ||
wrapper: appMockRender.AppWrapper, | ||
}); | ||
|
||
expect(result.current).toEqual({ | ||
appId: 'testAppId', | ||
appTitle: 'Test label', | ||
}); | ||
}); | ||
|
||
it('returns the title as appTitle if the categories label is missing', () => { | ||
appMockRender.coreStart.application.applications$ = new BehaviorSubject( | ||
new Map([['testAppId', getApp({ title: 'Test title' })]]) | ||
); | ||
|
||
const { result } = renderHook(() => useApplication(), { | ||
wrapper: appMockRender.AppWrapper, | ||
}); | ||
|
||
expect(result.current).toEqual({ | ||
appId: 'testAppId', | ||
appTitle: 'Test title', | ||
}); | ||
}); | ||
|
||
it('gets the value from the default value of the currentAppId observable if it exists', () => { | ||
appMockRender.coreStart.application.currentAppId$ = new BehaviorSubject('new-test-id'); | ||
|
||
const { result } = renderHook(() => useApplication(), { | ||
wrapper: appMockRender.AppWrapper, | ||
}); | ||
|
||
expect(result.current).toEqual({ appId: 'new-test-id' }); | ||
}); | ||
}); |
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
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
Oops, something went wrong.