Skip to content

Commit

Permalink
[Index management] Client-side NP ready (#57295)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebelga authored Feb 17, 2020
1 parent 5d3797e commit 8e17fda
Show file tree
Hide file tree
Showing 293 changed files with 1,138 additions and 903 deletions.
1 change: 1 addition & 0 deletions src/plugins/management/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export {
ManagementStart,
RegisterManagementApp,
RegisterManagementAppArgs,
ManagementAppMountParams,
} from './types';
export { ManagementApp } from './management_app';
export { ManagementSection } from './management_section';
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/management/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export type RegisterManagementApp = (managementApp: RegisterManagementAppArgs) =

export type Unmount = () => Promise<void> | void;

interface ManagementAppMountParams {
export interface ManagementAppMountParams {
basePath: string; // base path for setting up your router
element: HTMLElement; // element the section should render into
setBreadcrumbs: (crumbs: ChromeBreadcrumb[]) => void;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from '@kbn/i18n/react';
import { getIndexListUri } from '../../../../../../../../index_management/public/app/services/navigation';
import { getIndexListUri } from '../../../../../../../../index_management/public/application/services/navigation';

import {
EuiButtonEmpty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import React, { Component, Fragment } from 'react';
import PropTypes from 'prop-types';
import { FormattedMessage } from '@kbn/i18n/react';
import { getIndexListUri } from '../../../../../../../../index_management/public/app/services/navigation';
import { getIndexListUri } from '../../../../../../../../index_management/public/application/services/navigation';

import {
EuiButton,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { i18n } from '@kbn/i18n';
import { addBadgeExtension } from '../../../index_management/public/index_management_extensions';
import { extensionsService } from '../../../index_management/public';
import { get } from 'lodash';

const propertyPath = 'isFollowerIndex';
Expand All @@ -19,4 +19,4 @@ export const followerBadgeExtension = {
filterExpression: 'isFollowerIndex:true',
};

addBadgeExtension(followerBadgeExtension);
extensionsService.addBadge(followerBadgeExtension);
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import moment from 'moment-timezone';
import axios from 'axios';
import axiosXhrAdapter from 'axios/lib/adapters/xhr';

import { mountWithIntl } from '../../../../test_utils/enzyme_helpers';
import {
retryLifecycleActionExtension,
Expand All @@ -26,6 +27,10 @@ initHttp(axios.create({ adapter: axiosXhrAdapter }), path => path);
initUiMetric(() => () => {});

jest.mock('ui/new_platform');
jest.mock('../../index_management/public', async () => {
const { indexManagementMock } = await import('../../index_management/public/mocks.ts');
return indexManagementMock.createSetup();
});

const indexWithoutLifecyclePolicy = {
health: 'yellow',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {

import { RIGHT_ALIGNMENT } from '@elastic/eui/lib/services';

import { getIndexListUri } from '../../../../../../../../index_management/public/app/services/navigation';
import { getIndexListUri } from '../../../../../../../../index_management/public/application/services/navigation';
import { BASE_PATH } from '../../../../../../../common/constants';
import { UIM_EDIT_CLICK } from '../../../../constants';
import { getPolicyPath } from '../../../../services/navigation';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,7 @@ import { get, every, any } from 'lodash';
import { i18n } from '@kbn/i18n';
import { EuiSearchBar } from '@elastic/eui';

import {
addSummaryExtension,
addBannerExtension,
addActionExtension,
addFilterExtension,
} from '../../../../index_management/public/index_management_extensions';

import { extensionsService } from '../../../../index_management/public';
import { init as initUiMetric } from '../application/services/ui_metric';
import { init as initNotification } from '../application/services/notification';
import { retryLifecycleForIndex } from '../application/services/api';
Expand All @@ -27,13 +21,17 @@ const stepPath = 'ilm.step';

export const retryLifecycleActionExtension = ({
indices,
createUiStatsReporter,
usageCollection,
toasts,
fatalErrors,
}) => {
// These are hacks that we can remove once the New Platform migration is done. They're needed here
// because API requests and API errors require them.
initUiMetric(createUiStatsReporter);
const getLegacyReporter = appName => (type, name) => {
usageCollection.reportUiStats(appName, type, name);
};

initUiMetric(getLegacyReporter);
initNotification(toasts, fatalErrors);

const allHaveErrors = every(indices, index => {
Expand Down Expand Up @@ -207,11 +205,11 @@ export const ilmFilterExtension = indices => {
};

export const addAllExtensions = () => {
addActionExtension(retryLifecycleActionExtension);
addActionExtension(removeLifecyclePolicyActionExtension);
addActionExtension(addLifecyclePolicyActionExtension);
extensionsService.addAction(retryLifecycleActionExtension);
extensionsService.addAction(removeLifecyclePolicyActionExtension);
extensionsService.addAction(addLifecyclePolicyActionExtension);

addBannerExtension(ilmBannerExtension);
addSummaryExtension(ilmSummaryExtension);
addFilterExtension(ilmFilterExtension);
extensionsService.addBanner(ilmBannerExtension);
extensionsService.addSummary(ilmSummaryExtension);
extensionsService.addFilter(ilmFilterExtension);
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,22 @@ import {
findTestSubject,
nextTick,
} from '../../../../../../test_utils';
import { IndexManagementHome } from '../../../public/app/sections/home';
import { IndexManagementHome } from '../../../public/application/sections/home';
import { BASE_PATH } from '../../../common/constants';
import { indexManagementStore } from '../../../public/app/store';
import { indexManagementStore } from '../../../public/application/store';
import { Template } from '../../../common/types';
import { WithAppDependencies, services } from './setup_environment';

const testBedConfig: TestBedConfig = {
store: indexManagementStore,
store: () => indexManagementStore(services as any),
memoryRouter: {
initialEntries: [`${BASE_PATH}indices`],
componentRoutePath: `${BASE_PATH}:section(indices|templates)`,
},
doMountAsync: true,
};

const initTestBed = registerTestBed(IndexManagementHome, testBedConfig);
const initTestBed = registerTestBed(WithAppDependencies(IndexManagementHome), testBedConfig);

export interface IdxMgmtHomeTestBed extends TestBed<IdxMgmtTestSubjects> {
findAction: (action: 'edit' | 'clone' | 'delete') => ReactWrapper;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import React from 'react';
import axios from 'axios';
import axiosXhrAdapter from 'axios/lib/adapters/xhr';

import {
notificationServiceMock,
docLinksServiceMock,
} from '../../../../../../../src/core/public/mocks';
import { AppContextProvider } from '../../../public/application/app_context';
import { httpService } from '../../../public/application/services/http';
import { breadcrumbService } from '../../../public/application/services/breadcrumbs';
import { documentationService } from '../../../public/application/services/documentation';
import { notificationService } from '../../../public/application/services/notification';
import { ExtensionsService } from '../../../public/services';
import { UiMetricService } from '../../../public/application/services/ui_metric';
import { setUiMetricService } from '../../../public/application/services/api';
import { setExtensionsService } from '../../../public/application/store/selectors';
import { init as initHttpRequests } from './http_requests';

const mockHttpClient = axios.create({ adapter: axiosXhrAdapter });

export const services = {
extensionsService: new ExtensionsService(),
uiMetricService: new UiMetricService('index_management'),
};
services.uiMetricService.setup({ reportUiStats() {} } as any);
setExtensionsService(services.extensionsService);
setUiMetricService(services.uiMetricService);
const appDependencies = { services, core: {}, plugins: {} } as any;

export const setupEnvironment = () => {
// Mock initialization of services
// @ts-ignore
httpService.setup(mockHttpClient);
breadcrumbService.setup(() => undefined);
documentationService.setup(docLinksServiceMock.createStartContract());
notificationService.setup(notificationServiceMock.createSetupContract());

const { server, httpRequestsMockHelpers } = initHttpRequests();

return {
server,
httpRequestsMockHelpers,
};
};

export const WithAppDependencies = (Comp: any) => (props: any) => (
<AppContextProvider value={appDependencies}>
<Comp {...props} />
</AppContextProvider>
);
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

import { registerTestBed, TestBedConfig } from '../../../../../../test_utils';
import { BASE_PATH } from '../../../common/constants';
import { TemplateClone } from '../../../public/app/sections/template_clone';
import { TemplateClone } from '../../../public/application/sections/template_clone';
import { formSetup } from './template_form.helpers';
import { TEMPLATE_NAME } from './constants';
import { WithAppDependencies } from './setup_environment';

const testBedConfig: TestBedConfig = {
memoryRouter: {
Expand All @@ -18,6 +19,6 @@ const testBedConfig: TestBedConfig = {
doMountAsync: true,
};

const initTestBed = registerTestBed(TemplateClone, testBedConfig);
const initTestBed = registerTestBed(WithAppDependencies(TemplateClone), testBedConfig);

export const setup = formSetup.bind(null, initTestBed);
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

import { registerTestBed, TestBedConfig } from '../../../../../../test_utils';
import { BASE_PATH } from '../../../common/constants';
import { TemplateCreate } from '../../../public/app/sections/template_create';
import { TemplateCreate } from '../../../public/application/sections/template_create';
import { formSetup, TestSubjects } from './template_form.helpers';
import { WithAppDependencies } from './setup_environment';

const testBedConfig: TestBedConfig = {
memoryRouter: {
Expand All @@ -17,6 +18,9 @@ const testBedConfig: TestBedConfig = {
doMountAsync: true,
};

const initTestBed = registerTestBed<TestSubjects>(TemplateCreate, testBedConfig);
const initTestBed = registerTestBed<TestSubjects>(
WithAppDependencies(TemplateCreate),
testBedConfig
);

export const setup = formSetup.bind(null, initTestBed);
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

import { registerTestBed, TestBedConfig } from '../../../../../../test_utils';
import { BASE_PATH } from '../../../common/constants';
import { TemplateEdit } from '../../../public/app/sections/template_edit';
import { TemplateEdit } from '../../../public/application/sections/template_edit';
import { formSetup, TestSubjects } from './template_form.helpers';
import { TEMPLATE_NAME } from './constants';
import { WithAppDependencies } from './setup_environment';

const testBedConfig: TestBedConfig = {
memoryRouter: {
Expand All @@ -18,6 +19,6 @@ const testBedConfig: TestBedConfig = {
doMountAsync: true,
};

const initTestBed = registerTestBed<TestSubjects>(TemplateEdit, testBedConfig);
const initTestBed = registerTestBed<TestSubjects>(WithAppDependencies(TemplateEdit), testBedConfig);

export const setup = formSetup.bind(null, initTestBed);
Loading

0 comments on commit 8e17fda

Please sign in to comment.