Skip to content

Commit 2340335

Browse files
committed
Add support for Convert Index to Remote action
- Add new ConvertIndexToRemote UI component - Correct tests Signed-off-by: Tom Snuverink <[email protected]>
1 parent dfe73e4 commit 2340335

File tree

8 files changed

+112
-3
lines changed

8 files changed

+112
-3
lines changed

models/interfaces.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,13 @@ export interface SnapshotAction extends Action {
428428
};
429429
}
430430

431+
export interface ConvertIndexToRemoteAction extends Action {
432+
convert_index_to_remote: {
433+
repository: string;
434+
snapshot: string;
435+
};
436+
}
437+
431438
export interface IndexPriorityAction extends Action {
432439
index_priority: {
433440
priority?: number;

public/pages/Aliases/containers/Aliases/Aliases.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ describe("<Aliases /> spec", () => {
228228
userEvent.type(getByPlaceholderText("Specify alias name"), testAliasId);
229229
userEvent.click(getByTestId("createAliasButton"));
230230
await waitFor(() => {
231-
expect(browserServicesMock.commonService.apiCaller).toBeCalledTimes(17);
231+
expect(browserServicesMock.commonService.apiCaller).toBeCalledTimes(15);
232232
expect(browserServicesMock.commonService.apiCaller).toBeCalledWith({
233233
data: {
234234
index: ["1"],
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import React, { ChangeEvent } from "react";
7+
import { EuiCompressedFormRow, EuiCompressedFieldText, EuiSpacer } from "@elastic/eui";
8+
import { ConvertIndexToRemoteAction, UIAction } from "../../../../../models/interfaces";
9+
import { makeId } from "../../../../utils/helpers";
10+
import { ActionType } from "../../utils/constants";
11+
import EuiFormCustomLabel from "../EuiFormCustomLabel";
12+
13+
export default class ConvertIndexToRemoteUIAction implements UIAction<ConvertIndexToRemoteAction> {
14+
id: string;
15+
action: ConvertIndexToRemoteAction;
16+
type = ActionType.ConvertIndexToRemote;
17+
18+
constructor(action: ConvertIndexToRemoteAction, id: string = makeId()) {
19+
this.action = action;
20+
this.id = id;
21+
}
22+
23+
content = () => `Convert Index To Remote`;
24+
25+
clone = (action: ConvertIndexToRemoteAction) => new ConvertIndexToRemoteUIAction(action, this.id);
26+
27+
isValid = () => {
28+
return !!this.action.convert_index_to_remote.snapshot && !!this.action.convert_index_to_remote.repository;
29+
};
30+
31+
render = (action: UIAction<ConvertIndexToRemoteAction>, onChangeAction: (action: UIAction<ConvertIndexToRemoteAction>) => void) => {
32+
return (
33+
<>
34+
<EuiFormCustomLabel
35+
title="Repository"
36+
helpText="The repository name that you register through the native snapshot API operations."
37+
isInvalid={!this.isValid()}
38+
/>
39+
<EuiCompressedFormRow fullWidth isInvalid={!this.isValid()} error={null}>
40+
<EuiCompressedFieldText
41+
fullWidth
42+
value={(action.action as ConvertIndexToRemoteAction).convert_index_to_remote.repository}
43+
onChange={(e: ChangeEvent<HTMLInputElement>) => {
44+
const repository = e.target.value;
45+
onChangeAction(
46+
this.clone({
47+
convert_index_to_remote: {
48+
...action.action.convert_index_to_remote,
49+
repository,
50+
},
51+
})
52+
);
53+
}}
54+
data-test-subj="action-render-convert-index-to-remote-repository"
55+
/>
56+
</EuiCompressedFormRow>
57+
<EuiSpacer size="s" />
58+
<EuiFormCustomLabel title="Snapshot" helpText="The name of the snapshot." isInvalid={!this.isValid()} />
59+
<EuiCompressedFormRow fullWidth isInvalid={!this.isValid()} error={null}>
60+
<EuiCompressedFieldText
61+
fullWidth
62+
value={(action.action as ConvertIndexToRemoteAction).convert_index_to_remote.snapshot}
63+
onChange={(e: ChangeEvent<HTMLInputElement>) => {
64+
const snapshot = e.target.value;
65+
onChangeAction(
66+
this.clone({
67+
convert_index_to_remote: {
68+
...action.action.convert_index_to_remote,
69+
snapshot,
70+
},
71+
})
72+
);
73+
}}
74+
data-test-subj="action-render-convert-index-to-remote-snapshot"
75+
/>
76+
</EuiCompressedFormRow>
77+
</>
78+
);
79+
};
80+
81+
toAction = () => this.action;
82+
}

public/pages/VisualCreatePolicy/components/UIActions/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import AliasUIAction from "./AliasUIAction/AliasUIAction";
77
import AllocationUIAction from "./AllocationUIAction";
88
import CloseUIAction from "./CloseUIAction";
9+
import ConvertIndexToRemoteUIAction from "./ConvertIndexToRemoteUIAction";
910
import DeleteUIAction from "./DeleteUIAction";
1011
import ForceMergeUIAction from "./ForceMergeUIAction";
1112
import IndexPriorityUIAction from "./IndexPriorityUIAction";
@@ -23,6 +24,7 @@ export {
2324
AliasUIAction,
2425
AllocationUIAction,
2526
CloseUIAction,
27+
ConvertIndexToRemoteUIAction,
2628
DeleteUIAction,
2729
ForceMergeUIAction,
2830
IndexPriorityUIAction,

public/pages/VisualCreatePolicy/containers/CreateAction/__snapshots__/CreateAction.test.tsx.snap

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ exports[`<CreateAction /> spec renders the component 1`] = `
110110
>
111111
Close
112112
</option>
113+
<option
114+
value="convert_index_to_remote"
115+
>
116+
Convert Index To Remote
117+
</option>
113118
<option
114119
value="delete"
115120
>

public/pages/VisualCreatePolicy/utils/constants.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export enum ActionType {
99
Alias = "alias",
1010
Allocation = "allocation",
1111
Close = "close",
12+
ConvertIndexToRemote = "convert_index_to_remote",
1213
Delete = "delete",
1314
ForceMerge = "force_merge",
1415
IndexPriority = "index_priority",
@@ -82,6 +83,12 @@ export const DEFAULT_ALLOCATION: AllocationAction = {
8283
export const DEFAULT_CLOSE = {
8384
close: {},
8485
};
86+
export const DEFAULT_CONVERT_INDEX_TO_REMOTE = {
87+
convert_index_to_remote: {
88+
repository: "example-repository",
89+
snapshot: "example-snapshot",
90+
},
91+
};
8592
export const DEFAULT_DELETE = {
8693
delete: {},
8794
};
@@ -199,6 +206,7 @@ export const actions = [
199206
DEFAULT_ALIAS,
200207
DEFAULT_ALLOCATION,
201208
DEFAULT_CLOSE,
209+
DEFAULT_CONVERT_INDEX_TO_REMOTE,
202210
DEFAULT_DELETE,
203211
DEFAULT_FORCE_MERGE,
204212
DEFAULT_INDEX_PRIORITY,

public/pages/VisualCreatePolicy/utils/helpers.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ class DummyUIAction implements UIAction<DummyAction> {
7575
}
7676

7777
test("action repository usage", () => {
78-
expect(actionRepoSingleton.getAllActionTypes().length).toBe(15);
79-
actionRepoSingleton.registerAction("dummy", DummyUIAction, DEFAULT_DUMMY);
8078
expect(actionRepoSingleton.getAllActionTypes().length).toBe(16);
79+
actionRepoSingleton.registerAction("dummy", DummyUIAction, DEFAULT_DUMMY);
80+
expect(actionRepoSingleton.getAllActionTypes().length).toBe(17);
8181
expect(actionRepoSingleton.getUIAction("dummy") instanceof DummyUIAction).toBe(true);
8282
expect(actionRepoSingleton.getUIActionFromData(DEFAULT_DUMMY) instanceof DummyUIAction).toBe(true);
8383
});

public/pages/VisualCreatePolicy/utils/helpers.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {
99
DEFAULT_ALIAS,
1010
DEFAULT_ALLOCATION,
1111
DEFAULT_CLOSE,
12+
DEFAULT_CONVERT_INDEX_TO_REMOTE,
1213
DEFAULT_DELETE,
1314
DEFAULT_FORCE_MERGE,
1415
DEFAULT_INDEX_PRIORITY,
@@ -26,6 +27,7 @@ import {
2627
AliasUIAction,
2728
AllocationUIAction,
2829
CloseUIAction,
30+
ConvertIndexToRemoteUIAction,
2931
DeleteUIAction,
3032
ForceMergeUIAction,
3133
IndexPriorityUIAction,
@@ -75,6 +77,8 @@ export const getUIAction = (actionType: string): UIAction<any> => {
7577
return new AllocationUIAction(DEFAULT_ALLOCATION);
7678
case ActionType.Close:
7779
return new CloseUIAction(DEFAULT_CLOSE);
80+
case ActionType.ConvertIndexToRemote:
81+
return new ConvertIndexToRemoteUIAction(DEFAULT_CONVERT_INDEX_TO_REMOTE);
7882
case ActionType.Delete:
7983
return new DeleteUIAction(DEFAULT_DELETE);
8084
case ActionType.ForceMerge:
@@ -127,6 +131,7 @@ class ActionRepository {
127131
alias: [AliasUIAction, DEFAULT_ALIAS],
128132
allocation: [AllocationUIAction, DEFAULT_ALLOCATION],
129133
close: [CloseUIAction, DEFAULT_CLOSE],
134+
convert_index_to_remote: [ConvertIndexToRemoteUIAction, DEFAULT_CONVERT_INDEX_TO_REMOTE],
130135
delete: [DeleteUIAction, DEFAULT_DELETE],
131136
force_merge: [ForceMergeUIAction, DEFAULT_FORCE_MERGE],
132137
index_priority: [IndexPriorityUIAction, DEFAULT_INDEX_PRIORITY],

0 commit comments

Comments
 (0)