mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[FieldFormats] Cleanup: rename IFieldFormatType -> FieldFormatInstanceType (#64193)
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
parent
222fba5ddc
commit
d53997742b
12 changed files with 48 additions and 42 deletions
|
@ -7,5 +7,5 @@
|
|||
<b>Signature:</b>
|
||||
|
||||
```typescript
|
||||
baseFormattersPublic: (import("../../common").IFieldFormatType | typeof DateFormat)[]
|
||||
baseFormattersPublic: (import("../../common").FieldFormatInstanceType | typeof DateFormat)[]
|
||||
```
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
```typescript
|
||||
setup(core: CoreSetup, { usageCollection }: DataPluginSetupDependencies): {
|
||||
fieldFormats: {
|
||||
register: (customFieldFormat: import("../common").IFieldFormatType) => number;
|
||||
register: (customFieldFormat: import("../common").FieldFormatInstanceType) => number;
|
||||
};
|
||||
search: ISearchSetup;
|
||||
};
|
||||
|
@ -26,7 +26,7 @@ setup(core: CoreSetup, { usageCollection }: DataPluginSetupDependencies): {
|
|||
|
||||
`{
|
||||
fieldFormats: {
|
||||
register: (customFieldFormat: import("../common").IFieldFormatType) => number;
|
||||
register: (customFieldFormat: import("../common").FieldFormatInstanceType) => number;
|
||||
};
|
||||
search: ISearchSetup;
|
||||
}`
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
* under the License.
|
||||
*/
|
||||
|
||||
import { IFieldFormatType } from '../types';
|
||||
import { FieldFormatInstanceType } from '../types';
|
||||
|
||||
import {
|
||||
BoolFormat,
|
||||
|
@ -36,7 +36,7 @@ import {
|
|||
UrlFormat,
|
||||
} from '../converters';
|
||||
|
||||
export const baseFormatters: IFieldFormatType[] = [
|
||||
export const baseFormatters: FieldFormatInstanceType[] = [
|
||||
BoolFormat,
|
||||
BytesFormat,
|
||||
ColorFormat,
|
||||
|
|
|
@ -18,9 +18,9 @@
|
|||
*/
|
||||
|
||||
import { FieldFormat } from '../field_format';
|
||||
import { TextContextTypeConvert, FIELD_FORMAT_IDS, IFieldFormatType } from '../types';
|
||||
import { TextContextTypeConvert, FIELD_FORMAT_IDS, FieldFormatInstanceType } from '../types';
|
||||
|
||||
export const createCustomFieldFormat = (convert: TextContextTypeConvert): IFieldFormatType =>
|
||||
export const createCustomFieldFormat = (convert: TextContextTypeConvert): FieldFormatInstanceType =>
|
||||
class CustomFieldFormat extends FieldFormat {
|
||||
static id = FIELD_FORMAT_IDS.CUSTOM;
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ import { createCustomFieldFormat } from './converters/custom';
|
|||
import {
|
||||
FieldFormatsGetConfigFn,
|
||||
FieldFormatsContentType,
|
||||
IFieldFormatType,
|
||||
FieldFormatInstanceType,
|
||||
FieldFormatConvert,
|
||||
FieldFormatConvertFunction,
|
||||
HtmlContextTypeOptions,
|
||||
|
@ -199,7 +199,7 @@ export abstract class FieldFormat {
|
|||
};
|
||||
}
|
||||
|
||||
static from(convertFn: FieldFormatConvertFunction): IFieldFormatType {
|
||||
static from(convertFn: FieldFormatConvertFunction): FieldFormatInstanceType {
|
||||
return createCustomFieldFormat(convertFn);
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
*/
|
||||
import { FieldFormatsRegistry } from './field_formats_registry';
|
||||
import { BoolFormat, PercentFormat, StringFormat } from './converters';
|
||||
import { FieldFormatsGetConfigFn, IFieldFormatType } from './types';
|
||||
import { FieldFormatsGetConfigFn, FieldFormatInstanceType } from './types';
|
||||
import { KBN_FIELD_TYPES } from '../../common';
|
||||
|
||||
const getValueOfPrivateField = (instance: any, field: string) => instance[field];
|
||||
|
@ -75,10 +75,10 @@ describe('FieldFormatsRegistry', () => {
|
|||
test('should register field formats', () => {
|
||||
fieldFormatsRegistry.register([StringFormat, BoolFormat]);
|
||||
|
||||
const registeredFieldFormatters: Map<string, IFieldFormatType> = getValueOfPrivateField(
|
||||
fieldFormatsRegistry,
|
||||
'fieldFormats'
|
||||
);
|
||||
const registeredFieldFormatters: Map<
|
||||
string,
|
||||
FieldFormatInstanceType
|
||||
> = getValueOfPrivateField(fieldFormatsRegistry, 'fieldFormats');
|
||||
|
||||
expect(registeredFieldFormatters.size).toBe(2);
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ import {
|
|||
FieldFormatsGetConfigFn,
|
||||
FieldFormatConfig,
|
||||
FIELD_FORMAT_IDS,
|
||||
IFieldFormatType,
|
||||
FieldFormatInstanceType,
|
||||
FieldFormatId,
|
||||
IFieldFormatMetaParams,
|
||||
IFieldFormat,
|
||||
|
@ -35,7 +35,7 @@ import { SerializedFieldFormat } from '../../../expressions/common/types';
|
|||
import { ES_FIELD_TYPES, KBN_FIELD_TYPES } from '../types';
|
||||
|
||||
export class FieldFormatsRegistry {
|
||||
protected fieldFormats: Map<FieldFormatId, IFieldFormatType> = new Map();
|
||||
protected fieldFormats: Map<FieldFormatId, FieldFormatInstanceType> = new Map();
|
||||
protected defaultMap: Record<string, FieldFormatConfig> = {};
|
||||
protected metaParamsOptions: Record<string, any> = {};
|
||||
protected getConfig?: FieldFormatsGetConfigFn;
|
||||
|
@ -47,7 +47,7 @@ export class FieldFormatsRegistry {
|
|||
init(
|
||||
getConfig: FieldFormatsGetConfigFn,
|
||||
metaParamsOptions: Record<string, any> = {},
|
||||
defaultFieldConverters: IFieldFormatType[] = baseFormatters
|
||||
defaultFieldConverters: FieldFormatInstanceType[] = baseFormatters
|
||||
) {
|
||||
const defaultTypeMap = getConfig('format:defaultTypeMap');
|
||||
this.register(defaultFieldConverters);
|
||||
|
@ -79,23 +79,23 @@ export class FieldFormatsRegistry {
|
|||
* Get a derived FieldFormat class by its id.
|
||||
*
|
||||
* @param {FieldFormatId} formatId - the format id
|
||||
* @return {IFieldFormatType | undefined}
|
||||
* @return {FieldFormatInstanceType | undefined}
|
||||
*/
|
||||
getType = (formatId: FieldFormatId): IFieldFormatType | undefined => {
|
||||
getType = (formatId: FieldFormatId): FieldFormatInstanceType | undefined => {
|
||||
const fieldFormat = this.fieldFormats.get(formatId);
|
||||
|
||||
if (fieldFormat) {
|
||||
const decoratedFieldFormat: any = this.fieldFormatMetaParamsDecorator(fieldFormat);
|
||||
|
||||
if (decoratedFieldFormat) {
|
||||
return decoratedFieldFormat as IFieldFormatType;
|
||||
return decoratedFieldFormat as FieldFormatInstanceType;
|
||||
}
|
||||
}
|
||||
|
||||
return undefined;
|
||||
};
|
||||
|
||||
getTypeWithoutMetaParams = (formatId: FieldFormatId): IFieldFormatType | undefined => {
|
||||
getTypeWithoutMetaParams = (formatId: FieldFormatId): FieldFormatInstanceType | undefined => {
|
||||
return this.fieldFormats.get(formatId);
|
||||
};
|
||||
|
||||
|
@ -106,12 +106,12 @@ export class FieldFormatsRegistry {
|
|||
*
|
||||
* @param {KBN_FIELD_TYPES} fieldType
|
||||
* @param {ES_FIELD_TYPES[]} esTypes - Array of ES data types
|
||||
* @return {IFieldFormatType | undefined}
|
||||
* @return {FieldFormatInstanceType | undefined}
|
||||
*/
|
||||
getDefaultType = (
|
||||
fieldType: KBN_FIELD_TYPES,
|
||||
esTypes: ES_FIELD_TYPES[]
|
||||
): IFieldFormatType | undefined => {
|
||||
): FieldFormatInstanceType | undefined => {
|
||||
const config = this.getDefaultConfig(fieldType, esTypes);
|
||||
|
||||
return this.getType(config.id);
|
||||
|
@ -206,14 +206,16 @@ export class FieldFormatsRegistry {
|
|||
* Get filtered list of field formats by format type
|
||||
*
|
||||
* @param {KBN_FIELD_TYPES} fieldType
|
||||
* @return {IFieldFormatType[]}
|
||||
* @return {FieldFormatInstanceType[]}
|
||||
*/
|
||||
getByFieldType(fieldType: KBN_FIELD_TYPES): IFieldFormatType[] {
|
||||
getByFieldType(fieldType: KBN_FIELD_TYPES): FieldFormatInstanceType[] {
|
||||
return [...this.fieldFormats.values()]
|
||||
.filter((format: IFieldFormatType) => format && format.fieldType.indexOf(fieldType) !== -1)
|
||||
.filter(
|
||||
(format: FieldFormatInstanceType) => format && format.fieldType.indexOf(fieldType) !== -1
|
||||
)
|
||||
.map(
|
||||
(format: IFieldFormatType) =>
|
||||
this.fieldFormatMetaParamsDecorator(format) as IFieldFormatType
|
||||
(format: FieldFormatInstanceType) =>
|
||||
this.fieldFormatMetaParamsDecorator(format) as FieldFormatInstanceType
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -238,7 +240,7 @@ export class FieldFormatsRegistry {
|
|||
});
|
||||
}
|
||||
|
||||
register(fieldFormats: IFieldFormatType[]) {
|
||||
register(fieldFormats: FieldFormatInstanceType[]) {
|
||||
fieldFormats.forEach(fieldFormat => this.fieldFormats.set(fieldFormat.id, fieldFormat));
|
||||
}
|
||||
|
||||
|
@ -246,12 +248,12 @@ export class FieldFormatsRegistry {
|
|||
* FieldFormat decorator - provide a one way to add meta-params for all field formatters
|
||||
*
|
||||
* @private
|
||||
* @param {IFieldFormatType} fieldFormat - field format type
|
||||
* @return {IFieldFormatType | undefined}
|
||||
* @param {FieldFormatInstanceType} fieldFormat - field format type
|
||||
* @return {FieldFormatInstanceType | undefined}
|
||||
*/
|
||||
private fieldFormatMetaParamsDecorator = (
|
||||
fieldFormat: IFieldFormatType
|
||||
): IFieldFormatType | undefined => {
|
||||
fieldFormat: FieldFormatInstanceType
|
||||
): FieldFormatInstanceType | undefined => {
|
||||
const getMetaParams = (customParams: Record<string, any>) => this.buildMetaParams(customParams);
|
||||
|
||||
if (fieldFormat) {
|
||||
|
|
|
@ -52,6 +52,6 @@ export {
|
|||
FieldFormatConfig,
|
||||
FieldFormatId,
|
||||
// Used in data plugin only
|
||||
IFieldFormatType,
|
||||
FieldFormatInstanceType,
|
||||
IFieldFormat,
|
||||
} from './types';
|
||||
|
|
|
@ -16,9 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
import { FieldFormat } from './field_format';
|
||||
export { FieldFormat };
|
||||
|
||||
/** @public **/
|
||||
export type FieldFormatsContentType = 'html' | 'text';
|
||||
|
@ -82,10 +80,12 @@ export type IFieldFormat = PublicMethodsOf<FieldFormat>;
|
|||
*/
|
||||
export type FieldFormatId = FIELD_FORMAT_IDS | string;
|
||||
|
||||
export type IFieldFormatType = (new (
|
||||
/** @internal **/
|
||||
export type FieldFormatInstanceType = (new (
|
||||
params?: any,
|
||||
getConfig?: FieldFormatsGetConfigFn
|
||||
) => FieldFormat) & {
|
||||
// Static properties:
|
||||
id: FieldFormatId;
|
||||
title: string;
|
||||
fieldType: string | string[];
|
||||
|
|
|
@ -138,7 +138,7 @@ export class AggTypeFilters {
|
|||
// Warning: (ae-missing-release-tag) "baseFormattersPublic" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
// @public (undocumented)
|
||||
export const baseFormattersPublic: (import("../../common").IFieldFormatType | typeof DateFormat)[];
|
||||
export const baseFormattersPublic: (import("../../common").FieldFormatInstanceType | typeof DateFormat)[];
|
||||
|
||||
// Warning: (ae-missing-release-tag) "BUCKET_TYPES" is exported by the package, but it is missing a release tag (@alpha, @beta, @public, or @internal)
|
||||
//
|
||||
|
|
|
@ -17,16 +17,20 @@
|
|||
* under the License.
|
||||
*/
|
||||
import { has } from 'lodash';
|
||||
import { FieldFormatsRegistry, IFieldFormatType, baseFormatters } from '../../common/field_formats';
|
||||
import {
|
||||
FieldFormatsRegistry,
|
||||
FieldFormatInstanceType,
|
||||
baseFormatters,
|
||||
} from '../../common/field_formats';
|
||||
import { IUiSettingsClient } from '../../../../core/server';
|
||||
import { DateFormat } from './converters';
|
||||
|
||||
export class FieldFormatsService {
|
||||
private readonly fieldFormatClasses: IFieldFormatType[] = [DateFormat, ...baseFormatters];
|
||||
private readonly fieldFormatClasses: FieldFormatInstanceType[] = [DateFormat, ...baseFormatters];
|
||||
|
||||
public setup() {
|
||||
return {
|
||||
register: (customFieldFormat: IFieldFormatType) =>
|
||||
register: (customFieldFormat: FieldFormatInstanceType) =>
|
||||
this.fieldFormatClasses.push(customFieldFormat),
|
||||
};
|
||||
}
|
||||
|
|
|
@ -609,7 +609,7 @@ export class Plugin implements Plugin_2<PluginSetup, PluginStart> {
|
|||
// (undocumented)
|
||||
setup(core: CoreSetup, { usageCollection }: DataPluginSetupDependencies): {
|
||||
fieldFormats: {
|
||||
register: (customFieldFormat: import("../common").IFieldFormatType) => number;
|
||||
register: (customFieldFormat: import("../common").FieldFormatInstanceType) => number;
|
||||
};
|
||||
search: ISearchSetup;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue