Skip to content

Commit

Permalink
Merge branch 'main' into ismtemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
dbbaughe authored Aug 11, 2021
2 parents 69526f2 + 0d6b814 commit ab6737f
Show file tree
Hide file tree
Showing 27 changed files with 1,390 additions and 81 deletions.
105 changes: 104 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 @@ -157,6 +157,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 All @@ -165,6 +197,77 @@ export interface RolloverAction extends Action {
};
}

export interface UITransition {
transition: Transition;
id: string;
}

export interface Transition {
state_name: string;
conditions?: Condition;
}

export interface Condition {
min_index_age?: string;
min_doc_count?: number;
min_size?: string;
cron?: Cron;
}

export interface Cron {
cron: InnerCron;
}

export interface InnerCron {
expression: string;
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 @@ -13,19 +13,20 @@ import React from "react";
import "@testing-library/jest-dom/extend-expect";
import { render } from "@testing-library/react";
import { EuiDragDropContext, EuiDroppable } from "@elastic/eui";
import DraggableAction from "./DraggableAction";
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";

describe("<DraggableAction /> spec", () => {
describe("<DraggableItem /> spec", () => {
it("renders the component", () => {
const action: UIAction<any> = new RolloverUIAction(DEFAULT_ROLLOVER);
const content = action.content();
const { container } = render(
<EuiDragDropContext onDragEnd={() => {}}>
<EuiDroppable droppableId="STATE_ACTIONS_DROPPABLE_AREA">
<DraggableAction action={action} idx={0} isLast={true} onClickDeleteAction={() => {}} onClickEditAction={() => {}} />
<DraggableItem content={content} id={action.id} idx={0} isLast={true} onClickDelete={() => {}} onClickEdit={() => {}} />
</EuiDroppable>
</EuiDragDropContext>
);
Expand All @@ -34,31 +35,33 @@ describe("<DraggableAction /> spec", () => {

it("calls onclickdeleteaction when clicking delete button", () => {
const action: UIAction<any> = new RolloverUIAction(DEFAULT_ROLLOVER);
const onClickDeleteAction = jest.fn();
const onClickDelete = jest.fn();
const content = action.content();
const { getByTestId } = render(
<EuiDragDropContext onDragEnd={() => {}}>
<EuiDroppable droppableId="STATE_ACTIONS_DROPPABLE_AREA">
<DraggableAction action={action} idx={0} isLast={true} onClickDeleteAction={onClickDeleteAction} onClickEditAction={() => {}} />
<DraggableItem content={content} id={action.id} idx={0} isLast={true} onClickDelete={onClickDelete} onClickEdit={() => {}} />
</EuiDroppable>
</EuiDragDropContext>
);

fireEvent.click(getByTestId("draggable-action-delete-button"));
expect(onClickDeleteAction).toHaveBeenCalledTimes(1);
fireEvent.click(getByTestId("draggable-item-delete-button-" + action.id));
expect(onClickDelete).toHaveBeenCalledTimes(1);
});

it("calls onclickeditaction when clicking delete button", () => {
it("calls onclickeditaction when clicking edit button", () => {
const action: UIAction<any> = new RolloverUIAction(DEFAULT_ROLLOVER);
const onClickEditAction = jest.fn();
const onClickEdit = jest.fn();
const content = action.content();
const { getByTestId } = render(
<EuiDragDropContext onDragEnd={() => {}}>
<EuiDroppable droppableId="STATE_ACTIONS_DROPPABLE_AREA">
<DraggableAction action={action} idx={0} isLast={true} onClickDeleteAction={() => {}} onClickEditAction={onClickEditAction} />
<DraggableItem content={content} id={action.id} idx={0} isLast={true} onClickDelete={() => {}} onClickEdit={onClickEdit} />
</EuiDroppable>
</EuiDragDropContext>
);

fireEvent.click(getByTestId("draggable-action-edit-button"));
expect(onClickEditAction).toHaveBeenCalledTimes(1);
fireEvent.click(getByTestId("draggable-item-edit-button-" + action.id));
expect(onClickEdit).toHaveBeenCalledTimes(1);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@

import React from "react";
import { EuiFlexGroup, EuiFlexItem, EuiDraggable, EuiPanel, EuiIcon, EuiButtonIcon } from "@elastic/eui";
import { Action, UIAction } from "../../../../../models/interfaces";

interface DraggableActionProps {
action: UIAction<Action>;
interface DraggableItemProps {
content: string | JSX.Element | null;
id: string;
idx: number;
isLast: boolean;
onClickDeleteAction: () => void;
onClickEditAction: () => void;
onClickDelete: () => void;
onClickEdit: () => void;
}

const DraggableAction = ({ action: { id, content }, idx, isLast, onClickDeleteAction, onClickEditAction }: DraggableActionProps) => (
const DraggableItem = ({ content, id, idx, isLast, onClickDelete, onClickEdit }: DraggableItemProps) => (
<EuiDraggable style={{ padding: `0px 0px ${isLast ? "0px" : "10px"} 0px` }} key={id} index={idx} draggableId={id} customDragHandle={true}>
{(provided) => (
<EuiPanel className="custom" paddingSize="m">
Expand All @@ -31,23 +31,23 @@ const DraggableAction = ({ action: { id, content }, idx, isLast, onClickDeleteAc
<EuiIcon type="grab" />
</div>
</EuiFlexItem>
<EuiFlexItem>{content()}</EuiFlexItem>
<EuiFlexItem>{content}</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonIcon
iconType="trash"
aria-label="Delete"
color="danger"
onClick={onClickDeleteAction}
data-test-subj="draggable-action-delete-button"
onClick={onClickDelete}
data-test-subj={`draggable-item-delete-button-${id}`}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButtonIcon
iconType="pencil"
aria-label="Edit"
color="primary"
onClick={onClickEditAction}
data-test-subj="draggable-action-edit-button"
onClick={onClickEdit}
data-test-subj={`draggable-item-edit-button-${id}`}
/>
</EuiFlexItem>
</EuiFlexGroup>
Expand All @@ -56,4 +56,4 @@ const DraggableAction = ({ action: { id, content }, idx, isLast, onClickDeleteAc
</EuiDraggable>
);

export default DraggableAction;
export default DraggableItem;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<DraggableAction /> spec renders the component 1`] = `
exports[`<DraggableItem /> spec renders the component 1`] = `
<div
class="euiDroppable euiDroppable--noGrow"
data-rbd-droppable-context-id="0"
Expand Down Expand Up @@ -46,7 +46,7 @@ exports[`<DraggableAction /> spec renders the component 1`] = `
<button
aria-label="Delete"
class="euiButtonIcon euiButtonIcon--danger"
data-test-subj="draggable-action-delete-button"
data-test-subj="draggable-item-delete-button-some_html_id"
type="button"
>
EuiIconMock
Expand All @@ -58,7 +58,7 @@ exports[`<DraggableAction /> spec renders the component 1`] = `
<button
aria-label="Edit"
class="euiButtonIcon euiButtonIcon--primary"
data-test-subj="draggable-action-edit-button"
data-test-subj="draggable-item-edit-button-some_html_id"
type="button"
>
EuiIconMock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
* GitHub history for details.
*/

import DraggableAction from "./DraggableAction";
import DraggableItem from "./DraggableItem";

export default DraggableAction;
export default DraggableItem;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* 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 TransitionContent from "./TransitionContent";

describe("<TransitionContent /> spec", () => {
it("renders the component", () => {
const { container } = render(<TransitionContent transition={{ state_name: "some_state", conditions: { min_index_age: "30d" } }} />);
expect(container.firstChild).toMatchSnapshot();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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 { EuiText } from "@elastic/eui";
import { Transition } from "../../../../../models/interfaces";
import { getConditionContent } from "../../utils/helpers";

interface TransitionContentProps {
transition: Transition;
}

const TransitionContent = ({ transition }: TransitionContentProps) => (
<EuiText>
<dl>
<dt>Destination state</dt>
<dd>{transition.state_name}</dd>
<dt>Transition trigger logic</dt>
<dd>{getConditionContent(transition)}</dd>
</dl>
</EuiText>
);

export default TransitionContent;
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<TransitionContent /> spec renders the component 1`] = `
<div
class="euiText euiText--medium"
>
<dl>
<dt>
Destination state
</dt>
<dd>
some_state
</dd>
<dt>
Transition trigger logic
</dt>
<dd>
Minimum index age is 30d
</dd>
</dl>
</div>
`;
16 changes: 16 additions & 0 deletions public/pages/VisualCreatePolicy/components/Transition/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* 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 TransitionContent from "./TransitionContent";

export { TransitionContent };

export default Transition;
Loading

0 comments on commit ab6737f

Please sign in to comment.