Skip to content

Commit fed834a

Browse files
committed
Open 2 tabs on search if needed - #156
1 parent 9c4d53c commit fed834a

File tree

5 files changed

+91
-18
lines changed

5 files changed

+91
-18
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file.
1313
* Description for Group By fields ([issue #153](https://github.com/airbus-cyber/graylog-plugin-alert-wizard/issues/153))
1414
* Remove load message ([issue #146](https://github.com/airbus-cyber/graylog-plugin-alert-wizard/issues/146))
1515
* Open Search in new tab ([issue #147](https://github.com/airbus-cyber/graylog-plugin-alert-wizard/issues/147))
16+
* Open Search in two tabs for OR, THEN, AND ([issue #156](https://github.com/airbus-cyber/graylog-plugin-alert-wizard/issues/156))
1617

1718
## [6.1.1](https://github.com/airbus-cyber/graylog-plugin-alert-wizard/compare/6.1.0...6.1.1)
1819
### Bug Fixes

e2e/tests/test-utils.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ export async function open_alert_page_and_filter(page, filter) {
1515
await page.waitForTimeout(500);
1616
}
1717

18-
export async function fill_field_condition(page, input, option, value) {
19-
await page.getByRole('button', { name: 'add_circle' }).first().click();
18+
export async function fill_field_condition(page, input, option, value, nth= 0) {
19+
await page.getByRole('button', { name: 'add_circle' }).nth(nth).click();
2020
await page.waitForTimeout(200);
21-
await page.locator('#field-input').fill(input);
21+
await page.locator('#field-input').nth(nth).fill(input);
2222
await page.waitForTimeout(200);
23-
await page.getByText('arrow_drop_down').nth(2).click();
23+
await page.getByText('arrow_drop_down').nth(nth * 3 + 2).click();
2424
await page.getByRole('option', { name: option }).click();
25-
await page.locator('#value').fill(value);
25+
await page.locator('#value').nth(nth).fill(value);
2626
await page.waitForTimeout(200);
2727
}

e2e/tests/wizard.spec.js

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ test('go_on_search_page_when_click_on_search_button', async ({ page }) => {
5353

5454
// Go on search page
5555
await open_alert_page_and_filter(page, title);
56-
await page.getByRole('link', { name: 'play_arrow' }).click();
56+
await page.getByRole('button', { name: 'play_arrow' }).click();
5757

5858
// Wait new tab
5959
await page.waitForTimeout(200);
@@ -62,6 +62,59 @@ test('go_on_search_page_when_click_on_search_button', async ({ page }) => {
6262
await expect(pages[1].getByText(searchQuery)).toBeVisible();
6363
});
6464

65+
test('open_two_tabs_when_click_on_search_button', async ({ page }) => {
66+
await page.goto('/wizard/AlertRules');
67+
68+
await login_steps(page);
69+
70+
// Fill Title
71+
const title = `AAA-${crypto.randomUUID()}`;
72+
await page.getByRole('link', { name: 'Create' }).click();
73+
await page.getByRole('button', { name: 'OR' }).click();
74+
await page.locator('#title').fill(title);
75+
76+
// Add 1st Field Condition
77+
await fill_field_condition(page, 'message', 'matches exactly', 'abc');
78+
79+
// Fill 1st Search Query
80+
const searchQuery = 'a?c';
81+
await page.locator('#search_query').first().fill(searchQuery);
82+
await page.waitForTimeout(200);
83+
84+
// Add 2nd Field Condition
85+
await fill_field_condition(page, 'message', 'matches exactly', 'abc', 1);
86+
87+
// Fill 2nd Search Query
88+
const searchQuery2 = 'b?d';
89+
await page.locator('#search_query').nth(1).fill(searchQuery2);
90+
await page.waitForTimeout(200);
91+
92+
// Save
93+
await page.getByRole('button', { name: 'Save' }).click();
94+
95+
// Go on search page
96+
await open_alert_page_and_filter(page, title);
97+
await page.getByRole('button', { name: 'play_arrow' }).click();
98+
99+
// Wait new tabs
100+
await page.waitForTimeout(2000);
101+
let pages = page.context().pages();
102+
expect(pages.length).toBe(3);
103+
if (await pages[1].getByText(title + '#2').isVisible()) {
104+
await expect(pages[2].getByText(title)).toBeVisible();
105+
await expect(pages[2].getByText(searchQuery)).toBeVisible();
106+
107+
await expect(pages[1].getByText(title + '#2')).toBeVisible();
108+
await expect(pages[1].getByText(searchQuery2)).toBeVisible();
109+
} else {
110+
await expect(pages[1].getByText(title)).toBeVisible();
111+
await expect(pages[1].getByText(searchQuery)).toBeVisible();
112+
113+
await expect(pages[2].getByText(title + '#2')).toBeVisible();
114+
await expect(pages[2].getByText(searchQuery2)).toBeVisible();
115+
}
116+
});
117+
65118
test('OR rule should contains GroupBy field', async ({ page }) => {
66119
await page.goto('/wizard/AlertRules');
67120

src/web/wizard/components/buttons/ButtonToSearch.jsx

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,35 @@ import { Icon } from 'components/common';
2222
import { useIntl } from 'react-intl';
2323
import Routes from 'routing/Routes';
2424

25-
const ButtonToSearch = ({searchQuery, stream1, stream2, disabled}) => {
25+
function normalizeSearchQuery(searchQuery) {
26+
if (searchQuery && searchQuery !== '*') {
27+
return searchQuery;
28+
}
29+
30+
return '';
31+
}
32+
33+
function createUrl(searchQuery, stream) {
34+
const normSearchQuery = normalizeSearchQuery(searchQuery);
35+
return Routes.search_with_query(normSearchQuery, "relative", {"relative": 86400}, [stream]);
36+
}
37+
38+
const ButtonToSearch = ({searchQuery1, searchQuery2, stream1, stream2, disabled}) => {
2639
const intl = useIntl();
2740
const tooltip = intl.formatMessage({id: "wizard.tooltipSearch", defaultMessage: "Launch search for this alert rule"});
28-
const stream = [];
29-
if (stream1) {
30-
stream.push(stream1);
31-
}
32-
if (stream2) {
33-
stream.push(stream2);
41+
42+
const openSearchTabs = () => {
43+
const url1 = createUrl(searchQuery1, stream1);
44+
window.open(url1, '_blank', 'noopener,noreferrer')
45+
46+
if(stream2) {
47+
const url2 = createUrl(searchQuery2, stream2);
48+
window.open(url2, '_blank', 'noopener,noreferrer');
49+
}
3450
}
35-
const searchURL = Routes.search_with_query(searchQuery, "relative", {"relative": 86400}, stream);
36-
const link = Routes.SEARCH + searchURL.substring(searchURL.indexOf('?'));
3751

3852
return (
39-
<Button bsStyle="info" title={tooltip} disabled={disabled} href={link} target="_blank">
53+
<Button bsStyle="info" title={tooltip} disabled={disabled} onClick={openSearchTabs}>
4054
<Icon name="play_arrow" />
4155
</Button>
4256
);

src/web/wizard/components/rules/AlertRulesContainer.jsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ function _convertAlertToElement(alert) {
5454
if (alert.condition_parameters) {
5555
searchQuery = alert.condition_parameters.search_query;
5656
}
57+
let searchQuery2 = '';
58+
if (alert.condition_parameters) {
59+
searchQuery2 = alert.condition_parameters.additional_search_query;
60+
}
5761
return {
5862
id: alert.title,
5963
title: alert.title,
@@ -70,7 +74,8 @@ function _convertAlertToElement(alert) {
7074
condition: alert.condition,
7175
notification: alert.notification,
7276
secondEventDefinition: alert.second_event_definition,
73-
searchQuery: searchQuery
77+
searchQuery: searchQuery,
78+
searchQuery2: searchQuery2
7479
};
7580
}
7681

@@ -161,7 +166,7 @@ const AlertRulesContainer = ({ fieldOrder }) => {
161166
</IfPermitted>);
162167
const cloneAlert = <AlertRuleCloneForm alertTitle={element.title} disabled={!element.valid} onSubmit={_onCloneSubmit} />;
163168
return (<div className="pull-left" style={{display: 'flex', columnGap: '1px'}}>
164-
<ButtonToSearch searchQuery={element.searchQuery} stream1={element.streamId} stream2={element.streamId2} disabled={!element.valid}/>
169+
<ButtonToSearch searchQuery1={element.searchQuery} searchQuery2={element.searchQuery2} stream1={element.streamId} stream2={element.streamId2} disabled={!element.valid}/>
165170
{updateAlert}
166171
<ButtonToEventDefinition target={element.condition} disabled={!element.valid}/>
167172
<ButtonToNotification target={element.notification} disabled={!element.valid}/>

0 commit comments

Comments
 (0)