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

Expose NP FieldFormats service to server side #55419

Merged
merged 27 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
08c845d
Expose NP FieldFormats service to server side
alexwizp Jan 21, 2020
7752b6e
fix CI
alexwizp Jan 22, 2020
02df835
Merge branch 'master' into 54571
elasticmachine Jan 22, 2020
e86b069
Merge remote-tracking branch 'upstream/master' into 54571
alexwizp Jan 22, 2020
0be4619
fix PR comments
alexwizp Jan 22, 2020
b763a66
Merge remote-tracking branch 'upstream/master' into 54571
alexwizp Jan 23, 2020
9bb6300
fix PR comments
alexwizp Jan 23, 2020
cd12136
Merge remote-tracking branch 'upstream/master' into 54571
alexwizp Jan 23, 2020
0b1985f
fix CI
alexwizp Jan 23, 2020
73ee1e6
getFieldFormatsRegistry -> getFieldFormatRegistry
alexwizp Jan 23, 2020
8162165
Merge branch 'master' into 54571
alexwizp Jan 23, 2020
380a921
fix CI
alexwizp Jan 23, 2020
9f0cf97
Merge remote-tracking branch 'upstream/master' into 54571
alexwizp Jan 23, 2020
223738e
memoize - add resolve cache function
alexwizp Jan 23, 2020
81414fb
Merge remote-tracking branch 'upstream/master' into 54571
alexwizp Jan 23, 2020
1aa0097
fix Jest
alexwizp Jan 23, 2020
3d4adc3
Merge remote-tracking branch 'upstream/master' into 54571
alexwizp Jan 23, 2020
b25d81a
Merge remote-tracking branch 'upstream/master' into 54571
alexwizp Jan 24, 2020
32388e4
move IFieldFormatMetaParams to types.ts
alexwizp Jan 24, 2020
d76ceb3
Merge remote-tracking branch 'upstream/master' into 54571
alexwizp Jan 27, 2020
369b1c0
FieldFormatRegistry -> FieldFormatsRegistry
alexwizp Jan 27, 2020
91e6d12
update src/core/MIGRATION.md
alexwizp Jan 27, 2020
74d5735
update public contract
alexwizp Jan 27, 2020
b205ba6
Merge remote-tracking branch 'upstream/master' into 54571
alexwizp Jan 27, 2020
523d4b5
Merge branch 'master' into 54571
elasticmachine Jan 27, 2020
7ff4c2d
Merge remote-tracking branch 'upstream/master' into 54571
alexwizp Jan 27, 2020
5072086
Merge remote-tracking branch 'upstream/master' into 54571
alexwizp Jan 27, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -244,15 +244,15 @@ module.exports = {
{
target: [
'(src|x-pack)/plugins/**/*',
'!(src|x-pack)/plugins/*/server/**/*',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

modified to add support for:
x-pack/legacy/plugins/reporting/export_types/csv/server/

'!(src|x-pack)/plugins/**/server/**/*',

'src/legacy/core_plugins/**/*',
'!src/legacy/core_plugins/*/server/**/*',
'!src/legacy/core_plugins/*/index.{js,ts,tsx}',
'!src/legacy/core_plugins/**/server/**/*',
'!src/legacy/core_plugins/**/index.{js,ts,tsx}',

'x-pack/legacy/plugins/**/*',
'!x-pack/legacy/plugins/*/server/**/*',
'!x-pack/legacy/plugins/*/index.{js,ts,tsx}',
'!x-pack/legacy/plugins/**/server/**/*',
'!x-pack/legacy/plugins/**/index.{js,ts,tsx}',

'examples/**/*',
'!examples/**/server/**/*',
Expand Down
4 changes: 2 additions & 2 deletions src/core/MIGRATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -1231,8 +1231,8 @@ This table shows where these uiExports have moved to in the New Platform. In mos
| `docViews` | | |
| `embeddableActions` | | Should be an API on the embeddables plugin. |
| `embeddableFactories` | | Should be an API on the embeddables plugin. |
| `fieldFormatEditors` | | |
| `fieldFormats` | | |
| `fieldFormatEditors` | | |
| `fieldFormats` | [`plugins.data.fieldFormats`](./src/plugins/data/public/field_formats) | |
| `hacks` | n/a | Just run the code in your plugin's `start` method. |
| `home` | [`plugins.home.featureCatalogue.register`](./src/plugins/home/public/feature_catalogue) | Must add `home` as a dependency in your kibana.json. |
| `indexManagement` | | Should be an API on the indexManagement plugin. |
Expand Down
2 changes: 0 additions & 2 deletions src/legacy/core_plugins/kibana/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import { migrations } from './migrations';
import { importApi } from './server/routes/api/import';
import { exportApi } from './server/routes/api/export';
import { managementApi } from './server/routes/api/management';
import { registerFieldFormats } from './server/field_formats/register';
import * as systemApi from './server/lib/system_api';
import mappings from './mappings.json';
import { getUiSettingDefaults } from './ui_setting_defaults';
Expand Down Expand Up @@ -331,7 +330,6 @@ export default function(kibana) {
importApi(server);
exportApi(server);
managementApi(server);
registerFieldFormats(server);
registerCspCollector(usageCollection, server);
server.expose('systemApi', systemApi);
server.injectUiAppVars('kibana', () => injectVars(server));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { isColorDark } from '@elastic/eui';

import { getHeatmapColors, getFormat, Vis } from '../legacy_imports';
import { MetricVisValue } from './metric_vis_value';
import { FieldFormat, ContentType } from '../../../../../plugins/data/public';
import { fieldFormats } from '../../../../../plugins/data/public';
import { Context } from '../metric_vis_fn';
import { KibanaDatatable } from '../../../../../plugins/expressions/public';
import { VisParams, MetricVisMetric } from '../types';
Expand Down Expand Up @@ -100,9 +100,9 @@ export class MetricVisComponent extends Component<MetricVisComponentProps> {
}

private getFormattedValue = (
fieldFormatter: FieldFormat,
fieldFormatter: fieldFormats.FieldFormat,
value: any,
format: ContentType = 'text'
format: fieldFormats.ContentType = 'text'
) => {
if (isNaN(value)) return '-';
return fieldFormatter.convert(value, format);
Expand All @@ -119,7 +119,7 @@ export class MetricVisComponent extends Component<MetricVisComponentProps> {
const metrics: MetricVisMetric[] = [];

let bucketColumnId: string;
let bucketFormatter: FieldFormat;
let bucketFormatter: fieldFormats.FieldFormat;

if (dimensions.bucket) {
bucketColumnId = table.columns[dimensions.bucket.accessor].id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { npStart } from 'ui/new_platform';
import getStubIndexPattern from 'fixtures/stubbed_logstash_index_pattern';

import { Vis } from '../../visualizations/public';
import { UrlFormat } from '../../../../plugins/data/public';
import { fieldFormats } from '../../../../plugins/data/public';
import {
setup as visualizationsSetup,
start as visualizationsStart,
Expand All @@ -39,7 +39,7 @@ describe('metric_vis - createMetricVisTypeDefinition', () => {
beforeAll(() => {
visualizationsSetup.types.createReactVisualization(metricVisTypeDefinition);
(npStart.plugins.data.fieldFormats.getType as jest.Mock).mockImplementation(() => {
return UrlFormat;
return fieldFormats.UrlFormat;
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { calculateLabel } from '../../../../common/calculate_label';
import { isSortable } from './is_sortable';
import { EuiToolTip, EuiIcon } from '@elastic/eui';
import { replaceVars } from '../../lib/replace_vars';
import { FIELD_FORMAT_IDS } from '../../../../../../../plugins/data/public';
import { fieldFormats } from '../../../../../../../plugins/data/public';
import { FormattedMessage } from '@kbn/i18n/react';

import { METRIC_TYPES } from '../../../../common/metric_types';
Expand All @@ -49,8 +49,8 @@ export class TableVis extends Component {
constructor(props) {
super(props);

const fieldFormats = npStart.plugins.data.fieldFormats;
const DateFormat = fieldFormats.getType(FIELD_FORMAT_IDS.DATE);
const fieldFormatsService = npStart.plugins.data.fieldFormats;
const DateFormat = fieldFormatsService.getType(fieldFormats.FIELD_FORMAT_IDS.DATE);

this.dateFormatter = new DateFormat({}, this.props.getConfig);
}
Expand Down
20 changes: 0 additions & 20 deletions src/legacy/ui/field_formats/index.ts

This file was deleted.

45 changes: 0 additions & 45 deletions src/legacy/ui/field_formats/mixin/field_formats_mixin.ts

This file was deleted.

56 changes: 0 additions & 56 deletions src/legacy/ui/field_formats/mixin/field_formats_service.test.ts

This file was deleted.

79 changes: 0 additions & 79 deletions src/legacy/ui/field_formats/mixin/field_formats_service.ts

This file was deleted.

12 changes: 6 additions & 6 deletions src/legacy/ui/public/agg_types/agg_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import { AggConfigs } from './agg_configs';
import { Schema } from '../vis/editors/default/schemas';
import {
ISearchSource,
ContentType,
KBN_FIELD_TYPES,
FetchOptions,
fieldFormats,
KBN_FIELD_TYPES,
} from '../../../../plugins/data/public';

export interface AggConfigOptions {
Expand Down Expand Up @@ -375,7 +375,7 @@ export class AggConfig {
return this.aggConfigs.timeRange;
}

fieldFormatter(contentType?: ContentType, defaultFormat?: any) {
fieldFormatter(contentType?: fieldFormats.ContentType, defaultFormat?: any) {
const format = this.type && this.type.getFormat(this);

if (format) {
Expand All @@ -385,12 +385,12 @@ export class AggConfig {
return this.fieldOwnFormatter(contentType, defaultFormat);
}

fieldOwnFormatter(contentType?: ContentType, defaultFormat?: any) {
const fieldFormats = npStart.plugins.data.fieldFormats;
fieldOwnFormatter(contentType?: fieldFormats.ContentType, defaultFormat?: any) {
const fieldFormatsService = npStart.plugins.data.fieldFormats;
const field = this.getField();
let format = field && field.format;
if (!format) format = defaultFormat;
if (!format) format = fieldFormats.getDefaultInstance(KBN_FIELD_TYPES.STRING);
if (!format) format = fieldFormatsService.getDefaultInstance(KBN_FIELD_TYPES.STRING);
return format.getConverterFor(contentType);
}

Expand Down
10 changes: 5 additions & 5 deletions src/legacy/ui/public/agg_types/agg_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { AggConfigs } from './agg_configs';
import { Adapters } from '../inspector';
import { BaseParamType } from './param_types/base';
import { AggParamType } from '../agg_types/param_types/agg';
import { KBN_FIELD_TYPES, FieldFormat, ISearchSource } from '../../../../plugins/data/public';
import { KBN_FIELD_TYPES, fieldFormats, ISearchSource } from '../../../../plugins/data/public';

export interface AggTypeConfig<
TAggConfig extends AggConfig = AggConfig,
Expand All @@ -54,16 +54,16 @@ export interface AggTypeConfig<
inspectorAdapters: Adapters,
abortSignal?: AbortSignal
) => Promise<any>;
getFormat?: (agg: TAggConfig) => FieldFormat;
getFormat?: (agg: TAggConfig) => fieldFormats.FieldFormat;
getValue?: (agg: TAggConfig, bucket: any) => any;
getKey?: (bucket: any, key: any, agg: TAggConfig) => any;
}

const getFormat = (agg: AggConfig) => {
const field = agg.getField();
const fieldFormats = npStart.plugins.data.fieldFormats;
const fieldFormatsService = npStart.plugins.data.fieldFormats;

return field ? field.format : fieldFormats.getDefaultInstance(KBN_FIELD_TYPES.STRING);
return field ? field.format : fieldFormatsService.getDefaultInstance(KBN_FIELD_TYPES.STRING);
};

export class AggType<
Expand Down Expand Up @@ -191,7 +191,7 @@ export class AggType<
* @param {agg} agg - the agg to pick a format for
* @return {FieldFormat}
*/
getFormat: (agg: TAggConfig) => FieldFormat;
getFormat: (agg: TAggConfig) => fieldFormats.FieldFormat;

getValue: (agg: TAggConfig, bucket: any) => any;

Expand Down
Loading