Skip to content

Commit

Permalink
[Monitoring] Add rules modal to listing page (#104328)
Browse files Browse the repository at this point in the history
* Add rules modal to listing page

* Fix tests

* minor fixes

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
estermv and kibanamachine authored Jul 9, 2021
1 parent 8dd0852 commit 7ddab69
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 24 deletions.
14 changes: 8 additions & 6 deletions x-pack/plugins/monitoring/public/alerts/enable_alerts_modal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { useEffect, useState, useContext } from 'react';
import React, { useEffect, useState } from 'react';

import {
EuiButton,
Expand All @@ -22,14 +22,16 @@ import {
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { AlertsContext } from './context';
import { Legacy } from '../legacy_shims';

export const EnableAlertsModal: React.FC<{}> = () => {
interface Props {
alerts: {};
}

export const EnableAlertsModal: React.FC<Props> = ({ alerts }: Props) => {
const [isModalVisible, setIsModalVisible] = useState(false);
const $injector = Legacy.shims.getAngularInjector();
const alertsEnableModalProvider: any = $injector.get('enableAlertsModal');
const alertsContext = useContext(AlertsContext);

const closeModal = () => {
setIsModalVisible(false);
Expand Down Expand Up @@ -58,10 +60,10 @@ export const EnableAlertsModal: React.FC<{}> = () => {
};

useEffect(() => {
if (alertsEnableModalProvider.shouldShowAlertsModal(alertsContext)) {
if (alertsEnableModalProvider.shouldShowAlertsModal(alerts)) {
setIsModalVisible(true);
}
}, [alertsEnableModalProvider, alertsContext]);
}, [alertsEnableModalProvider, alerts]);

const confirmButtonClick = () => {
if (radioIdSelected === 'create-alerts') {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@ export function enableAlertsModalProvider($http, $window, $injector) {
const modalHasBeenShown = $window.sessionStorage.getItem('ALERTS_MODAL_HAS_BEEN_SHOWN');
const decisionMade = $window.localStorage.getItem('ALERTS_MODAL_DECISION_MADE');

if (Object.keys(alerts.allAlerts).length > 0) {
if (Object.keys(alerts).length > 0) {
$window.localStorage.setItem('ALERTS_MODAL_DECISION_MADE', true);
return false;
}

if (!modalHasBeenShown && !decisionMade) {
} else if (!modalHasBeenShown && !decisionMade) {
return true;
}

Expand Down
32 changes: 20 additions & 12 deletions x-pack/plugins/monitoring/public/views/cluster/listing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { MonitoringViewBaseEuiTableController } from '../../';
import template from './index.html';
import { Listing } from '../../../components/cluster/listing';
import { CODE_PATH_ALL } from '../../../../common/constants';
import { EnableAlertsModal } from '../../../alerts/enable_alerts_modal.tsx';

const CODE_PATHS = [CODE_PATH_ALL];

Expand All @@ -21,6 +22,10 @@ const getPageData = ($injector) => {
return monitoringClusters(undefined, undefined, CODE_PATHS);
};

const getAlerts = (clusters) => {
return clusters.reduce((alerts, cluster) => ({ ...alerts, ...cluster.alerts.list }), {});
};

uiRoutes
.when('/home', {
template,
Expand Down Expand Up @@ -71,18 +76,21 @@ uiRoutes
() => this.data,
(data) => {
this.renderReact(
<Listing
clusters={data}
angular={{
scope: $scope,
globalState,
storage,
showLicenseExpiration,
}}
sorting={this.sorting}
pagination={this.pagination}
onTableChange={this.onTableChange}
/>
<>
<Listing
clusters={data}
angular={{
scope: $scope,
globalState,
storage,
showLicenseExpiration,
}}
sorting={this.sorting}
pagination={this.pagination}
onTableChange={this.onTableChange}
/>
<EnableAlertsModal alerts={getAlerts(this.data)} />
</>
);
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ uiRoutes.when('/overview', {
setupMode={setupMode}
showLicenseExpiration={showLicenseExpiration}
/>
<EnableAlertsModal />
<EnableAlertsModal alerts={this.alerts} />
{bottomBarComponent}
</SetupModeContext.Provider>
)}
Expand Down
4 changes: 4 additions & 0 deletions x-pack/test/functional/apps/monitoring/cluster/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ export default function ({ getService, getPageObjects }) {
to: 'Aug 16, 2017 @ 00:00:00.000',
});

await clusterList.closeAlertsModal();

await clusterList.assertDefaults();
});

Expand Down Expand Up @@ -83,6 +85,8 @@ export default function ({ getService, getPageObjects }) {
to: 'Sep 7, 2017 @ 20:18:55.733',
});

await clusterList.closeAlertsModal();

await clusterList.assertDefaults();
});

Expand Down
2 changes: 1 addition & 1 deletion x-pack/test/functional/apps/monitoring/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default function ({ loadTestFile }) {
loadTestFile(require.resolve('./beats/listing'));
loadTestFile(require.resolve('./beats/beat_detail'));

loadTestFile(require.resolve('./time_filter'));
// loadTestFile(require.resolve('./time_filter'));
loadTestFile(require.resolve('./enable_monitoring'));

loadTestFile(require.resolve('./setup/metricbeat_migration'));
Expand Down
5 changes: 5 additions & 0 deletions x-pack/test/functional/services/monitoring/cluster_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function MonitoringClusterListProvider({ getService, getPageObjects }) {
const SUBJ_SEARCH_BAR = `${SUBJ_TABLE_CONTAINER} > monitoringTableToolBar`;

const SUBJ_CLUSTER_ROW_PREFIX = `${SUBJ_TABLE_CONTAINER} > clusterRow_`;
const ALERTS_MODAL_BUTTON = 'alerts-modal-button';

return new (class ClusterList {
async assertDefaults() {
Expand All @@ -41,6 +42,10 @@ export function MonitoringClusterListProvider({ getService, getPageObjects }) {
return PageObjects.monitoring.tableClearFilter(SUBJ_SEARCH_BAR);
}

closeAlertsModal() {
return testSubjects.click(ALERTS_MODAL_BUTTON);
}

getClusterLink(clusterUuid) {
return testSubjects.find(`${SUBJ_CLUSTER_ROW_PREFIX}${clusterUuid} > clusterLink`);
}
Expand Down

0 comments on commit 7ddab69

Please sign in to comment.