Skip to content

Commit

Permalink
[Alerting][Connectors] Removing ability to set refresh=true from ES…
Browse files Browse the repository at this point in the history
… Index Connector UI (#158102)

Resolves #155303

## Summary

Removes the refresh switch from the EX Index Connector UI

Before:
<img width="422" alt="Screenshot 2023-05-18 at 2 42 46 PM"
src="https://github.com/elastic/kibana/assets/13104637/1a2e2ff4-5247-43f7-89ae-776a23be9e95">

After:
<img width="410" alt="Screenshot 2023-05-18 at 2 50 09 PM"
src="https://github.com/elastic/kibana/assets/13104637/2be21cc6-f128-44b5-bd53-cf6945c6f729">

No changes to the API so this is not a breaking change. Previously
created Index Connectors should still work as before.

## To Verify

**Verify previously created connectors can be updated**
1. Create an ES Index connector with refresh=true on `main` or in a
previous version
2. Switch to this branch and verify the connector still loads and
changes to the connector preserves the `refresh` value

**Verify creating connector from UI**
1. On this branch, create an ES Index connector and verify that
`refresh` is set to `false`

**Verify creating connector from API**
1. On this branch, use the API to create an ES connector and verify you
can successfully create one with either refresh set to `true` or `false`

### Checklist

- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
ymao1 authored May 23, 2023
1 parent 3b4c772 commit b50c358
Show file tree
Hide file tree
Showing 8 changed files with 7 additions and 64 deletions.
5 changes: 1 addition & 4 deletions docs/management/connectors/action-types/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ image::management/connectors/images/index-connector.png[Index connector]
[[index-connector-configuration]]
==== Connector configuration

Index connectors must have a name and an {es} index. You can optionally set the
{ref}/docs-refresh.html[refresh] policy and the time field, which contains the
Index connectors must have a name and an {es} index. You can optionally set the time field, which contains the
details about when each alert condition was detected.

[float]
Expand All @@ -46,10 +45,8 @@ xpack.actions.preconfigured:
actionTypeId: .index
config:
index: .kibana
refresh: true <1>
executionTimeField: my-field
--
<1> By default, the {ref}/docs-refresh.html[refresh] policy is `false`.

For more information, go to <<pre-configured-connectors>>.

Expand Down
Binary file modified docs/management/connectors/images/index-connector.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ describe('IndexActionConnectorFields', () => {
const wrapper = await setup(connector);

expect(wrapper.find('[data-test-subj="connectorIndexesComboBox"]').exists()).toBeTruthy();
expect(wrapper.find('[data-test-subj="indexRefreshCheckbox"]').exists()).toBeTruthy();

// time field switch shouldn't show up initially
expect(wrapper.find('[data-test-subj="hasTimeFieldCheckbox"]').exists()).toBeFalsy();
Expand Down Expand Up @@ -177,7 +176,6 @@ describe('IndexActionConnectorFields', () => {
const wrapper = await setup(props);

expect(wrapper.find('[data-test-subj="connectorIndexesComboBox"]').exists()).toBeTruthy();
expect(wrapper.find('[data-test-subj="indexRefreshCheckbox"]').exists()).toBeTruthy();

// time related fields shouldn't show up
expect(wrapper.find('[data-test-subj="hasTimeFieldCheckbox"]').exists()).toBeFalsy();
Expand All @@ -187,9 +185,6 @@ describe('IndexActionConnectorFields', () => {
.find(EuiComboBox)
.filter('[data-test-subj="connectorIndexesComboBox"]');
expect(indexComboBox.prop('selectedOptions')).toEqual([{ label: indexName, value: indexName }]);

const refreshSwitch = wrapper.find(EuiSwitch).filter('[data-test-subj="indexRefreshCheckbox"]');
expect(refreshSwitch.prop('checked')).toEqual(false);
});

test('renders correctly when editing connector - refresh set to true', async () => {
Expand All @@ -208,17 +203,13 @@ describe('IndexActionConnectorFields', () => {
const wrapper = await setup(props);

expect(wrapper.find('[data-test-subj="connectorIndexesComboBox"]').exists()).toBeTruthy();
expect(wrapper.find('[data-test-subj="indexRefreshCheckbox"]').exists()).toBeTruthy();
expect(wrapper.find('[data-test-subj="hasTimeFieldCheckbox"]').exists()).toBeFalsy();
expect(wrapper.find('[data-test-subj="executionTimeFieldSelect"]').exists()).toBeFalsy();

const indexComboBox = wrapper
.find(EuiComboBox)
.filter('[data-test-subj="connectorIndexesComboBox"]');
expect(indexComboBox.prop('selectedOptions')).toEqual([{ label: indexName, value: indexName }]);

const refreshSwitch = wrapper.find(EuiSwitch).filter('[data-test-subj="indexRefreshCheckbox"]');
expect(refreshSwitch.prop('checked')).toEqual(true);
});

test('renders correctly when editing connector - with date type field mapping but no time field selected', async () => {
Expand All @@ -238,7 +229,6 @@ describe('IndexActionConnectorFields', () => {

await waitFor(() => {
expect(wrapper.find('[data-test-subj="connectorIndexesComboBox"]').exists()).toBeTruthy();
expect(wrapper.find('[data-test-subj="indexRefreshCheckbox"]').exists()).toBeTruthy();
expect(wrapper.find('[data-test-subj="hasTimeFieldCheckbox"]').exists()).toBeTruthy();
expect(wrapper.find('[data-test-subj="executionTimeFieldSelect"]').exists()).toBeFalsy();
});
Expand All @@ -248,9 +238,6 @@ describe('IndexActionConnectorFields', () => {
.filter('[data-test-subj="connectorIndexesComboBox"]');
expect(indexComboBox.prop('selectedOptions')).toEqual([{ label: indexName, value: indexName }]);

const refreshSwitch = wrapper.find(EuiSwitch).filter('[data-test-subj="indexRefreshCheckbox"]');
expect(refreshSwitch.prop('checked')).toEqual(false);

const timeFieldSwitch = wrapper
.find(EuiSwitch)
.filter('[data-test-subj="hasTimeFieldCheckbox"]');
Expand All @@ -275,7 +262,6 @@ describe('IndexActionConnectorFields', () => {
await waitFor(() => {
wrapper.update();
expect(wrapper.find('[data-test-subj="connectorIndexesComboBox"]').exists()).toBeTruthy();
expect(wrapper.find('[data-test-subj="indexRefreshCheckbox"]').exists()).toBeTruthy();
expect(wrapper.find('[data-test-subj="hasTimeFieldCheckbox"]').exists()).toBeTruthy();
expect(wrapper.find('[data-test-subj="executionTimeFieldSelect"]').exists()).toBeTruthy();
});
Expand All @@ -285,9 +271,6 @@ describe('IndexActionConnectorFields', () => {
.filter('[data-test-subj="connectorIndexesComboBox"]');
expect(indexComboBox.prop('selectedOptions')).toEqual([{ label: indexName, value: indexName }]);

const refreshSwitch = wrapper.find(EuiSwitch).filter('[data-test-subj="indexRefreshCheckbox"]');
expect(refreshSwitch.prop('checked')).toEqual(false);

const timeFieldSwitch = wrapper
.find(EuiSwitch)
.filter('[data-test-subj="hasTimeFieldCheckbox"]');
Expand Down Expand Up @@ -380,8 +363,8 @@ describe('IndexActionConnectorFields', () => {
actionTypeId: '.index',
config: {
index: 'test_es_index',
refresh: false,
executionTimeField: '1',
refresh: false,
},
id: 'test',
isDeprecated: false,
Expand Down Expand Up @@ -425,7 +408,6 @@ describe('IndexActionConnectorFields', () => {
actionTypeId: '.index',
config: {
index: 'test_es_index',
refresh: false,
},
id: 'test',
isDeprecated: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ import { ToggleField, SelectField } from '@kbn/es-ui-shared-plugin/static/forms/
import { DocLinksStart } from '@kbn/core/public';
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
import type { ActionConnectorFieldsProps } from '@kbn/triggers-actions-ui-plugin/public';
import {
type ActionConnectorFieldsProps,
HiddenField,
} from '@kbn/triggers-actions-ui-plugin/public';
import {
firstFieldOption,
getFields,
Expand Down Expand Up @@ -131,6 +134,7 @@ const IndexActionConnectorFields: React.FunctionComponent<ActionConnectorFieldsP
/>
</h5>
</EuiTitle>
<HiddenField path={'config.refresh'} />
<EuiSpacer size="m" />
<UseField path="config.index" config={getIndexConfig(docLinks)}>
{(field) => {
Expand Down Expand Up @@ -214,33 +218,6 @@ const IndexActionConnectorFields: React.FunctionComponent<ActionConnectorFieldsP
}}
</UseField>
<EuiSpacer size="m" />
<UseField
path="config.refresh"
component={ToggleField}
config={{
defaultValue: false,
}}
componentProps={{
euiFieldProps: {
label: (
<>
<FormattedMessage
id="xpack.stackConnectors.components.index.refreshLabel"
defaultMessage="Refresh index"
/>{' '}
<EuiIconTip
position="right"
type="questionInCircle"
content={translations.REFRESH_FIELD_TOGGLE_TOOLTIP}
/>
</>
),
disabled: readOnly,
'data-test-subj': 'indexRefreshCheckbox',
},
}}
/>
<EuiSpacer size="m" />
{showTimeFieldCheckbox ? (
<UseField
path="__internal__.hasTimeFieldCheckbox"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,6 @@ export const SHOW_TIME_FIELD_TOGGLE_TOOLTIP = i18n.translate(
}
);

export const REFRESH_FIELD_TOGGLE_TOOLTIP = i18n.translate(
'xpack.stackConnectors.components.index.refreshTooltip',
{
defaultMessage: 'Refresh the affected shards to make this operation visible to search.',
}
);

export const INDEX_LABEL = i18n.translate(
'xpack.stackConnectors.components.index.indicesToQueryLabel',
{
Expand Down
2 changes: 0 additions & 2 deletions x-pack/plugins/translations/translations/fr-FR.json
Original file line number Diff line number Diff line change
Expand Up @@ -35323,8 +35323,6 @@
"xpack.stackConnectors.components.index.jsonDocAriaLabel": "Éditeur de code",
"xpack.stackConnectors.components.index.preconfiguredIndex": "Index Elasticsearch",
"xpack.stackConnectors.components.index.preconfiguredIndexDocLink": "Affichez les documents.",
"xpack.stackConnectors.components.index.refreshLabel": "Actualiser l'index",
"xpack.stackConnectors.components.index.refreshTooltip": "Actualisez les partitions affectées pour rendre cette opération visible pour la recherche.",
"xpack.stackConnectors.components.index.resetDefaultIndexLabel": "Réinitialiser l'index par défaut",
"xpack.stackConnectors.components.index.selectMessageText": "Indexez les données dans Elasticsearch.",
"xpack.stackConnectors.components.jira.apiTokenTextFieldLabel": "Token d'API",
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 @@ -35304,8 +35304,6 @@
"xpack.stackConnectors.components.index.jsonDocAriaLabel": "コードエディター",
"xpack.stackConnectors.components.index.preconfiguredIndex": "Elasticsearchインデックス",
"xpack.stackConnectors.components.index.preconfiguredIndexDocLink": "ドキュメントを表示します。",
"xpack.stackConnectors.components.index.refreshLabel": "更新インデックス",
"xpack.stackConnectors.components.index.refreshTooltip": "影響を受けるシャードを更新し、この処理を検索できるようにします。",
"xpack.stackConnectors.components.index.resetDefaultIndexLabel": "デフォルトのインデックスをリセット",
"xpack.stackConnectors.components.index.selectMessageText": "データを Elasticsearch にインデックスしてください。",
"xpack.stackConnectors.components.jira.apiTokenTextFieldLabel": "APIトークン",
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 @@ -35298,8 +35298,6 @@
"xpack.stackConnectors.components.index.jsonDocAriaLabel": "代码编辑器",
"xpack.stackConnectors.components.index.preconfiguredIndex": "Elasticsearch 索引",
"xpack.stackConnectors.components.index.preconfiguredIndexDocLink": "查看文档。",
"xpack.stackConnectors.components.index.refreshLabel": "刷新索引",
"xpack.stackConnectors.components.index.refreshTooltip": "刷新影响的分片以使此操作对搜索可见。",
"xpack.stackConnectors.components.index.resetDefaultIndexLabel": "重置默认索引",
"xpack.stackConnectors.components.index.selectMessageText": "将数据索引到 Elasticsearch 中。",
"xpack.stackConnectors.components.jira.apiTokenTextFieldLabel": "API 令牌",
Expand Down

0 comments on commit b50c358

Please sign in to comment.