Skip to content

Commit

Permalink
Fix links to the numeral formatting in the index pattern field settin…
Browse files Browse the repository at this point in the history
  • Loading branch information
dokmic committed Mar 17, 2021
1 parent 9073407 commit 28d4fb1
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
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: {
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`,
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 @@ -392,6 +393,8 @@ export interface DocLinksStart {
readonly indexPatterns: {
readonly loadingData: string;
readonly introduction: string;
readonly fieldFormattersNumber: string;
readonly fieldFormattersString: string;
};
readonly addData: string;
readonly kibana: string;
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,19 @@ const formatParams = {
const onChange = jest.fn();
const onError = jest.fn();

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

describe('NumberFormatEditor', () => {
beforeAll(() => {
// @see https://github.com/airbnb/enzyme/issues/1553
(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 +54,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

0 comments on commit 28d4fb1

Please sign in to comment.