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

Fix browser date format #57714

Merged
merged 15 commits into from
Feb 20, 2020
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
BoolFormat,
BytesFormat,
ColorFormat,
DateFormat,
DateNanosFormat,
DurationFormat,
IpFormat,
Expand All @@ -41,7 +40,6 @@ export const baseFormatters: IFieldFormatType[] = [
BoolFormat,
BytesFormat,
ColorFormat,
DateFormat,
DateNanosFormat,
DurationFormat,
IpFormat,
Expand Down
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
1 change: 0 additions & 1 deletion src/plugins/data/common/field_formats/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export {
BoolFormat,
BytesFormat,
ColorFormat,
DateFormat,
DateNanosFormat,
DurationFormat,
IpFormat,
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ export * from './timefilter/types';
export * from './query/types';
export * from './kbn_field_types/types';
export * from './index_patterns/types';
export { TextContextTypeConvert, IFieldFormatMetaParams } from './field_formats/types';
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@
import { i18n } from '@kbn/i18n';
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 } from '../../../common/';
import { TextContextTypeConvert, FIELD_FORMAT_IDS } from '../../types';

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';
19 changes: 12 additions & 7 deletions src/plugins/data/public/field_formats/field_formats_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
*/

import { CoreSetup } from 'src/core/public';
import { FieldFormatsRegistry } from '../../common/field_formats';
import { DateFormat } from './converters/date';
import { FieldFormatsRegistry, baseFormatters } from '../../common';

export class FieldFormatsService {
private readonly fieldFormatsRegistry: FieldFormatsRegistry = new FieldFormatsRegistry();
Expand All @@ -32,13 +33,17 @@ export class FieldFormatsService {

const getConfig = core.uiSettings.get.bind(core.uiSettings);

this.fieldFormatsRegistry.init(getConfig, {
parsedUrl: {
origin: window.location.origin,
pathname: window.location.pathname,
basePath: core.http.basePath.get(),
this.fieldFormatsRegistry.init(
getConfig,
{
parsedUrl: {
origin: window.location.origin,
pathname: window.location.pathname,
basePath: core.http.basePath.get(),
},
},
});
[DateFormat, ...baseFormatters]
);

return this.fieldFormatsRegistry as FieldFormatsSetup;
}
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/field_formats/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@
*/

export { FieldFormatsService, FieldFormatsSetup, FieldFormatsStart } from './field_formats_service';
export { DateFormat } from './converters';
3 changes: 2 additions & 1 deletion src/plugins/data/public/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ import {
BoolFormat,
BytesFormat,
ColorFormat,
DateFormat,
DateNanosFormat,
DurationFormat,
IpFormat,
Expand All @@ -170,6 +169,8 @@ import {
TruncateFormat,
} from '../common/field_formats';

import { DateFormat } from './field_formats';

// Field formats helpers namespace:
export const fieldFormats = {
FieldFormat,
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import { IndexPatternSelectProps } from './ui/index_pattern_select';
import { IndexPatternsContract } from './index_patterns';
import { StatefulSearchBarProps } from './ui/search_bar/create_search_bar';

export { TextContextTypeConvert, FIELD_FORMAT_IDS } from '../common';

export interface DataSetupDependencies {
uiActions: UiActionsSetup;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@
import { i18n } from '@kbn/i18n';
import { memoize, noop } from 'lodash';
import moment from 'moment-timezone';
import { KBN_FIELD_TYPES } from '../../kbn_field_types/types';
import { FieldFormat } from '../field_format';
import { FieldFormat, KBN_FIELD_TYPES } from '../../../common';
import {
TextContextTypeConvert,
FIELD_FORMAT_IDS,
FieldFormatsGetConfigFn,
IFieldFormatMetaParams,
} from '../types';
} from '../../types';

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
Expand Up @@ -19,9 +19,10 @@
import { has } from 'lodash';
import { FieldFormatsRegistry, IFieldFormatType, baseFormatters } from '../../common/field_formats';
import { IUiSettingsClient } from '../../../../core/server';
import { DateFormat } from './converters';

export class FieldFormatsService {
private readonly fieldFormatClasses: IFieldFormatType[] = baseFormatters;
private readonly fieldFormatClasses: IFieldFormatType[] = [DateFormat, ...baseFormatters];

public setup() {
return {
Expand Down
3 changes: 0 additions & 3 deletions src/plugins/data/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ import {
BoolFormat,
BytesFormat,
ColorFormat,
DateFormat,
DateNanosFormat,
DurationFormat,
IpFormat,
Expand All @@ -100,11 +99,9 @@ import {
export const fieldFormats = {
FieldFormatsRegistry,
FieldFormat,

BoolFormat,
BytesFormat,
ColorFormat,
DateFormat,
DateNanosFormat,
DurationFormat,
IpFormat,
Expand Down
25 changes: 25 additions & 0 deletions src/plugins/data/server/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 {
mattkime marked this conversation as resolved.
Show resolved Hide resolved
TextContextTypeConvert,
FIELD_FORMAT_IDS,
FieldFormatsGetConfigFn,
IFieldFormatMetaParams,
} from '../common';
3 changes: 2 additions & 1 deletion src/test_utils/public/stub_field_formats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@
*/
import { CoreSetup } from 'kibana/public';
import { fieldFormats } from '../../plugins/data/public';
import { baseFormatters } from '../../plugins/data/common';

export const getFieldFormatsRegistry = (core: CoreSetup) => {
const fieldFormatsRegistry = new fieldFormats.FieldFormatsRegistry();
const getConfig = core.uiSettings.get.bind(core.uiSettings);

fieldFormatsRegistry.init(getConfig, {});
fieldFormatsRegistry.init(getConfig, {}, [fieldFormats.DateFormat, ...baseFormatters]);

return fieldFormatsRegistry;
};