Skip to content

Commit

Permalink
Merge branch '7.x' into backport/7.x/pr-102267
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine committed Jun 16, 2021
2 parents cf65748 + 043f24a commit 6e59d28
Show file tree
Hide file tree
Showing 17 changed files with 383 additions and 312 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { act } from 'react-dom/test-utils';
import { setup, SetupResult, getProcessorValue } from './processor.helpers';

const CIRCLE_TYPE = 'circle';

describe('Processor: Circle', () => {
let onUpdate: jest.Mock;
let testBed: SetupResult;

beforeAll(() => {
jest.useFakeTimers();
});

afterAll(() => {
jest.useRealTimers();
});

beforeEach(async () => {
onUpdate = jest.fn();

await act(async () => {
testBed = await setup({
value: {
processors: [],
},
onFlyoutOpen: jest.fn(),
onUpdate,
});
});
testBed.component.update();
const {
actions: { addProcessor, addProcessorType },
} = testBed;
// Open the processor flyout
addProcessor();

// Add type (the other fields are not visible until a type is selected)
await addProcessorType(CIRCLE_TYPE);
});

test('prevents form submission if required fields are not provided', async () => {
const {
actions: { saveNewProcessor },
form,
} = testBed;

// Click submit button with only the type defined
await saveNewProcessor();

// Expect form error as "field" and "shape_type" are required parameters
expect(form.getErrorsMessages()).toEqual([
'A field value is required.',
'A shape type value is required.',
]);
});

test('saves with required parameter values', async () => {
const {
actions: { saveNewProcessor },
form,
} = testBed;

// Add "field" value (required)
form.setInputValue('fieldNameField.input', 'field_1');
// Save the field
form.setSelectValue('shapeSelectorField', 'shape');
// Set the error distance
form.setInputValue('errorDistanceField.input', '10');

await saveNewProcessor();

const processors = getProcessorValue(onUpdate, CIRCLE_TYPE);

expect(processors[0].circle).toEqual({
field: 'field_1',
error_distance: 10,
shape_type: 'shape',
});
});

test('allows optional parameters to be set', async () => {
const {
actions: { saveNewProcessor },
form,
} = testBed;

// Add "field" value (required)
form.setInputValue('fieldNameField.input', 'field_1');
// Select the shape
form.setSelectValue('shapeSelectorField', 'geo_shape');
// Add "target_field" value
form.setInputValue('targetField.input', 'target_field');

form.setInputValue('errorDistanceField.input', '10');

// Save the field with new changes
await saveNewProcessor();

const processors = getProcessorValue(onUpdate, CIRCLE_TYPE);
expect(processors[0].circle).toEqual({
field: 'field_1',
error_distance: 10,
shape_type: 'geo_shape',
target_field: 'target_field',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ type TestSubject =
| 'keepOriginalField.input'
| 'removeIfSuccessfulField.input'
| 'targetFieldsField.input'
| 'shapeSelectorField'
| 'errorDistanceField.input'
| 'separatorValueField.input'
| 'quoteValueField.input'
| 'emptyValueField.input'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ export const Circle: FunctionComponent = () => {
/>

<UseField
data-test-subj="errorDistanceField"
config={fieldsConfig.error_distance}
component={NumericField}
path="fields.error_distance"
Expand All @@ -105,6 +106,7 @@ export const Circle: FunctionComponent = () => {
<UseField
componentProps={{
euiFieldProps: {
'data-test-subj': 'shapeSelectorField',
options: [
{
value: 'shape',
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -24311,8 +24311,6 @@
"xpack.watcher.sections.watchEdit.json.titlePanel.editWatchTitle": "{watchName}を編集",
"xpack.watcher.sections.watchEdit.loadingWatchDescription": "ウォッチの読み込み中…",
"xpack.watcher.sections.watchEdit.loadingWatchVisualizationDescription": "ウォッチビジュアライゼーションを読み込み中…",
"xpack.watcher.sections.watchEdit.monitoring.edit.calloutDescriptionText": "ウォッチ'{watchName}'はシステムウォッチであるため、編集できません。{watchStatusLink}",
"xpack.watcher.sections.watchEdit.monitoring.edit.calloutTitleText": "このウォッチは編集できません。",
"xpack.watcher.sections.watchEdit.monitoring.header.watchLinkTitle": "ウォッチステータスを表示します。",
"xpack.watcher.sections.watchEdit.simulate.form.actionModesFieldLabel": "アクションモード",
"xpack.watcher.sections.watchEdit.simulate.form.actionOverridesDescription": "ウォッチでアクションを実行またはスキップすることができるようにします。{actionsLink}",
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -24681,8 +24681,6 @@
"xpack.watcher.sections.watchEdit.json.titlePanel.editWatchTitle": "编辑 {watchName}",
"xpack.watcher.sections.watchEdit.loadingWatchDescription": "正在加载监视……",
"xpack.watcher.sections.watchEdit.loadingWatchVisualizationDescription": "正在加载监视可视化……",
"xpack.watcher.sections.watchEdit.monitoring.edit.calloutDescriptionText": "监视“{watchName}”为系统监视,无法编辑。{watchStatusLink}",
"xpack.watcher.sections.watchEdit.monitoring.edit.calloutTitleText": "此监视无法编辑。",
"xpack.watcher.sections.watchEdit.monitoring.header.watchLinkTitle": "查看监视状态。",
"xpack.watcher.sections.watchEdit.simulate.form.actionModesFieldLabel": "操作模式",
"xpack.watcher.sections.watchEdit.simulate.form.actionOverridesDescription": "允许监视执行或跳过操作。{actionsLink}",
Expand Down
44 changes: 25 additions & 19 deletions x-pack/plugins/watcher/public/application/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {

import { Router, Switch, Route, Redirect, withRouter, RouteComponentProps } from 'react-router-dom';

import { EuiCallOut, EuiLink } from '@elastic/eui';
import { EuiPageContent, EuiEmptyPrompt, EuiLink } from '@elastic/eui';

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

Expand Down Expand Up @@ -62,24 +62,30 @@ export const App = (deps: AppDeps) => {

if (!valid) {
return (
<EuiCallOut
title={
<FormattedMessage
id="xpack.watcher.app.licenseErrorTitle"
defaultMessage="License error"
/>
}
color="danger"
iconType="help"
>
{message}{' '}
<EuiLink href={deps.getUrlForApp('management', { path: 'stack/license_management/home' })}>
<FormattedMessage
id="xpack.watcher.app.licenseErrorLinkText"
defaultMessage="Manage your license."
/>
</EuiLink>
</EuiCallOut>
<EuiPageContent verticalPosition="center" horizontalPosition="center" color="danger">
<EuiEmptyPrompt
iconType="alert"
title={
<h1>
<FormattedMessage
id="xpack.watcher.app.licenseErrorTitle"
defaultMessage="License error"
/>
</h1>
}
body={<p>{message}</p>}
actions={[
<EuiLink
href={deps.getUrlForApp('management', { path: 'stack/license_management/home' })}
>
<FormattedMessage
id="xpack.watcher.app.licenseErrorLinkText"
defaultMessage="Manage your license"
/>
</EuiLink>,
]}
/>
</EuiPageContent>
);
}
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function getPageErrorCode(errorOrErrors: any) {
}
}

export function PageError({ errorCode, id }: { errorCode?: any; id?: any }) {
export function PageError({ errorCode, id }: { errorCode?: number; id?: string }) {
switch (errorCode) {
case 404:
return <PageErrorNotExist id={id} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ import { FormattedMessage } from '@kbn/i18n/react';
export function PageErrorForbidden() {
return (
<EuiEmptyPrompt
iconType="securityApp"
iconColor={undefined}
iconType="alert"
title={
<h1>
<FormattedMessage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ import React from 'react';
import { EuiEmptyPrompt } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';

export function PageErrorNotExist({ id }: { id: any }) {
export function PageErrorNotExist({ id }: { id?: string }) {
return (
<EuiEmptyPrompt
iconType="search"
iconColor="primary"
iconType="alert"
title={
<h1>
<FormattedMessage
Expand All @@ -25,11 +24,18 @@ export function PageErrorNotExist({ id }: { id: any }) {
}
body={
<p>
<FormattedMessage
id="xpack.watcher.pageErrorNotExist.description"
defaultMessage="A watch with ID '{id}' could not be found."
values={{ id }}
/>
{id ? (
<FormattedMessage
id="xpack.watcher.pageErrorNotExist.description"
defaultMessage="A watch with ID '{id}' could not be found."
values={{ id }}
/>
) : (
<FormattedMessage
id="xpack.watcher.pageErrorNotExist.noWatchIdDescription"
defaultMessage="A watch could not be found."
/>
)}
</p>
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,7 @@

import React, { useContext, useState } from 'react';

import {
EuiFlexGroup,
EuiFlexItem,
EuiPageContent,
EuiSpacer,
EuiTab,
EuiTabs,
EuiTitle,
} from '@elastic/eui';
import { EuiPageHeader, EuiSpacer, EuiPageContentBody } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { ExecuteDetails } from '../../../../models/execute_details';
import { getActionType } from '../../../../../../common/lib/get_action_type';
Expand Down Expand Up @@ -96,36 +88,31 @@ export const JsonWatchEdit = ({ pageTitle }: { pageTitle: string }) => {
const hasExecuteWatchErrors = !!Object.keys(executeWatchErrors).find(
(errorKey) => executeWatchErrors[errorKey].length >= 1
);

return (
<EuiPageContent>
<EuiFlexGroup>
<EuiFlexItem grow={false}>
<EuiTitle size="m">
<h1 data-test-subj="pageTitle">{pageTitle}</h1>
</EuiTitle>
</EuiFlexItem>
</EuiFlexGroup>
<EuiTabs>
{WATCH_TABS.map((tab, index) => (
<EuiTab
onClick={() => {
setSelectedTab(tab.id);
setExecuteDetails(
new ExecuteDetails({
...executeDetails,
actionModes: getActionModes(watchActions),
})
);
}}
isSelected={tab.id === selectedTab}
key={index}
data-test-subj="tab"
>
{tab.name}
</EuiTab>
))}
</EuiTabs>
<EuiPageContentBody restrictWidth style={{ width: '100%' }}>
<EuiPageHeader
pageTitle={<span data-test-subj="pageTitle">{pageTitle}</span>}
bottomBorder
tabs={WATCH_TABS.map((tab, index) => ({
onClick: () => {
setSelectedTab(tab.id);
setExecuteDetails(
new ExecuteDetails({
...executeDetails,
actionModes: getActionModes(watchActions),
})
);
},
isSelected: tab.id === selectedTab,
key: index,
'data-test-subj': 'tab',
label: tab.name,
}))}
/>

<EuiSpacer size="l" />

{selectedTab === WATCH_SIMULATE_TAB && (
<JsonWatchEditSimulate
executeDetails={executeDetails}
Expand All @@ -135,7 +122,8 @@ export const JsonWatchEdit = ({ pageTitle }: { pageTitle: string }) => {
watchActions={watchActions}
/>
)}

{selectedTab === WATCH_EDIT_TAB && <JsonWatchEditForm />}
</EuiPageContent>
</EuiPageContentBody>
);
};
Loading

0 comments on commit 6e59d28

Please sign in to comment.