-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[FieldFormats] Reduce any
usage
#111530
Merged
Merged
[FieldFormats] Reduce any
usage
#111530
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
4885f79
wip reduce any in ff
Dosant ebe94aa
fix ts
Dosant afee3b0
fix ts
Dosant 35ece5f
fix ts
Dosant 2a9ca82
fix ts
Dosant 3b25a6c
fix ts
Dosant e7c6d38
Merge branch 'master' of github.com:elastic/kibana into d/2021-08-26-…
Dosant 7796c4c
fix ts
Dosant 450ebef
wip
Dosant 7033024
Merge branch 'master' of github.com:elastic/kibana into d/2021-08-26-…
Dosant b31eb9e
Merge branch 'master' of github.com:elastic/kibana into d/2021-08-26-…
Dosant bf44b50
remove more hidden any
Dosant 83ad234
revert
Dosant 226d4e5
Merge branch 'master' into d/2021-08-26-ff-any
kibanamachine 4bfbc88
Merge branch 'master' into d/2021-08-26-ff-any
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ export class BoolFormat extends FieldFormat { | |
}); | ||
static fieldType = [KBN_FIELD_TYPES.BOOLEAN, KBN_FIELD_TYPES.NUMBER, KBN_FIELD_TYPES.STRING]; | ||
|
||
textConvert: TextContextTypeConvert = (value) => { | ||
textConvert: TextContextTypeConvert = (value: string | number | boolean) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For all of these formatters, I just specified types based on what I saw is supported in runtime |
||
if (typeof value === 'string') { | ||
value = value.trim().toLowerCase(); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,20 +13,27 @@ import moment, { Moment } from 'moment'; | |
import { FieldFormat, FIELD_FORMAT_IDS } from '../'; | ||
import { TextContextTypeConvert } from '../types'; | ||
|
||
interface FractPatternObject { | ||
length: number; | ||
patternNanos: string; | ||
pattern: string; | ||
patternEscaped: string; | ||
} | ||
|
||
/** | ||
* Analyse the given moment.js format pattern for the fractional sec part (S,SS,SSS...) | ||
* returning length, match, pattern and an escaped pattern, that excludes the fractional | ||
* part when formatting with moment.js -> e.g. [SSS] | ||
*/ | ||
export function analysePatternForFract(pattern: string) { | ||
const fracSecMatch = pattern.match('S+') as any; // extract fractional seconds sub-pattern | ||
export function analysePatternForFract(pattern: string): FractPatternObject { | ||
const fracSecMatch = pattern.match('S+'); // extract fractional seconds sub-pattern | ||
const fracSecMatchStr = fracSecMatch ? fracSecMatch[0] : ''; | ||
|
||
return { | ||
length: fracSecMatchStr.length, | ||
patternNanos: fracSecMatchStr, | ||
pattern, | ||
patternEscaped: fracSecMatchStr ? pattern.replace(fracSecMatch, `[${fracSecMatch}]`) : '', | ||
patternEscaped: fracSecMatchStr ? pattern.replace(fracSecMatchStr, `[${fracSecMatchStr}]`) : '', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
}; | ||
} | ||
|
||
|
@@ -38,7 +45,7 @@ export function analysePatternForFract(pattern: string) { | |
export function formatWithNanos( | ||
dateMomentObj: Moment, | ||
valRaw: string, | ||
fracPatternObj: Record<string, any> | ||
fracPatternObj: FractPatternObject | ||
) { | ||
if (fracPatternObj.length <= 3) { | ||
// S,SS,SSS is formatted correctly by moment.js | ||
|
@@ -77,7 +84,7 @@ export class DateNanosFormat extends FieldFormat { | |
}; | ||
} | ||
|
||
textConvert: TextContextTypeConvert = (val) => { | ||
textConvert: TextContextTypeConvert = (val: string | number) => { | ||
// don't give away our ref to converter so | ||
// we can hot-swap when config changes | ||
const pattern = this.param('pattern'); | ||
|
@@ -91,7 +98,7 @@ export class DateNanosFormat extends FieldFormat { | |
this.timeZone = timezone; | ||
this.memoizedPattern = pattern; | ||
|
||
this.memoizedConverter = memoize(function converter(value: any) { | ||
this.memoizedConverter = memoize(function converter(value: string | number) { | ||
if (value === null || value === undefined) { | ||
return '-'; | ||
} | ||
|
@@ -102,7 +109,7 @@ export class DateNanosFormat extends FieldFormat { | |
// fallback for max/min aggregation, where unixtime in ms is returned as a number | ||
// aggregations in Elasticsearch generally just return ms | ||
return date.format(fallbackPattern); | ||
} else if (date.isValid()) { | ||
} else if (date.isValid() && typeof value === 'string') { | ||
return formatWithNanos(date, value, fractPattern); | ||
} else { | ||
return value; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getHighlightRequest
didn't usequery
inside, so I decided to remove it from the function signature to removeany
.@lukasolson, could you review this one? Maybe this wasn't correct in the first place that query is not used inside
getHighlightRequest