import { mlJobService } from '../services/job_service' ; import { Entity } from './components/entity_control/entity_control' ; import { JobId } from '../../../common/types/anomaly_detection_jobs' ; /**
 * Extracts entities from the detector configuration
 */ export function getControlsForDetector ( selectedDetectorIndex , selectedEntities , selectedJobId ) { const selectedJob = mlJobService . getJob ( selectedJobId ) ; const entities = [ ] ; if ( selectedJob === undefined ) { return entities ; } const detectorIndex = selectedDetectorIndex ; const detector = selectedJob . analysis_config . detectors [ detectorIndex ] ; const entitiesState = selectedEntities ; const partitionFieldName = detector ?. partition_field_name ; const overFieldName = detector ?. over_field_name ; const byFieldName = detector ?. by_field_name ; if ( partitionFieldName !== undefined ) { const partitionFieldValue = entitiesState ?. [ partitionFieldName ] ?? null ; entities . push ( { fieldType : 'partition_field' , fieldName : partitionFieldName , fieldValue : partitionFieldValue , } ) ; } if ( overFieldName !== undefined ) { const overFieldValue = entitiesState ?. [ overFieldName ] ?? null ; entities . push ( { fieldType : 'over_field' , fieldName : overFieldName , fieldValue : overFieldValue , } ) ; } if ( byFieldName !== undefined && overFieldName === undefined ) { const byFieldValue = entitiesState ?. [ byFieldName ] ?? null ; entities . push ( { fieldType : 'by_field' , fieldName : byFieldName , fieldValue : byFieldValue } ) ; } return entities ; }