Skip to content

Commit

Permalink
Improve layout of create and edit forms.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjcenizal committed Sep 24, 2020
1 parent 4449800 commit ca02afb
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,25 @@
*/

import React from 'react';
import { EuiFormRow } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { EuiFormRow, EuiDescribedFormGroup } from '@elastic/eui';

import { CodeEditor, UseField } from '../../../shared_imports';
import { getFieldConfig } from '../../../lib';
import { EditFieldFormRow } from '../fields/edit_field';

export const PainlessScriptParameter = () => {
interface Props {
stack?: boolean;
}

export const PainlessScriptParameter = ({ stack }: Props) => {
return (
<UseField path="script.source" config={getFieldConfig('script')}>
{(scriptField) => {
const error = scriptField.getErrorsMessages();
const isInvalid = error ? Boolean(error.length) : false;

return (
const field = (
<EuiFormRow label={scriptField.label} error={error} isInvalid={isInvalid} fullWidth>
<CodeEditor
languageId="painless"
Expand All @@ -39,6 +45,35 @@ export const PainlessScriptParameter = () => {
/>
</EuiFormRow>
);

const fieldTitle = i18n.translate('xpack.idxMgmt.mappingsEditor.painlessScript.title', {
defaultMessage: 'Emitted value',
});

const fieldDescription = i18n.translate(
'xpack.idxMgmt.mappingsEditor.painlessScript.description',
{
defaultMessage: 'Use emit() to define the value of this runtime field.',
}
);

if (stack) {
return (
<EditFieldFormRow title={fieldTitle} description={fieldDescription} withToggle={false}>
{field}
</EditFieldFormRow>
);
}

return (
<EuiDescribedFormGroup
title={<h3>{fieldTitle}</h3>}
description={fieldDescription}
fullWidth={true}
>
{field}
</EuiDescribedFormGroup>
);
}}
</UseField>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,33 @@

import React from 'react';
import { i18n } from '@kbn/i18n';
import { EuiFormRow, EuiComboBox, EuiComboBoxOptionOption } from '@elastic/eui';
import {
EuiFormRow,
EuiComboBox,
EuiComboBoxOptionOption,
EuiDescribedFormGroup,
} from '@elastic/eui';

import { UseField } from '../../../shared_imports';
import { DataType } from '../../../types';
import { getFieldConfig } from '../../../lib';
import { RUNTIME_FIELD_OPTIONS, TYPE_DEFINITION } from '../../../constants';
import { EditFieldFormRow, FieldDescriptionSection } from '../fields/edit_field';

export const RuntimeTypeParameter = () => {
interface Props {
stack?: boolean;
}

export const RuntimeTypeParameter = ({ stack }: Props) => {
return (
<UseField path="runtime_type" config={getFieldConfig('runtime_type')}>
{(runtimeTypeField) => {
const { label, value, setValue } = runtimeTypeField;
const typeDefinition =
TYPE_DEFINITION[(value as EuiComboBoxOptionOption[])[0]!.value as DataType];

return (
<EditFieldFormRow
title={i18n.translate('xpack.idxMgmt.mappingsEditor.runtimeType.title', {
defaultMessage: 'Emitted type',
})}
description={i18n.translate('xpack.idxMgmt.mappingsEditor.runtimeType.description', {
defaultMessage: 'Select the type of value emitted by the runtime field.',
})}
withToggle={false}
>
const field = (
<>
<EuiFormRow label={label} fullWidth>
<EuiComboBox
placeholder={i18n.translate(
Expand All @@ -55,7 +56,36 @@ export const RuntimeTypeParameter = () => {
{typeDefinition.description?.() as JSX.Element}
</FieldDescriptionSection>
)}
</EditFieldFormRow>
</>
);

const fieldTitle = i18n.translate('xpack.idxMgmt.mappingsEditor.runtimeType.title', {
defaultMessage: 'Emitted type',
});

const fieldDescription = i18n.translate(
'xpack.idxMgmt.mappingsEditor.runtimeType.description',
{
defaultMessage: 'Select the type of value emitted by the runtime field.',
}
);

if (stack) {
return (
<EditFieldFormRow title={fieldTitle} description={fieldDescription} withToggle={false}>
{field}
</EditFieldFormRow>
);
}

return (
<EuiDescribedFormGroup
title={<h3>{fieldTitle}</h3>}
description={fieldDescription}
fullWidth={true}
>
{field}
</EuiDescribedFormGroup>
);
}}
</UseField>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { BasicParametersSection } from '../edit_field';
export const RuntimeType = () => {
return (
<BasicParametersSection>
<RuntimeTypeParameter />
<PainlessScriptParameter />
<RuntimeTypeParameter stack={true} />
<PainlessScriptParameter stack={true} />
</BasicParametersSection>
);
};

0 comments on commit ca02afb

Please sign in to comment.