Skip to content

Commit 4f13fca

Browse files
committed
Add stop replication visual policy action
Signed-off-by: wzyns <me@wzyns.com>
1 parent 6b82c47 commit 4f13fca

9 files changed

Lines changed: 100 additions & 4 deletions

File tree

models/interfaces.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,10 @@ export interface DeleteAction extends Action {
360360
delete: {};
361361
}
362362

363+
export interface StopReplicationAction extends Action {
364+
stop_replication: {};
365+
}
366+
363367
export interface RolloverAction extends Action {
364368
rollover: {
365369
min_size?: string;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* Copyright OpenSearch Contributors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import React from "react";
7+
import { StopReplicationAction, UIAction } from "../../../../../models/interfaces";
8+
import { makeId } from "../../../../utils/helpers";
9+
import { ActionType } from "../../utils/constants";
10+
11+
export class StopReplicationUIAction implements UIAction<StopReplicationAction> {
12+
id: string;
13+
action: StopReplicationAction;
14+
type = ActionType.StopReplication;
15+
16+
constructor(action: StopReplicationAction, id: string = makeId()) {
17+
this.action = action;
18+
this.id = id;
19+
}
20+
21+
content = () => `Stop replication`;
22+
23+
clone = (action: StopReplicationAction) => new StopReplicationUIAction(action, this.id);
24+
25+
isValid = () => true;
26+
27+
render = (action: UIAction<StopReplicationAction>, onChangeAction: (action: UIAction<StopReplicationAction>) => void) => {
28+
return <div />;
29+
};
30+
31+
toAction = () => this.action;
32+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import RolloverUIAction from "./RolloverUIAction";
1818
import RollupUIAction from "./RollupUIAction";
1919
import ShrinkUIAction from "./ShrinkUIAction";
2020
import SnapshotUIAction from "./SnapshotUIAction";
21+
import { StopReplicationUIAction } from "./StopReplicationUIAction";
2122

2223
export {
2324
AliasUIAction,
@@ -35,4 +36,5 @@ export {
3536
RollupUIAction,
3637
ShrinkUIAction,
3738
SnapshotUIAction,
39+
StopReplicationUIAction,
3840
};

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,21 @@ describe("<CreateAction /> spec", () => {
2626
);
2727
expect(container.firstChild).toMatchSnapshot();
2828
});
29+
30+
it("includes stop replication in the action type dropdown", () => {
31+
const rolloverAction: UIAction<any> = new RolloverUIAction(DEFAULT_ROLLOVER, "some_id");
32+
const { container } = render(
33+
<CreateAction
34+
stateName="some_state"
35+
actions={[rolloverAction]}
36+
editAction={rolloverAction}
37+
onClickCancelAction={() => {}}
38+
onClickSaveAction={() => {}}
39+
/>
40+
);
41+
42+
const stopReplicationOption = container.querySelector('option[value="stop_replication"]');
43+
expect(stopReplicationOption).toBeInTheDocument();
44+
expect(stopReplicationOption).toHaveTextContent("Stop Replication");
45+
});
2946
});

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ exports[`<CreateAction /> spec renders the component 1`] = `
170170
>
171171
Snapshot
172172
</option>
173+
<option
174+
value="stop_replication"
175+
>
176+
Stop Replication
177+
</option>
173178
</select>
174179
<div
175180
class="euiFormControlLayoutIcons euiFormControlLayoutIcons--right"

public/pages/VisualCreatePolicy/containers/CreateState/CreateState.test.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,26 @@ import "@testing-library/jest-dom/extend-expect";
88
import { render } from "@testing-library/react";
99
import CreateState from "./CreateState";
1010
import { DEFAULT_POLICY } from "../../utils/constants";
11+
import { Policy, State } from "../../../../../models/interfaces";
1112

1213
describe("<CreateState /> spec", () => {
1314
it("renders the component", () => {
1415
render(<CreateState policy={DEFAULT_POLICY} onSaveState={() => {}} onCloseFlyout={() => {}} state={null} />);
1516
expect(document.body.children[1]).toMatchSnapshot();
1617
});
18+
19+
it("loads a state with a stop replication action", () => {
20+
const state: State = {
21+
name: "stop_replication",
22+
actions: [{ stop_replication: {} }],
23+
transitions: [],
24+
};
25+
const policy: Policy = {
26+
...DEFAULT_POLICY,
27+
default_state: state.name,
28+
states: [state],
29+
};
30+
31+
expect(() => render(<CreateState policy={policy} onSaveState={() => {}} onCloseFlyout={() => {}} state={state} />)).not.toThrow();
32+
});
1733
});

public/pages/VisualCreatePolicy/utils/constants.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { AliasAction, AllocationAction } from "../../../../models/interfaces";
6+
import { AliasAction, AllocationAction, StopReplicationAction } from "../../../../models/interfaces";
77

88
export enum ActionType {
99
Alias = "alias",
@@ -21,6 +21,7 @@ export enum ActionType {
2121
Rollup = "rollup",
2222
Shrink = "shrink",
2323
Snapshot = "snapshot",
24+
StopReplication = "stop_replication",
2425
}
2526

2627
export const DEFAULT_POLICY = {
@@ -194,6 +195,9 @@ export const DEFAULT_SNAPSHOT = {
194195
snapshot: "example-snapshot",
195196
},
196197
};
198+
export const DEFAULT_STOP_REPLICATION: StopReplicationAction = {
199+
stop_replication: {},
200+
};
197201

198202
export const actions = [
199203
DEFAULT_ALIAS,
@@ -211,6 +215,7 @@ export const actions = [
211215
DEFAULT_ROLLUP,
212216
DEFAULT_SHRINK,
213217
DEFAULT_SNAPSHOT,
218+
DEFAULT_STOP_REPLICATION,
214219
];
215220

216221
export const ISM_TEMPLATE_INPUT_MAX_WIDTH = "400px";

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
import { actionRepoSingleton, capitalizeFirstLetter, convertTemplatesToArray, getOrderInfo, getUpdatedPolicy } from "./helpers";
77
import { Action, ISMTemplate, UIAction } from "../../../../models/interfaces";
88
import { makeId } from "../../../utils/helpers";
9-
import { DEFAULT_POLICY } from "./constants";
9+
import { DEFAULT_POLICY, DEFAULT_STOP_REPLICATION } from "./constants";
10+
import { StopReplicationUIAction } from "../components/UIActions";
1011

1112
test("converts all ism template formats into a list of ism templates", () => {
1213
expect(convertTemplatesToArray(null)).toEqual([]);
@@ -75,13 +76,22 @@ class DummyUIAction implements UIAction<DummyAction> {
7576
}
7677

7778
test("action repository usage", () => {
78-
expect(actionRepoSingleton.getAllActionTypes().length).toBe(15);
79-
actionRepoSingleton.registerAction("dummy", DummyUIAction, DEFAULT_DUMMY);
8079
expect(actionRepoSingleton.getAllActionTypes().length).toBe(16);
80+
actionRepoSingleton.registerAction("dummy", DummyUIAction, DEFAULT_DUMMY);
81+
expect(actionRepoSingleton.getAllActionTypes().length).toBe(17);
8182
expect(actionRepoSingleton.getUIAction("dummy") instanceof DummyUIAction).toBe(true);
8283
expect(actionRepoSingleton.getUIActionFromData(DEFAULT_DUMMY) instanceof DummyUIAction).toBe(true);
8384
});
8485

86+
test("action repository supports stop replication action", () => {
87+
expect(actionRepoSingleton.getAllActionTypes()).toContain("stop_replication");
88+
expect(actionRepoSingleton.getUIAction("stop_replication") instanceof StopReplicationUIAction).toBe(true);
89+
expect(actionRepoSingleton.getUIActionFromData(DEFAULT_STOP_REPLICATION) instanceof StopReplicationUIAction).toBe(true);
90+
expect(actionRepoSingleton.getUIActionFromData({ stop_replication: {} }).toAction()).toEqual({
91+
stop_replication: {},
92+
});
93+
});
94+
8595
test("changing the default state name correctly updates default_state", () => {
8696
const policy = DEFAULT_POLICY;
8797
const updatedState = { ...policy.states[0], name: "new_hot" };

public/pages/VisualCreatePolicy/utils/helpers.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
DEFAULT_ROLLUP,
2222
DEFAULT_SHRINK,
2323
DEFAULT_SNAPSHOT,
24+
DEFAULT_STOP_REPLICATION,
2425
} from "./constants";
2526
import {
2627
AliasUIAction,
@@ -38,6 +39,7 @@ import {
3839
RollupUIAction,
3940
ShrinkUIAction,
4041
SnapshotUIAction,
42+
StopReplicationUIAction,
4143
} from "../components/UIActions";
4244

4345
export const getConditionContent = (transition: Transition): string => {
@@ -99,6 +101,8 @@ export const getUIAction = (actionType: string): UIAction<any> => {
99101
return new ShrinkUIAction(DEFAULT_SHRINK);
100102
case ActionType.Snapshot:
101103
return new SnapshotUIAction(DEFAULT_SNAPSHOT);
104+
case ActionType.StopReplication:
105+
return new StopReplicationUIAction(DEFAULT_STOP_REPLICATION);
102106
default:
103107
throw new Error(`Action type [${actionType}] not supported`);
104108
}
@@ -139,6 +143,7 @@ class ActionRepository {
139143
rollup: [RollupUIAction, DEFAULT_ROLLUP],
140144
shrink: [ShrinkUIAction, DEFAULT_SHRINK],
141145
snapshot: [SnapshotUIAction, DEFAULT_SNAPSHOT],
146+
stop_replication: [StopReplicationUIAction, DEFAULT_STOP_REPLICATION],
142147
};
143148

144149
getAllActionTypes = () => {

0 commit comments

Comments
 (0)