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 links to the numeral formatting #94858

Merged
merged 2 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ readonly links: {
};
readonly indexPatterns: {
readonly introduction: string;
readonly fieldFormattersNumber: string;
readonly fieldFormattersString: string;
};
readonly addData: string;
readonly kibana: string;
Expand Down

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/core/public/doc_links/doc_links_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ export class DocLinksService {
},
indexPatterns: {
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`,
fieldFormattersString: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/field-formatters-string.html`,
},
addData: `${ELASTIC_WEBSITE_URL}guide/en/kibana/${DOC_LINK_VERSION}/connect-to-elasticsearch.html`,
Expand Down Expand Up @@ -391,6 +392,8 @@ export interface DocLinksStart {
};
readonly indexPatterns: {
readonly introduction: string;
readonly fieldFormattersNumber: string;
readonly fieldFormattersString: string;
};
readonly addData: string;
readonly kibana: string;
Expand Down
2 changes: 2 additions & 0 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,8 @@ export interface DocLinksStart {
};
readonly indexPatterns: {
readonly introduction: string;
readonly fieldFormattersNumber: string;
readonly fieldFormattersString: 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 @@ -417,7 +417,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">' +
Copy link
Contributor

@mattkime mattkime Mar 17, 2021

Choose a reason for hiding this comment

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

We should check to see if we can use the docLinks service for this but there's no reason to block this PR.


I spoke to the kibana core team and they're open to doing this - we should create an issue for this. I'll leave this in your hands and help out as needed.

i18n.translate('data.advancedSettings.format.numberFormat.numeralFormatLinkText', {
defaultMessage: 'numeral format',
}) +
Expand All @@ -439,7 +439,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 @@ -461,7 +461,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 @@ -483,7 +483,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 @@ -509,7 +509,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 @@ -15,12 +15,17 @@ 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 +48,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="indexPatternFieldEditor.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 'src/plugins/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