Skip to content

Commit b284bd1

Browse files
authored
Fixes policy details page (#80)
Signed-off-by: Drew Baugher <[email protected]>
1 parent 8b3c637 commit b284bd1

File tree

13 files changed

+586
-461
lines changed

13 files changed

+586
-461
lines changed

.github/workflows/cypress-workflow.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ jobs:
5555
- name: Build job-scheduler
5656
working-directory: ./job-scheduler
5757
run: ./gradlew publishToMavenLocal -Dopensearch.version=${{ env.OPENSEARCH_VERSION }}
58+
# dependencies: alerting-notification
5859
- name: Checkout alerting
5960
uses: actions/checkout@v2
6061
with:

models/interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ export interface Policy {
9595
error_notification?: ErrorNotification | null;
9696
states: State[];
9797
ism_template?: ISMTemplate[] | ISMTemplate | null;
98-
last_updated_time?: string;
98+
last_updated_time?: number;
9999
schema_version?: number;
100100
}
101101

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*
8+
* Modifications Copyright OpenSearch Contributors. See
9+
* GitHub history for details.
10+
*/
11+
12+
import React from "react";
13+
import "@testing-library/jest-dom/extend-expect";
14+
import { render, fireEvent } from "@testing-library/react";
15+
import JSONModal from "./JSONModal";
16+
import { DEFAULT_LEGACY_ERROR_NOTIFICATION } from "../../pages/VisualCreatePolicy/utils/constants";
17+
18+
describe("<JSONModal /> spec", () => {
19+
it("renders the component", () => {
20+
render(
21+
<JSONModal
22+
title="Some modal title"
23+
json={DEFAULT_LEGACY_ERROR_NOTIFICATION} // just some random json
24+
onClose={() => {}}
25+
/>
26+
);
27+
// EuiOverlayMask appends an element to the body so we should have two, an empty div from react-test-library
28+
// and our EuiOverlayMask element
29+
expect(document.body.children).toHaveLength(2);
30+
expect(document.body.children[1]).toMatchSnapshot();
31+
});
32+
33+
it("calls close when close button clicked", () => {
34+
const onClose = jest.fn();
35+
const { getByTestId } = render(
36+
<JSONModal
37+
title="Some modal title"
38+
json={DEFAULT_LEGACY_ERROR_NOTIFICATION} // just some random json
39+
onClose={onClose}
40+
/>
41+
);
42+
43+
fireEvent.click(getByTestId("jsonModalCloseButton"));
44+
expect(onClose).toHaveBeenCalled();
45+
});
46+
});
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*
8+
* Modifications Copyright OpenSearch Contributors. See
9+
* GitHub history for details.
10+
*/
11+
12+
import React from "react";
13+
import {
14+
EuiModal,
15+
EuiModalBody,
16+
EuiModalFooter,
17+
EuiModalHeader,
18+
EuiModalHeaderTitle,
19+
EuiOverlayMask,
20+
EuiCodeBlock,
21+
EuiButtonEmpty,
22+
} from "@elastic/eui";
23+
24+
interface JSONModalProps {
25+
title: string;
26+
json: object;
27+
onClose: () => void;
28+
}
29+
30+
const JSONModal: React.SFC<JSONModalProps> = ({ title, json, onClose }) => {
31+
return (
32+
<EuiOverlayMask>
33+
<EuiModal onClose={onClose} style={{ padding: "5px 30px" }}>
34+
<EuiModalHeader>
35+
<EuiModalHeaderTitle>{title}</EuiModalHeaderTitle>
36+
</EuiModalHeader>
37+
38+
<EuiModalBody>
39+
<EuiCodeBlock language="json" fontSize="m" paddingSize="m" overflowHeight={600} inline={false} isCopyable>
40+
{JSON.stringify(json, null, 4)}
41+
</EuiCodeBlock>
42+
</EuiModalBody>
43+
44+
<EuiModalFooter>
45+
<EuiButtonEmpty onClick={onClose} data-test-subj="jsonModalCloseButton">
46+
Close
47+
</EuiButtonEmpty>
48+
</EuiModalFooter>
49+
</EuiModal>
50+
</EuiOverlayMask>
51+
);
52+
};
53+
54+
export default JSONModal;
Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`<JSONModal /> spec renders the component 1`] = `
4+
<div
5+
class="euiOverlayMask euiOverlayMask--aboveHeader"
6+
>
7+
<div
8+
aria-hidden="true"
9+
data-aria-hidden="true"
10+
data-focus-guard="true"
11+
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
12+
tabindex="0"
13+
/>
14+
<div
15+
aria-hidden="true"
16+
data-aria-hidden="true"
17+
data-focus-guard="true"
18+
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
19+
tabindex="1"
20+
/>
21+
<div
22+
data-focus-lock-disabled="false"
23+
>
24+
<div
25+
class="euiModal euiModal--maxWidth-default"
26+
style="padding: 5px 30px;"
27+
tabindex="0"
28+
>
29+
<button
30+
aria-label="Closes this modal window"
31+
class="euiButtonIcon euiButtonIcon--text euiModal__closeIcon"
32+
type="button"
33+
>
34+
EuiIconMock
35+
</button>
36+
<div
37+
class="euiModal__flex"
38+
>
39+
<div
40+
class="euiModalHeader"
41+
>
42+
<div
43+
class="euiModalHeader__title"
44+
>
45+
Some modal title
46+
</div>
47+
</div>
48+
<div
49+
class="euiModalBody"
50+
>
51+
<div
52+
class="euiModalBody__overflow"
53+
>
54+
<div
55+
class="euiCodeBlock euiCodeBlock--fontMedium euiCodeBlock--paddingMedium euiCodeBlock--hasControls"
56+
style="max-height: 600px;"
57+
>
58+
<pre
59+
class="euiCodeBlock__pre euiCodeBlock__pre--whiteSpacePreWrap"
60+
style="max-height: 600px;"
61+
>
62+
<code
63+
class="euiCodeBlock__code json hljs"
64+
>
65+
{
66+
67+
<span
68+
class="hljs-attr"
69+
>
70+
"destination"
71+
</span>
72+
: {
73+
74+
<span
75+
class="hljs-attr"
76+
>
77+
"slack"
78+
</span>
79+
: {
80+
81+
<span
82+
class="hljs-attr"
83+
>
84+
"url"
85+
</span>
86+
:
87+
<span
88+
class="hljs-string"
89+
>
90+
"&lt;url&gt;"
91+
</span>
92+
93+
}
94+
},
95+
96+
<span
97+
class="hljs-attr"
98+
>
99+
"message_template"
100+
</span>
101+
: {
102+
103+
<span
104+
class="hljs-attr"
105+
>
106+
"source"
107+
</span>
108+
:
109+
<span
110+
class="hljs-string"
111+
>
112+
"The index {{ctx.index}} failed during policy execution."
113+
</span>
114+
115+
}
116+
}
117+
</code>
118+
</pre>
119+
<div
120+
class="euiCodeBlock__controls"
121+
>
122+
<button
123+
aria-label="Expand"
124+
class="euiButtonIcon euiButtonIcon--text euiCodeBlock__fullScreenButton"
125+
type="button"
126+
>
127+
EuiIconMock
128+
</button>
129+
<div
130+
class="euiCodeBlock__copyButton"
131+
>
132+
<span
133+
class="euiToolTipAnchor"
134+
>
135+
<button
136+
aria-label="Copy"
137+
class="euiButtonIcon euiButtonIcon--text"
138+
type="button"
139+
>
140+
EuiIconMock
141+
</button>
142+
</span>
143+
</div>
144+
</div>
145+
</div>
146+
</div>
147+
</div>
148+
<div
149+
class="euiModalFooter"
150+
>
151+
<button
152+
class="euiButtonEmpty euiButtonEmpty--primary"
153+
data-test-subj="jsonModalCloseButton"
154+
type="button"
155+
>
156+
<span
157+
class="euiButtonContent euiButtonEmpty__content"
158+
>
159+
<span
160+
class="euiButtonEmpty__text"
161+
>
162+
Close
163+
</span>
164+
</span>
165+
</button>
166+
</div>
167+
</div>
168+
</div>
169+
</div>
170+
<div
171+
aria-hidden="true"
172+
data-aria-hidden="true"
173+
data-focus-guard="true"
174+
style="width: 1px; height: 0px; padding: 0px; overflow: hidden; position: fixed; top: 1px; left: 1px;"
175+
tabindex="0"
176+
/>
177+
</div>
178+
`;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*
8+
* Modifications Copyright OpenSearch Contributors. See
9+
* GitHub history for details.
10+
*/
11+
12+
import JSONModal from "./JSONModal";
13+
14+
export default JSONModal;

