Skip to content

Commit

Permalink
[Mappings editor] Add support for histogram field type (#76671)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth authored Sep 17, 2020
1 parent 53c8fad commit 11f100b
Show file tree
Hide file tree
Showing 18 changed files with 167 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ export * from './other_type_name_parameter';

export * from './other_type_json_parameter';

export * from './meta_parameter';

export * from './ignore_above_parameter';

export const PARAMETER_SERIALIZERS = [relationsSerializer, dynamicSerializer];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import React, { FunctionComponent } from 'react';

import { i18n } from '@kbn/i18n';

import { documentationService } from '../../../../../services/documentation';
import { UseField, JsonEditorField } from '../../../shared_imports';
import { getFieldConfig } from '../../../lib';
import { EditFieldFormRow } from '../fields/edit_field';

interface Props {
defaultToggleValue: boolean;
}

export const MetaParameter: FunctionComponent<Props> = ({ defaultToggleValue }) => (
<EditFieldFormRow
title={i18n.translate('xpack.idxMgmt.mappingsEditor.metaParameterTitle', {
defaultMessage: 'Set metadata',
})}
description={i18n.translate('xpack.idxMgmt.mappingsEditor.metaParameterDescription', {
defaultMessage: 'Arbitrary information about the field. Specify as JSON key-value pairs.',
})}
defaultToggleValue={defaultToggleValue}
docLink={{
text: i18n.translate('xpack.idxMgmt.mappingsEditor.metaParameterDocLinkText', {
defaultMessage: 'Metadata documentation',
}),
href: documentationService.getMetaLink(),
}}
>
<UseField
path="meta"
config={getFieldConfig('meta')}
component={JsonEditorField}
componentProps={{
euiCodeEditorProps: {
height: '300px',
'aria-label': i18n.translate('xpack.idxMgmt.mappingsEditor.metaParameterAriaLabel', {
defaultMessage: 'metadata field data editor',
}),
},
}}
/>
</EditFieldFormRow>
);
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,25 @@
*/
import React from 'react';

import { StoreParameter, DocValuesParameter } from '../../field_parameters';
import { NormalizedField, ParameterName, Field as FieldType } from '../../../../types';
import { getFieldConfig } from '../../../../lib';
import { StoreParameter, DocValuesParameter, MetaParameter } from '../../field_parameters';
import { AdvancedParametersSection } from '../edit_field';

export const BinaryType = () => {
const getDefaultToggleValue = (param: ParameterName, field: FieldType) => {
return field[param] !== undefined && field[param] !== getFieldConfig(param).defaultValue;
};

interface Props {
field: NormalizedField;
}

export const BinaryType = ({ field }: Props) => {
return (
<AdvancedParametersSection>
<DocValuesParameter configPath="doc_values_binary" />
<StoreParameter />
<MetaParameter defaultToggleValue={getDefaultToggleValue('meta', field.source)} />
</AdvancedParametersSection>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ import {
DocValuesParameter,
BoostParameter,
NullValueParameter,
MetaParameter,
} from '../../field_parameters';
import { BasicParametersSection, AdvancedParametersSection } from '../edit_field';

const getDefaultToggleValue = (param: string, field: FieldType) => {
switch (param) {
case 'meta':
case 'boost': {
return field[param] !== undefined && field[param] !== getFieldConfig(param).defaultValue;
}
Expand Down Expand Up @@ -90,6 +92,8 @@ export const BooleanType = ({ field }: Props) => {

<StoreParameter />

<MetaParameter defaultToggleValue={getDefaultToggleValue('meta', field.source)} />

<BoostParameter defaultToggleValue={getDefaultToggleValue('boost', field.source)} />
</AdvancedParametersSection>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@ import { i18n } from '@kbn/i18n';
import { NormalizedField, Field as FieldType } from '../../../../types';
import { getFieldConfig } from '../../../../lib';
import { UseField, Field } from '../../../../shared_imports';
import { AnalyzersParameter } from '../../field_parameters';
import { AnalyzersParameter, MetaParameter } from '../../field_parameters';
import { EditFieldFormRow, AdvancedParametersSection } from '../edit_field';

const getDefaultToggleValue = (param: string, field: FieldType) => {
switch (param) {
case 'meta':
case 'max_input_length': {
return field[param] !== undefined && field[param] !== getFieldConfig(param).defaultValue;
}
Expand Down Expand Up @@ -88,6 +89,8 @@ export const CompletionType = ({ field }: Props) => {
)}
formFieldPath="preserve_position_increments"
/>

<MetaParameter defaultToggleValue={getDefaultToggleValue('meta', field.source)} />
</AdvancedParametersSection>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,20 @@
import React, { FunctionComponent } from 'react';
import { i18n } from '@kbn/i18n';

import { documentationService } from '../../../../../../services/documentation';
import { UseField, Field, JsonEditorField } from '../../../../shared_imports';
import { UseField, Field } from '../../../../shared_imports';
import { getFieldConfig } from '../../../../lib';
import { NormalizedField } from '../../../../types';
import { NormalizedField, Field as FieldType, ParameterName } from '../../../../types';
import { MetaParameter } from '../../field_parameters';
import { AdvancedParametersSection, EditFieldFormRow, BasicParametersSection } from '../edit_field';

interface Props {
field: NormalizedField;
}

const getDefaultToggleValue = (param: ParameterName, field: FieldType) => {
return field[param] !== undefined && field[param] !== getFieldConfig(param).defaultValue;
};

export const ConstantKeywordType: FunctionComponent<Props> = ({ field }) => {
return (
<>
Expand All @@ -32,50 +36,14 @@ export const ConstantKeywordType: FunctionComponent<Props> = ({ field }) => {
'The value of this field for all documents in the index. If not specified, defaults to the value specified in the first document indexed.',
}
)}
defaultToggleValue={field.source?.value !== undefined}
defaultToggleValue={getDefaultToggleValue('value', field.source)}
>
<UseField path="value" config={getFieldConfig('value')} component={Field} />
</EditFieldFormRow>
</BasicParametersSection>

<AdvancedParametersSection>
{/* Meta field */}
<EditFieldFormRow
title={i18n.translate('xpack.idxMgmt.mappingsEditor.constantKeyword.metaFieldTitle', {
defaultMessage: 'Set metadata',
})}
description={i18n.translate(
'xpack.idxMgmt.mappingsEditor.constantKeyword.metaFieldDescription',
{
defaultMessage:
'Arbitrary information about the field. Specify as JSON key-value pairs.',
}
)}
defaultToggleValue={field.source?.meta !== undefined}
docLink={{
text: i18n.translate('xpack.idxMgmt.mappingsEditor.constantKeyword.metaDocLinkText', {
defaultMessage: 'Metadata documentation',
}),
href: documentationService.getMetaLink(),
}}
>
<UseField
path="meta"
config={getFieldConfig('meta')}
component={JsonEditorField}
componentProps={{
euiCodeEditorProps: {
height: '300px',
'aria-label': i18n.translate(
'xpack.idxMgmt.mappingsEditor.constantKeyword.metaFieldAriaLabel',
{
defaultMessage: 'metadata field data editor',
}
),
},
}}
/>
</EditFieldFormRow>
<MetaParameter defaultToggleValue={getDefaultToggleValue('meta', field.source)} />
</AdvancedParametersSection>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ import {
IgnoreMalformedParameter,
FormatParameter,
LocaleParameter,
MetaParameter,
} from '../../field_parameters';
import { BasicParametersSection, AdvancedParametersSection } from '../edit_field';

const getDefaultToggleValue = (param: string, field: FieldType) => {
switch (param) {
case 'locale':
case 'format':
case 'meta':
case 'boost': {
return field[param] !== undefined && field[param] !== getFieldConfig(param).defaultValue;
}
Expand Down Expand Up @@ -73,6 +75,8 @@ export const DateType = ({ field }: Props) => {

<StoreParameter />

<MetaParameter defaultToggleValue={getDefaultToggleValue('meta', field.source)} />

<BoostParameter defaultToggleValue={getDefaultToggleValue('boost', field.source)} />
</AdvancedParametersSection>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
NullValueParameter,
SimilarityParameter,
SplitQueriesOnWhitespaceParameter,
MetaParameter,
IgnoreAboveParameter,
} from '../../field_parameters';
import { BasicParametersSection, EditFieldFormRow, AdvancedParametersSection } from '../edit_field';
Expand All @@ -30,6 +31,7 @@ const getDefaultToggleValue = (param: string, field: FieldType) => {
switch (param) {
case 'boost':
case 'ignore_above':
case 'meta':
case 'similarity': {
return field[param] !== undefined && field[param] !== getFieldConfig(param).defaultValue;
}
Expand Down Expand Up @@ -83,6 +85,8 @@ export const FlattenedType = React.memo(({ field }: Props) => {
defaultToggleValue={getDefaultToggleValue('null_value', field.source)}
/>

<MetaParameter defaultToggleValue={getDefaultToggleValue('meta', field.source)} />

<BoostParameter defaultToggleValue={getDefaultToggleValue('boost', field.source)} />
</AdvancedParametersSection>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ import {
IgnoreMalformedParameter,
NullValueParameter,
IgnoreZValueParameter,
MetaParameter,
} from '../../field_parameters';
import { BasicParametersSection, AdvancedParametersSection } from '../edit_field';

const getDefaultToggleValue = (param: string, field: FieldType) => {
switch (param) {
case 'meta':
return field[param] !== undefined && field[param] !== getFieldConfig(param).defaultValue;
case 'null_value': {
return field.null_value !== undefined;
}
Expand Down Expand Up @@ -65,6 +68,8 @@ export const GeoPointType = ({ field }: Props) => {
config={getFieldConfig('null_value_geo_point')}
/>
</NullValueParameter>

<MetaParameter defaultToggleValue={getDefaultToggleValue('meta', field.source)} />
</AdvancedParametersSection>
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import React from 'react';

import { NormalizedField, Field as FieldType, ParameterName } from '../../../../types';
import { getFieldConfig } from '../../../../lib';
import { IgnoreMalformedParameter, MetaParameter } from '../../field_parameters';
import { AdvancedParametersSection } from '../edit_field';

interface Props {
field: NormalizedField;
}

const getDefaultToggleValue = (param: ParameterName, field: FieldType) => {
return field[param] !== undefined && field[param] !== getFieldConfig(param).defaultValue;
};

export const HistogramType = ({ field }: Props) => {
return (
<AdvancedParametersSection>
<IgnoreMalformedParameter />

<MetaParameter defaultToggleValue={getDefaultToggleValue('meta', field.source)} />
</AdvancedParametersSection>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { ObjectType } from './object_type';
import { OtherType } from './other_type';
import { NestedType } from './nested_type';
import { JoinType } from './join_type';
import { HistogramType } from './histogram_type';
import { ConstantKeywordType } from './constant_keyword_type';
import { RankFeatureType } from './rank_feature_type';
import { WildcardType } from './wildcard_type';
Expand Down Expand Up @@ -55,6 +56,7 @@ const typeToParametersFormMap: { [key in DataType]?: ComponentType<any> } = {
other: OtherType,
nested: NestedType,
join: JoinType,
histogram: HistogramType,
constant_keyword: ConstantKeywordType,
rank_feature: RankFeatureType,
wildcard: WildcardType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
CoerceNumberParameter,
IgnoreMalformedParameter,
CopyToParameter,
MetaParameter,
} from '../../field_parameters';
import { BasicParametersSection, EditFieldFormRow, AdvancedParametersSection } from '../edit_field';
import { PARAMETERS_DEFINITION } from '../../../../constants';
Expand All @@ -26,6 +27,7 @@ const getDefaultToggleValue = (param: string, field: FieldType) => {
switch (param) {
case 'copy_to':
case 'boost':
case 'meta':
case 'ignore_malformed': {
return field[param] !== undefined && field[param] !== getFieldConfig(param).defaultValue;
}
Expand Down Expand Up @@ -95,6 +97,8 @@ export const NumericType = ({ field }: Props) => {

<StoreParameter />

<MetaParameter defaultToggleValue={getDefaultToggleValue('meta', field.source)} />

<BoostParameter defaultToggleValue={getDefaultToggleValue('boost', field.source)} />
</AdvancedParametersSection>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/
import React from 'react';

import { NormalizedField, Field as FieldType } from '../../../../types';
import { NormalizedField, Field as FieldType, ParameterName } from '../../../../types';
import { getFieldConfig } from '../../../../lib';
import {
StoreParameter,
Expand All @@ -14,11 +14,12 @@ import {
CoerceNumberParameter,
FormatParameter,
LocaleParameter,
MetaParameter,
} from '../../field_parameters';
import { BasicParametersSection, AdvancedParametersSection } from '../edit_field';
import { FormDataProvider } from '../../../../shared_imports';

const getDefaultToggleValue = (param: 'locale' | 'format' | 'boost', field: FieldType) => {
const getDefaultToggleValue = (param: ParameterName, field: FieldType) => {
return field[param] !== undefined && field[param] !== getFieldConfig(param).defaultValue;
};

Expand Down Expand Up @@ -57,6 +58,8 @@ export const RangeType = ({ field }: Props) => {

<StoreParameter />

<MetaParameter defaultToggleValue={getDefaultToggleValue('meta', field.source)} />

<BoostParameter defaultToggleValue={getDefaultToggleValue('boost', field.source)} />
</AdvancedParametersSection>
</>
Expand Down
Loading

0 comments on commit 11f100b

Please sign in to comment.