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

[Watcher] New Platform (NP) Migration #50908

Merged
merged 38 commits into from
Dec 11, 2019
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
2a401e3
First iteration of watch public -> new platform
jloleysens Nov 15, 2019
58b7d0c
Merge remote-tracking branch 'upstream/master' into np-migration/watc…
jloleysens Nov 18, 2019
b0afa91
- Switched to using np ready request
jloleysens Nov 18, 2019
4b26855
First attempt at server shim
jloleysens Nov 18, 2019
5e8b01b
Rename file and re-enable react hooks linting
jloleysens Nov 20, 2019
ac97bb7
Fix some public types and react hooks lint rules
jloleysens Nov 20, 2019
fb37ccf
Fix types
jloleysens Nov 20, 2019
12085c1
More ES lint react hooks fixes
jloleysens Nov 20, 2019
c8a3c13
Migrated server lib -> ts. Part way done with migrating routes to NP …
jloleysens Nov 20, 2019
ee2b87d
Big subset of routes to TS and NP router - almost there
jloleysens Nov 20, 2019
e26e7bb
Delete legacy error wrappers and moved last set of routes to TS and N…
jloleysens Nov 21, 2019
c40a6f0
Remove @ts-ignore's and update route registration to use shim with ht…
jloleysens Nov 21, 2019
25c1f6b
Added routes validations, fixes for hooks and fixes for types
jloleysens Nov 21, 2019
e0eefdc
Fix more types and finish testing API routes
jloleysens Nov 21, 2019
04709a4
Merge branch 'master' into np-migration/watcher
elasticmachine Nov 21, 2019
8067bd0
Fix usage of feature catalogue and fix time buckets types
jloleysens Nov 21, 2019
1d4771b
Fix error message shape [skip ci]
jloleysens Nov 21, 2019
21df366
Merge branch 'master' into np-migration/watcher
elasticmachine Nov 21, 2019
1fa7917
Split legacy from new platform dependencies server-side
jloleysens Dec 3, 2019
e0232df
Refactor: Seperate client legacy and NP dependencies
jloleysens Dec 3, 2019
4ab3cf9
Add file: added types file
jloleysens Dec 3, 2019
55bb85e
Merge branch 'master' into np-migration/watcher
elasticmachine Dec 3, 2019
37ca71c
Fix UISettings client type import
jloleysens Dec 3, 2019
4cb17dc
Update license pre-routing factory spec
jloleysens Dec 3, 2019
5a628b8
Merge branch 'master' into np-migration/watcher
elasticmachine Dec 5, 2019
991cee2
Merge branch 'master' into np-migration/watcher
elasticmachine Dec 9, 2019
0ed3d4b
Update variable names, use of I18nContext (use NP) and docs
jloleysens Dec 9, 2019
f65a526
Use NP elasticsearchclient
jloleysens Dec 9, 2019
3d0e61b
Simplify is_es_error_factory
jloleysens Dec 9, 2019
cbf30e1
Fix types
jloleysens Dec 9, 2019
c47884c
Improve code legibility and remove second use of `useAppContext`
jloleysens Dec 10, 2019
61078aa
Use @kbn/config-schema (not validate: false) on routes!
jloleysens Dec 10, 2019
293265b
Fix watch create JSON spec
jloleysens Dec 10, 2019
c3ed455
Create threshold test working
jloleysens Dec 10, 2019
fd8b0ec
Unskip watch_edit.test.ts
jloleysens Dec 10, 2019
c6aef83
Unskip watch_list.test.ts
jloleysens Dec 10, 2019
6e90b77
Done re-enabling component integration tests
jloleysens Dec 10, 2019
471c801
TimeBuckets typo + remove unnecessary // @ts-ignore
jloleysens Dec 10, 2019
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
7 changes: 0 additions & 7 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,6 @@ module.exports = {
'react-hooks/rules-of-hooks': 'off',
},
},
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you close #49566 once this PR is merged?

files: ['x-pack/legacy/plugins/watcher/**/*.{js,ts,tsx}'],
rules: {
'react-hooks/rules-of-hooks': 'off',
'react-hooks/exhaustive-deps': 'off',
},
},

