diff --git a/.eslintrc.js b/.eslintrc.js index 7dd0860aac04e..03a674993ab50 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -189,13 +189,6 @@ module.exports = { 'react-hooks/exhaustive-deps': 'off', }, }, - { - files: ['x-pack/legacy/plugins/uptime/**/*.{js,ts,tsx}'], - rules: { - 'react-hooks/exhaustive-deps': 'off', - 'react-hooks/rules-of-hooks': 'off', - }, - }, /** * Files that require Apache 2.0 headers, settings diff --git a/NOTICE.txt b/NOTICE.txt index 230e511746022..955c3127fa955 100644 --- a/NOTICE.txt +++ b/NOTICE.txt @@ -1,5 +1,5 @@ Kibana source code with Kibana X-Pack source code -Copyright 2012-2019 Elasticsearch B.V. +Copyright 2012-2020 Elasticsearch B.V. --- Pretty handling of logarithmic axes. diff --git a/docs/canvas/canvas-expression-lifecycle.asciidoc b/docs/canvas/canvas-expression-lifecycle.asciidoc new file mode 100644 index 0000000000000..895c1382c4d36 --- /dev/null +++ b/docs/canvas/canvas-expression-lifecycle.asciidoc @@ -0,0 +1,261 @@ +[role="xpack"] +[[canvas-expression-lifecycle]] +== Canvas expression lifecycle + +Elements in Canvas are all created using an *expression language* that defines how to retrieve, manipulate, and ultimately visualize data. The goal is to allow you to do most of what you need without understanding the *expression language*, but learning how it works unlocks a lot of Canvas's power. + + +[[canvas-expressions-always-start-with-a-function]] +=== Expressions always start with a function + +Expressions simply execute <> in a specific order, which produce some output value. That output can then be inserted into another function, and another after that, until it produces the output you need. + +To use demo dataset available in Canvas to produce a table, run the following expression: + +[source,text] +---- +filters +| demodata +| table +| render +---- + +This expression starts out with the <> function, which provides the value of any time filters or dropdown filters in the workpad. This is then inserted into <>, a function that returns exactly what you expect, demo data. Because the <> function receives the filter information from the <> function before it, it applies those filters to reduce the set of data it returns. We call the output from the previous function _context_. + +The filtered <> becomes the _context_ of the next function, <>, which creates a table visualization from this data set. The <> function isn’t strictly required, but by being explicit, you have the option of providing arguments to control things like the font used in the table. The output of the <> function becomes the _context_ of the <> function. Like the <>, the <> function isn’t required either, but it allows access to other arguments, such as styling the border of the element or injecting custom CSS. + + +[[canvas-function-arguments]] +=== Function arguments + +Let’s look at another expression, which uses the same <> function, but instead produces a pie chart. + +image::images/canvas-functions-can-take-arguments-pie-chart.png[Pie Chart, height=400] +[source,text] +---- +filters +| demodata +| pointseries color="state" size="max(price)" +| pie +| render +---- + +To produce a filtered set of random data, the expression uses the <> and <> functions. This time, however, the output becomes the context for the <> function, which is a way to aggregate your data, similar to how Elasticsearch works, but more generalized. In this case, the data is split up using the `color` and `size` dimensions, using arguments on the <> function. Each unique value in the state column will have an associated size value, which in this case, will be the maximum value of the price column. + +If the expression stopped there, it would produce a `pointseries` data type as the output of this expression. But instead of looking at the raw values, the result is inserted into the <> function, which will produce an output that will render a pie visualization. And just like before, this is inserted into the <> function, which is useful for its arguments. + +The end result is a simple pie chart that uses the default color palette, but the <> function can take additional arguments that control how it gets rendered. For example, you can provide a `hole` argument to turn your pie chart into a donut chart by changing the expression to: + + +image::images/canvas-functions-can-take-arguments-donut-chart.png[Donut Chart, height=400] +[source,text] +---- +filters +| demodata +| pointseries color="state" size="max(price)" +| pie hole=50 +| render +---- + + +[[canvas-aliases-and-unnamed-arguments]] +=== Aliases and unnamed arguments + +Argument definitions have one canonical name, which is always provided in the underlying code. When argument definitions are used in an expression, they often include aliases that make them easier or faster to type. + +For example, the <> function has 2 arguments: + +* `expression` - Produces a calculated value. +* `name` - The name of column. + +The `expression` argument includes some aliases, namely `exp`, `fn`, and `function`. That means that you can use any of those four options to provide that argument’s value. + +So `mapColumn name=newColumn fn={string example}` is equal to `mapColumn name=newColumn expression={string example}`. + +There’s also a special type of alias which allows you to leave off the argument’s name entirely. The alias for this is an underscore, which indicates that the argument is an _unnamed_ argument and can be provided without explicitly naming it in the expression. The `name` argument here uses the _unnamed_ alias, which means that you can further simplify our example to `mapColumn newColumn fn={string example}`. + +NOTE: There can only be one _unnamed_ argument for each function. + + +[[canvas-change-your-expression-change-your-output]] +=== Change your expression, change your output +You can substitute one function for another to change the output. For example, you could change the visualization by swapping out the <> function for another renderer, a function that returns a `render` data type. + +Let’s change that last pie chart into a bubble chart by replacing the <> function with the <> function. This is possible because both functions can accept a `pointseries` data type as their _context_. Switching the functions will work, but it won’t produce a useful visualization on its own since you don’t have the x-axis and y-axis defined. You will also need to modify the <> function to change its output. In this case, you can change the `size` argument to `y`, so the maximum price values are plotted on the y-axis, and add an `x` argument using the `@timestamp` field in the data to plot those values over time. This leaves you with the following expression and produces a bubble chart showing the max price of each state over time: + +image::images/canvas-change-your-expression-chart.png[Bubble Chart, height=400] +[source,text] +---- +filters +| demodata +| pointseries color="state" y="max(price)" x="@timestamp" +| plot +| render +---- + +Similar to the <> function, the <> function takes arguments that control the design elements of the visualization. As one example, passing a `legend` argument with a value of `false` to the function will hide the legend on the chart. + +image::images/canvas-change-your-expression-chart-no-legend.png[Bubble Chart Without Legend, height=400] +[source,text,subs=+quotes] +---- +filters +| demodata +| pointseries color="state" y="max(price)" x="@timestamp" +| plot *legend=false* +| render +---- + + +[[canvas-fetch-and-manipulate-data]] +=== Fetch and manipulate data +So far, you have only seen expressions as a way to produce visualizations, but that’s not really what’s happening. Expressions only produce data, which is then used to create something, which in the case of Canvas, means rendering an element. An element can be a visualization, driven by data, but it can also be something much simpler, like a static image. Either way, an expression is used to produce an output that is used to render the desired result. For example, here’s an expression that shows an image: + +[source,text] +---- +image dataurl=https://placekitten.com/160/160 mode="cover" +---- + +But as mentioned, this doesn’t actually _render that image_, but instead it _produces some output that can be used to render that image_. That’s an important distinction, and you can see the actual output by adding in the render function and telling it to produce debug output. For example: + +[source,text] +---- +image dataurl=https://placekitten.com/160/160 mode="cover" +| render as=debug +---- + +The follow appears as JSON output: + +[source,JSON] +---- +{ + "type": "image", + "mode": "cover", + "dataurl": "https://placekitten.com/160/160" +} +---- + +NOTE: You may need to expand the element’s size to see the whole output. + +Canvas uses this output’s data type to map to a specific renderer and passes the entire output into it. It’s up to the image render function to produce an image on the workpad’s page. In this case, the expression produces some JSON output, but expressions can also produce other, simpler data, like a string or a number. Typically, useful results use JSON. + +Canvas uses the output to render an element, but other applications can use expressions to do pretty much anything. As stated previously, expressions simply execute functions, and the functions are all written in Javascript. That means if you can do something in Javascript, you can do it with an expression. + +This can include: + +* Sending emails +* Sending notifications +* Reading from a file +* Writing to a file +* Controlling devices with WebUSB or Web Bluetooth +* Consuming external APIs + +If your Javascript works in the environment where the code will run, such as in Node.js or in a browser, you can do it with an expression. + +[[canvas-expressions-compose-functions-with-subexpressions]] +=== Compose functions with sub-expressions + +You may have noticed another syntax in examples from other sections, namely expressions inside of curly brackets. These are called sub-expressions, and they can be used to provide a calculated value to another expression, instead of just a static one. + +A simple example of this is when you upload your own images to a Canvas workpad. That upload becomes an asset, and that asset can be retrieved using the `asset` function. Usually you’ll just do this from the UI, adding an image element to the page and uploading your image from the control in the sidebar, or picking an existing asset from there as well. In both cases, the system will consume that asset via the `asset` function, and you’ll end up with an expression similar to this: + +[source,text] +---- +image dataurl={asset 3cb3ec3a-84d7-48fa-8709-274ad5cc9e0b} +---- + +Sub-expressions are executed before the function that uses them is executed. In this case, `asset` will be run first, it will produce a value, the base64-encoded value of the image and that value will be used as the value for the `dataurl` argument in the <> function. After the asset function executes, you will get the following output: + +[source,text] +---- +image dataurl="data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0" +---- + +Since all of the sub-expressions are now resolved into actual values, the <> function can be executed to produce its JSON output, just as it’s explained previously. In the case of images, the ability to nest sub-expressions is particularly useful to show one of several images conditionally. For example, you could swap between two images based on some calculated value by mixing in the <> function, like in this example expression: + +[source,text] +---- +demodata +| image dataurl={ + if condition={getCell price | gte 100} + then={asset 3cb3ec3a-84d7-48fa-8709-274ad5cc9e0b} + else={asset cbc11a1f-8f25-4163-94b4-2c3a060192e7} +} +---- + +NOTE: The examples in this section can’t be copy and pasted directly, since the values used throughout will not exist in your workpad. + +Here, the expression to use for the value of the `condition` argument, `getCell price | gte 100`, runs first since it is nested deeper. + +The expression does the following: + +* Retrieves the value from the *price* column in the first row of the `demodata` data table +* Inputs the value to the `gte` function +* Compares the value to `100` +* Returns `true` if the value is 100 or greater, and `false` if the value is 100 or less + +That boolean value becomes the value for the `condition` argument. The output from the `then` expression is used as the output when `condition` is `true`. The output from the `else` expression is used when `condition` is false. In both cases, a base64-encoded image will be returned, and one of the two images will be displayed. + +You might be wondering how the <> function in the sub-expression accessed the data from the <> function, even though <> was not being directly inserted into <>. The answer is simple, but important to understand. When nested sub-expressions are executed, they automatically receive the same _context_, or output of the previous function that its parent function receives. In this specific expression, demodata’s data table is automatically provided to the nested expression’s `getCell` function, which allows that expression to pull out a value and compare it to another value. + +The passing of the _context_ is automatic, and it happens no matter how deeply you nest your sub-expressions. To demonstrate this, let’s modify the expression slightly to compare the value of the price against multiple conditions using the <> function. + +[source,text] +---- +demodata +| image dataurl={ + if condition={getCell price | all {gte 100} {neq 105}} + then={asset 3cb3ec3a-84d7-48fa-8709-274ad5cc9e0b} + else={asset cbc11a1f-8f25-4163-94b4-2c3a060192e7} +} +---- + +This time, `getCell price` is run, and the result is passed into the next function as the context. Then, each sub-expression of the <> function is run, with the context given to their parent, which in this case is the result of `getCell price`. If `all` of these sub-expressions evaluate to `true`, then the `if` condition argument will be true. + +Sub-expressions can seem a little foreign, especially if you aren’t a developer, but they’re worth getting familiar with, since they provide a ton of power and flexibility. Since you can nest any expression you want, you can also use this behavior to mix data from multiple indices, or even data from multiple sources. As an example, you could query an API for a value to use as part of the query provided to <>. + +This whole section is really just scratching the surface, but hopefully after reading it, you at least understand how to read expressions and make sense of what they are doing. With a little practice, you’ll get the hang of mixing _context_ and sub-expressions together to turn any input into your desired output. + +[[canvas-handling-context-and-argument-types]] +=== Handling context and argument types +If you look through the <>, you may notice that all of them define what a function accepts and what it returns. Additionally, every argument includes a type property that specifies the kind of data that can be used. These two types of values are actually the same, and can be used as a guide for how to deal with piping to other functions and using subexpressions for argument values. + +To explain how this works, consider the following expression from the previous section: + +[source,text] +---- +image dataurl={asset 3cb3ec3a-84d7-48fa-8709-274ad5cc9e0b} +---- + +If you <> for the `image` function, you’ll see that it accepts the `null` data type and returns an `image` data type. Accepting `null` effectively means that it does not use context at all, so if you insert anything to `image`, the value that was produced previously will be ignored. When the function executes, it will produce an `image` output, which is simply an object of type `image` that contains the information required to render an image. + +NOTE: The function does not render an image itself. + +As explained in the "<>" section, the output of an expression is just data. So the `image` type here is just a specific shape of data, not an actual image. + +Next, let’s take a look at the `asset` function. Like `image`, it accepts `null`, but it returns something different, a `string` in this case. Because `asset` will produce a string, its output can be used as the input for any function or argument that accepts a string. + +<> for the `dataurl` argument, its type is `string`, meaning it will accept any kind of string. There are some rules about the value of the string that the function itself enforces, but as far as the interpreter is concerned, that expression is valid because the argument accepts a string and the output of `asset` is a string. + +The interpreter also attempts to cast some input types into others, which allows you to use a string input even when the function or argument calls for a number. Keep in mind that it’s not able to convert any string value, but if the string is a number, it can easily be cast into a `number` type. Take the following expression for example: + +[source,text] +---- +string "0.4" +| revealImage image={asset asset-06511b39-ec44-408a-a5f3-abe2da44a426} +---- + +If you <> for the `revealImage` function, you’ll see that it accepts a `number` but the `string` function returns a `string` type. In this case, because the string value is a number, it can be converted into a `number` type and used without you having to do anything else. + +Most `primitive` types can be converted automatically, as you might expect. You just saw that a `string` can be cast into a `number`, but you can also pretty easily cast things into `boolean` too, and you can cast anything to `null`. + +There are other useful type casting options available. For example, something of type `datatable` can be cast to a type `pointseries` simply by only preserving specific columns from the data (namely x, y, size, color, and text). This allows you to treat your source data, which is generally of type `datatable`, like a `pointseries` type simply by convention. + +You can fetch data from Elasticsearch using `essql`, which allows you to aggregate the data, provide a custom name for the value, and insert that data directly to another function that only accepts `pointseries` even though `essql` will output a `datatable` type. This makes the following example expression valid: + +[source,text] +---- +essql "SELECT user AS x, sum(cost) AS y FROM index GROUP BY user" +| plot +---- + +In the docs you can see that `essql` returns a `datatable` type, but `plot` expects a `pointseries` context. This works because the `datatable` output will have the columns `x` and `y` as a result of using `AS` in the sql statement to name them. Because the data follows the convention of the `pointseries` data type, casting it into `pointseries` is possible, and it can be passed directly to `plot` as a result. diff --git a/docs/images/canvas-change-your-expression-chart-no-legend.png b/docs/images/canvas-change-your-expression-chart-no-legend.png new file mode 100644 index 0000000000000..f54437c1eba3c Binary files /dev/null and b/docs/images/canvas-change-your-expression-chart-no-legend.png differ diff --git a/docs/images/canvas-change-your-expression-chart.png b/docs/images/canvas-change-your-expression-chart.png new file mode 100755 index 0000000000000..4400ce4dfb2c3 Binary files /dev/null and b/docs/images/canvas-change-your-expression-chart.png differ diff --git a/docs/images/canvas-functions-can-take-arguments-donut-chart.png b/docs/images/canvas-functions-can-take-arguments-donut-chart.png new file mode 100644 index 0000000000000..d126830c4fdc9 Binary files /dev/null and b/docs/images/canvas-functions-can-take-arguments-donut-chart.png differ diff --git a/docs/images/canvas-functions-can-take-arguments-pie-chart.png b/docs/images/canvas-functions-can-take-arguments-pie-chart.png new file mode 100644 index 0000000000000..be923675bea80 Binary files /dev/null and b/docs/images/canvas-functions-can-take-arguments-pie-chart.png differ diff --git a/docs/maps/maps-aggregations.asciidoc b/docs/maps/maps-aggregations.asciidoc index 98aa21f6a07a3..627fd49dafa51 100644 --- a/docs/maps/maps-aggregations.asciidoc +++ b/docs/maps/maps-aggregations.asciidoc @@ -47,6 +47,7 @@ To enable top hits: . Set *Entity* to the field that identifies entities in your documents. This field will be used in the terms aggregation to group your documents into entity buckets. . Set *Documents per entity* to configure the maximum number of documents accumulated per entity. +This setting is limited to the `index.max_inner_result_window` index setting, which defaults to 100. [role="screenshot"] image::maps/images/top_hits.png[] diff --git a/docs/maps/vector-layer.asciidoc b/docs/maps/vector-layer.asciidoc index 1b9d0e6556f54..1d4ba9912529a 100644 --- a/docs/maps/vector-layer.asciidoc +++ b/docs/maps/vector-layer.asciidoc @@ -15,7 +15,7 @@ See map.regionmap.* in <> for details. *Documents*:: Vector data from a Kibana index pattern. The index must contain at least one field mapped as {ref}/geo-point.html[geo_point] or {ref}/geo-shape.html[geo_shape]. -NOTE: Document results are limited to the first 10000 matching documents. +NOTE: Document results are limited to the `index.max_result_window` index setting, which defaults to 10000. Use <> to plot large data sets. *Grid aggregation*:: Geospatial data grouped in grids with metrics for each gridded cell. diff --git a/docs/user/canvas.asciidoc b/docs/user/canvas.asciidoc index c58635ba97769..5c5f5c2f80bf9 100644 --- a/docs/user/canvas.asciidoc +++ b/docs/user/canvas.asciidoc @@ -37,6 +37,8 @@ include::{kib-repo-dir}/canvas/canvas-present-workpad.asciidoc[] include::{kib-repo-dir}/canvas/canvas-share-workpad.asciidoc[] +include::{kib-repo-dir}/canvas/canvas-expression-lifecycle.asciidoc[] + include::{kib-repo-dir}/canvas/canvas-function-reference.asciidoc[] -include::{kib-repo-dir}/canvas/canvas-tinymath-functions.asciidoc[] +include::{kib-repo-dir}/canvas/canvas-tinymath-functions.asciidoc[] \ No newline at end of file diff --git a/package.json b/package.json index 651ffb60d7b88..a0f5dd3af14c0 100644 --- a/package.json +++ b/package.json @@ -234,7 +234,7 @@ "react-resize-detector": "^4.2.0", "react-router-dom": "^5.1.2", "react-sizeme": "^2.3.6", - "react-use": "^13.10.2", + "react-use": "^13.13.0", "reactcss": "1.2.3", "redux": "4.0.0", "redux-actions": "2.2.1", diff --git a/src/legacy/core_plugins/console/server/api_server/es_6_0/filter.js b/src/legacy/core_plugins/console/server/api_server/es_6_0/filter.js index 2a1a903c8565f..bf669cff788e8 100644 --- a/src/legacy/core_plugins/console/server/api_server/es_6_0/filter.js +++ b/src/legacy/core_plugins/console/server/api_server/es_6_0/filter.js @@ -260,7 +260,7 @@ filters.range = { gt: 1, lte: 20, lt: 20, - time_zone: '+1:00', + time_zone: '+01:00', format: 'dd/MM/yyyy||yyyy', execution: { __one_of: ['index', 'fielddata'] }, }, diff --git a/src/legacy/core_plugins/console/server/api_server/es_6_0/query/dsl.js b/src/legacy/core_plugins/console/server/api_server/es_6_0/query/dsl.js index 3ff9bed848346..a5f0d15dee0e9 100644 --- a/src/legacy/core_plugins/console/server/api_server/es_6_0/query/dsl.js +++ b/src/legacy/core_plugins/console/server/api_server/es_6_0/query/dsl.js @@ -467,7 +467,7 @@ export function queryDsl(api) { __one_of: [true, false], }, tie_breaker: 0, - time_zone: '+1:00', + time_zone: '+01:00', }, simple_query_string: { __template: { @@ -493,7 +493,7 @@ export function queryDsl(api) { gt: 10, lte: 20, lt: 20, - time_zone: '+1:00', + time_zone: '+01:00', boost: 1.0, format: 'dd/MM/yyyy||yyyy', }, diff --git a/src/legacy/core_plugins/data/public/index.ts b/src/legacy/core_plugins/data/public/index.ts index 09881c00c63b6..4514d67ea5fcd 100644 --- a/src/legacy/core_plugins/data/public/index.ts +++ b/src/legacy/core_plugins/data/public/index.ts @@ -28,8 +28,6 @@ export function plugin() { /** @public types */ export { DataStart }; - -export { Field, FieldType, IFieldList, IndexPattern } from './index_patterns'; export { EsQuerySortValue, FetchOptions, ISearchSource, SortDirection } from './search/types'; export { SearchSourceFields } from './search/types'; export { @@ -41,5 +39,4 @@ export { /** @public static code */ export * from '../common'; export { FilterStateManager } from './filter/filter_manager'; -export { getFromSavedObject, getRoutes, flattenHitWrapper } from './index_patterns'; export { getRequestInspectorStats, getResponseInspectorStats } from './search'; diff --git a/src/legacy/core_plugins/data/public/index_patterns/index.ts b/src/legacy/core_plugins/data/public/index_patterns/index.ts deleted file mode 100644 index 96995c10e5469..0000000000000 --- a/src/legacy/core_plugins/data/public/index_patterns/index.ts +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 { IFieldType, indexPatterns } from '../../../../../plugins/data/public'; - -const getFromSavedObject = indexPatterns.getFromSavedObject; -const getRoutes = indexPatterns.getRoutes; -const flattenHitWrapper = indexPatterns.flattenHitWrapper; - -export { getFromSavedObject, getRoutes, flattenHitWrapper }; -export { IFieldType as FieldType }; -export { - Field, - IFieldList, - IndexPattern, - IndexPatternsContract, -} from '../../../../../plugins/data/public'; diff --git a/src/legacy/core_plugins/kbn_doc_views/public/views/json_code_block.test.tsx b/src/legacy/core_plugins/kbn_doc_views/public/views/json_code_block.test.tsx index 776971e57091d..ea11ea7b7df10 100644 --- a/src/legacy/core_plugins/kbn_doc_views/public/views/json_code_block.test.tsx +++ b/src/legacy/core_plugins/kbn_doc_views/public/views/json_code_block.test.tsx @@ -19,7 +19,7 @@ import React from 'react'; import { shallow } from 'enzyme'; import { JsonCodeBlock } from './json_code_block'; -import { IndexPattern } from 'ui/index_patterns'; +import { IndexPattern } from '../../../../../plugins/data/public'; it('returns the `JsonCodeEditor` component', () => { const props = { diff --git a/src/legacy/core_plugins/kbn_doc_views/public/views/table/table.test.tsx b/src/legacy/core_plugins/kbn_doc_views/public/views/table/table.test.tsx index 24efbc2d41f4f..91b98865a0207 100644 --- a/src/legacy/core_plugins/kbn_doc_views/public/views/table/table.test.tsx +++ b/src/legacy/core_plugins/kbn_doc_views/public/views/table/table.test.tsx @@ -18,12 +18,12 @@ */ import React from 'react'; import { mount } from 'enzyme'; -import { IndexPattern } from 'ui/index_patterns'; // @ts-ignore import { findTestSubject } from '@elastic/eui/lib/test'; -import { flattenHitWrapper } from '../../../../data/public/'; import { DocViewTable } from './table'; +import { IndexPattern, indexPatterns } from '../../../../../../plugins/data/public'; + jest.mock('ui/new_platform'); // @ts-ignore @@ -70,7 +70,7 @@ const indexPattern = { formatHit: jest.fn(hit => hit._source), } as IndexPattern; -indexPattern.flattenHit = flattenHitWrapper(indexPattern, indexPattern.metaFields); +indexPattern.flattenHit = indexPatterns.flattenHitWrapper(indexPattern, indexPattern.metaFields); describe('DocViewTable at Discover', () => { // At Discover's main view, all buttons are rendered diff --git a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app_controller.tsx b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app_controller.tsx index 5ba457b6c3362..08637174c8cec 100644 --- a/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app_controller.tsx +++ b/src/legacy/core_plugins/kibana/public/dashboard/np_ready/dashboard_app_controller.tsx @@ -39,8 +39,13 @@ import { unhashUrl, VISUALIZE_EMBEDDABLE_TYPE, } from '../legacy_imports'; -import { FilterStateManager, IndexPattern } from '../../../../data/public'; -import { Query, SavedQuery, IndexPatternsContract } from '../../../../../../plugins/data/public'; +import { FilterStateManager } from '../../../../data/public'; +import { + IndexPattern, + Query, + SavedQuery, + IndexPatternsContract, +} from '../../../../../../plugins/data/public'; import { DashboardContainer, diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/__jest__/render.test.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/__jest__/render.test.js index be4866f9dfdd4..375e80028f317 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/__jest__/render.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/__jest__/render.test.js @@ -22,12 +22,6 @@ const unmountComponentAtNode = jest.fn(); jest.doMock('react-dom', () => ({ render, unmountComponentAtNode })); -// If we don't mock this, Jest fails with the error `TypeError: Cannot redefine property: prototype -// at Function.defineProperties`. -jest.mock('ui/index_patterns', () => ({ - INDEX_PATTERN_ILLEGAL_CHARACTERS: ['\\', '/', '?', '"', '<', '>', '|', ' '], -})); - jest.mock('ui/chrome', () => ({ getUiSettingsClient: () => ({ get: () => '', diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/__jest__/step_index_pattern.test.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/__jest__/step_index_pattern.test.js index 1797fc203ccd8..85e610bbbf993 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/__jest__/step_index_pattern.test.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/__jest__/step_index_pattern.test.js @@ -32,11 +32,6 @@ const mockIndexPatternCreationType = { checkIndicesForErrors: () => false, getShowSystemIndices: () => false, }; -// If we don't mock this, Jest fails with the error `TypeError: Cannot redefine property: prototype -// at Function.defineProperties`. -jest.mock('ui/index_patterns', () => ({ - INDEX_PATTERN_ILLEGAL_CHARACTERS: ['\\', '/', '?', '"', '<', '>', '|', ' '], -})); jest.mock('ui/chrome', () => ({ getUiSettingsClient: () => ({ diff --git a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js index 4764b516dffec..c990efaf43547 100644 --- a/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js +++ b/src/legacy/core_plugins/kibana/public/management/sections/index_patterns/create_index_pattern_wizard/components/step_index_pattern/step_index_pattern.js @@ -19,7 +19,7 @@ import React, { Component } from 'react'; import PropTypes from 'prop-types'; -import { INDEX_PATTERN_ILLEGAL_CHARACTERS as ILLEGAL_CHARACTERS } from 'ui/index_patterns'; +import { indexPatterns } from '../../../../../../../../../../plugins/data/public'; import { MAX_SEARCH_SIZE } from '../../constants'; import { getIndices, @@ -71,7 +71,7 @@ export class StepIndexPattern extends Component { indexPatternName: indexPatternCreationType.getIndexPatternName(), }; - this.ILLEGAL_CHARACTERS = [...ILLEGAL_CHARACTERS]; + this.ILLEGAL_CHARACTERS = [...indexPatterns.ILLEGAL_CHARACTERS]; this.lastQuery = null; } @@ -243,7 +243,7 @@ export class StepIndexPattern extends Component { if (!query || !query.length || query === '.' || query === '..') { // This is an error scenario but do not report an error containsErrors = true; - } else if (containsIllegalCharacters(query, ILLEGAL_CHARACTERS)) { + } else if (containsIllegalCharacters(query, indexPatterns.ILLEGAL_CHARACTERS)) { const errorMessage = i18n.translate( 'kbn.management.createIndexPattern.step.invalidCharactersErrorMessage', { diff --git a/src/legacy/ui/public/agg_types/agg_configs.ts b/src/legacy/ui/public/agg_types/agg_configs.ts index ece9c90d09b68..6e811afb1849d 100644 --- a/src/legacy/ui/public/agg_types/agg_configs.ts +++ b/src/legacy/ui/public/agg_types/agg_configs.ts @@ -31,7 +31,7 @@ import { TimeRange } from 'src/plugins/data/public'; import { Schema } from '../vis/editors/default/schemas'; import { AggConfig, AggConfigOptions } from './agg_config'; import { AggGroupNames } from '../vis/editors/default/agg_groups'; -import { IndexPattern } from '../../../core_plugins/data/public'; +import { IndexPattern } from '../../../../plugins/data/public'; import { ISearchSource, FetchOptions } from '../courier/types'; type Schemas = Record; diff --git a/src/legacy/ui/public/agg_types/filter/agg_type_filters.test.ts b/src/legacy/ui/public/agg_types/filter/agg_type_filters.test.ts index f470ebbc90b48..517cee23e6be1 100644 --- a/src/legacy/ui/public/agg_types/filter/agg_type_filters.test.ts +++ b/src/legacy/ui/public/agg_types/filter/agg_type_filters.test.ts @@ -17,7 +17,7 @@ * under the License. */ -import { IndexPattern } from 'ui/index_patterns'; +import { IndexPattern } from '../../../../../plugins/data/public'; import { AggTypeFilters } from './agg_type_filters'; import { AggType } from '..'; import { AggConfig } from '../../vis'; diff --git a/src/legacy/ui/public/agg_types/filter/agg_type_filters.ts b/src/legacy/ui/public/agg_types/filter/agg_type_filters.ts index 4d99575e4ae38..2388d458d4abb 100644 --- a/src/legacy/ui/public/agg_types/filter/agg_type_filters.ts +++ b/src/legacy/ui/public/agg_types/filter/agg_type_filters.ts @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -import { IndexPattern } from '../../index_patterns'; +import { IndexPattern } from '../../../../../plugins/data/public'; import { AggConfig } from '../../vis'; import { AggType } from '..'; diff --git a/src/legacy/ui/public/agg_types/param_types/field.ts b/src/legacy/ui/public/agg_types/param_types/field.ts index 4fda86bd1379f..0ca60267becec 100644 --- a/src/legacy/ui/public/agg_types/param_types/field.ts +++ b/src/legacy/ui/public/agg_types/param_types/field.ts @@ -25,7 +25,7 @@ import { FieldParamEditor } from '../../vis/editors/default/controls/field'; import { BaseParamType } from './base'; import { toastNotifications } from '../../notify'; import { propFilter } from '../filter'; -import { Field, IFieldList } from '../../index_patterns'; +import { Field, IFieldList } from '../../../../../plugins/data/public'; const filterByType = propFilter('type'); diff --git a/src/legacy/ui/public/agg_types/param_types/filter/field_filters.test.ts b/src/legacy/ui/public/agg_types/param_types/filter/field_filters.test.ts index e8d53754f6682..978b7edaa83ff 100644 --- a/src/legacy/ui/public/agg_types/param_types/filter/field_filters.test.ts +++ b/src/legacy/ui/public/agg_types/param_types/filter/field_filters.test.ts @@ -17,10 +17,10 @@ * under the License. */ -import { Field } from 'ui/index_patterns'; import { IndexedArray } from 'ui/indexed_array'; import { AggTypeFieldFilters } from './field_filters'; import { AggConfig } from 'ui/vis'; +import { Field } from '../../../../../../plugins/data/public'; describe('AggTypeFieldFilters', () => { let registry: AggTypeFieldFilters; diff --git a/src/legacy/ui/public/agg_types/param_types/filter/field_filters.ts b/src/legacy/ui/public/agg_types/param_types/filter/field_filters.ts index b3dbcf05681db..e5cb5226435ff 100644 --- a/src/legacy/ui/public/agg_types/param_types/filter/field_filters.ts +++ b/src/legacy/ui/public/agg_types/param_types/filter/field_filters.ts @@ -16,8 +16,8 @@ * specific language governing permissions and limitations * under the License. */ -import { Field } from 'ui/index_patterns'; import { AggConfig } from '../../../vis'; +import { Field } from '../../../../../../plugins/data/public'; type AggTypeFieldFilter = (field: Field, aggConfig: AggConfig) => boolean; diff --git a/src/legacy/ui/public/index_patterns/__mocks__/index.ts b/src/legacy/ui/public/index_patterns/__mocks__/index.ts deleted file mode 100644 index 0cb1cf897b166..0000000000000 --- a/src/legacy/ui/public/index_patterns/__mocks__/index.ts +++ /dev/null @@ -1,25 +0,0 @@ -/* - * 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 { indexPatterns as npIndexPatterns } from '../../../../../plugins/data/public'; - -export const flattenHitWrapper = npIndexPatterns.flattenHitWrapper; - -// static code -export { getFromSavedObject, getRoutes } from '../../../../core_plugins/data/public'; diff --git a/src/legacy/ui/public/index_patterns/index.ts b/src/legacy/ui/public/index_patterns/index.ts deleted file mode 100644 index 47f6e697c54e9..0000000000000 --- a/src/legacy/ui/public/index_patterns/index.ts +++ /dev/null @@ -1,40 +0,0 @@ -/* - * 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. - */ - -/** - * Nothing to see here! - * - * Index Patterns have moved to the data plugin, and are being re-exported - * from ui/index_patterns for backwards compatibility. - */ - -import { indexPatterns } from '../../../../plugins/data/public'; - -// static code -export const INDEX_PATTERN_ILLEGAL_CHARACTERS = indexPatterns.ILLEGAL_CHARACTERS; -export const INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE = indexPatterns.ILLEGAL_CHARACTERS_VISIBLE; -export const ILLEGAL_CHARACTERS = indexPatterns.ILLEGAL_CHARACTERS_KEY; -export const CONTAINS_SPACES = indexPatterns.CONTAINS_SPACES_KEY; -export const validateIndexPattern = indexPatterns.validate; -export const flattenHitWrapper = indexPatterns.flattenHitWrapper; -export const getFromSavedObject = indexPatterns.getFromSavedObject; -export const getRoutes = indexPatterns.getRoutes; - -// types -export { Field, FieldType, IFieldList, IndexPattern } from '../../../core_plugins/data/public'; diff --git a/src/legacy/ui/public/indices/constants/index.js b/src/legacy/ui/public/indices/constants/index.js index 87d36d1c6d14a..72ecc2e4c87de 100644 --- a/src/legacy/ui/public/indices/constants/index.js +++ b/src/legacy/ui/public/indices/constants/index.js @@ -17,11 +17,11 @@ * under the License. */ -import { INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE } from '../../index_patterns'; +import { indexPatterns } from '../../../../../plugins/data/public'; -export const INDEX_ILLEGAL_CHARACTERS_VISIBLE = [...INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE, '*']; +export const INDEX_ILLEGAL_CHARACTERS_VISIBLE = [...indexPatterns.ILLEGAL_CHARACTERS_VISIBLE, '*']; // Insert the comma into the middle, so it doesn't look as if it has grammatical meaning when // these characters are rendered in the UI. -const insertionIndex = Math.floor(INDEX_PATTERN_ILLEGAL_CHARACTERS_VISIBLE.length / 2); +const insertionIndex = Math.floor(indexPatterns.ILLEGAL_CHARACTERS_VISIBLE.length / 2); INDEX_ILLEGAL_CHARACTERS_VISIBLE.splice(insertionIndex, 0, ','); diff --git a/src/legacy/ui/public/registry/doc_views_types.ts b/src/legacy/ui/public/registry/doc_views_types.ts index f078f374b4579..eb2a5bdc4b3b7 100644 --- a/src/legacy/ui/public/registry/doc_views_types.ts +++ b/src/legacy/ui/public/registry/doc_views_types.ts @@ -16,9 +16,9 @@ * specific language governing permissions and limitations * under the License. */ -import { IndexPattern } from 'src/legacy/core_plugins/data/public'; import { ComponentType } from 'react'; import { IScope } from 'angular'; +import { IndexPattern } from '../../../../plugins/data/public'; export interface AngularDirective { controller: (scope: AngularScope) => void; diff --git a/src/legacy/ui/public/saved_objects/helpers/apply_es_resp.ts b/src/legacy/ui/public/saved_objects/helpers/apply_es_resp.ts index bec0a1d96ba92..ee49b7495f2af 100644 --- a/src/legacy/ui/public/saved_objects/helpers/apply_es_resp.ts +++ b/src/legacy/ui/public/saved_objects/helpers/apply_es_resp.ts @@ -20,7 +20,7 @@ import _ from 'lodash'; import { EsResponse, SavedObject, SavedObjectConfig } from 'ui/saved_objects/types'; import { parseSearchSource } from 'ui/saved_objects/helpers/parse_search_source'; import { expandShorthand, SavedObjectNotFound } from '../../../../../plugins/kibana_utils/public'; -import { IndexPattern } from '../../../../core_plugins/data/public'; +import { IndexPattern } from '../../../../../plugins/data/public'; /** * A given response of and ElasticSearch containing a plain saved object is applied to the given diff --git a/src/legacy/ui/public/vis/editors/config/editor_config_providers.ts b/src/legacy/ui/public/vis/editors/config/editor_config_providers.ts index 3dd911efc324c..31fc0d90be101 100644 --- a/src/legacy/ui/public/vis/editors/config/editor_config_providers.ts +++ b/src/legacy/ui/public/vis/editors/config/editor_config_providers.ts @@ -20,7 +20,7 @@ import { TimeIntervalParam } from 'ui/vis/editors/config/types'; import { AggConfig } from '../..'; import { AggType } from '../../../agg_types'; -import { IndexPattern } from '../../../index_patterns'; +import { IndexPattern } from '../../../../../../plugins/data/public'; import { leastCommonMultiple } from '../../../utils/math'; import { parseEsInterval } from '../../../../../core_plugins/data/public'; import { leastCommonInterval } from '../../lib/least_common_interval'; diff --git a/src/legacy/ui/public/vis/editors/default/components/agg.test.tsx b/src/legacy/ui/public/vis/editors/default/components/agg.test.tsx index 661ece5944fa3..c19f101fa2c32 100644 --- a/src/legacy/ui/public/vis/editors/default/components/agg.test.tsx +++ b/src/legacy/ui/public/vis/editors/default/components/agg.test.tsx @@ -24,8 +24,8 @@ import { AggGroupNames } from '../agg_groups'; import { DefaultEditorAgg, DefaultEditorAggProps } from './agg'; import { act } from 'react-dom/test-utils'; import { DefaultEditorAggParams } from './agg_params'; -import { IndexPattern } from 'ui/index_patterns'; import { AggType } from 'ui/agg_types'; +import { IndexPattern } from '../../../../../../../plugins/data/public'; jest.mock('./agg_params', () => ({ DefaultEditorAggParams: () => null, diff --git a/src/legacy/ui/public/vis/editors/default/components/agg_param_props.ts b/src/legacy/ui/public/vis/editors/default/components/agg_param_props.ts index aafba008f97c5..df77ea9e43eab 100644 --- a/src/legacy/ui/public/vis/editors/default/components/agg_param_props.ts +++ b/src/legacy/ui/public/vis/editors/default/components/agg_param_props.ts @@ -17,13 +17,13 @@ * under the License. */ -import { Field } from 'ui/index_patterns'; import { AggParam } from 'ui/agg_types'; import { AggConfig } from '../../../../agg_types/agg_config'; import { ComboBoxGroupedOptions } from '../utils'; import { EditorConfig } from '../../config/types'; import { VisState } from '../../..'; import { SubAggParamsProp } from './agg_params'; +import { Field } from '../../../../../../../plugins/data/public'; // NOTE: we cannot export the interface with export { InterfaceName } // as there is currently a bug on babel typescript transform plugin for it diff --git a/src/legacy/ui/public/vis/editors/default/components/agg_params.test.tsx b/src/legacy/ui/public/vis/editors/default/components/agg_params.test.tsx index 25e2db8ef1836..9f3f5bff3f56e 100644 --- a/src/legacy/ui/public/vis/editors/default/components/agg_params.test.tsx +++ b/src/legacy/ui/public/vis/editors/default/components/agg_params.test.tsx @@ -19,9 +19,9 @@ import React from 'react'; import { mount, shallow } from 'enzyme'; -import { IndexPattern } from 'ui/index_patterns'; import { AggConfig, VisState } from '../../..'; import { DefaultEditorAggParams, DefaultEditorAggParamsProps } from './agg_params'; +import { IndexPattern } from '../../../../../../../plugins/data/public'; const mockEditorConfig = { useNormalizedEsInterval: { hidden: false, fixedValue: false }, diff --git a/src/legacy/ui/public/vis/editors/default/components/agg_params.tsx b/src/legacy/ui/public/vis/editors/default/components/agg_params.tsx index 4f4c0bda6520a..c62e2837908c7 100644 --- a/src/legacy/ui/public/vis/editors/default/components/agg_params.tsx +++ b/src/legacy/ui/public/vis/editors/default/components/agg_params.tsx @@ -20,10 +20,11 @@ import React, { useReducer, useEffect, useMemo } from 'react'; import { EuiForm, EuiAccordion, EuiSpacer, EuiFormRow } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; +import useUnmount from 'react-use/lib/useUnmount'; import { VisState } from 'ui/vis'; import { aggTypes, AggType, AggParam, AggConfig } from 'ui/agg_types/'; -import { IndexPattern } from 'ui/index_patterns'; +import { IndexPattern } from '../../../../../../../plugins/data/public'; import { DefaultEditorAggSelect } from './agg_select'; import { DefaultEditorAggParam } from './agg_param'; @@ -44,9 +45,6 @@ import { } from './agg_params_state'; import { editorConfigProviders } from '../../config/editor_config_providers'; import { FixedParam, TimeIntervalParam, EditorParamConfig } from '../../config/types'; -// TODO: Below import is temporary, use `react-use` lib instead. -// eslint-disable-next-line @kbn/eslint/no-restricted-paths -import { useUnmount } from '../../../../../../../plugins/kibana_react/public/util/use_unmount'; import { AggGroupNames } from '../agg_groups'; import { OnAggParamsChange } from './agg_common_props'; diff --git a/src/legacy/ui/public/vis/editors/default/components/agg_params_helper.test.ts b/src/legacy/ui/public/vis/editors/default/components/agg_params_helper.test.ts index eb6bef4887642..fb37dd5d94618 100644 --- a/src/legacy/ui/public/vis/editors/default/components/agg_params_helper.test.ts +++ b/src/legacy/ui/public/vis/editors/default/components/agg_params_helper.test.ts @@ -19,7 +19,6 @@ import { AggConfig, VisState } from '../../..'; import { AggType } from 'ui/agg_types'; -import { IndexPattern, Field } from 'ui/index_patterns'; import { IndexedArray } from 'ui/indexed_array'; import { getAggParamsToRender, @@ -28,6 +27,7 @@ import { isInvalidParamsTouched, } from './agg_params_helper'; import { EditorConfig } from '../../config/types'; +import { IndexPattern, Field } from '../../../../../../../plugins/data/public'; jest.mock('ui/agg_types', () => ({ aggTypes: { diff --git a/src/legacy/ui/public/vis/editors/default/components/agg_params_helper.ts b/src/legacy/ui/public/vis/editors/default/components/agg_params_helper.ts index d233f561940da..e0e014f69ef3f 100644 --- a/src/legacy/ui/public/vis/editors/default/components/agg_params_helper.ts +++ b/src/legacy/ui/public/vis/editors/default/components/agg_params_helper.ts @@ -20,7 +20,6 @@ import { get, isEmpty } from 'lodash'; import { i18n } from '@kbn/i18n'; import { aggTypeFilters } from 'ui/agg_types/filter'; -import { IndexPattern, Field } from 'ui/index_patterns'; import { aggTypes, AggParam, FieldParamType, AggType } from 'ui/agg_types'; import { aggTypeFieldFilters } from 'ui/agg_types/param_types/filter'; import { AggConfig, VisState } from '../../..'; @@ -28,6 +27,7 @@ import { groupAndSortBy, ComboBoxGroupedOptions } from '../utils'; import { EditorConfig } from '../../config/types'; import { AggTypeState, AggParamsState } from './agg_params_state'; import { AggParamEditorProps } from './agg_param_props'; +import { IndexPattern, Field } from '../../../../../../../plugins/data/public'; interface ParamInstanceBase { agg: AggConfig; diff --git a/src/legacy/ui/public/vis/editors/default/components/agg_select.tsx b/src/legacy/ui/public/vis/editors/default/components/agg_select.tsx index 2934711b2357a..443c655912a55 100644 --- a/src/legacy/ui/public/vis/editors/default/components/agg_select.tsx +++ b/src/legacy/ui/public/vis/editors/default/components/agg_select.tsx @@ -23,9 +23,9 @@ import { EuiComboBox, EuiComboBoxOptionProps, EuiFormRow, EuiLink, EuiText } fro import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; import { AggType } from 'ui/agg_types'; -import { IndexPattern } from 'ui/index_patterns'; import { documentationLinks } from '../../../../documentation_links/documentation_links'; import { ComboBoxGroupedOptions } from '../utils'; +import { IndexPattern } from '../../../../../../../plugins/data/public'; interface DefaultEditorAggSelectProps { aggError?: string; diff --git a/src/legacy/ui/public/vis/editors/default/controls/field.test.tsx b/src/legacy/ui/public/vis/editors/default/controls/field.test.tsx index aac32e28c80a5..4d15ac8e80e63 100644 --- a/src/legacy/ui/public/vis/editors/default/controls/field.test.tsx +++ b/src/legacy/ui/public/vis/editors/default/controls/field.test.tsx @@ -21,7 +21,7 @@ import React from 'react'; import { act } from 'react-dom/test-utils'; import { mount, shallow, ReactWrapper } from 'enzyme'; import { EuiComboBoxProps, EuiComboBox } from '@elastic/eui'; -import { Field } from '../../../../index_patterns'; +import { Field } from '../../../../../../../plugins/data/public'; import { ComboBoxGroupedOptions, SubAggParamsProp } from '..'; import { FieldParamEditor, FieldParamEditorProps } from './field'; import { AggConfig, VisState } from '../../..'; diff --git a/src/legacy/ui/public/vis/editors/default/controls/field.tsx b/src/legacy/ui/public/vis/editors/default/controls/field.tsx index a96be3a14b7ef..75a9e24cd0dee 100644 --- a/src/legacy/ui/public/vis/editors/default/controls/field.tsx +++ b/src/legacy/ui/public/vis/editors/default/controls/field.tsx @@ -23,7 +23,7 @@ import React, { useEffect } from 'react'; import { EuiComboBox, EuiComboBoxOptionProps, EuiFormRow } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { AggConfig } from '../../..'; -import { Field } from '../../../../index_patterns'; +import { Field } from '../../../../../../../plugins/data/public'; import { formatListAsProse, parseCommaSeparatedList } from '../../../../../../utils'; import { AggParam, FieldParamType } from '../../../../agg_types'; import { AggParamEditorProps, ComboBoxGroupedOptions } from '..'; diff --git a/src/legacy/ui/public/vis/editors/default/controls/top_field.tsx b/src/legacy/ui/public/vis/editors/default/controls/top_field.tsx index 5a5f2ceee3a56..e15187621954f 100644 --- a/src/legacy/ui/public/vis/editors/default/controls/top_field.tsx +++ b/src/legacy/ui/public/vis/editors/default/controls/top_field.tsx @@ -19,7 +19,7 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; -import { Field } from '../../../../index_patterns'; +import { Field } from '../../../../../../../plugins/data/public'; import { FieldParamEditor } from './field'; import { getCompatibleAggs } from './top_aggregate'; import { AggParamEditorProps } from '..'; diff --git a/src/legacy/ui/public/vis/editors/default/controls/top_sort_field.tsx b/src/legacy/ui/public/vis/editors/default/controls/top_sort_field.tsx index 4116ae878209e..905bd052ec695 100644 --- a/src/legacy/ui/public/vis/editors/default/controls/top_sort_field.tsx +++ b/src/legacy/ui/public/vis/editors/default/controls/top_sort_field.tsx @@ -19,7 +19,7 @@ import React from 'react'; import { i18n } from '@kbn/i18n'; -import { Field } from '../../../../index_patterns'; +import { Field } from '../../../../../../../plugins/data/public'; import { FieldParamEditor } from './field'; import { AggParamEditorProps } from '..'; diff --git a/src/legacy/ui/public/vis/editors/default/vis_type_agg_filter.ts b/src/legacy/ui/public/vis/editors/default/vis_type_agg_filter.ts index 5842d7579f60a..c64907fff58a1 100644 --- a/src/legacy/ui/public/vis/editors/default/vis_type_agg_filter.ts +++ b/src/legacy/ui/public/vis/editors/default/vis_type_agg_filter.ts @@ -18,7 +18,7 @@ */ import { AggType } from '../../../agg_types'; import { aggTypeFilters, propFilter } from '../../../agg_types/filter'; -import { IndexPattern } from '../../../index_patterns'; +import { IndexPattern } from '../../../../../../plugins/data/public'; import { AggConfig } from '../../../vis'; const filterByName = propFilter('name'); diff --git a/src/plugins/data/public/query/timefilter/timefilter.ts b/src/plugins/data/public/query/timefilter/timefilter.ts index 639f3f4a66f18..58806a9328b1c 100644 --- a/src/plugins/data/public/query/timefilter/timefilter.ts +++ b/src/plugins/data/public/query/timefilter/timefilter.ts @@ -20,13 +20,13 @@ import _ from 'lodash'; import { Subject, BehaviorSubject } from 'rxjs'; import moment from 'moment'; -import { IndexPattern } from 'src/legacy/core_plugins/data/public'; import { areRefreshIntervalsDifferent, areTimeRangesDifferent } from './lib/diff_time_picker_vals'; import { parseQueryString } from './lib/parse_querystring'; import { calculateBounds, getTime } from './get_time'; import { TimefilterConfig, InputTimeRange, TimeRangeBounds } from './types'; import { RefreshInterval, TimeRange } from '../../../common'; import { TimeHistoryContract } from './time_history'; +import { IndexPattern } from '../../index_patterns'; // TODO: remove! diff --git a/src/plugins/es_ui_shared/static/forms/helpers/field_validators/index_pattern_field.ts b/src/plugins/es_ui_shared/static/forms/helpers/field_validators/index_pattern_field.ts index 7f178eabdcd19..48702a32bfde8 100644 --- a/src/plugins/es_ui_shared/static/forms/helpers/field_validators/index_pattern_field.ts +++ b/src/plugins/es_ui_shared/static/forms/helpers/field_validators/index_pattern_field.ts @@ -16,12 +16,13 @@ * specific language governing permissions and limitations * under the License. */ -import { ILLEGAL_CHARACTERS, validateIndexPattern } from 'ui/index_patterns'; import { ValidationFunc } from '../../hook_form_lib'; import { containsChars } from '../../../validators/string'; import { ERROR_CODE } from './types'; +import { indexPatterns } from '../../../../../data/public'; + export const indexPatternField = (i18n: any) => ( ...args: Parameters ): ReturnType> => { @@ -45,9 +46,9 @@ export const indexPatternField = (i18n: any) => ( } // Validate illegal characters - const errors = validateIndexPattern(value); + const errors = indexPatterns.validate(value); - if (errors[ILLEGAL_CHARACTERS]) { + if (errors[indexPatterns.ILLEGAL_CHARACTERS_KEY]) { return { code: 'ERR_FIELD_FORMAT', formatType: 'INDEX_PATTERN', @@ -55,8 +56,8 @@ export const indexPatternField = (i18n: any) => ( defaultMessage: 'The index pattern contains the invalid {characterListLength, plural, one {character} other {characters}} { characterList }.', values: { - characterList: errors[ILLEGAL_CHARACTERS].join(' '), - characterListLength: errors[ILLEGAL_CHARACTERS].length, + characterList: errors[indexPatterns.ILLEGAL_CHARACTERS_KEY].join(' '), + characterListLength: errors[indexPatterns.ILLEGAL_CHARACTERS_KEY].length, }, }), }; diff --git a/src/plugins/expressions/public/expression_renderer.tsx b/src/plugins/expressions/public/expression_renderer.tsx index 3989f4ed7d698..5c04d8405479f 100644 --- a/src/plugins/expressions/public/expression_renderer.tsx +++ b/src/plugins/expressions/public/expression_renderer.tsx @@ -22,9 +22,9 @@ import React from 'react'; import classNames from 'classnames'; import { Subscription } from 'rxjs'; import { filter } from 'rxjs/operators'; +import useShallowCompareEffect from 'react-use/lib/useShallowCompareEffect'; import { EuiLoadingChart, EuiProgress } from '@elastic/eui'; import theme from '@elastic/eui/dist/eui_theme_light.json'; -import { useShallowCompareEffect } from '../../kibana_react/public'; import { IExpressionLoaderParams, IInterpreterRenderHandlers, RenderError } from './types'; import { ExpressionAST } from '../common/types'; import { ExpressionLoader } from './loader'; diff --git a/src/plugins/kibana_react/public/index.ts b/src/plugins/kibana_react/public/index.ts index 258b0e94ef955..10b7dd2b4da44 100644 --- a/src/plugins/kibana_react/public/index.ts +++ b/src/plugins/kibana_react/public/index.ts @@ -25,4 +25,4 @@ export * from './overlays'; export * from './ui_settings'; export * from './field_icon'; export * from './table_list_view'; -export { toMountPoint, useObservable, useShallowCompareEffect } from './util'; +export { toMountPoint } from './util'; diff --git a/src/plugins/kibana_react/public/ui_settings/use_ui_setting.test.tsx b/src/plugins/kibana_react/public/ui_settings/use_ui_setting.test.tsx index 0879b0cb3f36a..db6d92a12841a 100644 --- a/src/plugins/kibana_react/public/ui_settings/use_ui_setting.test.tsx +++ b/src/plugins/kibana_react/public/ui_settings/use_ui_setting.test.tsx @@ -24,10 +24,10 @@ import { useUiSetting$ } from './use_ui_setting'; import { createKibanaReactContext } from '../context'; import { KibanaServices } from '../context/types'; import { Subject } from 'rxjs'; -import { useObservable } from '../util/use_observable'; import { coreMock } from '../../../../core/public/mocks'; +import useObservable from 'react-use/lib/useObservable'; -jest.mock('../util/use_observable'); +jest.mock('react-use/lib/useObservable'); const useObservableSpy = (useObservable as any) as jest.SpyInstance; useObservableSpy.mockImplementation((observable, def) => def); diff --git a/src/plugins/kibana_react/public/ui_settings/use_ui_setting.ts b/src/plugins/kibana_react/public/ui_settings/use_ui_setting.ts index 295515bfa51af..a8bc01bb8d2c4 100644 --- a/src/plugins/kibana_react/public/ui_settings/use_ui_setting.ts +++ b/src/plugins/kibana_react/public/ui_settings/use_ui_setting.ts @@ -18,8 +18,8 @@ */ import { useCallback, useMemo } from 'react'; +import useObservable from 'react-use/lib/useObservable'; import { useKibana } from '../context'; -import { useObservable } from '../util/use_observable'; /** * Returns the current UI-settings value. diff --git a/src/plugins/kibana_react/public/util/index.ts b/src/plugins/kibana_react/public/util/index.ts index 4f64d6c9c81ab..71a281dbdaad3 100644 --- a/src/plugins/kibana_react/public/util/index.ts +++ b/src/plugins/kibana_react/public/util/index.ts @@ -17,7 +17,4 @@ * under the License. */ -export * from './use_observable'; -export * from './use_unmount'; export * from './react_mount'; -export * from './use_shallow_compare_effect'; diff --git a/src/plugins/kibana_react/public/util/use_observable.test.tsx b/src/plugins/kibana_react/public/util/use_observable.test.tsx deleted file mode 100644 index 2dfbea06ecbb3..0000000000000 --- a/src/plugins/kibana_react/public/util/use_observable.test.tsx +++ /dev/null @@ -1,54 +0,0 @@ -/* - * 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 { renderHook, act } from '@testing-library/react-hooks'; -import { Subject } from 'rxjs'; -import { useObservable } from './use_observable'; - -test('default initial value is undefined', () => { - const subject$ = new Subject(); - const { result } = renderHook(() => useObservable(subject$)); - - expect(result.current).toBe(undefined); -}); - -test('can specify initial value', () => { - const subject$ = new Subject(); - const { result } = renderHook(() => useObservable(subject$, 123)); - - expect(result.current).toBe(123); -}); - -test('returns the latest value of observables', () => { - const subject$ = new Subject(); - const { result } = renderHook(() => useObservable(subject$, 123)); - - act(() => { - subject$.next(125); - }); - expect(result.current).toBe(125); - - act(() => { - subject$.next(300); - subject$.next(400); - }); - expect(result.current).toBe(400); -}); - -xtest('subscribes to observable only once', () => {}); diff --git a/src/plugins/kibana_react/public/util/use_observable.ts b/src/plugins/kibana_react/public/util/use_observable.ts deleted file mode 100644 index 6a7ce1f5290d2..0000000000000 --- a/src/plugins/kibana_react/public/util/use_observable.ts +++ /dev/null @@ -1,34 +0,0 @@ -/* - * 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 { useLayoutEffect, useState } from 'react'; -import { Observable } from 'rxjs'; - -export function useObservable(observable$: Observable): T | undefined; -export function useObservable(observable$: Observable, initialValue: T): T; -export function useObservable(observable$: Observable, initialValue?: T): T | undefined { - const [value, update] = useState(initialValue); - - useLayoutEffect(() => { - const s = observable$.subscribe(update); - return () => s.unsubscribe(); - }, [observable$]); - - return value; -} diff --git a/src/plugins/kibana_react/public/util/use_shallow_compare_effect.test.ts b/src/plugins/kibana_react/public/util/use_shallow_compare_effect.test.ts deleted file mode 100644 index 810c727fcdb0b..0000000000000 --- a/src/plugins/kibana_react/public/util/use_shallow_compare_effect.test.ts +++ /dev/null @@ -1,86 +0,0 @@ -/* - * 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 { renderHook } from '@testing-library/react-hooks'; -import { useShallowCompareEffect } from './use_shallow_compare_effect'; - -describe('useShallowCompareEffect', () => { - test("doesn't run effect on shallow change", () => { - const callback = jest.fn(); - let deps = [1, { a: 'b' }, true]; - const { rerender } = renderHook(() => useShallowCompareEffect(callback, deps)); - - expect(callback).toHaveBeenCalledTimes(1); - callback.mockClear(); - - // no change - rerender(); - expect(callback).toHaveBeenCalledTimes(0); - callback.mockClear(); - - // no-change (new object with same properties) - deps = [1, { a: 'b' }, true]; - rerender(); - expect(callback).toHaveBeenCalledTimes(0); - callback.mockClear(); - - // change (new primitive value) - deps = [2, { a: 'b' }, true]; - rerender(); - expect(callback).toHaveBeenCalledTimes(1); - callback.mockClear(); - - // no-change - rerender(); - expect(callback).toHaveBeenCalledTimes(0); - callback.mockClear(); - - // change (new primitive value) - deps = [1, { a: 'b' }, false]; - rerender(); - expect(callback).toHaveBeenCalledTimes(1); - callback.mockClear(); - - // change (new properties on object) - deps = [1, { a: 'c' }, false]; - rerender(); - expect(callback).toHaveBeenCalledTimes(1); - callback.mockClear(); - }); - - test('runs effect on deep change', () => { - const callback = jest.fn(); - let deps = [1, { a: { b: 'c' } }, true]; - const { rerender } = renderHook(() => useShallowCompareEffect(callback, deps)); - - expect(callback).toHaveBeenCalledTimes(1); - callback.mockClear(); - - // no change - rerender(); - expect(callback).toHaveBeenCalledTimes(0); - callback.mockClear(); - - // change (new nested object ) - deps = [1, { a: { b: 'c' } }, true]; - rerender(); - expect(callback).toHaveBeenCalledTimes(1); - callback.mockClear(); - }); -}); diff --git a/src/plugins/kibana_react/public/util/use_shallow_compare_effect.ts b/src/plugins/kibana_react/public/util/use_shallow_compare_effect.ts deleted file mode 100644 index dfba7b907f5fb..0000000000000 --- a/src/plugins/kibana_react/public/util/use_shallow_compare_effect.ts +++ /dev/null @@ -1,80 +0,0 @@ -/* - * 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, { useEffect, useRef } from 'react'; - -/** - * Similar to https://github.com/kentcdodds/use-deep-compare-effect - * but uses shallow compare instead of deep - */ -export function useShallowCompareEffect( - callback: React.EffectCallback, - deps: React.DependencyList -) { - useEffect(callback, useShallowCompareMemoize(deps)); -} -function useShallowCompareMemoize(deps: React.DependencyList) { - const ref = useRef(undefined); - - if (!ref.current || deps.some((dep, index) => !shallowEqual(dep, ref.current![index]))) { - ref.current = deps; - } - - return ref.current; -} -// https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/shallowEqual.js -function shallowEqual(objA: any, objB: any): boolean { - if (is(objA, objB)) { - return true; - } - - if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) { - return false; - } - - const keysA = Object.keys(objA); - const keysB = Object.keys(objB); - - if (keysA.length !== keysB.length) { - return false; - } - - // Test for A's keys different from B. - for (let i = 0; i < keysA.length; i++) { - if ( - !Object.prototype.hasOwnProperty.call(objB, keysA[i]) || - !is(objA[keysA[i]], objB[keysA[i]]) - ) { - return false; - } - } - - return true; -} - -/** - * IE11 does not support Object.is - */ -function is(x: any, y: any): boolean { - if (x === y) { - return x !== 0 || y !== 0 || 1 / x === 1 / y; - } else { - return x !== x && y !== y; - } -} diff --git a/src/plugins/kibana_react/public/util/use_unmount.ts b/src/plugins/kibana_react/public/util/use_unmount.ts deleted file mode 100644 index 009bf8c4caa1c..0000000000000 --- a/src/plugins/kibana_react/public/util/use_unmount.ts +++ /dev/null @@ -1,24 +0,0 @@ -/* - * 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 { useEffect } from 'react'; - -export function useUnmount(fn: () => void): void { - useEffect(() => fn, []); -} diff --git a/test/common/fixtures/plugins/newsfeed/newsfeed_simulation.ts b/test/common/fixtures/plugins/newsfeed/newsfeed_simulation.ts index 2a7ea3793324d..4bf92868b0eca 100644 --- a/test/common/fixtures/plugins/newsfeed/newsfeed_simulation.ts +++ b/test/common/fixtures/plugins/newsfeed/newsfeed_simulation.ts @@ -88,7 +88,7 @@ const mockNewsfeed = (version: string) => ({ badge: null, image_url: null, publish_on: '2019-06-21T00:00:00', - expire_on: '2019-12-31T00:00:00', + expire_on: '2040-01-31T00:00:00', hash: '39ca7d409c7eb25f4c69a5a6a11309b2f5ced7ca3f9b3a0109517126e0fd91ca', }, { @@ -100,6 +100,18 @@ const mockNewsfeed = (version: string) => ({ badge: null, image_url: null, publish_on: '2019-06-21T00:00:00', + expire_on: '2040-01-31T00:00:00', + hash: 'db445c9443eb50ea2eb15f20edf89cf0f7dac2b058b11cafc2c8c288b6e4ce2a', + }, + { + title: { en: 'This item is expired!' }, + description: { en: 'This should not show up.' }, + link_text: { en: 'Generic feed-viewer could go here' }, + link_url: { en: 'https://feeds-staging.elastic.co' }, + languages: null, + badge: null, + image_url: null, + publish_on: '2019-06-21T00:00:00', expire_on: '2019-12-31T00:00:00', hash: 'db445c9443eb50ea2eb15f20edf89cf0f7dac2b058b11cafc2c8c288b6e4ce2a', }, diff --git a/test/functional/apps/home/_newsfeed.ts b/test/functional/apps/home/_newsfeed.ts index 0019b817b72d8..35d7ac8adefa5 100644 --- a/test/functional/apps/home/_newsfeed.ts +++ b/test/functional/apps/home/_newsfeed.ts @@ -24,8 +24,7 @@ export default function({ getService, getPageObjects }: FtrProviderContext) { const globalNav = getService('globalNav'); const PageObjects = getPageObjects(['common', 'newsfeed']); - // Failing: https://github.com/elastic/kibana/issues/53860 - describe.skip('Newsfeed', () => { + describe('Newsfeed', () => { before(async () => { await PageObjects.newsfeed.resetPage(); }); diff --git a/test/functional/page_objects/common_page.ts b/test/functional/page_objects/common_page.ts index 9629b8ccf28e1..75a15cc16db2e 100644 --- a/test/functional/page_objects/common_page.ts +++ b/test/functional/page_objects/common_page.ts @@ -39,6 +39,14 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo const defaultTryTimeout = config.get('timeouts.try'); const defaultFindTimeout = config.get('timeouts.find'); + interface NavigateProps { + appConfig: {}; + ensureCurrentUrl: boolean; + shouldLoginIfPrompted: boolean; + shouldAcceptAlert: boolean; + useActualUrl: boolean; + } + class CommonPage { /** * Navigates the browser window to provided URL @@ -115,6 +123,34 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo return currentUrl; } + private async navigate(navigateProps: NavigateProps) { + const { + appConfig, + ensureCurrentUrl, + shouldLoginIfPrompted, + shouldAcceptAlert, + useActualUrl, + } = navigateProps; + const appUrl = getUrl.noAuth(config.get('servers.kibana'), appConfig); + + await retry.try(async () => { + if (useActualUrl) { + log.debug(`navigateToActualUrl ${appUrl}`); + await browser.get(appUrl); + } else { + await CommonPage.navigateToUrlAndHandleAlert(appUrl, shouldAcceptAlert); + } + + const currentUrl = shouldLoginIfPrompted + ? await this.loginIfPrompted(appUrl) + : await browser.getCurrentUrl(); + + if (ensureCurrentUrl && !currentUrl.includes(appUrl)) { + throw new Error(`expected ${currentUrl}.includes(${appUrl})`); + } + }); + } + /** * Navigates browser using the pathname from the appConfig and subUrl as the hash * @param appName As defined in the apps config, e.g. 'home' @@ -137,23 +173,44 @@ export function CommonPageProvider({ getService, getPageObjects }: FtrProviderCo hash: useActualUrl ? subUrl : `/${appName}/${subUrl}`, }; - const appUrl = getUrl.noAuth(config.get('servers.kibana'), appConfig); - - await retry.try(async () => { - if (useActualUrl) { - log.debug(`navigateToActualUrl ${appUrl}`); - await browser.get(appUrl); - } else { - await CommonPage.navigateToUrlAndHandleAlert(appUrl, shouldAcceptAlert); - } + await this.navigate({ + appConfig, + ensureCurrentUrl, + shouldLoginIfPrompted, + shouldAcceptAlert, + useActualUrl, + }); + } - const currentUrl = shouldLoginIfPrompted - ? await this.loginIfPrompted(appUrl) - : await browser.getCurrentUrl(); + /** + * Navigates browser using the pathname from the appConfig and subUrl as the extended path. + * This was added to be able to test an application that uses browser history over hash history. + * @param appName As defined in the apps config, e.g. 'home' + * @param subUrl The route after the appUrl, e.g. 'tutorial_directory/sampleData' + * @param args additional arguments + */ + public async navigateToUrlWithBrowserHistory( + appName: string, + subUrl?: string, + { + basePath = '', + ensureCurrentUrl = true, + shouldLoginIfPrompted = true, + shouldAcceptAlert = true, + useActualUrl = true, + } = {} + ) { + const appConfig = { + // subUrl following the basePath, assumes no hashes. Ex: 'app/endpoint/management' + pathname: `${basePath}${config.get(['apps', appName]).pathname}${subUrl}`, + }; - if (ensureCurrentUrl && !currentUrl.includes(appUrl)) { - throw new Error(`expected ${currentUrl}.includes(${appUrl})`); - } + await this.navigate({ + appConfig, + ensureCurrentUrl, + shouldLoginIfPrompted, + shouldAcceptAlert, + useActualUrl, }); } diff --git a/vars/githubPr.groovy b/vars/githubPr.groovy index 09a166192bf7a..ce164ab98ab1e 100644 --- a/vars/githubPr.groovy +++ b/vars/githubPr.groovy @@ -35,7 +35,7 @@ def withDefaultPrComments(closure) { def message = getNextCommentMessage(info) postComment(message) - if (lastComment) { + if (lastComment && lastComment.user.login == 'kibanamachine') { deleteComment(lastComment.id) } } @@ -49,7 +49,7 @@ def isPr() { def getLatestBuildComment() { return getComments() .reverse() - .find { it.user.login == 'elasticmachine' && it.body =~ /