diff --git a/models/interfaces.ts b/models/interfaces.ts index c39c20060..ab1bc1a33 100644 --- a/models/interfaces.ts +++ b/models/interfaces.ts @@ -142,7 +142,7 @@ export interface Action { } export interface Retry { - count: number; + count?: number; backoff?: string; delay?: string; } diff --git a/public/pages/VisualCreatePolicy/components/TimeoutRetrySettings/TimeoutRetrySettings.test.tsx b/public/pages/VisualCreatePolicy/components/TimeoutRetrySettings/TimeoutRetrySettings.test.tsx new file mode 100644 index 000000000..d883afb1f --- /dev/null +++ b/public/pages/VisualCreatePolicy/components/TimeoutRetrySettings/TimeoutRetrySettings.test.tsx @@ -0,0 +1,26 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import React from "react"; +import "@testing-library/jest-dom/extend-expect"; +import { render } from "@testing-library/react"; +import TimeoutRetrySettings from "./TimeoutRetrySettings"; +import { RolloverUIAction } from "../UIActions"; +import { DEFAULT_ROLLOVER } from "../../utils/constants"; +import { UIAction } from "../../../../../models/interfaces"; + +describe(" spec", () => { + it("renders the component", () => { + const action: UIAction = new RolloverUIAction(DEFAULT_ROLLOVER, "abc-123-id"); + const { container } = render( {}} />); + expect(container.firstChild).toMatchSnapshot(); + }); +}); diff --git a/public/pages/VisualCreatePolicy/components/TimeoutRetrySettings/TimeoutRetrySettings.tsx b/public/pages/VisualCreatePolicy/components/TimeoutRetrySettings/TimeoutRetrySettings.tsx new file mode 100644 index 000000000..86d83e8ff --- /dev/null +++ b/public/pages/VisualCreatePolicy/components/TimeoutRetrySettings/TimeoutRetrySettings.tsx @@ -0,0 +1,117 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import React, { ChangeEvent } from "react"; +import { EuiAccordion, EuiText, EuiFlexGroup, EuiFlexItem, EuiFormRow, EuiFieldNumber, EuiFieldText, EuiSelect } from "@elastic/eui"; +import "brace/theme/github"; +import "brace/mode/json"; +import { Action, UIAction } from "../../../../../models/interfaces"; +import EuiFormCustomLabel from "../EuiFormCustomLabel"; + +interface TimeoutRetrySettingsProps { + action: UIAction; + editAction: boolean; + onChangeAction: (action: UIAction) => void; +} + +const options = [ + { value: "exponential", text: "Exponential" }, + { value: "constant", text: "Constant" }, + { value: "linear", text: "Linear" }, +]; + +const TimeoutRetrySettings = ({ action, editAction, onChangeAction }: TimeoutRetrySettingsProps) => ( + + + + +

+ + Timeout and retry settings are supported to handle an action failure. You can specify parameters based on your need. + +

+
+
+ + + + + + ) => { + const timeout = e.target.value; + onChangeAction(action.clone({ ...action.action, timeout })); + }} + /> + + + + + + + + + + ) => { + const count = e.target.valueAsNumber; + onChangeAction(action.clone({ ...action.action, retry: { ...action.action.retry, count } })); + }} + /> + + + + + + + + ) => { + const backoff = e.target.value; + onChangeAction(action.clone({ ...action.action, retry: { ...action.action.retry, backoff } })); + }} + /> + + + + + + + + ) => { + const delay = e.target.value; + onChangeAction(action.clone({ ...action.action, retry: { ...action.action.retry, delay } })); + }} + /> + + + + +
+
+); + +export default TimeoutRetrySettings; diff --git a/public/pages/VisualCreatePolicy/components/TimeoutRetrySettings/__snapshots__/TimeoutRetrySettings.test.tsx.snap b/public/pages/VisualCreatePolicy/components/TimeoutRetrySettings/__snapshots__/TimeoutRetrySettings.test.tsx.snap new file mode 100644 index 000000000..f2a3319ad --- /dev/null +++ b/public/pages/VisualCreatePolicy/components/TimeoutRetrySettings/__snapshots__/TimeoutRetrySettings.test.tsx.snap @@ -0,0 +1,289 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[` spec renders the component 1`] = ` +
+
+ +
+
+
+
+
+
+
+

+ + Timeout and retry settings are supported to handle an action failure. You can specify parameters based on your need. + +

+
+
+
+
+
+ Timeout +
+

+ + + The timeout period for the action. Accepts time units, e.g. "5h" or "1d". + +

+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+ Retry count +
+

+ + + The number of times the action should be retried if it fails. + +

+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+ Retry backoff +
+

+ + + The backoff policy type to use when retrying. + +

+
+
+
+
+
+ +
+ + EuiIconMock + +
+
+
+
+
+
+
+
+
+ Retry delay +
+

+ + + The time to wait between retries. Accepts time units, e.g. "2h" or "1d" + +

+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+`; diff --git a/public/pages/VisualCreatePolicy/components/TimeoutRetrySettings/index.ts b/public/pages/VisualCreatePolicy/components/TimeoutRetrySettings/index.ts new file mode 100644 index 000000000..8a5b8df1e --- /dev/null +++ b/public/pages/VisualCreatePolicy/components/TimeoutRetrySettings/index.ts @@ -0,0 +1,14 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + * + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +import TimeoutRetrySettings from "./TimeoutRetrySettings"; + +export default TimeoutRetrySettings;