Skip to content

Commit

Permalink
Fix links to the numeral formatting (#94858) (#94954)
Browse files Browse the repository at this point in the history
* Fix links to the numeral formatting in the advanced settings (#84167)
* Fix a link to the numeral formatting in the index pattern field settings (#84167)
# Conflicts:
#	docs/development/core/public/kibana-plugin-core-public.doclinksstart.md
#	src/core/public/doc_links/doc_links_service.ts
#	src/plugins/index_pattern_field_editor/public/components/field_format_editor/editors/bytes/__snapshots__/bytes.test.tsx.snap
#	src/plugins/index_pattern_field_editor/public/components/field_format_editor/editors/number/__snapshots__/number.test.tsx.snap
#	src/plugins/index_pattern_field_editor/public/components/field_format_editor/editors/number/number.tsx
#	src/plugins/index_pattern_field_editor/public/components/field_format_editor/editors/percent/__snapshots__/percent.test.tsx.snap
#	src/plugins/index_pattern_field_editor/public/components/field_format_editor/editors/percent/percent.test.tsx
  • Loading branch information
dokmic committed Mar 18, 2021
1 parent 91a6bff commit 37dfe5f
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ readonly links: {
readonly indexPatterns: {
readonly loadingData: string;
readonly introduction: string;
readonly fieldFormattersNumber: string;
};
readonly addData: string;
readonly kibana: string;
Expand Down

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/core/public/doc_links/doc_links_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export class DocLinksService {
indexPatterns: {
loadingData: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/tutorial-load-dataset.html`,
introduction: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/index-patterns.html`,
fieldFormattersNumber: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/numeral.html`,
},
addData: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/connect-to-elasticsearch.html`,
kibana: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/index.html`,
Expand Down Expand Up @@ -354,6 +355,7 @@ export interface DocLinksStart {
readonly indexPatterns: {
readonly loadingData: string;
readonly introduction: string;
readonly fieldFormattersNumber: string;
};
readonly addData: string;
readonly kibana: string;
Expand Down
1 change: 1 addition & 0 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ export interface DocLinksStart {
readonly indexPatterns: {
readonly loadingData: string;
readonly introduction: string;
readonly fieldFormattersNumber: string;
};
readonly addData: string;
readonly kibana: string;
Expand Down
10 changes: 5 additions & 5 deletions src/plugins/data/server/ui_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ export function getUiSettings(): Record<string, UiSettingsParams<unknown>> {
'data.advancedSettings.format.numberFormat.numeralFormatLinkText',
values: {
numeralFormatLink:
'<a href="http://numeraljs.com/" target="_blank" rel="noopener noreferrer">' +
'<a href="https://www.elastic.co/guide/en/kibana/current/numeral.html" target="_blank" rel="noopener">' +
i18n.translate('data.advancedSettings.format.numberFormat.numeralFormatLinkText', {
defaultMessage: 'numeral format',
}) +
Expand All @@ -434,7 +434,7 @@ export function getUiSettings(): Record<string, UiSettingsParams<unknown>> {
'data.advancedSettings.format.percentFormat.numeralFormatLinkText',
values: {
numeralFormatLink:
'<a href="http://numeraljs.com/" target="_blank" rel="noopener noreferrer">' +
'<a href="https://www.elastic.co/guide/en/kibana/current/numeral.html" target="_blank" rel="noopener">' +
i18n.translate('data.advancedSettings.format.percentFormat.numeralFormatLinkText', {
defaultMessage: 'numeral format',
}) +
Expand All @@ -456,7 +456,7 @@ export function getUiSettings(): Record<string, UiSettingsParams<unknown>> {
'data.advancedSettings.format.bytesFormat.numeralFormatLinkText',
values: {
numeralFormatLink:
'<a href="http://numeraljs.com/" target="_blank" rel="noopener noreferrer">' +
'<a href="https://www.elastic.co/guide/en/kibana/current/numeral.html" target="_blank" rel="noopener">' +
i18n.translate('data.advancedSettings.format.bytesFormat.numeralFormatLinkText', {
defaultMessage: 'numeral format',
}) +
Expand All @@ -478,7 +478,7 @@ export function getUiSettings(): Record<string, UiSettingsParams<unknown>> {
'data.advancedSettings.format.currencyFormat.numeralFormatLinkText',
values: {
numeralFormatLink:
'<a href="http://numeraljs.com/" target="_blank" rel="noopener noreferrer">' +
'<a href="https://www.elastic.co/guide/en/kibana/current/numeral.html" target="_blank" rel="noopener">' +
i18n.translate('data.advancedSettings.format.currencyFormat.numeralFormatLinkText', {
defaultMessage: 'numeral format',
}) +
Expand All @@ -504,7 +504,7 @@ export function getUiSettings(): Record<string, UiSettingsParams<unknown>> {
'data.advancedSettings.format.formattingLocaleText',
values: {
numeralLanguageLink:
'<a href="http://numeraljs.com/" target="_blank" rel="noopener noreferrer">' +
'<a href="https://www.elastic.co/guide/en/kibana/current/numeral.html" target="_blank" rel="noopener">' +
i18n.translate(
'data.advancedSettings.format.formattingLocale.numeralLanguageLinkText',
{
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 @@ -8,9 +8,13 @@

import React from 'react';
import { shallow } from 'enzyme';
import { coreMock } from 'src/core/public/mocks';
import { createKibanaReactContext } from '../../../../../../../../kibana_react/public';
import { FieldFormat } from 'src/plugins/data/public';

import { BytesFormatEditor } from './bytes';
import { FieldFormat } from 'src/plugins/data/public';

type BytesFormatEditorProps = React.ComponentProps<typeof BytesFormatEditor>;

const fieldType = 'number';
const format = {
Expand All @@ -25,7 +29,20 @@ const formatParams = {
const onChange = jest.fn();
const onError = jest.fn();

const KibanaReactContext = createKibanaReactContext(
coreMock.createStart({ basePath: 'my-base-path' })
);

describe('BytesFormatEditor', () => {
beforeAll(() => {
// Enzyme does not support the new Context API in shallow rendering.
// @see https://github.com/enzymejs/enzyme/issues/2189
(BytesFormatEditor as React.ComponentType<BytesFormatEditorProps>).contextTypes = {
services: () => null,
};
delete (BytesFormatEditor as Partial<typeof BytesFormatEditor>).contextType;
});

it('should have a formatId', () => {
expect(BytesFormatEditor.formatId).toEqual('bytes');
});
Expand All @@ -38,7 +55,8 @@ describe('BytesFormatEditor', () => {
formatParams={formatParams}
onChange={onChange}
onError={onError}
/>
/>,
{ context: KibanaReactContext.value }
);
expect(component).toMatchSnapshot();
});
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 @@ -8,10 +8,14 @@

import React from 'react';
import { shallow } from 'enzyme';
import { coreMock } from 'src/core/public/mocks';
import { createKibanaReactContext } from '../../../../../../../../kibana_react/public';
import { FieldFormat } from 'src/plugins/data/public';

import { NumberFormatEditor } from './number';

type NumberFormatEditorProps = React.ComponentProps<typeof NumberFormatEditor>;

const fieldType = 'number';
const format = {
getConverterFor: jest.fn().mockImplementation(() => (input: number) => input * 2),
Expand All @@ -25,7 +29,20 @@ const formatParams = {
const onChange = jest.fn();
const onError = jest.fn();

const KibanaReactContext = createKibanaReactContext(
coreMock.createStart({ basePath: 'my-base-path' })
);

describe('NumberFormatEditor', () => {
beforeAll(() => {
// Enzyme does not support the new Context API in shallow rendering.
// @see https://github.com/enzymejs/enzyme/issues/2189
(NumberFormatEditor as React.ComponentType<NumberFormatEditorProps>).contextTypes = {
services: () => null,
};
delete (NumberFormatEditor as Partial<typeof NumberFormatEditor>).contextType;
});

it('should have a formatId', () => {
expect(NumberFormatEditor.formatId).toEqual('number');
});
Expand All @@ -38,7 +55,8 @@ describe('NumberFormatEditor', () => {
formatParams={formatParams}
onChange={onChange}
onError={onError}
/>
/>,
{ context: KibanaReactContext.value }
);
expect(component).toMatchSnapshot();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@ import { FormattedMessage } from '@kbn/i18n/react';
import { DefaultFormatEditor, defaultState } from '../default';

import { FormatEditorSamples } from '../../samples';
import { context as contextType } from '../../../../../../../../kibana_react/public';

export interface NumberFormatEditorParams {
pattern: string;
}

export class NumberFormatEditor extends DefaultFormatEditor<NumberFormatEditorParams> {
static contextType = contextType;
static formatId = 'number';

context!: React.ContextType<typeof contextType>;
state = {
...defaultState,
sampleInputs: [10000, 12.345678, -1, -999, 0.52],
Expand All @@ -43,7 +47,10 @@ export class NumberFormatEditor extends DefaultFormatEditor<NumberFormatEditorPa
}
helpText={
<span>
<EuiLink target="_blank" href="https://adamwdraper.github.io/Numeral-js/">
<EuiLink
target="_blank"
href={this.context.services.docLinks?.links.indexPatterns.fieldFormattersNumber}
>
<FormattedMessage
id="indexPatternManagement.number.documentationLabel"
defaultMessage="Documentation"
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 @@ -8,10 +8,14 @@

import React from 'react';
import { shallow } from 'enzyme';
import { coreMock } from 'src/core/public/mocks';
import { createKibanaReactContext } from '../../../../../../../../kibana_react/public';
import { FieldFormat } from '../../../../../../../../data/public';

import { PercentFormatEditor } from './percent';

type PercentFormatEditorProps = React.ComponentProps<typeof PercentFormatEditor>;

const fieldType = 'number';
const format = {
getConverterFor: jest.fn().mockImplementation(() => (input: number) => input * 2),
Expand All @@ -25,7 +29,20 @@ const formatParams = {
const onChange = jest.fn();
const onError = jest.fn();

const KibanaReactContext = createKibanaReactContext(
coreMock.createStart({ basePath: 'my-base-path' })
);

describe('PercentFormatEditor', () => {
beforeAll(() => {
// Enzyme does not support the new Context API in shallow rendering.
// @see https://github.com/enzymejs/enzyme/issues/2189
(PercentFormatEditor as React.ComponentType<PercentFormatEditorProps>).contextTypes = {
services: () => null,
};
delete (PercentFormatEditor as Partial<typeof PercentFormatEditor>).contextType;
});

it('should have a formatId', () => {
expect(PercentFormatEditor.formatId).toEqual('percent');
});
Expand All @@ -38,7 +55,8 @@ describe('PercentFormatEditor', () => {
formatParams={formatParams}
onChange={onChange}
onError={onError}
/>
/>,
{ context: KibanaReactContext.value }
);
expect(component).toMatchSnapshot();
});
Expand Down

0 comments on commit 37dfe5f

Please sign in to comment.