Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ML] Injectables refactor #50512

Merged
merged 11 commits into from
Nov 18, 2019

Conversation

jgowdyelastic
Copy link
Member

@jgowdyelastic jgowdyelastic commented Nov 13, 2019

New platform related refactor PR.
Removes the use of soon to be obsolete injectables.
Removed:
Private
kbnBaseUrl
kbnUrl
reactDirective
some uses of $scope
Removes the use of $route by SearchItemsProvider and so removes the need of a provider wrapper entirely.

Also typescriptifies and refactors some simple util files and directives.

@peteharverson special care is needed when reviewing the changes made to field_format_service. From my tests everything appears to be correct, but there may be edge cases i've missed.

Checklist

Use strikethroughs to remove checklist items you don't feel are applicable to this PR.

For maintainers

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

Pinging @elastic/ml-ui (:ml)

@jgowdyelastic jgowdyelastic added non-issue Indicates to automation that a pull request should not appear in the release notes release_note:skip Skip the PR/issue when compiling release notes labels Nov 14, 2019
@jgowdyelastic jgowdyelastic marked this pull request as ready for review November 14, 2019 15:27
@jgowdyelastic jgowdyelastic requested a review from a team as a code owner November 14, 2019 15:27
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

resolve(this.formatsByJob);
})
.catch(err => {
// console.log('fieldFormatService error populating formats:', err);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this be removed?

@@ -62,7 +46,7 @@ export function getIndexPatternIdFromName(name: string) {
return indexPatternCache[j].id;
}
}
return name;
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just to clarify, this is changing the default return type to null rather than returning the name for cases where no matching index pattern could be found. Probably makes more sense, but just want to make sure!

Copy link
Member Author

Choose a reason for hiding this comment

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

i checked the places where this is called and returning null makes more sense.
After this refactor, there are no places where returning the originally supplied index name is expected.

Copy link
Contributor

@peteharverson peteharverson left a comment

Choose a reason for hiding this comment

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

Tested this out, including where the field format service is using, and all looks good.

Other than the minor comments added above, LGTM

import { VALIDATION_STATUS } from '../constants/validation';

// get the most severe status level from a list of messages
const contains = (arr: string[], str: string) => arr.findIndex(v => v === str) >= 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

just migration to TS, but for an array of primitives it's easier to use arr.indexOf(str)

Comment on lines 24 to 25
indexPattern: any,
savedSearch: any
Copy link
Contributor

Choose a reason for hiding this comment

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

we have interfaces for those two 🙂

import React from 'react';
// @ts-ignore No declaration file for module
import { banners } from 'ui/notify';
// import chrome from 'ui/chrome';
Copy link
Contributor

Choose a reason for hiding this comment

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

commented import

let licenseType = null;
let expiredLicenseBannerId;
let licenseType: LICENSE_TYPE | null = null;
let expiredLicenseBannerId: any;
Copy link
Contributor

Choose a reason for hiding this comment

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

is it possible to provide a type?

Copy link
Member Author

Choose a reason for hiding this comment

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

Adding type of string but it's worth noting that it's a guess because banners is js.
It's also worth noting that the value expiredLicenseBannerId is never really used, it's only checked to see if it has been set.

this.indexPatternIdsByJob = {};
this.formatsByJob = {};
}
indexPatternIdsByJob: any = {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Record?

Comment on lines -97 to +91
const formatsByDetector = {};
const formatsByDetector: any[] = [];
Copy link
Contributor

Choose a reason for hiding this comment

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

object replaced with an array 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

yes, it looks like it was incorrect being an object.
formatsByDetector is indexed using detector_index from each detector which is an incrementing integer.

return {
restrict: 'E',
replace: false,
scope: {},
link: function (scope, element) {
link(scope: any, element: ng.IAugmentedJQuery) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ng.IScope ?

return {
restrict: 'E',
replace: false,
scope: {},
link: function (scope, element) {
link(scope: any, element: ng.IAugmentedJQuery) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ng.IScope ?

return {
restrict: 'E',
replace: false,
scope: {},
link: function (scope, element) {
link(scope: any, element: ng.IAugmentedJQuery) {
Copy link
Contributor

Choose a reason for hiding this comment

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

ng.IScope?

Comment on lines -65 to +49
return name;
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

is it correct?

Copy link
Contributor

@darnautov darnautov left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@jgowdyelastic
Copy link
Member Author

@elasticmachine merge upstream

@elasticmachine
Copy link
Contributor

merge conflict between base and head

Copy link
Contributor

@walterra walterra left a comment

Choose a reason for hiding this comment

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

LGTM, just added some minor comments.

import expect from '@kbn/expect';
import { parseInterval } from '../parse_interval';

describe('ML parse interval util', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

We also need to migrate away from mocha. Since these tests don't include anything angular related, they could be moved to .../util/parse_interval.test.ts and migrated to jest.

@@ -4,14 +4,11 @@
* you may not use this file except in compliance with the Elastic License.
*/



import expect from '@kbn/expect';
import { renderTemplate } from '../string_utils';

describe('ML - string utils', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be moved to .../util/string_utils.test.ts and migrated to jest.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, makes sense to move it over

import dateMath from '@elastic/datemath';

type SupportedUnits = unitOfTime.Base;
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wondering if this should be singular SupportedUnit since later on it's used as an array like SupportedUnits[].

Copy link
Member Author

@jgowdyelastic jgowdyelastic Nov 18, 2019

Choose a reason for hiding this comment

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

unitOfTime.Base is a list of string literal types, something like ms | s | m | h |....
so from a language point of view i thought the plural made sense.
but i guess it's a union so it'll only have one value.

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💔 Build Failed

@elasticmachine
Copy link
Contributor

💚 Build Succeeded

@jgowdyelastic jgowdyelastic merged commit eb4c47e into elastic:master Nov 18, 2019
@jgowdyelastic jgowdyelastic deleted the injectables-refactor branch November 18, 2019 14:36
jgowdyelastic added a commit to jgowdyelastic/kibana that referenced this pull request Nov 18, 2019
* [ML] Injectables refactor

* removing unrelated files

* additional typescript conversion

* more typescript conversion

* adding some return types

* fixing eui errors

* typescripting license checks

* updated based on review

* fixing merge conflict error

* converting tests to jest

* fixing types
jgowdyelastic added a commit that referenced this pull request Nov 18, 2019
* [ML] Injectables refactor

* removing unrelated files

* additional typescript conversion

* more typescript conversion

* adding some return types

* fixing eui errors

* typescripting license checks

* updated based on review

* fixing merge conflict error

* converting tests to jest

* fixing types
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:NP Migration :ml non-issue Indicates to automation that a pull request should not appear in the release notes release_note:skip Skip the PR/issue when compiling release notes review v7.6.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants