-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support MDS on DetectorDetails page #719
Changes from 6 commits
d3de573
8258d5c
c21d6c7
e0333ec
8a94a9b
10c730b
6aab2f4
6d8bd5b
5057c07
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,6 +205,7 @@ export type Detector = { | |
taskState?: DETECTOR_STATE; | ||
taskProgress?: number; | ||
taskError?: string; | ||
dataSourceId?: string; | ||
}; | ||
|
||
export type DetectorListItem = { | ||
|
@@ -218,6 +219,7 @@ export type DetectorListItem = { | |
lastUpdateTime: number; | ||
enabledTime?: number; | ||
detectorType?: string; | ||
dataSourceId: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is dataSourceId optional? |
||
}; | ||
|
||
export type EntityData = { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,7 +43,8 @@ export const useFetchDetectorInfo = ( | |
useEffect(() => { | ||
const fetchDetector = async () => { | ||
if (!detector) { | ||
await dispatch(getDetector(detectorId)); | ||
// hardcoding the datasource id for now, will update it later when working on create page | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we have a tracker for all the TODOs so we don't forget what needs to be done? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. tracked here - #721 |
||
await dispatch(getDetector(detectorId, '4585f560-d1ef-11ee-aa63-2181676cc573')); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add a TODO in the comment so it is clear |
||
} | ||
if (selectedIndices) { | ||
await dispatch(getMappings(selectedIndices)); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,10 +24,10 @@ import { | |
EuiLoadingSpinner, | ||
EuiButton, | ||
} from '@elastic/eui'; | ||
import { CoreStart } from '../../../../../../src/core/public'; | ||
import { CoreStart, MountPoint } from '../../../../../../src/core/public'; | ||
import { CoreServicesContext } from '../../../components/CoreServices/CoreServices'; | ||
import { get, isEmpty } from 'lodash'; | ||
import { RouteComponentProps, Switch, Route, Redirect } from 'react-router-dom'; | ||
import { RouteComponentProps, Switch, Route, Redirect, useLocation } from 'react-router-dom'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { useFetchDetectorInfo } from '../../CreateDetectorSteps/hooks/useFetchDetectorInfo'; | ||
import { useHideSideNavBar } from '../../main/hooks/useHideSideNavBar'; | ||
|
@@ -58,12 +58,16 @@ import { | |
import { DETECTOR_STATE } from '../../../../server/utils/constants'; | ||
import { CatIndex } from '../../../../server/models/types'; | ||
import { containsIndex } from '../utils/helpers'; | ||
import { DataSourceManagementPluginSetup, DataSourceViewConfig } from '../../../../../../src/plugins/data_source_management/public'; | ||
|
||
export interface DetectorRouterProps { | ||
detectorId?: string; | ||
} | ||
interface DetectorDetailProps | ||
extends RouteComponentProps<DetectorRouterProps> {} | ||
interface DetectorDetailProps extends RouteComponentProps<DetectorRouterProps> { | ||
dataSourceEnabled: boolean; | ||
dataSourceManagement: DataSourceManagementPluginSetup; | ||
setActionMenu: (menuMount: MountPoint | undefined) => void; | ||
} | ||
|
||
const tabs = [ | ||
{ | ||
|
@@ -103,6 +107,11 @@ export const DetectorDetail = (props: DetectorDetailProps) => { | |
const core = React.useContext(CoreServicesContext) as CoreStart; | ||
const dispatch = useDispatch(); | ||
const detectorId = get(props, 'match.params.detectorId', '') as string; | ||
|
||
const location = useLocation(); | ||
const queryParams = new URLSearchParams(location.search); | ||
const dataSourceId = queryParams.get('dataSourceId') as string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does dataSourceId always exist in the query param? |
||
|
||
const { detector, hasError, isLoadingDetector, errorMessage } = | ||
useFetchDetectorInfo(detectorId); | ||
const { monitor, fetchMonitorError, isLoadingMonitor } = | ||
|
@@ -156,7 +165,7 @@ export const DetectorDetail = (props: DetectorDetailProps) => { | |
// detector starts, result index recreated or user switches tabs to re-fetch detector) | ||
useEffect(() => { | ||
const getInitialIndices = async () => { | ||
await dispatch(getIndices('')).catch((error: any) => { | ||
await dispatch(getIndices('', dataSourceId)).catch((error: any) => { | ||
console.error(error); | ||
core.notifications.toasts.addDanger('Error getting all indices'); | ||
}); | ||
|
@@ -201,23 +210,23 @@ export const DetectorDetail = (props: DetectorDetailProps) => { | |
...detectorDetailModel, | ||
selectedTab: DETECTOR_DETAIL_TABS.CONFIGURATIONS, | ||
}); | ||
props.history.push(`/detectors/${detectorId}/configurations`); | ||
props.history.push(`/detectors/${detectorId}/configurations?dataSourceId=${dataSourceId}`); | ||
}, []); | ||
|
||
const handleSwitchToHistoricalTab = useCallback(() => { | ||
setDetectorDetailModel({ | ||
...detectorDetailModel, | ||
selectedTab: DETECTOR_DETAIL_TABS.HISTORICAL, | ||
}); | ||
props.history.push(`/detectors/${detectorId}/historical`); | ||
props.history.push(`/detectors/${detectorId}/historical?dataSourceId=${dataSourceId}`); | ||
}, []); | ||
|
||
const handleTabChange = (route: DETECTOR_DETAIL_TABS) => { | ||
setDetectorDetailModel({ | ||
...detectorDetailModel, | ||
selectedTab: route, | ||
}); | ||
props.history.push(`/detectors/${detectorId}/${route}`); | ||
props.history.push(`/detectors/${detectorId}/${route}?dataSourceId=${dataSourceId}`); | ||
}; | ||
|
||
const hideMonitorCalloutModal = () => { | ||
|
@@ -261,8 +270,8 @@ export const DetectorDetail = (props: DetectorDetailProps) => { | |
// Await for the start detector call to succeed before displaying toast. | ||
// Don't wait for get detector call; the page will be updated | ||
// via hooks automatically when the new detector info is returned. | ||
await dispatch(startDetector(detectorId)); | ||
dispatch(getDetector(detectorId)); | ||
await dispatch(startDetector(detectorId, dataSourceId)); | ||
dispatch(getDetector(detectorId, dataSourceId)); | ||
core.notifications.toasts.addSuccess( | ||
`Successfully started the detector job` | ||
); | ||
|
@@ -278,10 +287,10 @@ export const DetectorDetail = (props: DetectorDetailProps) => { | |
const handleStopAdJob = async (detectorId: string, listener?: Listener) => { | ||
try { | ||
if (isRTJobRunning) { | ||
await dispatch(stopDetector(detectorId)); | ||
await dispatch(stopDetector(detectorId, dataSourceId)); | ||
} | ||
if (isHistoricalJobRunning) { | ||
await dispatch(stopHistoricalDetector(detectorId)); | ||
await dispatch(stopHistoricalDetector(detectorId, dataSourceId)); | ||
} | ||
core.notifications.toasts.addSuccess( | ||
`Successfully stopped the ${runningJobsAsString}` | ||
|
@@ -302,7 +311,7 @@ export const DetectorDetail = (props: DetectorDetailProps) => { | |
|
||
const handleDelete = useCallback(async (detectorId: string) => { | ||
try { | ||
await dispatch(deleteDetector(detectorId)); | ||
await dispatch(deleteDetector(detectorId, dataSourceId)); | ||
core.notifications.toasts.addSuccess(`Successfully deleted the detector`); | ||
hideDeleteDetectorModal(); | ||
props.history.push('/detectors'); | ||
|
@@ -350,6 +359,8 @@ export const DetectorDetail = (props: DetectorDetailProps) => { | |
></EuiCallOut> | ||
) : null; | ||
|
||
const DataSourceMenu = props.dataSourceManagement.ui.getDataSourceMenu<DataSourceViewConfig>(); | ||
|
||
return ( | ||
<React.Fragment> | ||
{!isEmpty(detector) && !hasError ? ( | ||
|
@@ -361,6 +372,18 @@ export const DetectorDetail = (props: DetectorDetailProps) => { | |
: { ...lightStyles, flexGrow: 'unset' }), | ||
}} | ||
> | ||
|
||
{props.dataSourceEnabled && ( | ||
<DataSourceMenu | ||
setMenuMountPoint={props.setActionMenu} | ||
componentType={'DataSourceView'} | ||
componentConfig={{ | ||
// give a placeholder label for now, will update it once neo team allows empty label field | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably adding a |
||
activeOption: [{label: 'labelPlaceHolder', id: dataSourceId}], | ||
fullWidth: true | ||
}} | ||
/> | ||
)} | ||
<EuiFlexGroup | ||
justifyContent="spaceBetween" | ||
style={{ padding: '10px' }} | ||
|
@@ -542,6 +565,7 @@ export const DetectorDetail = (props: DetectorDetailProps) => { | |
<AnomalyResults | ||
{...resultsProps} | ||
detectorId={detectorId} | ||
dataSourceId={dataSourceId} | ||
onStartDetector={() => handleStartAdJob(detectorId)} | ||
onStopDetector={() => handleStopAdJob(detectorId)} | ||
onSwitchToConfiguration={handleSwitchToConfigurationTab} | ||
|
@@ -556,6 +580,7 @@ export const DetectorDetail = (props: DetectorDetailProps) => { | |
<HistoricalDetectorResults | ||
{...configProps} | ||
detectorId={detectorId} | ||
dataSourceId={dataSourceId} | ||
/> | ||
)} | ||
/> | ||
|
@@ -566,6 +591,7 @@ export const DetectorDetail = (props: DetectorDetailProps) => { | |
<DetectorConfig | ||
{...configProps} | ||
detectorId={detectorId} | ||
dataSourceId={dataSourceId} | ||
onEditFeatures={handleEditFeature} | ||
onEditDetector={handleEditDetector} | ||
/> | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks like the dataSource object is not used below