/**
* Prettier
Expand Down
22 changes: 22 additions & 0 deletions src/legacy/ui/public/time_buckets/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

declare module 'ui/time_buckets' {
export const TimeBuckets: any;
}
9 changes: 6 additions & 3 deletions src/plugins/es_ui_shared/public/request/np_ready_request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@

import { useEffect, useState, useRef } from 'react';

import { HttpServiceBase } from '../../../../../src/core/public';
import { HttpServiceBase, HttpFetchQuery } from '../../../../../src/core/public';

export interface SendRequestConfig {
path: string;
method: 'get' | 'post' | 'put' | 'delete' | 'patch' | 'head';
query?: HttpFetchQuery;
body?: any;
}

Expand All @@ -48,10 +49,10 @@ export interface UseRequestResponse {

export const sendRequest = async (
httpClient: HttpServiceBase,
{ path, method, body }: SendRequestConfig
{ path, method, body, query }: SendRequestConfig
): Promise<SendRequestResponse> => {
try {
const response = await httpClient[method](path, { body });
const response = await httpClient[method](path, { body, query });

return {
data: response.data ? response.data : response,
Expand All @@ -70,6 +71,7 @@ export const useRequest = (
{
path,
method,
query,
body,
pollIntervalMs,
initialData,
Expand Down Expand Up @@ -112,6 +114,7 @@ export const useRequest = (
const requestBody = {
path,
method,
query,
body,
};

Expand Down
3 changes: 2 additions & 1 deletion x-pack/dev-tools/jest/create_jest_config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ export function createJestConfig({ kibanaDirectory, xPackKibanaDirectory }) {
'uiExports/(.*)': fileMockPath,
'^src/core/(.*)': `${kibanaDirectory}/src/core/$1`,
'^src/legacy/(.*)': `${kibanaDirectory}/src/legacy/$1`,
'^plugins/watcher/models/(.*)': `${xPackKibanaDirectory}/legacy/plugins/watcher/public/models/$1`,
'^plugins/watcher/np_ready/application/models/(.*)':
`${xPackKibanaDirectory}/legacy/plugins/watcher/public/np_ready/application/models/$1`,
'^plugins/([^/.]*)(.*)': `${kibanaDirectory}/src/legacy/core_plugins/$1/public$2`,
'^legacy/plugins/xpack_main/(.*);': `${xPackKibanaDirectory}/legacy/plugins/xpack_main/public/$1`,
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$': fileMockPath,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* 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 { ComponentType } from 'enzyme';

import { AppContextProvider } from '../../../public/np_ready/application/app_context';

export const withAppContext = (Component: ComponentType<any>) => (props: any) => {
return (
<AppContextProvider
value={
{
docLinks: {
DOC_LINK_VERSION: 'test',
ELASTIC_WEBSITE_URL: 'test',
links: {} as any,
},
chrome: {
setBreadcrumbs: () => {},
} as any,
legacy: {
TimeBuckets: class MockTimeBuckets {
setBounds(_domain: any) {
return {};
}
getInterval() {
return {
expression: {},
};
}
},
MANAGEMENT_BREADCRUMB: { text: 'test' },
savedObjects: {
create: jest.fn(),
} as any,
},
uiSettings: {
get: () => {},
isDefault: () => true,
} as any,
} as any
}
>
<Component {...props} />
</AppContextProvider>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import axios from 'axios';
import axiosXhrAdapter from 'axios/lib/adapters/xhr';
import { init as initHttpRequests } from './http_requests';
import { setHttpClient, setSavedObjectsClient } from '../../../public/lib/api';
import { setHttpClient, setSavedObjectsClient } from '../../../public/np_ready/application/lib/api';

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

Expand All @@ -23,7 +23,7 @@ export const setupEnvironment = () => {
// @ts-ignore
setHttpClient(mockHttpClient);

setSavedObjectsClient(mockSavedObjectsClient());
setSavedObjectsClient(mockSavedObjectsClient() as any);

return {
server,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { withAppContext } from './app_context.mock';
import { registerTestBed, TestBed, TestBedConfig } from '../../../../../../test_utils';
import { WatchEdit } from '../../../public/sections/watch_edit/components/watch_edit';
import { WatchEdit } from '../../../public/np_ready/application/sections/watch_edit/components/watch_edit';
import { ROUTES, WATCH_TYPES } from '../../../common/constants';
import { registerRouter } from '../../../public/lib/navigation';
import { registerRouter } from '../../../public/np_ready/application/lib/navigation';

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

const initTestBed = registerTestBed(WatchEdit, testBedConfig);
const initTestBed = registerTestBed(withAppContext(WatchEdit), testBedConfig);

export interface WatchCreateJsonTestBed extends TestBed<WatchCreateJsonTestSubjects> {
actions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { registerTestBed, TestBed, TestBedConfig } from '../../../../../../test_utils';
import { WatchEdit } from '../../../public/sections/watch_edit/components/watch_edit';
import { WatchEdit } from '../../../public/np_ready/application/sections/watch_edit/components/watch_edit';
import { ROUTES, WATCH_TYPES } from '../../../common/constants';
import { registerRouter } from '../../../public/lib/navigation';
import { registerRouter } from '../../../public/np_ready/application/lib/navigation';
import { withAppContext } from './app_context.mock';

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

const initTestBed = registerTestBed(WatchEdit, testBedConfig);
const initTestBed = registerTestBed(withAppContext(WatchEdit), testBedConfig);

export interface WatchCreateThresholdTestBed extends TestBed<WatchCreateThresholdTestSubjects> {
actions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { registerTestBed, TestBed, TestBedConfig } from '../../../../../../test_utils';
import { WatchEdit } from '../../../public/sections/watch_edit/components/watch_edit';
import { WatchEdit } from '../../../public/np_ready/application/sections/watch_edit/components/watch_edit';
import { ROUTES } from '../../../common/constants';
import { registerRouter } from '../../../public/lib/navigation';
import { registerRouter } from '../../../public/np_ready/application/lib/navigation';
import { WATCH_ID } from './constants';
import { withAppContext } from './app_context.mock';

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

const initTestBed = registerTestBed(WatchEdit, testBedConfig);
const initTestBed = registerTestBed(withAppContext(WatchEdit), testBedConfig);

export interface WatchEditTestBed extends TestBed<WatchEditSubjects> {
actions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ import {
TestBedConfig,
nextTick,
} from '../../../../../../test_utils';
import { WatchList } from '../../../public/sections/watch_list/components/watch_list';
import { WatchList } from '../../../public/np_ready/application/sections/watch_list/components/watch_list';
import { ROUTES } from '../../../common/constants';
import { withAppContext } from './app_context.mock';

const testBedConfig: TestBedConfig = {
memoryRouter: {
Expand All @@ -23,7 +24,7 @@ const testBedConfig: TestBedConfig = {
doMountAsync: true,
};

const initTestBed = registerTestBed(WatchList, testBedConfig);
const initTestBed = registerTestBed(withAppContext(WatchList), testBedConfig);

export interface WatchListTestBed extends TestBed<WatchListTestSubjects> {
actions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import {
TestBedConfig,
nextTick,
} from '../../../../../../test_utils';
import { WatchStatus } from '../../../public/sections/watch_status/components/watch_status';
import { WatchStatus } from '../../../public/np_ready/application/sections/watch_status/components/watch_status';
import { ROUTES } from '../../../common/constants';
import { WATCH_ID } from './constants';
import { withAppContext } from './app_context.mock';

const testBedConfig: TestBedConfig = {
memoryRouter: {
Expand All @@ -25,7 +26,7 @@ const testBedConfig: TestBedConfig = {
doMountAsync: true,
};

const initTestBed = registerTestBed(WatchStatus, testBedConfig);
const initTestBed = registerTestBed(withAppContext(WatchStatus), testBedConfig);

export interface WatchStatusTestBed extends TestBed<WatchStatusTestSubjects> {
actions: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,9 @@ import { act } from 'react-dom/test-utils';
import { setupEnvironment, pageHelpers, nextTick } from './helpers';
import { WatchCreateJsonTestBed } from './helpers/watch_create_json.helpers';
import { WATCH } from './helpers/constants';
import defaultWatchJson from '../../public/models/watch/default_watch.json';
import defaultWatchJson from '../../public/np_ready/application/models/watch/default_watch.json';
import { getExecuteDetails } from '../../test/fixtures';

jest.mock('ui/chrome', () => ({
breadcrumbs: { set: () => {} },
addBasePath: (path: string) => path || '/api/watcher',
}));

jest.mock('ui/time_buckets', () => {});

const { setup } = pageHelpers.watchCreateJson;

describe.skip('<JsonWatchEdit /> create route', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,8 @@ const WATCH_VISUALIZE_DATA = {

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

jest.mock('ui/chrome', () => ({
breadcrumbs: { set: () => {} },
addBasePath: (path: string) => path || '/api/watcher',
getUiSettingsClient: () => ({
get: () => {},
isDefault: () => true,
}),
}));

jest.mock('ui/time_buckets', () => {
class MockTimeBuckets {
setBounds(_domain: any) {
return {};
}
getInterval() {
return {
expression: {},
};
}
}
return { TimeBuckets: MockTimeBuckets };
});

jest.mock('../../public/lib/api', () => ({
...jest.requireActual('../../public/lib/api'),
jest.mock('../../public/np_ready/application/lib/api', () => ({
...jest.requireActual('../../public/np_ready/application/lib/api'),
loadIndexPatterns: async () => {
const INDEX_PATTERNS = [
{ attributes: { title: 'index1' } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,14 @@ import axios from 'axios';
import { setupEnvironment, pageHelpers, nextTick } from './helpers';
import { WatchEditTestBed } from './helpers/watch_edit.helpers';
import { WATCH } from './helpers/constants';
import defaultWatchJson from '../../public/models/watch/default_watch.json';
import defaultWatchJson from '../../public/np_ready/application/models/watch/default_watch.json';
import { getWatch } from '../../test/fixtures';
import { getRandomString } from '../../../../../test_utils';

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

jest.mock('ui/chrome', () => ({
breadcrumbs: { set: () => {} },
addBasePath: (path: string) => path || '/api/watcher',
}));

jest.mock('ui/time_buckets', () => {
class MockTimeBuckets {
setBounds(_domain: any) {
return {};
}
getInterval() {
return {
expression: {},
};
}
}
return { TimeBuckets: MockTimeBuckets };
});

jest.mock('../../public/lib/api', () => ({
...jest.requireActual('../../public/lib/api'),
jest.mock('../../public/np_ready/application/lib/api', () => ({
...jest.requireActual('../../public/np_ready/application/lib/api'),
loadIndexPatterns: async () => {
const INDEX_PATTERNS = [
{ attributes: { title: 'index1' } },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,6 @@ import { ROUTES } from '../../common/constants';

const { API_ROOT } = ROUTES;

jest.mock('ui/chrome', () => ({
breadcrumbs: { set: () => {} },
addBasePath: (path: string) => path || '/api/watcher',
}));

jest.mock('ui/time_buckets', () => {});

const { setup } = pageHelpers.watchList;

describe.skip('<WatchList />', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@ import { WATCH_STATES, ACTION_STATES } from '../../common/constants';

const { API_ROOT } = ROUTES;

jest.mock('ui/chrome', () => ({
breadcrumbs: { set: () => {} },
addBasePath: (path: string) => path || '/api/watcher',
}));

jest.mock('ui/time_buckets', () => {});

const { setup } = pageHelpers.watchStatus;

const watchHistory1 = getWatchHistory({ startTime: '2019-06-04T01:11:11.294' });
Expand Down
9 changes: 9 additions & 0 deletions x-pack/legacy/plugins/watcher/kibana.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "watcher",
"version": "kibana",
"requiredPlugins": [
"home"
],
"server": true,
"ui": true
}
Loading