Skip to content
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

[Index Management] Add an index template link to data stream details #82592

Merged
merged 4 commits into from
Nov 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ export type TestSubjects =
| 'templateList'
| 'templatesTab'
| 'templateTable'
| 'title'
| 'viewButton';
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export interface DataStreamsTabTestBed extends TestBed<TestSubjects> {
clickDeleteActionAt: (index: number) => void;
clickConfirmDelete: () => void;
clickDeleteDataStreamButton: () => void;
clickDetailPanelIndexTemplateLink: () => void;
};
findDeleteActionAt: (index: number) => ReactWrapper;
findDeleteConfirmationModal: () => ReactWrapper;
Expand All @@ -38,6 +39,7 @@ export interface DataStreamsTabTestBed extends TestBed<TestSubjects> {
findEmptyPromptIndexTemplateLink: () => ReactWrapper;
findDetailPanelIlmPolicyLink: () => ReactWrapper;
findDetailPanelIlmPolicyName: () => ReactWrapper;
findDetailPanelIndexTemplateLink: () => ReactWrapper;
}

export const setup = async (overridingDependencies: any = {}): Promise<DataStreamsTabTestBed> => {
Expand Down Expand Up @@ -143,6 +145,17 @@ export const setup = async (overridingDependencies: any = {}): Promise<DataStrea
find('deleteDataStreamButton').simulate('click');
};

const clickDetailPanelIndexTemplateLink = async () => {
const { component, router, find } = testBed;
const indexTemplateLink = find('indexTemplateLink');

await act(async () => {
router.navigateTo(indexTemplateLink.props().href!);
});

component.update();
};

const findDetailPanel = () => {
const { find } = testBed;
return find('dataStreamDetailPanel');
Expand All @@ -158,6 +171,11 @@ export const setup = async (overridingDependencies: any = {}): Promise<DataStrea
return find('ilmPolicyLink');
};

const findDetailPanelIndexTemplateLink = () => {
const { find } = testBed;
return find('indexTemplateLink');
};

const findDetailPanelIlmPolicyName = () => {
const descriptionList = testBed.component.find(EuiDescriptionListDescription);
// ilm policy is the last in the details list
Expand All @@ -176,6 +194,7 @@ export const setup = async (overridingDependencies: any = {}): Promise<DataStrea
clickDeleteActionAt,
clickConfirmDelete,
clickDeleteDataStreamButton,
clickDetailPanelIndexTemplateLink,
},
findDeleteActionAt,
findDeleteConfirmationModal,
Expand All @@ -184,6 +203,7 @@ export const setup = async (overridingDependencies: any = {}): Promise<DataStrea
findEmptyPromptIndexTemplateLink,
findDetailPanelIlmPolicyLink,
findDetailPanelIlmPolicyName,
findDetailPanelIndexTemplateLink,
};
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { act } from 'react-dom/test-utils';
import { createMemoryHistory } from 'history';

import { API_BASE_PATH } from '../../../common/constants';
import * as fixtures from '../../../test/fixtures';
import { setupEnvironment } from '../helpers';

import {
Expand Down Expand Up @@ -89,6 +90,8 @@ describe('Data Streams tab', () => {
setLoadIndicesResponse,
setLoadDataStreamsResponse,
setLoadDataStreamResponse,
setLoadTemplateResponse,
setLoadTemplatesResponse,
} = httpRequestsMockHelpers;

setLoadIndicesResponse([
Expand All @@ -103,6 +106,10 @@ describe('Data Streams tab', () => {
]);
setLoadDataStreamResponse(dataStreamForDetailPanel);

const indexTemplate = fixtures.getTemplate({ name: 'indexTemplate' });
setLoadTemplatesResponse({ templates: [indexTemplate], legacyTemplates: [] });
setLoadTemplateResponse(indexTemplate);

testBed = await setup({ history: createMemoryHistory() });
await act(async () => {
testBed.actions.goToDataStreamsList();
Expand Down Expand Up @@ -244,6 +251,26 @@ describe('Data Streams tab', () => {
dataStreams: ['dataStream1'],
});
});

test('clicking index template name navigates to the index template details', async () => {
const {
actions: { clickNameAt, clickDetailPanelIndexTemplateLink },
findDetailPanelIndexTemplateLink,
component,
find,
} = testBed;

await clickNameAt(0);

const indexTemplateLink = findDetailPanelIndexTemplateLink();
expect(indexTemplateLink.text()).toBe('indexTemplate');

await clickDetailPanelIndexTemplateLink();

component.update();
expect(find('summaryTab').exists()).toBeTruthy();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we add a check that the correct index template has been loaded?

Looking at the router path + the data-test-subj "title" of the flyout. You might have to mock the response on httpRequestsMockHelpers.setLoadTemplateResponse().

expect(find('title').text().trim()).toBe('indexTemplate');
});
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ import { useLoadDataStream } from '../../../../services/api';
import { DeleteDataStreamConfirmationModal } from '../delete_data_stream_confirmation_modal';
import { humanizeTimeStamp } from '../humanize_time_stamp';
import { useUrlGenerator } from '../../../../services/use_url_generator';
import { getIndexListUri, getTemplateDetailsLink } from '../../../../services/routing';
import { ILM_PAGES_POLICY_EDIT, ILM_URL_GENERATOR_ID } from '../../../../constants';
import { useAppContext } from '../../../../app_context';
import { getIndexListUri } from '../../../../..';

interface DetailsListProps {
details: Array<{
Expand Down Expand Up @@ -207,7 +207,14 @@ export const DataStreamDetailPanel: React.FunctionComponent<Props> = ({
defaultMessage:
'The index template that configured the data stream and configures its backing indices',
}),
content: indexTemplateName,
content: (
<EuiLink
data-test-subj={'indexTemplateLink'}
{...reactRouterNavigate(history, getTemplateDetailsLink(indexTemplateName))}
>
{indexTemplateName}
</EuiLink>
),
},
{
name: i18n.translate('xpack.idxMgmt.dataStreamDetailPanel.ilmPolicyTitle', {
Expand All @@ -218,10 +225,7 @@ export const DataStreamDetailPanel: React.FunctionComponent<Props> = ({
}),
content:
ilmPolicyName && ilmPolicyLink ? (
<EuiLink
data-test-subj={'ilmPolicyLink'}
{...reactRouterNavigate(history, ilmPolicyLink)}
>
<EuiLink data-test-subj={'ilmPolicyLink'} href={ilmPolicyLink}>
{ilmPolicyName}
</EuiLink>
) : (
Expand Down