Skip to content

Commit

Permalink
Merge branch 'main' into fix-flaky-archive-test
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Mar 28, 2023
2 parents 32276d4 + 9ae3749 commit 63cd8b0
Show file tree
Hide file tree
Showing 13 changed files with 393 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,20 @@ export const EnginesList: React.FC = () => {
const throttledSearchQuery = useThrottle(searchQuery, INPUT_THROTTLE_DELAY_MS);

useEffect(() => {
fetchEngines();
// Don't fetch engines if we don't have a valid license
if (!isGated) {
fetchEngines();
}
}, [meta.from, meta.size, throttledSearchQuery]);

useEffect(() => {
// We don't want to trigger loading for each search query change, so we need this
// flag to set if the call to backend is first request.
setIsFirstRequest();
if (!isGated) {
setIsFirstRequest();
}
}, []);

return (
<>
{isDeleteModalVisible ? (
Expand Down Expand Up @@ -135,7 +141,7 @@ export const EnginesList: React.FC = () => {
: [],
}}
pageViewTelemetry="Engines"
isLoading={isLoading}
isLoading={isLoading && !isGated}
>
{isGated && (
<EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ for (let i = 0; i < 105; i++) {
});
}

const urlServiceMock = {
locators: {
get: () => ({
navigate: async () => {},
}),
},
};

let component = null;

// Resolve outstanding API requests. See https://www.benmvp.com/blog/asynchronous-testing-with-enzyme-react-jest/
Expand Down Expand Up @@ -159,6 +167,7 @@ describe('index table', () => {
executionContext: executionContextServiceMock.createStartContract(),
},
plugins: {},
url: urlServiceMock,
};

component = (
Expand Down Expand Up @@ -317,6 +326,7 @@ describe('index table', () => {
indexNameLink.simulate('click');
rendered.update();
expect(findTestSubject(rendered, 'indexDetailFlyout').length).toBe(1);
expect(findTestSubject(rendered, 'indexDetailFlyoutDiscover').length).toBe(1);
});

test('should show the right context menu options when one index is selected and open', async () => {
Expand Down
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);
});
});
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>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
EuiTitle,
} from '@elastic/eui';

import { renderDiscoverLink } from '../../../../lib/render_discover_link';
import { SectionLoading, reactRouterNavigate } from '../../../../../shared_imports';
import { SectionError, Error, DataHealth } from '../../../../components';
import { useLoadDataStream } from '../../../../services/api';
Expand Down Expand Up @@ -265,6 +266,7 @@ export const DataStreamDetailPanel: React.FunctionComponent<Props> = ({
<EuiTitle size="m">
<h2 id="dataStreamDetailPanelTitle" data-test-subj="dataStreamDetailPanelTitle">
{dataStreamName}
{renderDiscoverLink(dataStreamName)}
{dataStream && <DataStreamsBadges dataStream={dataStream} />}
</h2>
</EuiTitle>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { ShowJson } from './show_json';
import { Summary } from './summary';
import { EditSettingsJson } from './edit_settings_json';
import { useServices } from '../../../../app_context';
import { renderDiscoverLink } from '../../../../lib/render_discover_link';

const tabToHumanizedMap = {
[TAB_SUMMARY]: (
Expand Down Expand Up @@ -158,6 +159,7 @@ export const DetailPanel = ({ panelType, indexName, index, openDetailPanel, clos
<EuiTitle id="indexDetailsFlyoutTitle">
<h2>
{indexName}
{renderDiscoverLink(indexName)}
{renderBadges(index, undefined, extensionsService)}
</h2>
</EuiTitle>
Expand Down
Loading

0 comments on commit 63cd8b0

Please sign in to comment.