Commit graph

217 commits

Author SHA1 Message Date
Steph Milovic 06be699862
[Security Solution] [Cases] Various Cases cleanups (#102103) 2021-06-17 10:52:04 -06:00
Constance 12986fb8fc
[Enterprise Search] Mocks/tests tech debt - avoid hungry mocking (#101107)
* Move enzyme & misc test helpers out of __mocks__/ and into new test_helpers/

They're not technically mocks since nothing is being mocked, so we should move them into a test_helpers folder for specificity & organization

* Move React Router mocks into its own separate folder/import

This was part of the initial feedback, that it was unclear why importing something for Kea in __mocks__/index.ts was mocking react router along for the ride. Separating this out makes things clearer and imports more explicit

+ add some handy new mock useX jest.fn()s helpers, so we're not doing `useParams() as jest.Mock` errywhere

* Move Kea & logic mocks/helpers into kea_logic subfolder
- for organization

NOTE: It can't be a plain kea/ folder because then Jest automatically mocks the `kea` module itself kea 🤦

* Fix type failures

- Caused by switch from any to unknown (changed back to any + added a .test_helper suffix exclusion for any)

* Fix Enterprise Search tests/imports

- I checked all application folders but this one, whoops

* PR feedback: comment copy

* Update tests/files added since PR open with new import locations

* Fix misc react router typing

- null not being type-able as a boolean
- forgot to remove various useParam imports after adding mockUseParams
+ misc unused kea import, probably added while debugging kea mocks
2021-06-08 21:36:06 -07:00
Larry Gregory 907203d68e
Ban use of lodash.template (#100277)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-05-19 10:06:52 -04:00
Tim Roes 349b7e9f8e
Add more strict eslint rules for discover (#99241) 2021-05-05 10:54:15 +02:00
Frank Hassanabad af228f0f20
[Security Solutions] (Phase 1) Adds an application cache called metrics entities and integrates it within Security Solutions behind a feature flag (#96446)
## Summary

Phase 1 of a multi-phase cautious approach for adding an experimental application cache for Kibana solutions called `metric_entities` and integrates it within Security Solutions.

Phase 1 is putting experimental support into the application without breaking existing features. Lots of TODO's, conversations and a possible RFC from phase 1 to phase 2 approach. Some features are missing, but for phase 1 the general idea and code is all there.

To enable this first phase after checking out the branch add this to your `kibana.dev.yml`

```yml
xpack.metricsEntities.enabled: true
xpack.securitySolution.enableExperimental: ['metricsEntitiesEnabled']
```

Then go into Stack Management -> Advanced Settings (Under Security Solutions) and set the enabled to true like so:
<img width="1229" alt="Screen Shot 2021-04-08 at 2 21 02 PM" src="https://user-images.githubusercontent.com/1151048/114091276-b3cbb700-9875-11eb-9083-5c1d91dd20ed.png">

Next go to the security_solutions page and you will see it being activated and you will have these transforms running if you look under stack management:
<img width="1710" alt="Screen Shot 2021-04-29 at 2 00 27 PM" src="https://user-images.githubusercontent.com/1151048/116611174-4a2e4e00-a8f3-11eb-9e15-55cb504dfb2a.png">

On the hosts page, network, page, etc... You can see them being activated when you have no query/filter and you click on request:
<img width="1405" alt="Screen Shot 2021-04-29 at 2 01 28 PM" src="https://user-images.githubusercontent.com/1151048/116611274-6a5e0d00-a8f3-11eb-9998-9f5b3d1c5c63.png">

You will see in the request the index patterns all starting with `estc_xyz*`

### Checklist

Delete any items that are not applicable to this PR.

- [x] Any text added follows [EUI's writing guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses sentence case text and includes [i18n support](https://github.com/elastic/kibana/blob/master/packages/kbn-i18n/README.md)

We have lots of TODO's but no concrete docs with this just yet.
- [ ] [Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html) was added for features that require explanation or tutorials

Behind a feature flag and this isn't there yet.
- [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios
2021-04-30 12:36:06 -06:00
Alejandro Fernández Haro 6ed93c3571
[Telemetry] Remove all usages of any (#98338) 2021-04-27 21:45:19 +02:00
Aleh Zasypkin 808959e316
Handle 401 Unauthorized errors in a more user-friendly way (#94927) 2021-04-27 19:09:54 +02:00
Pierre Gayvallet 251bd9afc6
Remove /src/legacy (#95510)
* starting removing stuff

* fix jest config

* disable CLI mode until other PR is merged

* fix the schema

* add deprecation for maxPayloadBytes

* fix legacy start logic

* deletes `env` from unknown args

* fix FTR test config

* some legacy service deletion

* move config validation

* remove legacy exports from entrypoint

* preserve legacy logging in core logging config

* try to fix uiSettings integration tests

* fix legacy service tests

* more type fix

* use fromRoot from @kbn/utils

* cleanup kibana.d.ts

* fix unit tests

* remove src/core/server/utils

* fix server script

* add integration test for `/{path*}` route

* add unit tests on legacy config

* adapt uiSetting IT bis

* fix tests

* update generated doc

* address some review comments

* move review comments

* fix some stuff

* fix some stuff

* fix some stuff

* fix some stuff bis

* generated doc

* add test for ensureValidConfiguration
2021-04-06 09:25:36 +02:00
Constance 3237fd0637
[Enterprise Search] Fix eslint import rule not ordering sibling mocks with parent mocks (#96070)
* Enterprise Search eslint import order rule fix
- mocks in current folder should be grouped with mocks from parent folders

* Run --fix/update instances of importing ./__mocks__
2021-04-02 09:05:53 -04:00
Pierre Gayvallet 265cc76247
Remove core->cli dependency (#95145)
* extract http_tools to package

* fix readme

* start moving stuff

* cleaning up `isDevCliParent`

* choose bootstrap script

* fix bootstrap script logic

* fix watch paths logic

* import REPO_ROOT from correct package

* create the @kbn/crypto package

* update core's `dev` config

* only export bootstrap function

* extract sslConfig to http-tools package

* fix core types

* fix optimizer tests

* fix cli_dev_mode tests

* fix basePath proxy tests

* update generated doc

* fix unit tests

* create @kbn/dev-cli-mode package

* remove useless comment

* self-review NITS

* update CODEOWNERS file

* add devOnly flag

* use variable for DEV_MODE_PATH

* review comments

* fix logger/log adapter

* fix log calls in base path proxy server

* address some review comments

* rename @kbn/http-tools to @kbn/server-http-tools

* more review comments

* move test to correct file

* add comment on getBootstrapScript

* fix lint

* lint

* add cli-dev-mode to eslint dev packages

* review comments

* update yarn.lock

* Revert "[ci] skip building ts refs when not necessary (#95739)"

This reverts commit e46a74f7
2021-03-30 13:39:32 +02:00
Larry Gregory 31ea160fc7
Move production dependencies out of devDependencies (#93997)
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-03-26 15:23:45 -04:00
Yara Tercero bbee40c819
[Lists][Exceptions] - Adding basic linting, i18n and storybook support (#94772)
### Summary

In preparation for moving all the exceptions UI components into the lists plugin adds some linting, adds the lists plugin to the i18n config and adds storybook support. Tried to add a bit stricter linting than exists in the security solution right now, rules that we've talked about wanting to enable.
2021-03-16 21:46:20 -04:00
Frank Hassanabad 3afaebc49b
[Security Solutions] Remove commented out old linter rules (#94753)
## Summary

Cleanup .. 

* Removes commented out old linter rules from 2+ years ago. The project is very large and a lot of people are in the code base now and the comments are not relevant.
* Removes ts config optimize we don't use anymore
* Removes old script for rules we don't use anymore with elastic searches.
2021-03-16 17:40:09 -04:00
John Schulz a4fa4a62cb
Use consistent-type-imports lint rule to autofix type-only imports (#94464)
## Summary

Use the [`consistent-type-imports` lint rule ](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/consistent-type-imports.md) to use `import type ...` where possible

Code-only changes like this were recently added in https://github.com/elastic/kibana/pull/92979, but it was a more manual process.  This PR adds an autofixable lint rule which will keep the changes up-to-date and Just Work ™️
2021-03-15 13:58:50 +01:00
Pierre Gayvallet d0949121c8
Migrate /bootstrap.js endpoint to core (#92784)
* move bootstrap endpoint to core

* some initial cleanup

* hack around the 'try' auth status

* some UT

* more UT

* add try/catch around uISettings access

* add 'auth.isEnabled'

* remove dead files

* use `try` authent mode

* adapt UT

* revert themeTag movearound

* migrate apps route to core

* some cleanup

* nit

* add integration tests

* update generated doc

* add UT for /app route

* add etag IT

* nits

* remove auth.isEnabled API

* add tests on get_apm_config

* use string template instead of handlebars for bootstrap template

* improve plugin bundle tests

* update generated doc

* remove response.etag API

* update generated doc

* update generated doc

* update generated doc again

* extract getThemeTag

* add more unit tests
2021-03-10 10:35:26 +01:00
Patryk Kopyciński ed2a1bfb1f
[Asset Management] Add support for Live queries in Osquery (#89889) 2021-03-09 13:25:47 +01:00
Mike Côté 23ce8dcfdb
Rename alerts plugin to alerting (#92898)
* Rename alerts plugin to alerting

* Deprecate old config values

* Few more renames

* Update plugin list

* Rename xpack.alerts -> xpack.alerting

* Fix some ESLint rules

* Fix typecheck

* Fix some test failures

* Some more renames

* Fix ESLint

* Fix some test failures

* Fix failing jest test

* Undo exclusive test

* Fix APM deps

* Fix docs

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-03-05 13:59:34 -05:00
Joe Portner 171567d70a
ESLint rules for Spaces and Security (#93644) 2021-03-04 18:47:39 -05:00
Anton Dosov fe1ae92957
Fix wrong import in data plugin causing 100kB bundle increase (#93448) 2021-03-04 05:42:36 -05:00
John Schulz b5522ed30c
[Fleet] Add lint rule/fix for import order groups (#93300)
## Problem
Blocks of 10-15 `import`s are common in the plugin and there a few places which have ~50 lines of `import`s. It makes it more difficult to understand the where/why of what's being imported.

We've had instances while files import from the same module in different lines. i.e.

```ts
import { a } from './file';
... 5-10 lines later
import { b } from './file';
```

## Proposed solution
Add a lint rule to enforce a convention on the module `import` order. This can help in the same way Prettier & ESLint help to format type signatures or other code. It makes it easier to understand or notice any changes in the code. It's also able to be fixed automatically (`node scripts/eslint.js --fix` or any existing "format on save" in an editor).

## This PR
replaces #92980 (based on https://github.com/elastic/kibana/pull/92980#pullrequestreview-601070556)

### Lint rule
f9be98d Add eslint rule to enforce/autofix import group order. Use the same rule as a few other plugins. Groups `import` statements by type as shown in the [lint rule docs](https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md#importorder-enforce-a-convention-in-module-import-order
). The order is:

  1. node "builtin" modules
  2. "external" modules
  3. "internal" modules
  4. modules from a "parent" directory
  5. "sibling" modules from the same or a sibling's directory, "index" of the current directory, everything else

e.g.

```typescript
import fs from 'fs';
import path from 'path';

import _ from 'lodash';
import chalk from 'chalk';

import foo from 'src/foo';

import foo from '../foo';
import qux from '../../foo/qux';

import bar from './bar';
import baz from './bar/baz';
import main from './';
```
The [lint rule](https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md#importorder-enforce-a-convention-in-module-import-order) is relatively light handed. It only ensures  the `imports` are groups together in the given order. It doesn't alphabetize or otherwise sort the order of the files.


e.g. imports aren't rewritten to be in alphabetical order. This is fine

```ts
import from './c';
import from './a';
import from './b';
```

The [docs show other options](https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/order.md#options) and 2831f02bc7/.eslintrc.js (L1138-L1168) uses many of them

### Newlines option
The newlines settings means a change from something like

```typescript
import fs from 'fs';
import path from 'path';
import _ from 'lodash';
import chalk from 'chalk';
import foo from 'src/foo';
import foo from '../foo';
import qux from '../../foo/qux';
import bar from './bar';
import baz from './bar/baz';
import main from './';
```

to 

```typescript
import fs from 'fs';
import path from 'path';

import _ from 'lodash';
import chalk from 'chalk';

import foo from 'src/foo';

import foo from '../foo';
import qux from '../../foo/qux';

import bar from './bar';
import baz from './bar/baz';
import main from './';
```



Added it as a separate commit 2831f02 in case we want to avoid it, but I believe it's an improvement overall. Especially on the files with 25+ lines of imports. Even the "worst case" of something like this isn't bad (IMO). Especially since it's an automatic reformat like anything else in prettier


```typescript
import fs from 'fs';

import _ from 'lodash';

import foo from '../foo';

import main from './';
```
2021-03-03 13:58:20 -05:00
Alejandro Fernández Haro c0535abc06
[chore] Enable core's eslint rule: @ts-expect-error (#93086)
* [chore] Enable core's eslint rules

* Change comment from platform-team to core-team
2021-03-02 05:53:36 -05:00
Constance f3399620cf
[Enterprise Search] Add eslint import/order rules (#90530)
* Add import rules

- newlines between each group
- mocks in test files before everything else
- React before all other externals

* Run --fix on public/applications/workplace_search

* Manually fix errors still present in WS public files

- these appear to be mostly due to jest.mock() or const mixed in with imports, which confuses the autofixer

* Run --fix on public/applications/app_search

+ some manual fixes/tweaks along the way

* Run --fix on public/applications/shared

- some opinionated changes, particularly around IFlashMessages and grouping together types coming from Kibana (src->../../src)

* Run --fix on public/applications/enterprise_search

- mostly straightforward

* Run --fix on public/applications/__mocks__

* Fix remaining top-level public files

- Some opinionated changes (src/core -> ../../src/core) to keep types/mocks together

* Run --fix on server/ files

- same opinionated src->../src changes to keep deps grouped together

- opinionated require->import fetch change in enterprise_esarch_config_api.test.ts

- opinionated [] inclusion of builtins & external imports together (mostly for enterprise_search_request_handler.ts)
2021-02-09 09:33:39 -08:00
Constance 0c0a74b364
[Enterprise Search] eslint rule override: catch unnecessary backticks (#90347)
* Add eslint rule for linting unnecessary backticks

This needs to be below the Prettier overrides at the bottom of the file to override Prettier

* Run --fix

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-02-05 10:38:37 -08:00
Constance 3166ff3761
[Enterprise Search] eslint rule update: react/jsx-boolean-value (#90345)
* [Setup] Split rule that explicitly allows `any` in test/mock files into its own section

- so that the rules we're about to add apply correctly to all files

* Add react/jsx-boolean-value rule

* Run --fix

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2021-02-05 09:01:01 -08:00
Brandon Kobel 4584a8b570
Elastic License 2.0 (#90099)
* Updating everything except the license headers themselves

* Applying ESLint rules

* Manually replacing the stragglers
2021-02-03 18:12:39 -08:00
Patryk Kopyciński d7028e1a5f
[Security Solution] Init Osquery plugin (#87109) 2021-01-28 08:24:55 +01:00
Brandon Kobel 170a2956c8
Updating the License (#88343)
* Updating the Licenses, except for applying eslint, building

* Applying ESLint rules,building @kbn/pm, regenerating api docs
2021-01-19 17:52:56 -08:00
Tiago Costa 9139ab15fd
chore(NA): remove mocha junit ci integrations (#88129)
* chore(NA): remove mocha junit ci integrations

* chore(NA): remove mocha script from xpack

* chore(NA): single rule exclusion on eslint config for mocha

* chore(NA): remove unused custom mocha integration code from kbn/test

* chore(NA): rewording packages readme

* docs(NA): remoe mocha mention from development-unit-tests
2021-01-15 21:17:25 +00:00
Tyler Smalley a34cd20498
[@kbn/ui-framework] Removes all but dist files (#85347)
This package has long since been deprecated and no longer maintained.
The only reason it still exists is that not all plugins have migrated
away from using the kui classes to EUI. This removes all src and build
files as a step forward.

Signed-off-by: Tyler Smalley <tyler.smalley@elastic.co>
2020-12-10 08:23:33 -08:00
Mikhail Shustov 4917df30b9
Update typescript eslint to v4.8 (#83520)
* update deps

* update rules

use type-aware @typescript-eslint/no-shadow instead of no-shadow. do not use no-undef, rely on TypeScript instead

* fix or mute all lint errors

* react-hooks eslint plugin fails on ? syntax

* fix wrong typings in viz

* remove React as a global type

* fix eslint errors

* update version to 4.8.1

* fix a new error
2020-11-18 18:23:08 +01:00
Gidi Meir Morris ab72206da3
[Alerting] Moves the Index & Geo Threshold UIs into the Stack Alerts Public Plugin (#82951)
This PR includes the following refactors:
1. Moves the Index Pattern Api from _Stack Alerts_ to the _Server_ plugin of _Trigger Actions UI_. This fixes a potential bug where a user could disable the _Stack Alerts_ plugin and inadvertently break the UI of the _ES Index _ action type.
2. Extracts the UI components for _Index Threshold_ and _Geo Threshold_ from the _Trigger Actions UI_ plugin and moves them into _Stack Alerts_.
2020-11-12 16:39:40 +00:00
Alexey Antonov b2d6b66fe5
[bundle optimization] fix imports of react-use lib (#82847)
* [bundle optimization] fix imports of react-use lib

* add 2 more files

* add rule into eslintrc.js

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2020-11-10 17:15:26 +03:00
Tiago Costa 0eeaafa722
chore(NA): move into single pkg json (#80015)
* chore(NA): update gitignore to include first changes from moving into a single package.json

* chore(NA): update gitignore

* chore(NA): move all the dependencies into the single package.json and apply changes to bootstrap

* chore(NA): fix types problems after the single package json

* chore(NA): include code to find the dependencies used across the code

* chore(NA): introduce pure lockfile for install dependencies on build

* chore(NA): update clean task to not delete anything from xpack node_modules

* chore(NA): update gitignore to remove development temporary rules

* chore(NA): update notice file

* chore(NA): update jest snapshots

* chore(NA): fix whitelisted licenses to include a new specify form of an already included one

* chore(NA): remove check lockfile symlinks from child projects

* chore(NA): fix eslint and add missing declared deps on single pkg json

* chore(NA): correctly update notice

* chore(NA): fix failing jest test for storyshots.test.tsx

* chore(NA): fix cypress multi reporter path

* chore(NA): fix Project tests check

* chore(NA): fix problem with logic to detect used dependes on oss build

* chore(NA): include correct x-pack plugins dep discovery

* chore(NA): discover entries under dynamic requires on vis_type_timelion

* chore(NA): remove canvas

* test(NA): fix jest unit tests

* chore(NA): remove double react declaration from storyshot test file

* chore(NA): try removing isOSS check

* chore(NA): support for plugin development

* chore(NA): update logic to fix unit tests and typechecking

* chore(NA): support to run npm scripts in child kbn projects across all envs

* chore(NA): support github checks reporter on x-pack and remove cpy types as the package correctly provides them

* chore(NA): update cpy version

* chore(NA): include last kbn pm changes

* chore(NA): update style on build_production_projects.ts

* chore(NA): remove any cast fom telemetry opt in stats

* chore(NA): remove del and re-use rm -rf again

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2020-11-02 21:18:52 +00:00
Uladzislau Lasitsa ba8e9a52b6
Timelion y-axis label not displayed (#80007)
* Moved flot in ui-shared-deps and leavt only one version.

* Removed unneeded import

* use commonJS so we can execute code between loading specific modules

* prefix i18n keys with flot.

* Fix Internationalization

* remove duplicate pie plugin

Co-authored-by: spalger <spalger@users.noreply.github.com>
Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
2020-10-14 16:58:35 +03:00
Gidi Meir Morris 25c5daa83a
Renames "Built-In Alerts" feature to "Stack Alerts" and "Actions" feature to "Actions and Connectors" (#79513)
Renames "Built-In Alerts" feature to "Stack Alerts" and "Actions" feature to "Actions and Connectors" as we've decided these names make more appropriate and better communicate what these features are.
2020-10-06 17:51:05 +01:00
Nathan L Smith 564a7b1a17
Storybook 6 and config changes (#75357)
Upgrade to Storybook 6 and attempt to use the declarative configuration.

The goals of this PR (as part of Kibana's Storybook roadmap, are:

Upgrade to Storybook 6
Still allow running Storybooks with yarn storybook plugin_name
Use the declarative configuration to (hopefully) make the configuration simpler to use an easier to understand, as well as avoiding deprecation warnings and loss of future compatibility
The ways in which what I have so far differs from how we do things today are:

In the alias configuration it takes a path to a storybook configuration directory instead of the storybook.js file from before
Each plugin (it doesn't have to be a plugin; can be any directory) has a .storybook/main.js (the aliases file in @kbn/storybook specifies these locations) where they can define their Storybook configuration. You can require('@kbn/storybook').defaultConfig to get defaults and override them
@kbn/storybook has a preset that can provide Webpack and Babel configuration and Storybook parameters and decorators
Instead of dynamically creating the list of stories to import, we define them in the globs of the stories property in .storybook/main.js.
Do not build a DLL. We are using @kbn/ui-shared-deps as externals. Startup time is not quite as fast but still acceptable.
Other things done in this PR:

Allow default exports in .stories. to allow for Common Story Format CSF stories
Add guard in Webpack configuration needed for overriding CSS rules
Update filename casing check to allow for files with required names in Storybook
Clean up observability stories
Rename *.examples.tsx and *.story.tsx to *.stories.tsx
2020-09-29 19:34:05 -05:00
Brittany Joiner 63ce752dc2
Adding comment about importing lodash library (#78156)
* added comment about importing lodash library

* fixed space with prefer

* cleaned up extra space and removed comments for lodash/fp

* took out the comment in server files

* Remove newlines

Co-authored-by: Nathan L Smith <smith@nlsmith.com>
2020-09-24 11:38:11 -05:00
Pierre Gayvallet 0d09cea436
Remove legacy plugins support (#77599)
* remove ALL the things.

* adapt some types and tests

* restore ensureValidConfiguration

* fix legacy service tests

* adapt uiRender mixin

* remove legacy types

* update generated doc

* restore legacy plugin schema

* update generated doc

* remove remaining code of x-pack/legacy

* adapt imports due to merge

* cleanup CODEOWNERS

* cleanup gitignore & i18nrc

* cleanup tsconfig.json

* remove unused i18n keys

* add back `"legacy/plugins/**/*",` to tsconfig until legacy space plugin is deleted

* fix create_jest_config

* remove references from eslintrc

* more eslint cleanup

* remove `x-pack/index.js`

* fix xpack gulp scripts

* fix bug with default + named imports from boom

* remove rules from eslintrc

* remove LegacyInternals

* review comments

* update generated doc

* cleanup legacy metadatas

* revert changes to eslintrc

* update generated doc
2020-09-23 09:52:51 +02:00
Mikhail Shustov cd86b81b82
Move streams utils to the core (#76397)
* move utils/streams to the KP

* allow imports from src/core/server/utils

* ts-ify

* import streams from KP

* remove unnecessary ts-expect-error

* fix kbn-es-archiver build

* lost export

* copy array in createListStream

* remove streams from legacy utils

Co-authored-by: spalger <spalger@users.noreply.github.com>
2020-09-03 10:57:03 +02:00
CJ Cenizal e13d8dcfb7
Fix es_ui_shared eslint violations for useRequest hook (#72947)
* Reconcile request helpers with eslint rules for React hooks.
  - Add clearer cleanup logic for unmounted components.
  - Align logic and comments in np_ready_request.ts and original request.ts.
* Reorganize modules and convert tests to TS.
  - Split request.ts into send_request.ts and use_request.ts.
  - Convert test files into TS.
  - Relax SendRequestResponse type definition to type error as any instead of expecting an Error, since we weren't actually fulfilling this expectation.
* Convert everything to hooks and add test coverage for request behavior.
* Fix Watcher memoization bugs.
2020-08-31 12:55:39 -07:00
Cauê Marcondes 712c4bdde7
[APM] Prevent imports of public in server code (#75979)
* renaming test file

* removing eslint rule

* restructuring observability types

* refactoring fetchOptions type
2020-08-28 12:43:49 +02:00
Spencer 9cafade2b9
[remove] production deps which are only used in public code (#75838)
Co-authored-by: spalger <spalger@users.noreply.github.com>
2020-08-25 08:27:15 -07:00
Spencer 7b23e7cd8b
[kbn/plugin-generator] remove sao, modernize (#75465)
Co-authored-by: spalger <spalger@users.noreply.github.com>
2020-08-20 18:50:36 -07:00
Spencer 4c810be335
Remove legacy optimizer (#73154)
Co-authored-by: spalger <spalger@users.noreply.github.com>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
2020-08-13 09:08:44 -07:00
Marta Bondyra 626fbc2948
[Lens] Clean and inline disabling of react-hooks/exhaustive-deps eslint rule (#70010) 2020-08-06 10:10:09 +02:00
Spencer 827e91c447
move and unify postcss config into @kbn/optimizer (#73633)
Co-authored-by: spalger <spalger@users.noreply.github.com>
2020-07-30 11:16:49 -07:00
Nathan L Smith d3ddcd2027
[APM] APM & Observability plugin lint improvements (#72702)
* [APM] APM & Observability plugin lint improvements

This is a large change, but most of it is automatic `eslint --fix` changes.

* Apply the same ESLint ovderrides in APM and Observability plugins.
* Remove the `no-unused-vars` rule. We can turn on the TypeScript check if needed.
* Check both JS and TS files.
* Add a rule for react function component definitions
* Upgrade eslint-plugin-react to include that rule
2020-07-27 08:18:36 -05:00
Clint Andrew Hall bfbb8d2138
[pre-req] Move .storybook to storybook; standardize files (#72384) 2020-07-20 22:18:20 -04:00
Thomas Watson fc5bc6b6a2
Add @elastic/safer-lodash-set as an alternative to lodash.set (#67452) 2020-07-15 10:29:57 +02:00
Constance f7b5144e1d
New Enterprise Search Kibana plugin (#66922)
* Initial App Search in Kibana plugin work

- Initializes a new platform plugin that ships out of the box w/ x-pack
- Contains a very basic front-end that shows AS engines, error states, or a Setup Guide
- Contains a very basic server that remotely calls the AS internal engines API and returns results

* Update URL casing to match Kibana best practices

- URL casing appears to be snake_casing, but kibana.json casing appears to be camelCase

* Register App Search plugin in Home Feature Catalogue

* Add custom App Search in Kibana logo

- I haven't had much success in surfacing a SVG file via a server-side endpoint/URL, but then I realized EuiIcon supports passing in a ReactElement directly. Woo!

* Fix appSearch.host config setting to be optional

- instead of crashing folks on load

* Rename plugin to Enterprise Search

- per product decision, URL should be enterprise_search/app_search and Workplace Search should also eventually live here
- reorganize folder structure in anticipation for another workplace_search plugin/codebase living alongside app_search
- rename app.tsx/main.tsx to a standard top-level index.tsx (which will contain top-level routes/state)
- rename AS->ES files/vars where applicable
- TODO: React Router

* Set up React Router URL structure

* Convert showSetupGuide action/flag to a React Router link

- remove showSetupGuide flag
- add a new shared helper component for combining EuiButton/EuiLink with React Router behavior (https://github.com/elastic/eui/blob/master/wiki/react-router.md#react-router-51)

* Implement Kibana Chrome breadcrumbs

- create shared helper (WS will presumably also want this) for generating EUI breadcrumb objects with React Router links+click behavior
- create React component that calls chrome.setBreadcrumbs on page mount
- clean up type definitions - move app-wide props to IAppSearchProps and update most pages/views to simply import it instead of calling their own definitions

* Added server unit tests (#2)

* Added unit test for server

* PR Feedback

* Refactor top-level Kibana props to a global context state

- rather them passing them around verbosely as props, the components that need them should be able to call the useContext hook

+ Remove IAppSearchProps in favor of IKibanaContext

+ Also rename `appSearchUrl` to `enterpriseSearchUrl`, since this context will contained shared/Kibana-wide values/actions useful to both AS and WS

* Added unit tests for public (#4)

* application.test.ts

* Added Unit Test for EngineOverviewHeader

* Added Unit Test for generate_breadcrumbs

* Added Unit Test for set_breadcrumb.tsx

* Added a unit test for link_events

- Also changed link_events.tsx to link_events.ts since it's just TS, no
React
- Modified letBrowserHandleEvent so it will still return a false
boolean when target is blank

* Betterize these tests

Co-Authored-By: Constance <constancecchen@users.noreply.github.com>

Co-authored-by: Constance <constancecchen@users.noreply.github.com>

* Add UI telemetry tracking to AS in Kibana (#5)

* Set up Telemetry usageCollection, savedObjects, route, & shared helper

- The Kibana UsageCollection plugin handles collecting our telemetry UI data (views, clicks, errors, etc.) and pushing it to elastic's telemetry servers
- That data is stored in incremented in Kibana's savedObjects lib/plugin (as well as mapped)
- When an end-user hits a certain view or action, the shared helper will ping the app search telemetry route which increments the savedObject store

* Update client-side views/links to new shared telemetry helper

* Write tests for new telemetry files

* Implement remaining unit tests (#7)

* Write tests for React Router+EUI helper components

* Update generate_breadcrumbs test

- add test suite for generateBreadcrumb() itself (in order to cover a missing branch)
- minor lint fixes
- remove unnecessary import from set_breadcrumbs test

* Write test for get_username util

+ update test to return a more consistent falsey value (null)

* Add test for SetupGuide

* [Refactor] Pull out various Kibana context mocks into separate files

- I'm creating a reusable useContext mock for shallow()ed enzyme components
+ add more documentation comments + examples

* Write tests for empty state components

+ test new usecontext shallow mock

* Empty state components: Add extra getUserName branch test

* Write test for app search index/routes

* Write tests for engine overview table

+ fix bonus bug

* Write Engine Overview tests

+ Update EngineOverview logic to account for issues found during tests :)
  - Move http to async/await syntax instead of promise syntax (works better with existing HttpServiceMock jest.fn()s)
  - hasValidData wasn't strict enough in type checking/object nest checking and was causing the app itself to crash (no bueno)

* Refactor EngineOverviewHeader test to use shallow + to full coverage

- missed adding this test during telemetry work
- switching to shallow and beforeAll reduces the test time from 5s to 4s!

* [Refactor] Pull out React Router history mocks into a test util helper

+ minor refactors/updates

* Add small tests to increase branch coverage

- mostly testing fallbacks or removing fallbacks in favor of strict type interface
- these are slightly obsessive so I'd also be fine ditching them if they aren't terribly valuable

* Address larger tech debt/TODOs (#8)

* Fix optional chaining TODO

- turns out my local Prettier wasn't up to date, completely my bad

* Fix constants TODO

- adds a common folder/architecture for others to use in the future

* Remove TODO for eslint-disable-line and specify lint rule being skipped

- hopefully that's OK for review, I can't think of any other way to sanely do this without re-architecting the entire file or DDoSing our API

* Add server-side logging to route dependencies

+ add basic example of error catching/logging to Telemetry route
+ [extra] refactor mockResponseFactory name to something slightly easier to read

* Move more Engines Overview API logic/logging to server-side

- handle data validation in the server-side
- wrap server-side API in a try/catch to account for fetch issues
- more correctly return 2xx/4xx statuses and more correctly deal with those responses in the front-end
- Add server info/error/debug logs (addresses TODO)
- Update tests + minor refactors/cleanup
    - remove expectResponseToBe200With helper (since we're now returning multiple response types) and instead make mockResponse var name more readable
    - one-line header auth
    - update tests with example error logs
    - update schema validation for `type` to be an enum of `indexed`/`meta` (more accurately reflecting API)

* Per telemetry team feedback, rename usageCollection telemetry mapping name to simpler 'app_search'

- since their mapping already nests under 'kibana.plugins'
- note: I left the savedObjects name with the '_telemetry' suffix, as there very well may be a use case for top-level generic 'app_search' saved objects

* Update Setup Guide installation instructions (#9)

Co-authored-by: Chris Cressman <chris@chriscressman.com>

* [Refactor] DRY out route test helper

* [Refactor] Rename public/test_utils to public/__mocks__

- to better follow/use jest setups and for .mock.ts suffixes

* Add platinum licensing check to Meta Engines table/call (#11)

* Licensing plugin setup

* Add LicensingContext setup

* Update EngineOverview to not hit meta engines API on platinum license

* Add Jest test helpers for future shallow/context use

* Update plugin to use new Kibana nav + URL update (#12)

* Update new nav categories to add Enterprise Search + update plugin to use new category

- per @johnbarrierwilson and Matt Riley, Enterprise Search should be under Kibana and above Observability
- Run `node scripts/check_published_api_changes.js --accept` since this new category affects public API

* [URL UPDATE] Change '/app/enterprise_search/app_search' to '/app/app_search'

- This needs to be done because App Search and Workplace search *have* to be registered as separate plugins to have 2 distinct nav links
- Currently Kibana doesn't support nested app names (see: https://github.com/elastic/kibana/issues/59190) but potentially will in the future

- To support this change, we need to update applications/index.tsx to NOT handle '/app/enterprise_search' level routing, but instead accept an async imported app component (e.g. AppSearch, WorkplaceSearch).
- AppSearch should now treat its router as root '/' instead of '/app_search'

- (Addl) Per Josh Dover's recommendation, switch to `<Router history={params.history}>` from `<BrowserRouter basename={params.appBasePath}>` since they're deprecating appBasePath

* Update breadcrumbs helper to account for new URLs

- Remove path for Enterprise Search breadcrumb, since '/app/enterprise_search' will not link anywhere meaningful for the foreseeable future, so the Enterprise Search root should not go anywhere
- Update App Search helper to go to root path, per new React Router setup

Test changes:
- Mock custom basepath for App Search tests
- Swap enterpriseSearchBreadcrumbs and appSearchBreadcrumbs test order (since the latter overrides the default mock)

* Add create_first_engine_button telemetry tracking to EmptyState

* Switch plugin URLs back to /app/enterprise_search/app_search

Now that https://github.com/elastic/kibana/pull/66455 has been merged in 🎉

* Add i18n formatted messages / translations (#13)

* Add i18n provider and formatted/i18n translated messages

* Update tests to account for new I18nProvider context + FormattedMessage components

- Add new mountWithContext helper that provides all contexts+providers used in top-level app
- Add new shallowWithIntl helper for shallow() components that dive into FormattedMessage

* Format i18n dates and numbers

+ update some mock tests to not throw react-intl invalid date messages

* Update EngineOverviewHeader to disable button on prop

* Address review feedback (#14)

* Fix Prettier linting issues

* Escape App Search API endpoint URLs

- per PR feedback
- querystring should automatically encodeURIComponent / escape query param strings

* Update server plugin.ts to use getStartServices() rather than storing local references from start()

- Per feedback: https://github.com/elastic/kibana/blob/master/src/core/CONVENTIONS.md#applications

- Note: savedObjects.registerType needs to be outside of getStartServices, or an error is thrown

- Side update to registerTelemetryUsageCollector to simplify args

- Update/fix tests to account for changes

* E2E testing (#6)

* Wired up basics for E2E testing

* Added version with App Search

* Updated naming

* Switched configuration around

* Added concept of 'fixtures'

* Figured out how to log in as the enterprise_search user

* Refactored to use an App Search service

* Added some real tests

* Added a README

* Cleanup

* More cleanup

* Error handling + README updatre

* Removed unnecessary files

* Apply suggestions from code review

Co-authored-by: Constance <constancecchen@users.noreply.github.com>

* Update x-pack/plugins/enterprise_search/public/applications/app_search/components/engine_overview/engine_table.tsx

Co-authored-by: Constance <constancecchen@users.noreply.github.com>

* PR feedback - updated README

* Additional lint fixes

Co-authored-by: Constance <constancecchen@users.noreply.github.com>

* Add README and CODEOWNERS (#15)

* Add plugin README and CODEOWNERS

* Fix Typescript errors (#16)

* Fix public mocks

* Fix empty states types

* Fix engine table component errors

* Fix engine overview component errors

* Fix setup guide component errors

- SetBreadcrumbs will be fixed in a separate commit

* Fix App Search index errors

* Fix engine overview header component errors

* Fix applications context index errors

* Fix kibana breadcrumb helper errors

* Fix license helper errors

*  Refactor React Router EUI link/button helpers
- in order to fix typescript errors

- this changes the component logic significantly to a react render prop, so that the Link and Button components can have different types - however, end behavior should still remain the same

* Fix telemetry helper errors

* Minor unused var cleanup in plugin files

* Fix telemetry collector/savedobjects errors

* Fix MockRouter type errors and add IRouteDependencies export

- routes will use IRouteDependencies in the next few commits

* Fix engines route errors

* Fix telemetry route errors

* Remove any type from source code

- thanks to Scotty for the inspiration

* Add eslint rules for Enterprise Search plugin

- Add checks for type any, but only on non-test files
- Disable react-hooks/exhaustive-deps, since we're already disabling it in a few files and other plugins also have it turned off

* Cover uncovered lines in engines_table and telemetry tests

* Fixed TS warnings in E2E tests (#17)

* Feedback: Convert static CSS values to EUI variables where possible

* Feedback: Flatten nested CSS where possible

- Prefer setting CSS class overrides on individual EUI components, not on a top-level page

+ Change CSS class casing from kebab-case to camelCase to better match EUI/Kibana

+ Remove unnecessary .euiPageContentHeader margin-bottom override by changing the panelPaddingSize of euiPageContent

+ Decrease engine overview table padding on mobile

* Refactor out components shared with Workplace Search (#18)

* Move getUserName helper to shared

- in preparation for Workplace Search plugin also using this helper

* Move Setup Guide layout to a shared component

* Setup Guide: add extra props for standard/native auth links

Note: It's possible this commit may be unnecessary if we can publish shared Enterprise Search security mode docs

* Update copy per feedback from copy team

* Address various telemetry issues

- saved objects: removing indexing per #43673
- add schema and generate json per #64942
- move definitions over to collectors since saved objects is mostly empty at this point, and schema throws an error when it imports an obj instead of being defined inline
- istanbul ignore saved_objects file since it doesn't have anything meaningful to test but was affecting code coverage

* Disable plugin access if a normal user does not have access to App Search (#19)

* Set up new server security dependency and configs

* Set up access capabilities

* Set up checkAccess helper/caller

* Remove NoUserState component from the public UI

- Since this is now being handled by checkAccess / normal users should never see the plugin at all if they don't have an account/access, the component is no longer needed

* Update server routes to account for new changes

- Remove login redirect catch from routes, since the access helper should now handle that for most users by disabling the plugin (superusers will see a generic cannot connect/error screen)
- Refactor out new config values to a shared mock

* Refactor Enterprise Search http call to hit/return new internal API endpoint

+ pull out the http call to a separate library for upcoming public URL work (so that other files can call it directly as well)

* [Discussion] Increase timeout but add another warning timeout for slow servers

- per recommendation/convo with Brandon

* Register feature control

* Remove no_as_account from UI telemetry

- since we're no longer tracking that in the UI

* Address PR feedback - isSuperUser check

* Public URL support for Elastic Cloud (#21)

* Add server-side public URL route

- Per feedback from Kibana platform team, it's not possible to pass info from server/ to public/ without a HTTP call :[

* Update MockRouter for routes without any payload/params

* Add client-side helper for calling the new public URL API

+ API seems to return a URL a trailing slash, which we need to omit

* Update public/plugin.ts to check and set a public URL

- relies on this.hasCheckedPublicUrl to only make the call once per page load instead of on every page nav

* Fix failing feature control tests

- Split up scenario cases as needed
- Add plugin as an exception alongside ML & Monitoring

* Address PR feedback

- version: kibana
- copy edits
- Sass vars
- code cleanup

* Casing feedback: change all plugin registration IDs from snake_case to camelCase

- note: current remainng snake_case exceptions are telemetry keys
- file names and api endpoints are snake_case per conventions

* Misc security feedback

- remove set
- remove unnecessary capabilities registration
- telemetry namespace agnostic

* Security feedback: add warn logging to telemetry collector

see https://github.com/elastic/kibana/pull/66922#discussion_r451215760
- add if statement
- pass log dependency around (this is kinda medium, should maybe refactor)
- update tests
- move test file comment to the right file (was meant for telemetry route file)

* Address feedback from Pierre

- Remove unnecessary ServerConfigType
- Remove unnecessary uiCapabilities
- Move registerTelemetryRoute / SavedObjectsServiceStart workaround
- Remove unnecessary license optional chaining

* PR feedback

Address type/typos

* Fix telemetry API call returning 415 on Chrome

- I can't even?? I swear charset=utf-8 fixed the same error a few weeks ago

* Fix failing tests

* Update Enterprise Search functional tests (without host) to run on CI

- Fix incorrect navigateToApp slug (hadn't realized this was a URL, not an ID)
- Update without_host_configured tests to run without API key
- Update README

* Address PR feedback from Pierre

- remove unnecessary authz?
- remove unnecessary content-type json headers
- add loggingSystemMock.collect(mockLogger).error assertion
- reconstrcut new MockRouter on beforeEach for better sandboxing
- fix incorrect describe()s -should be it()
- pull out reusable mockDependencies helper (renamed/extended from mockConfig) for tests that don't particularly use config/log but still want to pass type definitions
- Fix comment copy

Co-authored-by: Jason Stoltzfus <jastoltz24@gmail.com>
Co-authored-by: Chris Cressman <chris@chriscressman.com>
Co-authored-by: scottybollinger <scotty.bollinger@elastic.co>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
2020-07-09 13:10:31 -07:00