Skip to content

Commit 69d8fe1

Browse files
authored
Adds VisualCreatePolicy page, missing backend routes/configs, updates… (#61)
* Adds VisualCreatePolicy page, missing backend routes/configs, updates all creation paths to show new modal, updates rates, etc. Signed-off-by: Drew Baugher <[email protected]> * Updates cypress tests Signed-off-by: Drew Baugher <[email protected]> * Fixes cypress test Signed-off-by: Drew Baugher <[email protected]> * Fixes duplicate action type, filters retry/timeout keys, and fixes transition condition default value when switching Signed-off-by: Drew Baugher <[email protected]>
1 parent b9645f1 commit 69d8fe1

File tree

32 files changed

+658
-126
lines changed

32 files changed

+658
-126
lines changed

cypress/integration/managed_indices_spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ describe("Managed indices", () => {
211211
// Confirm we got the change policy toaster
212212
cy.contains("Changed policy on 1 indices");
213213

214-
// Click back to Managed Indices page
215-
cy.contains("Managed Indices").click();
214+
// Click back to Managed Indices page by clicking "Managed indices" breadcrumb
215+
cy.contains("Managed indices").click();
216216

217217
// Speed up execution of managed index
218218
cy.updateManagedIndexConfigStartTime(SAMPLE_INDEX);

cypress/integration/policies_spec.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@ describe("Policies", () => {
5353
// Route us to create policy page
5454
cy.contains("Create policy").click({ force: true });
5555

56+
// Route us to create policy page
57+
cy.contains("JSON editor").click({ force: true });
58+
59+
// Route us to create policy page
60+
cy.contains("Continue").click({ force: true });
61+
5662
// Wait for input to load and then type in the policy ID
5763
cy.get(`input[placeholder="hot_cold_workflow"]`).type(POLICY_ID, { force: true });
5864

@@ -97,6 +103,12 @@ describe("Policies", () => {
97103
// Click Edit button
98104
cy.get(`[data-test-subj="EditButton"]`).click({ force: true });
99105

106+
// Route us to edit policy page
107+
cy.contains("JSON editor").click({ force: true });
108+
109+
// Route us to edit policy page
110+
cy.contains("Continue").click({ force: true });
111+
100112
// Wait for initial policy JSON to load
101113
cy.contains("A simple description");
102114

models/interfaces.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ export interface DocumentTransform {
9292
export interface Policy {
9393
description: string;
9494
default_state: string;
95-
error_notification?: ErrorNotification;
95+
error_notification?: ErrorNotification | null;
9696
states: State[];
9797
ism_template?: ISMTemplate[] | ISMTemplate | null;
98+
last_updated_time?: string;
99+
schema_version?: number;
98100
}
99101

100102
export interface ErrorNotification {

public/app.scss

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,41 @@
1212
* express or implied. See the License for the specific language governing
1313
* permissions and limitations under the License.
1414
*/
15+
16+
// Copies over styling from eui library to be used in custom classes
17+
// Core
18+
$euiColorPrimary: #006BB4 !default;
19+
$euiColorDarkestShade: #343741 !default;
20+
$euiColorGhost: #FFF !default;
21+
$euiColorInk: #000 !default;
22+
$euiTextColor: $euiColorDarkestShade !default;
23+
24+
.selected-radio-panel {
25+
background-color: tintOrShade($euiColorPrimary, 90%, 70%);
26+
border-color: $euiColorPrimary;
27+
}
28+
29+
@function tintOrShade($color, $tint, $shade) {
30+
@if (lightness($euiTextColor) > 50) {
31+
@return shade($color, $shade);
32+
} @else {
33+
@return tint($color, $tint);
34+
}
35+
}
36+
37+
@function tint($color, $percent) {
38+
@return mix($euiColorGhost, $color, $percent);
39+
}
40+
41+
@function shade($color, $percent) {
42+
@return mix($euiColorInk, $color, $percent);
43+
}
44+
45+
.refresh-button {
46+
min-width: 0;
47+
.euiButtonContent {
48+
.euiButton__text {
49+
margin: 0;
50+
}
51+
}
52+
}

public/components/ConfirmationModal/ConfirmationModal.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,18 +39,28 @@ import {
3939

4040
interface ConfirmationModalProps {
4141
title: string;
42-
bodyMessage: string;
42+
bodyMessage: string | JSX.Element;
4343
actionMessage: string;
44+
actionProps?: object;
45+
modalProps?: object;
4446
onClose: () => void;
4547
onAction: () => void;
4648
}
4749

48-
const ConfirmationModal: React.SFC<ConfirmationModalProps> = ({ title, bodyMessage, actionMessage, onClose, onAction }) => {
50+
const ConfirmationModal: React.SFC<ConfirmationModalProps> = ({
51+
title,
52+
bodyMessage,
53+
actionMessage,
54+
onClose,
55+
onAction,
56+
actionProps = {},
57+
modalProps = {},
58+
}) => {
4959
return (
5060
<EuiOverlayMask>
5161
{/*
5262
// @ts-ignore */}
53-
<EuiModal onCancel={onClose} onClose={onClose} maxWidth={1000}>
63+
<EuiModal onCancel={onClose} onClose={onClose} maxWidth={1000} {...modalProps}>
5464
<EuiModalHeader>
5565
<EuiModalHeaderTitle>{title}</EuiModalHeaderTitle>
5666
</EuiModalHeader>
@@ -68,6 +78,7 @@ const ConfirmationModal: React.SFC<ConfirmationModalProps> = ({ title, bodyMessa
6878
}}
6979
fill
7080
data-test-subj="confirmationModalActionButton"
81+
{...actionProps}
7182
>
7283
{actionMessage}
7384
</EuiButton>

public/components/PolicyModal/PolicyModal.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ interface PolicyModalProps {
4646
policy: object | null;
4747
errorMessage?: string;
4848
onClose: () => void;
49-
onEdit: () => void;
49+
onEdit: (visual: boolean) => void;
5050
}
5151

5252
const PolicyModal: React.SFC<PolicyModalProps> = ({ policyId, policy, errorMessage, onClose, onEdit }) => {
@@ -61,7 +61,7 @@ const PolicyModal: React.SFC<PolicyModalProps> = ({ policyId, policy, errorMessa
6161
</EuiModalHeader>
6262

6363
<EuiModalBody>
64-
<EuiCodeBlock language="json" fontSize="m">
64+
<EuiCodeBlock language="json" fontSize="m" style={{ minWidth: 600 }}>
6565
{errorMessage != null ? errorMessage : policyString}
6666
</EuiCodeBlock>
6767
</EuiModalBody>
@@ -83,7 +83,12 @@ const PolicyModal: React.SFC<PolicyModalProps> = ({ policyId, policy, errorMessa
8383
</EuiButtonEmpty>
8484
</EuiFlexItem>
8585
<EuiFlexItem grow={false}>
86-
<EuiButton onClick={onEdit} fill disabled={!policyId || !policy} data-test-subj="policyModalEditButton">
86+
<EuiButton onClick={() => onEdit(false)} fill disabled={!policyId || !policy} data-test-subj="policyModalEditJsonButton">
87+
Edit as JSON
88+
</EuiButton>
89+
</EuiFlexItem>
90+
<EuiFlexItem grow={false}>
91+
<EuiButton onClick={() => onEdit(true)} fill disabled={!policyId || !policy} data-test-subj="policyModalEditButton">
8792
Edit
8893
</EuiButton>
8994
</EuiFlexItem>

public/components/PolicyModal/__snapshots__/PolicyModal.test.tsx.snap

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ exports[`<PolicyModal /> spec renders the component 1`] = `
5959
>
6060
<code
6161
class="euiCodeBlock__code json hljs"
62+
style="min-width: 600px;"
6263
>
6364
{
6465
@@ -138,6 +139,25 @@ exports[`<PolicyModal /> spec renders the component 1`] = `
138139
</span>
139140
</button>
140141
</div>
142+
<div
143+
class="euiFlexItem euiFlexItem--flexGrowZero"
144+
>
145+
<button
146+
class="euiButton euiButton--primary euiButton--fill"
147+
data-test-subj="policyModalEditJsonButton"
148+
type="button"
149+
>
150+
<span
151+
class="euiButtonContent euiButton__content"
152+
>
153+
<span
154+
class="euiButton__text"
155+
>
156+
Edit as JSON
157+
</span>
158+
</span>
159+
</button>
160+
</div>
141161
<div
142162
class="euiFlexItem euiFlexItem--flexGrowZero"
143163
>

public/index_management_app.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import {
4040
import { DarkModeContext } from "./components/DarkMode";
4141
import Main from "./pages/Main";
4242
import { CoreServicesContext } from "./components/core_services";
43+
import "./app.scss";
4344

4445
export function renderApp(coreStart: CoreStart, params: AppMountParameters) {
4546
const http = coreStart.http;

public/pages/CreatePolicy/containers/CreatePolicy/CreatePolicy.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export default class CreatePolicy extends Component<CreatePolicyProps, CreatePol
113113
}
114114
};
115115

116-
onCreate = async (policyId: string, policy: Policy): Promise<void> => {
116+
onCreate = async (policyId: string, policy: { policy: Policy }): Promise<void> => {
117117
const { policyService } = this.props;
118118
try {
119119
const response = await policyService.putPolicy(policy, policyId);
@@ -128,7 +128,7 @@ export default class CreatePolicy extends Component<CreatePolicyProps, CreatePol
128128
}
129129
};
130130

131-
onUpdate = async (policyId: string, policy: Policy): Promise<void> => {
131+
onUpdate = async (policyId: string, policy: { policy: Policy }): Promise<void> => {
132132
try {
133133
const { policyService } = this.props;
134134
const { policyPrimaryTerm, policySeqNo } = this.state;

public/pages/Main/Main.tsx

Lines changed: 44 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import Policies from "../Policies";
3333
import ManagedIndices from "../ManagedIndices";
3434
import Indices from "../Indices";
3535
import CreatePolicy from "../CreatePolicy";
36+
import VisualCreatePolicy from "../VisualCreatePolicy";
3637
import ChangePolicy from "../ChangePolicy";
3738
import Rollups from "../Rollups";
3839
import { ModalProvider, ModalRoot } from "../../components/Modal";
@@ -46,6 +47,8 @@ import EditRollup from "../EditRollup/containers";
4647
import RollupDetails from "../RollupDetails/containers/RollupDetails";
4748
import { EditTransform, Transforms } from "../Transforms";
4849
import TransformDetails from "../Transforms/containers/Transforms/TransformDetails";
50+
import queryString from "query-string";
51+
import PolicyDetails from "../PolicyDetails/containers/PolicyDetails";
4952

5053
enum Navigation {
5154
IndexManagement = "Index Management",
@@ -64,6 +67,18 @@ enum Pathname {
6467
Transforms = "/transforms",
6568
}
6669

70+
const HIDDEN_NAV_ROUTES = [
71+
ROUTES.CREATE_ROLLUP,
72+
ROUTES.EDIT_ROLLUP,
73+
ROUTES.ROLLUP_DETAILS,
74+
ROUTES.CREATE_TRANSFORM,
75+
ROUTES.EDIT_TRANSFORM,
76+
ROUTES.TRANSFORM_DETAILS,
77+
ROUTES.CREATE_POLICY,
78+
ROUTES.EDIT_POLICY,
79+
ROUTES.CHANGE_POLICY,
80+
];
81+
6782
interface MainProps extends RouteComponentProps {}
6883

6984
export default class Main extends Component<MainProps, object> {
@@ -121,16 +136,11 @@ export default class Main extends Component<MainProps, object> {
121136
<ModalRoot services={services} />
122137
<EuiPage restrictWidth="100%">
123138
{/*Hide side navigation bar when creating or editing rollup job*/}
124-
{pathname != ROUTES.CREATE_ROLLUP &&
125-
pathname != ROUTES.EDIT_ROLLUP &&
126-
pathname != ROUTES.ROLLUP_DETAILS &&
127-
pathname != ROUTES.CREATE_TRANSFORM &&
128-
pathname != ROUTES.EDIT_TRANSFORM &&
129-
pathname != ROUTES.TRANSFORM_DETAILS && (
130-
<EuiPageSideBar style={{ minWidth: 150 }}>
131-
<EuiSideNav style={{ width: 150 }} items={sideNav} />
132-
</EuiPageSideBar>
133-
)}
139+
{!HIDDEN_NAV_ROUTES.includes(pathname) && (
140+
<EuiPageSideBar style={{ minWidth: 150 }}>
141+
<EuiSideNav style={{ width: 150 }} items={sideNav} />
142+
</EuiPageSideBar>
143+
)}
134144
<EuiPageBody>
135145
<Switch>
136146
<Route
@@ -145,15 +155,33 @@ export default class Main extends Component<MainProps, object> {
145155
/>
146156
<Route
147157
path={ROUTES.CREATE_POLICY}
148-
render={(props: RouteComponentProps) => (
149-
<CreatePolicy {...props} isEdit={false} policyService={services.policyService} />
150-
)}
158+
render={(props: RouteComponentProps) =>
159+
queryString.parse(this.props.location.search).type == "visual" ? (
160+
<VisualCreatePolicy
161+
{...props}
162+
isEdit={false}
163+
policyService={services.policyService}
164+
notificationService={services.notificationService}
165+
/>
166+
) : (
167+
<CreatePolicy {...props} isEdit={false} policyService={services.policyService} />
168+
)
169+
}
151170
/>
152171
<Route
153172
path={ROUTES.EDIT_POLICY}
154-
render={(props: RouteComponentProps) => (
155-
<CreatePolicy {...props} isEdit={true} policyService={services.policyService} />
156-
)}
173+
render={(props: RouteComponentProps) =>
174+
queryString.parse(this.props.location.search).type == "visual" ? (
175+
<VisualCreatePolicy
176+
{...props}
177+
isEdit={true}
178+
policyService={services.policyService}
179+
notificationService={services.notificationService}
180+
/>
181+
) : (
182+
<CreatePolicy {...props} isEdit={true} policyService={services.policyService} />
183+
)
184+
}
157185
/>
158186
<Route
159187
path={ROUTES.INDEX_POLICIES}

0 commit comments

Comments
 (0)