Skip to content

Commit

Permalink
Shim input_control_vis for KP (#52243)
Browse files Browse the repository at this point in the history
* Shim input_control_vis
* Convert input_control_vis src files to typescript
* Add Required, Optional, Required and Class types to kbn-utility-types
* Collect all ui/* imports into legacy imports file
* Pass down plugin deps from top level
* Add timeout and terminate_after options to SearchSourceFields
  • Loading branch information
nickofthyme authored Dec 18, 2019
1 parent 87a9b6b commit 72c5c5c
Show file tree
Hide file tree
Showing 79 changed files with 2,067 additions and 1,305 deletions.
1 change: 1 addition & 0 deletions packages/kbn-utility-types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/

import { PromiseType } from 'utility-types';
export { $Values, Required, Optional, Class } from 'utility-types';

/**
* Returns wrapped type of a promise.
Expand Down
2 changes: 1 addition & 1 deletion packages/kbn-utility-types/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"clean": "del target"
},
"dependencies": {
"utility-types": "^3.7.0"
"utility-types": "^3.10.0"
},
"devDependencies": {
"del-cli": "^3.0.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export function ScriptHighlightRules() {
},
{
token: 'script.keyword.operator',

regex:
'\\?\\.|\\*\\.|=~|==~|!|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|->|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|typeof|void)',
},
Expand Down
44 changes: 44 additions & 0 deletions src/legacy/core_plugins/input_control_vis/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* 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.
*/

import { resolve } from 'path';
import { Legacy } from 'kibana';

import { LegacyPluginApi, LegacyPluginInitializer } from '../../../../src/legacy/types';

const inputControlVisPluginInitializer: LegacyPluginInitializer = ({ Plugin }: LegacyPluginApi) =>
new Plugin({
id: 'input_control_vis',
require: ['kibana', 'elasticsearch', 'visualizations', 'interpreter', 'data'],
publicDir: resolve(__dirname, 'public'),
uiExports: {
styleSheetPaths: resolve(__dirname, 'public/index.scss'),
hacks: [resolve(__dirname, 'public/legacy')],
injectDefaultVars: server => ({}),
},
init: (server: Legacy.Server) => ({}),
config(Joi: any) {
return Joi.object({
enabled: Joi.boolean().default(true),
}).default();
},
} as Legacy.PluginSpecOptions);

// eslint-disable-next-line import/no-default-export
export default inputControlVisPluginInitializer;

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

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

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

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
@@ -0,0 +1,76 @@
/*
* 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.
*/

import React from 'react';
import { FieldList } from 'src/plugins/data/public';
import { InputControlVisDependencies } from '../../../plugin';

const fields: FieldList = [] as any;
fields.push({ name: 'myField' } as any);
fields.getByName = (name: any) => {
return fields.find(({ name: n }) => n === name);
};

export const getDepsMock = (): InputControlVisDependencies =>
({
core: {
getStartServices: jest.fn().mockReturnValue([
null,
{
data: {
ui: {
IndexPatternSelect: () => (<div />) as any,
},
indexPatterns: {
get: () => ({
fields,
}),
},
},
},
]),
injectedMetadata: {
getInjectedVar: jest.fn().mockImplementation(key => {
switch (key) {
case 'autocompleteTimeout':
return 1000;
case 'autocompleteTerminateAfter':
return 100000;
default:
return '';
}
}),
},
},
data: {
query: {
filterManager: {
fieldName: 'myField',
getIndexPattern: () => ({
fields,
}),
getAppFilters: jest.fn().mockImplementation(() => []),
getGlobalFilters: jest.fn().mockImplementation(() => []),
},
timefilter: {
timefilter: {},
},
},
},
} as any);
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,12 @@
* under the License.
*/

export const getIndexPatternMock = () => {
import { IIndexPattern } from '../../../../../../../plugins/data/public';

/**
* Returns forced **Partial** IndexPattern for use in tests
*/
export const getIndexPatternMock = (): Promise<IIndexPattern> => {
return Promise.resolve({
id: 'mockIndexPattern',
title: 'mockIndexPattern',
Expand All @@ -26,5 +31,5 @@ export const getIndexPatternMock = () => {
{ name: 'textField', type: 'string', aggregatable: false },
{ name: 'numberField', type: 'number', aggregatable: true },
],
});
} as IIndexPattern);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.
*/

import { SearchSource } from '../../../legacy_imports';

export const getSearchSourceMock = (esSearchResponse?: any): SearchSource =>
jest.fn().mockImplementation(() => ({
setParent: jest.fn(),
setField: jest.fn(),
fetch: jest.fn().mockResolvedValue(
esSearchResponse
? esSearchResponse
: {
aggregations: {
termsAgg: {
buckets: [
{
key: 'Zurich Airport',
doc_count: 691,
},
{
key: 'Xi an Xianyang International Airport',
doc_count: 526,
},
],
},
},
}
),
}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.
*/

import { ShallowWrapper, ReactWrapper } from 'enzyme';

export const updateComponent = async (
component:
| ShallowWrapper<any, Readonly<{}>, React.Component<{}, {}, any>>
| ReactWrapper<any, Readonly<{}>, React.Component<{}, {}, any>>
) => {
// Ensure all promises resolve
await new Promise(resolve => process.nextTick(resolve));
// Ensure the state changes are reflected
component.update();
};
Loading

0 comments on commit 72c5c5c

Please sign in to comment.