Skip to content

Commit da5ead3

Browse files
authored
Migrate entire plugin to new platform (#328)
1 parent 91f637a commit da5ead3

File tree

85 files changed

+3436
-3062
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+3436
-3062
lines changed

.cypress/support/commands.ts

+14-24
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,9 @@ Cypress.Commands.add('mockGetDetectorOnAction', function (
5050
funcMockedOn: VoidFunction
5151
) {
5252
cy.server();
53-
cy.route(
54-
'GET',
55-
buildAdApiUrl(DETECTORS + '*'),
56-
`fixture:${fixtureFileName}`
57-
).as('getDetectors');
53+
cy.route2(buildAdApiUrl(DETECTORS + '*'), `fixture:${fixtureFileName}`).as(
54+
'getDetectors'
55+
);
5856

5957
funcMockedOn();
6058

@@ -66,11 +64,9 @@ Cypress.Commands.add('mockCreateDetectorOnAction', function (
6664
funcMockedOn: VoidFunction
6765
) {
6866
cy.server();
69-
cy.route(
70-
'POST',
71-
buildAdApiUrl(DETECTORS + '*'),
72-
`fixture:${fixtureFileName}`
73-
).as('createDetector');
67+
cy.route2(buildAdApiUrl(DETECTORS + '*'), `fixture:${fixtureFileName}`).as(
68+
'createDetector'
69+
);
7470

7571
funcMockedOn();
7672

@@ -82,11 +78,9 @@ Cypress.Commands.add('mockSearchIndexOnAction', function (
8278
funcMockedOn: VoidFunction
8379
) {
8480
cy.server();
85-
cy.route(
86-
'GET',
87-
buildAdApiUrl(INDICES_PATH + '*'),
88-
`fixture:${fixtureFileName}`
89-
).as('getIndices');
81+
cy.route2(buildAdApiUrl(INDICES_PATH + '*'), `fixture:${fixtureFileName}`).as(
82+
'getIndices'
83+
);
9084

9185
funcMockedOn();
9286

@@ -98,7 +92,7 @@ Cypress.Commands.add('mockSearchOnAction', function (
9892
funcMockedOn: VoidFunction
9993
) {
10094
cy.server();
101-
cy.route('POST', buildAdApiUrl(SEARCH_PATH), `fixture:${fixtureFileName}`).as(
95+
cy.route2(buildAdApiUrl(SEARCH_PATH), `fixture:${fixtureFileName}`).as(
10296
'searchES'
10397
);
10498

@@ -112,8 +106,7 @@ Cypress.Commands.add('mockGetIndexMappingsOnAction', function (
112106
funcMockedOn: VoidFunction
113107
) {
114108
cy.server();
115-
cy.route(
116-
'GET',
109+
cy.route2(
117110
buildAdApiUrl(MAPPINGS_PATH + '*'),
118111
`fixture:${fixtureFileName}`
119112
).as('getMappings');
@@ -129,8 +122,7 @@ Cypress.Commands.add('mockStartDetectorOnAction', function (
129122
funcMockedOn: VoidFunction
130123
) {
131124
cy.server();
132-
cy.route(
133-
'POST',
125+
cy.route2(
134126
buildAdApiUrl([DETECTORS, detectorId, START_PATH].join(SLASH)),
135127
`fixture:${fixtureFileName}`
136128
).as('startDetector');
@@ -146,8 +138,7 @@ Cypress.Commands.add('mockStopDetectorOnAction', function (
146138
funcMockedOn: VoidFunction
147139
) {
148140
cy.server();
149-
cy.route(
150-
'POST',
141+
cy.route2(
151142
buildAdApiUrl([DETECTORS, detectorId, STOP_PATH].join(SLASH)),
152143
`fixture:${fixtureFileName}`
153144
).as('stopDetector');
@@ -163,8 +154,7 @@ Cypress.Commands.add('mockDeleteDetectorOnAction', function (
163154
funcMockedOn: VoidFunction
164155
) {
165156
cy.server();
166-
cy.route(
167-
'DELETE',
157+
cy.route2(
168158
buildAdApiUrl([DETECTORS, detectorId].join(SLASH)),
169159
`fixture:${fixtureFileName}`
170160
).as('deleteDetector');

.cypress/utils/helpers.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ export const buildAdApiUrl = (apiPath: string): string => {
2626
};
2727

2828
export const buildServerApiUrl = (appPath: string, apiPath: string): string => {
29-
return [API_URL_PREFIX, appPath, apiPath].join(SLASH);
29+
return [Cypress.config('baseUrl'), API_URL_PREFIX, appPath, apiPath].join(
30+
SLASH
31+
);
3032
};
3133

3234
export const buildAdAppUrl = (pagePath: string): string => {

.github/workflows/e2e-tests-workflow.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
sleep 180
8989
9090
- name: Run e2e tests
91-
uses: cypress-io/github-action@v1
91+
uses: cypress-io/github-action@v2.5.0
9292
with:
9393
working-directory: kibana/plugins/anomaly-detection-kibana-plugin
9494
command: yarn cy:run --env SECURITY_ENABLED=true
@@ -149,7 +149,7 @@ jobs:
149149
cd kibana/plugins/anomaly-detection-kibana-plugin
150150
yarn kbn bootstrap
151151
- name: Run e2e tests
152-
uses: cypress-io/github-action@v1
152+
uses: cypress-io/github-action@v2.5.0
153153
with:
154154
working-directory: kibana/plugins/anomaly-detection-kibana-plugin
155155
command: yarn test:e2e

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ offline-module-cache/v2/*
1616
offline-module-cache/v1/*
1717
.cypress/screenshots
1818
.cypress/videos
19+
target

cypress.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"requestTimeout": 90000,
1111
"responseTimeout": 90000,
1212
"defaultCommandTimeout": 90000,
13+
"experimentalNetworkStubbing": true,
1314
"env": {
1415
"SECURITY_ENABLED": false
1516
}

index.js

-79
This file was deleted.

kibana.json

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"id": "opendistroAnomalyDetectionKibana",
3+
"version": "1.11.0.0",
4+
"kibanaVersion": "7.9.1",
5+
"configPath": ["opendistro_anomaly_detection_kibana"],
6+
"requiredPlugins": ["navigation"],
7+
"optionalPlugins": [],
8+
"server": true,
9+
"ui": true
10+
}

package.json

+2-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
"test:jest": "../../node_modules/.bin/jest --config ./test/jest.config.js",
1818
"build": "plugin-helpers build",
1919
"release": "./tasks/release.sh",
20-
"start-cy-server": "yarn start --no-base-path --oss",
2120
"cy:open": "cypress open",
2221
"cy:run": "cypress run",
2322
"cy:run-with-security": "cypress run --env SECURITY_ENABLED=true",
24-
"test:e2e": "CHOKIDAR_USEPOLLING=1 CYPRESS_responseTimeout=180000 WAIT_ON_TIMEOUT=900000 start-server-and-test 'yarn start-cy-server' http-get://localhost:5601/app/opendistro-anomaly-detection-kibana 'echo sleeping to wait for server to get ready && sleep 180 && yarn cy:run'"
23+
"test:e2e": "CHOKIDAR_USEPOLLING=1 CYPRESS_responseTimeout=180000 WAIT_ON_TIMEOUT=900000 start-server-and-test 'cd ../../ && yarn start --no-base-path --oss && cd plugins/anomaly-detection-kibana-plugin' http-get://localhost:5601/app/opendistro-anomaly-detection-kibana 'echo sleeping to wait for server to get ready && sleep 180 && yarn cy:run'"
2524
},
2625
"lint-staged": {
2726
"*.{ts,tsx,js,jsx,json,css,md}": [
@@ -42,7 +41,6 @@
4241
"@testing-library/jest-dom": "^4.0.0",
4342
"@testing-library/react": "^8.0.6",
4443
"@testing-library/user-event": "^4.2.3",
45-
"@types/angular": "^1.6.55",
4644
"@types/chance": "^1.0.6",
4745
"@types/elasticsearch": "^5.0.34",
4846
"@types/hapi": "^18.0.2",
@@ -60,7 +58,7 @@
6058
"babel-jest": "^24.8.0",
6159
"babel-polyfill": "^6.26.0",
6260
"chance": "^1.1.0",
63-
"cypress": "^4.11.0",
61+
"cypress": "^5.6.0",
6462
"eslint": "^5.6.0",
6563
"eslint-plugin-babel": "^5.2.0",
6664
"eslint-plugin-import": "^2.14.0",
@@ -85,7 +83,6 @@
8583
"formik": "^1.5.8",
8684
"lodash": "^4.17.19",
8785
"plotly.js": "^1.55.2",
88-
"query-string": "^6.8.2",
8986
"react-plotly.js": "^2.4.0",
9087
"react-redux": "^7.1.0",
9188
"react-vis": "^1.11.7",

public/anomaly_detection_app.tsx

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
import { CoreStart, AppMountParameters } from '../../../src/core/public';
17+
import React from 'react';
18+
import ReactDOM from 'react-dom';
19+
import { HashRouter as Router, Route } from 'react-router-dom';
20+
import { Main } from './pages/main';
21+
import { Provider } from 'react-redux';
22+
import configureStore from './redux/configureStore';
23+
import { CoreServicesContext } from './components/CoreServices/CoreServices';
24+
25+
export function renderApp(coreStart: CoreStart, params: AppMountParameters) {
26+
const http = coreStart.http;
27+
const store = configureStore(http);
28+
29+
// Load Chart's dark mode CSS (if applicable)
30+
const isDarkMode = coreStart.uiSettings.get('theme:darkMode') || false;
31+
if (isDarkMode) {
32+
require('@elastic/charts/dist/theme_only_dark.css');
33+
} else {
34+
require('@elastic/charts/dist/theme_only_light.css');
35+
}
36+
ReactDOM.render(
37+
<Provider store={store}>
38+
<Router>
39+
<Route
40+
render={(props) => (
41+
<CoreServicesContext.Provider value={coreStart}>
42+
<Main {...props} />
43+
</CoreServicesContext.Provider>
44+
)}
45+
/>
46+
</Router>
47+
</Provider>,
48+
params.element
49+
);
50+
return () => ReactDOM.unmountComponentAtNode(params.element);
51+
}

public/app.js

-64
This file was deleted.

0 commit comments

Comments
 (0)