-
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.
Merge branch 'main' into fix-flaky-archive-test
- Loading branch information
Showing
13 changed files
with
393 additions
and
84 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
45 changes: 45 additions & 0 deletions
45
x-pack/plugins/index_management/public/application/lib/render_discover_link.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,45 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { mountWithIntl } from '@kbn/test-jest-helpers'; | ||
import { EuiButtonIcon } from '@elastic/eui'; | ||
import { renderDiscoverLink } from './render_discover_link'; | ||
import { AppContextProvider, AppDependencies } from '../app_context'; | ||
|
||
describe('renderDiscoverLink', () => { | ||
const indexName = 'my-fancy-index'; | ||
|
||
it('calls navigate method when button is clicked', async () => { | ||
const navigateMock = jest.fn(); | ||
const ctx = { | ||
url: { | ||
locators: { | ||
get: () => ({ navigate: navigateMock }), | ||
}, | ||
}, | ||
} as unknown as AppDependencies; | ||
|
||
const component = mountWithIntl( | ||
<AppContextProvider value={ctx}>{renderDiscoverLink(indexName)}</AppContextProvider> | ||
); | ||
const button = component.find(EuiButtonIcon); | ||
|
||
await button.simulate('click'); | ||
expect(navigateMock).toHaveBeenCalledWith({ dataViewSpec: { title: indexName } }); | ||
}); | ||
|
||
it('does not render a button if locators is not defined', () => { | ||
const ctx = {} as unknown as AppDependencies; | ||
|
||
const component = mountWithIntl( | ||
<AppContextProvider value={ctx}>{renderDiscoverLink(indexName)}</AppContextProvider> | ||
); | ||
const button = component.find(EuiButtonIcon); | ||
|
||
expect(button).toHaveLength(0); | ||
}); | ||
}); |
46 changes: 46 additions & 0 deletions
46
x-pack/plugins/index_management/public/application/lib/render_discover_link.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,46 @@ | ||
/* | ||
* 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 React from 'react'; | ||
import { EuiButtonIcon, EuiToolTip } from '@elastic/eui'; | ||
import { i18n } from '@kbn/i18n'; | ||
import { AppContextConsumer } from '../app_context'; | ||
|
||
export const renderDiscoverLink = (indexName: string) => { | ||
return ( | ||
<AppContextConsumer> | ||
{(ctx) => { | ||
const locators = ctx?.url?.locators.get('DISCOVER_APP_LOCATOR'); | ||
|
||
if (!locators) { | ||
return null; | ||
} | ||
const onClick = async () => { | ||
await locators.navigate({ dataViewSpec: { title: indexName } }); | ||
}; | ||
return ( | ||
<EuiToolTip | ||
content={i18n.translate('xpack.idxMgmt.goToDiscover', { | ||
defaultMessage: 'Show {indexName} in Discover', | ||
values: { indexName }, | ||
})} | ||
> | ||
<EuiButtonIcon | ||
onClick={onClick} | ||
display="empty" | ||
size="xs" | ||
iconType="discoverApp" | ||
aria-label="Discover" | ||
data-test-subj="indexDetailFlyoutDiscover" | ||
css={{ margin: '0 0.3em' }} | ||
/> | ||
</EuiToolTip> | ||
); | ||
}} | ||
</AppContextConsumer> | ||
); | ||
}; |
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.