/* * 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 { EuiLink, EuiText, EuiIcon, EuiDataGrid } from '@elastic/eui'; import { getAlertingMonitorListLink } from '../../../../../utils/utils'; import { Monitor } from '../../../../../models/interfaces'; import { DetectorListItem } from '../../../../../models/interfaces'; import { PLUGIN_NAME } from '../../../../../utils/constants'; import { get, isEmpty } from 'lodash'; import { DETECTOR_STATE } from '../../../../../../server/utils/constants'; const getNames = (detectors: DetectorListItem[]) => { let data = []; for (let i = 0; i < detectors.length; i++) { data.push({ Detector: ( {detectors[i].name} /> ), }); } return data; }; const getNamesAndMonitors = ( detectors: DetectorListItem[], monitors: { [key: string]: Monitor } ) => { let data = []; for (let i = 0; i < detectors.length; i++) { const relatedMonitor = get(monitors, `${detectors[i].id}`); if (relatedMonitor) { data.push({ Detector: ( {detectors[i].name} /> ), Monitor: ( {relatedMonitor.name} /> ), }); } else { data.push({ Detector: ( {detectors[i].name} /> ), Monitor: '-', }); } } return data; }; const getNamesAndMonitorsAndStates = ( detectors: DetectorListItem[], monitors: { [key: string]: Monitor } ) => { let data = []; for (let i = 0; i < detectors.length; i++) { const relatedMonitor = get(monitors, `${detectors[i].id}`); const isRunning = detectors[i].curState === DETECTOR_STATE.INIT || detectors[i].curState === DETECTOR_STATE.RUNNING; if (relatedMonitor) { data.push({ Detector: ( {detectors[i].name} /> ), Monitor: ( {relatedMonitor.name} /> ), Running: {isRunning ? 'Yes' : 'No'}, }); } else { data.push({ Detector: ( {detectors[i].name} ), Monitor: '-', Running: {isRunning ? 'Yes' : 'No'}, }); } } return data; }; export const getNamesGrid = (detectors: DetectorListItem[]) => { const gridData = getNames(detectors); return ( {}, }} rowCount={gridData.length} renderCellValue={({ rowIndex, columnId }) => //@ts-ignore gridData[rowIndex][columnId] } gridStyle={{ border: 'horizontal', header: 'shade', rowHover: 'highlight', stripes: true, }} toolbarVisibility={false} /> ); }; export const getNamesAndMonitorsGrid = ( detectors: DetectorListItem[], monitors: { [key: string]: Monitor } ) => { const gridData = getNamesAndMonitors(detectors, monitors); return ( {}, }} rowCount={gridData.length} renderCellValue={({ rowIndex, columnId }) => //@ts-ignore gridData[rowIndex][columnId] } gridStyle={{ border: 'horizontal', header: 'shade', rowHover: 'highlight', stripes: true, }} toolbarVisibility={false} /> ); }; export const getNamesAndMonitorsAndStatesGrid = ( detectors: DetectorListItem[], monitors: { [key: string]: Monitor } ) => { const gridData = getNamesAndMonitorsAndStates(detectors, monitors); return ( {}, }} rowCount={gridData.length} renderCellValue={({ rowIndex, columnId }) => //@ts-ignore gridData[rowIndex][columnId] } gridStyle={{ border: 'horizontal', header: 'shade', rowHover: 'highlight', stripes: true, }} toolbarVisibility={false} /> ); }; export const containsEnabledDetectors = (detectors: DetectorListItem[]) => { const enabledDetectors = detectors.filter( (detector) => detector.curState === DETECTOR_STATE.RUNNING || detector.curState === DETECTOR_STATE.INIT ); return !isEmpty(enabledDetectors); };