Skip to content

Commit

Permalink
Fix browser date format (elastic#57714)
Browse files Browse the repository at this point in the history
* fix browser date formatter
  • Loading branch information
mattkime committed Feb 20, 2020
1 parent 0a87f2d commit 8e235eb
Show file tree
Hide file tree
Showing 17 changed files with 161 additions and 51 deletions.
1 change: 1 addition & 0 deletions src/plugins/data/common/field_formats/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
*/

export { DEFAULT_CONVERTER_COLOR } from './color_default';
export { baseFormatters } from './base_formatters';
1 change: 0 additions & 1 deletion src/plugins/data/common/field_formats/converters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

export { UrlFormat } from './url';
export { BytesFormat } from './bytes';
export { DateFormat } from './date_server';
export { DateNanosFormat } from './date_nanos';
export { RelativeDateFormat } from './relative_date';
export { DurationFormat } from './duration';
Expand Down
7 changes: 1 addition & 6 deletions src/plugins/data/common/field_formats/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,7 @@
*/

export { HTML_CONTEXT_TYPE, TEXT_CONTEXT_TYPE } from './content_types';
export {
FieldFormat,
IFieldFormatType,
IFieldFormatId,
IFieldFormatMetaParams,
} from './field_format';
export { FieldFormat, IFieldFormatType, IFieldFormatId } from './field_format';
export { getHighlightRequest, asPrettyString, getHighlightHtml } from './utils';
export * from './converters';
export * from './constants';
1 change: 1 addition & 0 deletions src/plugins/data/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ export * from './timefilter/types';
export * from './query/types';
export * from './kbn_field_types/types';
export * from './index_patterns/types';
export { TextContextTypeConvert } from './field_formats/types';
23 changes: 23 additions & 0 deletions src/plugins/data/public/field_formats/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { baseFormatters } from '../../common';
import { DateFormat } from './converters/date';

export const baseFormattersPublic = [DateFormat, ...baseFormatters];
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@

import { memoize, noop } from 'lodash';
import moment from 'moment';
import { KBN_FIELD_TYPES } from '../../kbn_field_types/types';
import { FieldFormat } from '../field_format';
import { TextContextTypeConvert, FIELD_FORMAT_IDS } from '../types';
import {
FieldFormat,
KBN_FIELD_TYPES,
TextContextTypeConvert,
FIELD_FORMAT_IDS,
} from '../../../common';

export class DateFormat extends FieldFormat {
static id = FIELD_FORMAT_IDS.DATE;
Expand Down
20 changes: 20 additions & 0 deletions src/plugins/data/public/field_formats/converters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { DateFormat } from './date';
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { FieldFormatsService } from './field_formats_service';
import { coreMock } from '../../../../../src/core/public/mocks';
import { DateFormat } from './converters/date';

describe('FieldFormatService', () => {
test('DateFormat is public version', () => {
const mockCore = coreMock.createSetup();
const service = new FieldFormatsService();
service.setup(mockCore);
const fieldFormatsRegistry = service.start();
const DateFormatFromRegsitry = fieldFormatsRegistry.getTypeWithoutMetaParams('date');

expect(DateFormatFromRegsitry).toEqual(DateFormat);
});
});
4 changes: 3 additions & 1 deletion src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export {
TimeRange,
} from '../common';

export { DateFormat } from './field_formats';
export { baseFormattersPublic } from './field_formats/constants';

/**
* Static code to be shared externally
* @public
Expand All @@ -68,7 +71,6 @@ export {
BoolFormat,
BytesFormat,
ColorFormat,
DateFormat,
DateNanosFormat,
DEFAULT_CONVERTER_COLOR,
DurationFormat,
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ const fieldFormatsMock: PublicMethodsOf<FieldFormatRegisty> = {
init: jest.fn(),
register: jest.fn(),
parseDefaultTypeMap: jest.fn(),
deserialize: jest.fn(),
getTypeWithoutMetaParams: jest.fn(),
};

const createSetupContract = (): Setup => {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@

import { memoize, noop } from 'lodash';
import moment from 'moment-timezone';
import { KBN_FIELD_TYPES } from '../../kbn_field_types/types';
import { FieldFormat, IFieldFormatMetaParams } from '../field_format';
import { TextContextTypeConvert, FIELD_FORMAT_IDS } from '../types';

import {
FieldFormat,
KBN_FIELD_TYPES,
TextContextTypeConvert,
FIELD_FORMAT_IDS,
IFieldFormatMetaParams,
} from '../../../common';

export class DateFormat extends FieldFormat {
static id = FIELD_FORMAT_IDS.DATE;
Expand Down
20 changes: 20 additions & 0 deletions src/plugins/data/server/field_formats/converters/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export { DateFormat } from './date_server';
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { FieldFormatsService } from './field_formats_service';
import { DateFormat } from './converters/date_server';
import { coreMock } from '../../../../core/server/mocks';

describe('FieldFormatService', () => {
test('DateFormat is server version', async () => {
const service = new FieldFormatsService();
const fieldFormatsService = await service.start();
const uiSettings = coreMock.createStart().uiSettings.asScopedToClient({} as any);
const fieldFormatsRegistry = await fieldFormatsService.fieldFormatServiceFactory(uiSettings);
const DateFormatFromRegsitry = fieldFormatsRegistry.getTypeWithoutMetaParams('date');

expect(DateFormatFromRegsitry).toEqual(DateFormat);
});
});
1 change: 0 additions & 1 deletion src/plugins/data/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ export {
BoolFormat,
BytesFormat,
ColorFormat,
DateFormat,
DateNanosFormat,
DEFAULT_CONVERTER_COLOR,
DurationFormat,
Expand Down
38 changes: 2 additions & 36 deletions src/test_utils/public/stub_field_formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,46 +18,12 @@
*/
import { CoreSetup } from 'kibana/public';

import {
FieldFormatRegisty,
BoolFormat,
BytesFormat,
ColorFormat,
DateFormat,
DateNanosFormat,
DurationFormat,
IpFormat,
NumberFormat,
PercentFormat,
RelativeDateFormat,
SourceFormat,
StaticLookupFormat,
StringFormat,
TruncateFormat,
UrlFormat,
} from '../../plugins/data/public/';
import { FieldFormatRegisty, baseFormattersPublic } from '../../plugins/data/public/';

export const getFieldFormatsRegistry = (core: CoreSetup) => {
const fieldFormats = new FieldFormatRegisty();

fieldFormats.register([
BoolFormat,
BytesFormat,
ColorFormat,
DateFormat,
DateNanosFormat,
DurationFormat,
IpFormat,
NumberFormat,
PercentFormat,
RelativeDateFormat,
SourceFormat,
StaticLookupFormat,
StringFormat,
TruncateFormat,
UrlFormat,
]);

fieldFormats.register(baseFormattersPublic);
fieldFormats.init(core);

return fieldFormats;
Expand Down

0 comments on commit 8e235eb

Please sign in to comment.