public/pages/Policies/containers/Policies/Policies.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,14 @@ export default class Policies extends Component<PoliciesProps, PoliciesState> {
281281
},
282282
modal: {
283283
onClickModal: (onShow: (component: any, props: object) => void) => () =>
284-
onShow(CreatePolicyModal, { isEdit: true, history: this.props.history, onClickContinue: this.onClickEdit }),
284+
onShow(CreatePolicyModal, { isEdit: true, onClickContinue: this.onClickEdit }),
285285
},
286286
},
287287
{
288288
text: "Create policy",
289289
modal: {
290290
onClickModal: (onShow: (component: any, props: object) => void) => () =>
291-
onShow(CreatePolicyModal, { history: this.props.history, onClickContinue: this.onClickCreate }),
291+
onShow(CreatePolicyModal, { onClickContinue: this.onClickCreate }),
292292
},
293293
},
294294
];

public/pages/PolicyDetails/components/PolicySettings/PolicySettings.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import PolicySettings from "./PolicySettings";
1616

1717
describe("<PolicySettings /> spec", () => {
1818
beforeAll(() => {
19-
jest.useFakeTimers('modern');
19+
jest.useFakeTimers("modern");
2020
jest.setSystemTime(new Date(2021, 7, 1));
2121
});
2222

@@ -28,13 +28,13 @@ describe("<PolicySettings /> spec", () => {
2828
const { container } = render(
2929
<PolicySettings
3030
policyId={"some_id"}
31-
channelId={"some_channel_id"}
31+
errorNotification={null}
3232
primaryTerm={1}
33-
lastUpdated={new Date().toString()}
33+
lastUpdated={new Date().valueOf()}
3434
description={"some description"}
3535
sequenceNumber={2}
36-
schemaVersion={3}
3736
ismTemplates={[]}
37+
onEdit={() => {}}
3838
/>
3939
);
4040

0 commit comments

Comments
 (0)