Skip to content

Commit

Permalink
Adds UI actions for all the supported ISM actions (#49)
Browse files Browse the repository at this point in the history
* Adds UI actions for all the supported ISM actions

Signed-off-by: Drew Baugher <[email protected]>

* Moves ActionType to constants

Signed-off-by: Drew Baugher <[email protected]>
  • Loading branch information
dbbaughe authored Aug 11, 2021
1 parent dfca9f4 commit 0d6b814
Show file tree
Hide file tree
Showing 19 changed files with 1,210 additions and 53 deletions.
79 changes: 78 additions & 1 deletion models/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

// TODO: Backend has PR out to change this model, this needs to be updated once that goes through

import { ActionType } from "../public/pages/VisualCreatePolicy/utils/actions";
import { ActionType } from "../public/pages/VisualCreatePolicy/utils/constants";

export interface ManagedIndexMetaData {
index: string;
Expand Down Expand Up @@ -152,6 +152,38 @@ export interface UIAction<Data> {
toAction: () => Action;
}

export interface ForceMergeAction extends Action {
force_merge: {
max_num_segments: number;
};
}

export interface ReadOnlyAction extends Action {
read_only: {};
}

export interface ReadWriteAction extends Action {
read_write: {};
}

export interface ReplicaCountAction extends Action {
replica_count: {
number_of_replicas: number;
};
}

export interface CloseAction extends Action {
close: {};
}

export interface OpenAction extends Action {
open: {};
}

export interface DeleteAction extends Action {
delete: {};
}

export interface RolloverAction extends Action {
rollover: {
min_size?: string;
Expand Down Expand Up @@ -186,6 +218,51 @@ export interface InnerCron {
timezone: string;
}

export interface NotificationAction extends Action {
notification: {
destination?: Destination;
channel?: {
id: string;
};
message_template: MessageTemplate;
};
notificationJsonString?: string;
}

export interface SnapshotAction extends Action {
snapshot: {
repository: string;
snapshot: string;
};
}

export interface IndexPriorityAction extends Action {
index_priority: {
priority: number;
};
}

export interface AllocationAction extends Action {
allocation: {
require: {
[key: string]: string;
};
include: {
[key: string]: string;
};
exclude: {
[key: string]: string;
};
wait_for: boolean;
};
}

export interface RollupAction extends Action {
rollup: {
jsonString: string;
};
}

export interface Rollup {
continuous: boolean;
delay: number | null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { render } from "@testing-library/react";
import { EuiDragDropContext, EuiDroppable } from "@elastic/eui";
import DraggableItem from "./DraggableItem";
import { DEFAULT_ROLLOVER } from "../../utils/constants";
import { RolloverUIAction } from "../../utils/actions";
import { RolloverUIAction } from "../UIActions";
import { UIAction } from "../../../../../models/interfaces";
import { fireEvent } from "@testing-library/dom";

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 { AllocationAction, UIAction } from "../../../../../models/interfaces";
import { makeId } from "../../../../utils/helpers";
import { ActionType } from "../../utils/constants";

export default class AllocationUIAction implements UIAction<AllocationAction> {
id: string;
action: AllocationAction;
type = ActionType.Allocation;

constructor(action: AllocationAction, id: string = makeId()) {
this.action = action;
this.id = id;
}

content = () => `Allocation`;

clone = (action: AllocationAction = this.action) => new AllocationUIAction(action, this.id);

render = (action: UIAction<AllocationAction>, onChangeAction: (action: UIAction<AllocationAction>) => void) => {
return <div />;
};

toAction = () => this.action;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 { CloseAction, UIAction } from "../../../../../models/interfaces";
import { makeId } from "../../../../utils/helpers";
import { ActionType } from "../../utils/constants";

export default class CloseUIAction implements UIAction<CloseAction> {
id: string;
action: CloseAction;
type = ActionType.Close;

constructor(action: CloseAction, id: string = makeId()) {
this.action = action;
this.id = id;
}

content = () => `Close`;

clone = (action: CloseAction) => new CloseUIAction(action, this.id);

render = (action: UIAction<CloseAction>, onChangeAction: (action: UIAction<CloseAction>) => void) => {
return <div />;
};

toAction = () => this.action;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 { DeleteAction, UIAction } from "../../../../../models/interfaces";
import { makeId } from "../../../../utils/helpers";
import { ActionType } from "../../utils/constants";

export default class DeleteUIAction implements UIAction<DeleteAction> {
id: string;
action: DeleteAction;
type = ActionType.Delete;

constructor(action: DeleteAction, id: string = makeId()) {
this.action = action;
this.id = id;
}

content = () => `Delete`;

clone = (action: DeleteAction) => new DeleteUIAction(action, this.id);

render = (action: UIAction<DeleteAction>, onChangeAction: (action: UIAction<DeleteAction>) => void) => {
return <div />;
};

toAction = () => this.action;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* 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 { EuiFormRow, EuiFieldNumber } from "@elastic/eui";
import EuiFormCustomLabel from "../EuiFormCustomLabel";
import { ForceMergeAction, UIAction } from "../../../../../models/interfaces";
import { makeId } from "../../../../utils/helpers";
import { ActionType } from "../../utils/constants";

export default class ForceMergeUIAction implements UIAction<ForceMergeAction> {
id: string;
action: ForceMergeAction;
type = ActionType.ForceMerge;

constructor(action: ForceMergeAction, id: string = makeId()) {
this.action = action;
this.id = id;
}

content = () => `Force merge to ${this.action.force_merge.max_num_segments} segments`;

clone = (action: ForceMergeAction) => new ForceMergeUIAction(action, this.id);

render = (action: UIAction<ForceMergeAction>, onChangeAction: (action: UIAction<ForceMergeAction>) => void) => {
return (
<>
<EuiFormCustomLabel title="Max num segments" helpText="The number of segments to merge to." />
<EuiFormRow isInvalid={false} error={null}>
<EuiFieldNumber
value={(action.action as ForceMergeAction).force_merge.max_num_segments}
style={{ textTransform: "capitalize" }}
onChange={(e: ChangeEvent<HTMLInputElement>) => {
const maxNumSegments = e.target.valueAsNumber;
onChangeAction(
this.clone({
force_merge: {
max_num_segments: maxNumSegments,
},
})
);
}}
data-test-subj="action-render-force-merge"
/>
</EuiFormRow>
</>
);
};

toAction = () => this.action;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* 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 { EuiFormRow, EuiFieldNumber } from "@elastic/eui";
import EuiFormCustomLabel from "../EuiFormCustomLabel";
import { IndexPriorityAction, UIAction } from "../../../../../models/interfaces";
import { makeId } from "../../../../utils/helpers";
import { ActionType } from "../../utils/constants";

export default class IndexPriorityUIAction implements UIAction<IndexPriorityAction> {
id: string;
action: IndexPriorityAction;
type = ActionType.IndexPriority;

constructor(action: IndexPriorityAction, id: string = makeId()) {
this.action = action;
this.id = id;
}

content = () => `Set index priority to ${this.action.index_priority.priority}`;

clone = (action: IndexPriorityAction) => new IndexPriorityUIAction(action, this.id);

render = (action: UIAction<IndexPriorityAction>, onChangeAction: (action: UIAction<IndexPriorityAction>) => void) => {
return (
<>
<EuiFormCustomLabel title="Priority" helpText="Higher priority indices are recovered first when possible." />
<EuiFormRow isInvalid={false} error={null}>
<EuiFieldNumber
value={(action.action as IndexPriorityAction).index_priority.priority}
style={{ textTransform: "capitalize" }}
onChange={(e: ChangeEvent<HTMLInputElement>) => {
const priority = e.target.valueAsNumber;
onChangeAction(
this.clone({
index_priority: { priority },
})
);
}}
data-test-subj="action-render-index-priority"
/>
</EuiFormRow>
</>
);
};

toAction = () => this.action;
}
Loading

0 comments on commit 0d6b814

Please sign in to comment.