-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Maps] convert tooltip classes to typescript (#59589)
* getting started * fix ts lint errors * TS es_tooltip_property * convert ESAggTooltipProperty to TS * final clean up * ts lint cleanup * review feedback * remove unused import Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
- Loading branch information
1 parent
848188e
commit eb533c8
Showing
13 changed files
with
194 additions
and
151 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { IESTermSource } from '../sources/es_term_source'; | ||
|
||
export interface IJoin { | ||
getRightJoinSource(): IESTermSource; | ||
} |
12 changes: 12 additions & 0 deletions
12
x-pack/legacy/plugins/maps/public/layers/sources/es_term_source.d.ts
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import { IField } from '../fields/field'; | ||
import { IESAggSource } from './es_agg_source'; | ||
|
||
export interface IESTermSource extends IESAggSource { | ||
getTermField(): IField; | ||
} |
12 changes: 12 additions & 0 deletions
12
x-pack/legacy/plugins/maps/public/layers/tooltips/es_agg_tooltip_property.ts
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
import { ESTooltipProperty } from './es_tooltip_property'; | ||
|
||
export class ESAggTooltipProperty extends ESTooltipProperty { | ||
isFilterable(): boolean { | ||
return false; | ||
} | ||
} |
40 changes: 0 additions & 40 deletions
40
x-pack/legacy/plugins/maps/public/layers/tooltips/es_aggmetric_tooltip_property.js
This file was deleted.
Oops, something went wrong.
49 changes: 0 additions & 49 deletions
49
x-pack/legacy/plugins/maps/public/layers/tooltips/es_tooltip_property.js
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
x-pack/legacy/plugins/maps/public/layers/tooltips/es_tooltip_property.ts
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 |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License; | ||
* you may not use this file except in compliance with the Elastic License. | ||
*/ | ||
|
||
import _ from 'lodash'; | ||
import { ITooltipProperty } from './tooltip_property'; | ||
import { IField } from '../fields/field'; | ||
import { esFilters, IFieldType, IndexPattern } from '../../../../../../../src/plugins/data/public'; | ||
import { PhraseFilter } from '../../../../../../../src/plugins/data/public'; | ||
|
||
export class ESTooltipProperty implements ITooltipProperty { | ||
private readonly _tooltipProperty: ITooltipProperty; | ||
private readonly _indexPattern: IndexPattern; | ||
private readonly _field: IField; | ||
|
||
constructor(tooltipProperty: ITooltipProperty, indexPattern: IndexPattern, field: IField) { | ||
this._tooltipProperty = tooltipProperty; | ||
this._indexPattern = indexPattern; | ||
this._field = field; | ||
} | ||
|
||
getPropertyKey(): string { | ||
return this._tooltipProperty.getPropertyKey(); | ||
} | ||
|
||
getPropertyName(): string { | ||
return this._tooltipProperty.getPropertyName(); | ||
} | ||
|
||
getRawValue(): string | undefined { | ||
return this._tooltipProperty.getRawValue(); | ||
} | ||
|
||
_getIndexPatternField(): IFieldType | undefined { | ||
return this._indexPattern.fields.getByName(this._field.getRootName()); | ||
} | ||
|
||
getHtmlDisplayValue(): string { | ||
if (typeof this.getRawValue() === 'undefined') { | ||
return '-'; | ||
} | ||
|
||
const indexPatternField = this._getIndexPatternField(); | ||
if (!indexPatternField || !this._field.canValueBeFormatted()) { | ||
return _.escape(this.getRawValue()); | ||
} | ||
|
||
const htmlConverter = indexPatternField.format.getConverterFor('html'); | ||
return htmlConverter | ||
? htmlConverter(this.getRawValue()) | ||
: indexPatternField.format.convert(this.getRawValue()); | ||
} | ||
|
||
isFilterable(): boolean { | ||
const indexPatternField = this._getIndexPatternField(); | ||
return ( | ||
!!indexPatternField && | ||
(indexPatternField.type === 'string' || | ||
indexPatternField.type === 'date' || | ||
indexPatternField.type === 'ip' || | ||
indexPatternField.type === 'number') | ||
); | ||
} | ||
|
||
async getESFilters(): Promise<PhraseFilter[]> { | ||
const indexPatternField = this._getIndexPatternField(); | ||
if (!indexPatternField) { | ||
return []; | ||
} | ||
|
||
return [esFilters.buildPhraseFilter(indexPatternField, this.getRawValue(), this._indexPattern)]; | ||
} | ||
} |
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
39 changes: 0 additions & 39 deletions
39
x-pack/legacy/plugins/maps/public/layers/tooltips/tooltip_property.js
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.