Skip to content

Commit

Permalink
[ILM] Added index templates flyout to the policies list
Browse files Browse the repository at this point in the history
  • Loading branch information
yuliacech committed Jul 27, 2021
1 parent 64873c1 commit 953b5a0
Show file tree
Hide file tree
Showing 19 changed files with 237 additions and 145 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ const getTestBedConfig = (testBedConfigArgs?: Partial<TestBedConfig>): TestBedCo
initialEntries: [`/policies/edit/${POLICY_NAME}`],
componentRoutePath: `/policies/edit/:policyName`,
},
defaultProps: {
getUrlForApp: () => {},
},
...testBedConfigArgs,
};
};
Expand All @@ -38,6 +35,7 @@ const EditPolicyContainer = ({ appServicesContext, ...rest }: any) => {
services={{
breadcrumbService,
license: licensingMock.createLicense({ license: { type: 'enterprise' } }),
getUrlForApp: () => {},
...appServicesContext,
}}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { findTestSubject, takeMountedSnapshot } from '@elastic/eui/lib/test';
import {
fatalErrorsServiceMock,
injectedMetadataServiceMock,
scopedHistoryMock,
} from '../../../../src/core/public/mocks';
import { HttpService } from '../../../../src/core/public/http';
import { usageCollectionPluginMock } from '../../../../src/plugins/usage_collection/public/mocks';
Expand All @@ -35,21 +34,42 @@ initUiMetric(usageCollectionPluginMock.createSetupContract());
// use a date far in the past to check the sorting
const testDate = '2020-07-21T14:16:58.666Z';
const testDateFormatted = moment(testDate).format('YYYY-MM-DD HH:mm:ss');
const testVersion = 0;

const policies: PolicyFromES[] = [];
for (let i = 0; i < 105; i++) {
const policies: PolicyFromES[] = [
{
version: testVersion,
modifiedDate: testDate,
indices: [`index1`],
indexTemplates: [`indexTemplate1`, `indexTemplate2`, `indexTemplate3`, `indexTemplate4`],
name: `testy0`,
policy: {
name: `testy0`,
phases: {},
},
},
];
for (let i = 1; i < 105; i++) {
policies.push({
version: i,
modifiedDate: i === 0 ? testDate : moment().subtract(i, 'days').toISOString(),
modifiedDate: moment().subtract(i, 'days').toISOString(),
indices: i % 2 === 0 ? [`index${i}`] : [],
indexTemplates: i % 2 === 0 ? [`indexTemplate${i}`] : [],
name: `testy${i}`,
policy: {
name: `testy${i}`,
phases: {},
},
});
}
jest.mock('');

jest.mock('react-router-dom', () => ({
...jest.requireActual('react-router-dom'),
useHistory: () => ({
createHref: jest.fn(),
}),
}));

let component: ReactElement;

const snapshot = (rendered: string[]) => {
Expand Down Expand Up @@ -87,25 +107,11 @@ const openContextMenu = (buttonIndex: number) => {

describe('policy table', () => {
beforeEach(() => {
component = (
<PolicyTable
policies={policies}
history={scopedHistoryMock.create()}
navigateToApp={jest.fn()}
updatePolicies={jest.fn()}
/>
);
component = <PolicyTable policies={policies} updatePolicies={jest.fn()} />;
});

test('should show empty state when there are not any policies', () => {
component = (
<PolicyTable
policies={[]}
history={scopedHistoryMock.create()}
navigateToApp={jest.fn()}
updatePolicies={jest.fn()}
/>
);
component = <PolicyTable policies={[]} updatePolicies={jest.fn()} />;
const rendered = mountWithIntl(component);
mountedSnapshot(rendered);
});
Expand Down Expand Up @@ -147,6 +153,9 @@ describe('policy table', () => {
test('should sort when linked indices header is clicked', () => {
testSort('indices');
});
test('should sort when linked index templates header is clicked', () => {
testSort('indexTemplates');
});
test('should have proper actions in context menu when there are linked indices', () => {
const rendered = openContextMenu(0);
const buttons = rendered.find('button.euiContextMenuItem');
Expand Down Expand Up @@ -181,8 +190,10 @@ describe('policy table', () => {
test('displays policy properties', () => {
const rendered = mountWithIntl(component);
const firstRow = findTestSubject(rendered, 'policyTableRow').at(0).text();
const version = 0;
const numberOfIndices = 1;
expect(firstRow).toBe(`testy0${numberOfIndices}${version}${testDateFormatted}Actions`);
const numberOfIndexTemplates = 4;
expect(firstRow).toBe(
`testy0${numberOfIndices}${numberOfIndexTemplates}${testVersion}${testDateFormatted}Actions`
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -7,50 +7,25 @@

import React, { useEffect } from 'react';
import { Router, Switch, Route, Redirect } from 'react-router-dom';
import { ScopedHistory, ApplicationStart } from 'kibana/public';
import { ScopedHistory } from 'kibana/public';
import { METRIC_TYPE } from '@kbn/analytics';

import { UIM_APP_LOAD } from './constants/ui_metric';
import { UIM_APP_LOAD } from './constants';
import { EditPolicy } from './sections/edit_policy';
import { PolicyTable } from './sections/policy_table';
import { trackUiMetric } from './services/ui_metric';
import { ROUTES } from './services/navigation';

export const AppWithRouter = ({
history,
navigateToApp,
getUrlForApp,
}: {
history: ScopedHistory;
navigateToApp: ApplicationStart['navigateToApp'];
getUrlForApp: ApplicationStart['getUrlForApp'];
}) => (
<Router history={history}>
<App navigateToApp={navigateToApp} getUrlForApp={getUrlForApp} />
</Router>
);

export const App = ({
navigateToApp,
getUrlForApp,
}: {
navigateToApp: ApplicationStart['navigateToApp'];
getUrlForApp: ApplicationStart['getUrlForApp'];
}) => {
export const App = ({ history }: { history: ScopedHistory }) => {
useEffect(() => trackUiMetric(METRIC_TYPE.LOADED, UIM_APP_LOAD), []);

return (
<Switch>
<Redirect exact from="/" to={ROUTES.list} />
<Route
exact
path={ROUTES.list}
render={(props) => <PolicyTable {...props} navigateToApp={navigateToApp} />}
/>
<Route
path={ROUTES.edit}
render={(props) => <EditPolicy {...props} getUrlForApp={getUrlForApp} />}
/>
</Switch>
<Router history={history}>
<Switch>
<Redirect exact from="/" to={ROUTES.list} />
<Route exact path={ROUTES.list} component={PolicyTable} />
<Route path={ROUTES.edit} component={EditPolicy} />
</Switch>
</Router>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* 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, { FunctionComponent } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import {
EuiButtonEmpty,
EuiFlyout,
EuiFlyoutBody,
EuiFlyoutFooter,
EuiFlyoutHeader,
EuiInMemoryTable,
EuiLink,
EuiTitle,
} from '@elastic/eui';
import { PolicyFromES } from '../../../common/types';
import { useKibana } from '../../shared_imports';
import { getTemplateDetailsLink } from '../../../../index_management/public/';

interface Props {
policy: PolicyFromES;
close: () => void;
}
export const IndexTemplatesFlyout: FunctionComponent<Props> = ({ policy, close }) => {
const {
services: { getUrlForApp },
} = useKibana();
const getUrlForIndexTemplate = (name: string) => {
return getUrlForApp('management', {
path: `data/index_management${getTemplateDetailsLink(name)}`,
});
};
return (
<EuiFlyout onClose={close}>
<EuiFlyoutHeader hasBorder>
<EuiTitle size="m">
<h2>
<FormattedMessage
id="xpack.indexLifecycleMgmt.policyTable.indexTemplatesFlyout.headerText"
defaultMessage="Index templates linked to policy {policyName}"
values={{ policyName: policy.name }}
/>
</h2>
</EuiTitle>
</EuiFlyoutHeader>
<EuiFlyoutBody>
<EuiInMemoryTable
pagination={true}
items={policy.indexTemplates ?? []}
columns={[
{
name: i18n.translate(
'xpack.indexLifecycleMgmt.policyTable.indexTemplatesTable.nameHeader',
{ defaultMessage: 'Index template name' }
),
render: (value: string) => {
return (
<EuiLink className="eui-textBreakAll" href={getUrlForIndexTemplate(value)}>
{value}
</EuiLink>
);
},
},
]}
/>
</EuiFlyoutBody>
<EuiFlyoutFooter>
<EuiButtonEmpty iconType="cross" onClick={close} flush="left">
<FormattedMessage
id="xpack.indexLifecycleMgmt.indexTemplatesFlyout.closeButtonLabel"
defaultMessage="Close"
/>
</EuiButtonEmpty>
</EuiFlyoutFooter>
</EuiFlyout>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,30 +14,31 @@ import { ILicense } from '../../../licensing/public';

import { KibanaContextProvider } from '../shared_imports';

import { AppWithRouter } from './app';
import { App } from './app';

import { BreadcrumbService } from './services/breadcrumbs';
import { RedirectAppLinks } from '../../../../../src/plugins/kibana_react/public';

export const renderApp = (
element: Element,
I18nContext: I18nStart['Context'],
history: ScopedHistory,
navigateToApp: ApplicationStart['navigateToApp'],
getUrlForApp: ApplicationStart['getUrlForApp'],
application: ApplicationStart,
breadcrumbService: BreadcrumbService,
license: ILicense,
cloud?: CloudSetup
): UnmountCallback => {
const { navigateToApp, getUrlForApp } = application;
render(
<I18nContext>
<KibanaContextProvider services={{ cloud, breadcrumbService, license }}>
<AppWithRouter
history={history}
navigateToApp={navigateToApp}
getUrlForApp={getUrlForApp}
/>
</KibanaContextProvider>
</I18nContext>,
<RedirectAppLinks application={application}>
<I18nContext>
<KibanaContextProvider
services={{ cloud, breadcrumbService, license, navigateToApp, getUrlForApp }}
>
<App history={history} />
</KibanaContextProvider>
</I18nContext>
</RedirectAppLinks>,
element
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({
canBeDisabled = true,
}) => {
const {
services: { cloud },
services: { cloud, getUrlForApp },
} = useKibana();
const { getUrlForApp, policy, license, isNewPolicy } = useEditPolicyContext();
const { policy, license, isNewPolicy } = useEditPolicyContext();
const { isUsingSearchableSnapshotInHotPhase } = useConfiguration();

const searchableSnapshotRepoPath = `phases.${phase}.actions.searchable_snapshot.snapshot_repository`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,19 @@ import {
EuiSpacer,
} from '@elastic/eui';

import { ComboBoxField, useFormData } from '../../../../../../shared_imports';
import { ComboBoxField, useFormData, useKibana } from '../../../../../../shared_imports';
import { useLoadSnapshotPolicies } from '../../../../../services/api';

import { useEditPolicyContext } from '../../../edit_policy_context';
import { UseField } from '../../../form';

import { FieldLoadingError, LearnMoreLink, OptionalLabel } from '../../';

const waitForSnapshotFormField = 'phases.delete.actions.wait_for_snapshot.policy';

export const SnapshotPoliciesField: React.FunctionComponent = () => {
const { getUrlForApp } = useEditPolicyContext();
const {
services: { getUrlForApp },
} = useKibana();
const { error, isLoading, data, resendRequest } = useLoadSnapshotPolicies();
const [formData] = useFormData({
watch: waitForSnapshotFormField,
Expand Down
Loading

0 comments on commit 953b5a0

Please sign in to comment.