mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 17:59:23 -04:00
[ML] Rename isRecord to isPopulatedObject
This commit is contained in:
parent
211937a3cf
commit
bc435134b7
13 changed files with 31 additions and 31 deletions
|
@ -5,7 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { isRecord } from '../../common/util/record_utils';
|
||||
import { isPopulatedObject } from '../util/object_utils';
|
||||
|
||||
export type FeatureImportanceClassName = string | number | boolean;
|
||||
|
||||
|
@ -89,7 +89,7 @@ export function isClassificationFeatureImportanceBaseline(
|
|||
baselineData: any
|
||||
): baselineData is ClassificationFeatureImportanceBaseline {
|
||||
return (
|
||||
isRecord(baselineData) &&
|
||||
isPopulatedObject(baselineData) &&
|
||||
baselineData.hasOwnProperty('classes') &&
|
||||
Array.isArray(baselineData.classes)
|
||||
);
|
||||
|
@ -98,5 +98,5 @@ export function isClassificationFeatureImportanceBaseline(
|
|||
export function isRegressionFeatureImportanceBaseline(
|
||||
baselineData: any
|
||||
): baselineData is RegressionFeatureImportanceBaseline {
|
||||
return isRecord(baselineData) && baselineData.hasOwnProperty('baseline');
|
||||
return isPopulatedObject(baselineData) && baselineData.hasOwnProperty('baseline');
|
||||
}
|
||||
|
|
|
@ -28,7 +28,7 @@ import {
|
|||
getDatafeedAggregations,
|
||||
} from './datafeed_utils';
|
||||
import { findAggField } from './validation_utils';
|
||||
import { isRecord } from '../../common/util/record_utils';
|
||||
import { isPopulatedObject } from './object_utils';
|
||||
|
||||
export interface ValidationResults {
|
||||
valid: boolean;
|
||||
|
@ -52,9 +52,9 @@ export function calculateDatafeedFrequencyDefaultSeconds(bucketSpanSeconds: numb
|
|||
}
|
||||
|
||||
export function hasRuntimeMappings(job: CombinedJob): boolean {
|
||||
const hasDatafeed = isRecord(job.datafeed_config);
|
||||
const hasDatafeed = isPopulatedObject(job.datafeed_config);
|
||||
if (hasDatafeed) {
|
||||
return isRecord(job.datafeed_config.runtime_mappings);
|
||||
return isPopulatedObject(job.datafeed_config.runtime_mappings);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -120,7 +120,7 @@ export function isSourceDataChartableForDetector(job: CombinedJob, detectorIndex
|
|||
scriptFields.indexOf(dtr.over_field_name!) === -1;
|
||||
}
|
||||
|
||||
const hasDatafeed = isRecord(job.datafeed_config);
|
||||
const hasDatafeed = isPopulatedObject(job.datafeed_config);
|
||||
if (hasDatafeed) {
|
||||
// We cannot plot the source data for some specific aggregation configurations
|
||||
const aggs = getDatafeedAggregations(job.datafeed_config);
|
||||
|
|
|
@ -5,6 +5,6 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
export const isRecord = <T = Record<string, any>>(arg: any): arg is T => {
|
||||
export const isPopulatedObject = <T = Record<string, any>>(arg: any): arg is T => {
|
||||
return typeof arg === 'object' && arg !== null && Object.keys(arg).length > 0;
|
||||
};
|
|
@ -46,7 +46,7 @@ import { mlFieldFormatService } from '../../services/field_format_service';
|
|||
import { DataGridItem, IndexPagination, RenderCellValue } from './types';
|
||||
import type { RuntimeField } from '../../../../../../../src/plugins/data/common/index_patterns';
|
||||
import { RuntimeMappings } from '../../../../common/types/fields';
|
||||
import { isRecord } from '../../../../common/util/record_utils';
|
||||
import { isPopulatedObject } from '../../../../common/util/object_utils';
|
||||
|
||||
export const INIT_MAX_COLUMNS = 10;
|
||||
|
||||
|
@ -101,14 +101,14 @@ export const getRuntimeFieldsMapping = (
|
|||
const ipRuntimeMappings = indexPattern.getComputedFields().runtimeFields;
|
||||
let combinedRuntimeMappings: RuntimeMappings = {};
|
||||
|
||||
if (isRecord(ipRuntimeMappings)) {
|
||||
if (isPopulatedObject(ipRuntimeMappings)) {
|
||||
indexPatternFields.forEach((ipField) => {
|
||||
if (ipRuntimeMappings.hasOwnProperty(ipField)) {
|
||||
combinedRuntimeMappings[ipField] = ipRuntimeMappings[ipField];
|
||||
}
|
||||
});
|
||||
}
|
||||
if (isRecord(clonedRuntimeMappings)) {
|
||||
if (isPopulatedObject(clonedRuntimeMappings)) {
|
||||
combinedRuntimeMappings = { ...combinedRuntimeMappings, ...clonedRuntimeMappings };
|
||||
}
|
||||
return Object.keys(combinedRuntimeMappings).length > 0
|
||||
|
|
|
@ -19,7 +19,7 @@ import { stringMatch } from '../../../util/string_utils';
|
|||
import { JOB_STATE, DATAFEED_STATE } from '../../../../../common/constants/states';
|
||||
import { parseInterval } from '../../../../../common/util/parse_interval';
|
||||
import { mlCalendarService } from '../../../services/calendar_service';
|
||||
import { isRecord } from '../../../../../common/util/record_utils';
|
||||
import { isPopulatedObject } from '../../../../../common/util/object_utils';
|
||||
|
||||
export function loadFullJob(jobId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
@ -380,7 +380,7 @@ export function checkForAutoStartDatafeed() {
|
|||
mlJobService.tempJobCloningObjects.datafeed = undefined;
|
||||
mlJobService.tempJobCloningObjects.createdBy = undefined;
|
||||
|
||||
const hasDatafeed = isRecord(mlJobService.tempJobCloningObjects.datafeed);
|
||||
const hasDatafeed = isPopulatedObject(mlJobService.tempJobCloningObjects.datafeed);
|
||||
const datafeedId = hasDatafeed ? datafeed.datafeed_id : '';
|
||||
return {
|
||||
id: job.job_id,
|
||||
|
|
|
@ -21,7 +21,7 @@ import { CombinedJob } from '../../../../../../../../common/types/anomaly_detect
|
|||
import { MLJobEditor } from '../../../../../jobs_list/components/ml_job_editor';
|
||||
import { mlJobService } from '../../../../../../services/job_service';
|
||||
import { ML_DATA_PREVIEW_COUNT } from '../../../../../../../../common/util/job_utils';
|
||||
import { isRecord } from '../../../../../../../../common/util/record_utils';
|
||||
import { isPopulatedObject } from '../../../../../../../../common/util/object_utils';
|
||||
|
||||
export const DatafeedPreview: FC<{
|
||||
combinedJob: CombinedJob | null;
|
||||
|
@ -65,7 +65,7 @@ export const DatafeedPreview: FC<{
|
|||
const resp = await mlJobService.searchPreview(combinedJob);
|
||||
let data = resp.hits.hits;
|
||||
// the first item under aggregations can be any name
|
||||
if (isRecord(resp.aggregations)) {
|
||||
if (isPopulatedObject(resp.aggregations)) {
|
||||
const accessor = Object.keys(resp.aggregations)[0];
|
||||
data = resp.aggregations[accessor].buckets.slice(0, ML_DATA_PREVIEW_COUNT);
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ import { findAggField } from '../../../../common/util/validation_utils';
|
|||
import { getDatafeedAggregations } from '../../../../common/util/datafeed_utils';
|
||||
import { aggregationTypeTransform } from '../../../../common/util/anomaly_utils';
|
||||
import { ES_AGGREGATION } from '../../../../common/constants/aggregation_types';
|
||||
import { isRecord } from '../../../../common/util/record_utils';
|
||||
import { isPopulatedObject } from '../../../../common/util/object_utils';
|
||||
|
||||
interface ResultResponse {
|
||||
success: boolean;
|
||||
|
@ -176,7 +176,7 @@ export function resultsServiceRxProvider(mlApiServices: MlApiServices) {
|
|||
// when the field is an aggregation field, because the field doesn't actually exist in the indices
|
||||
// we need to pass all the sub aggs from the original datafeed config
|
||||
// so that we can access the aggregated field
|
||||
if (isRecord(aggFields)) {
|
||||
if (isPopulatedObject(aggFields)) {
|
||||
// first item under aggregations can be any name, not necessarily 'buckets'
|
||||
const accessor = Object.keys(aggFields)[0];
|
||||
const tempAggs = { ...(aggFields[accessor].aggs ?? aggFields[accessor].aggregations) };
|
||||
|
|
|
@ -39,7 +39,7 @@ import {
|
|||
} from '../../../common/util/job_utils';
|
||||
import { groupsProvider } from './groups';
|
||||
import type { MlClient } from '../../lib/ml_client';
|
||||
import { isRecord } from '../../../common/util/record_utils';
|
||||
import { isPopulatedObject } from '../../../common/util/object_utils';
|
||||
|
||||
interface Results {
|
||||
[id: string]: {
|
||||
|
@ -173,7 +173,7 @@ export function jobsProvider(client: IScopedClusterClient, mlClient: MlClient) {
|
|||
});
|
||||
|
||||
const jobs = fullJobsList.map((job) => {
|
||||
const hasDatafeed = isRecord(job.datafeed_config);
|
||||
const hasDatafeed = isPopulatedObject(job.datafeed_config);
|
||||
const dataCounts = job.data_counts;
|
||||
const errorMessage = getSingleMetricViewerJobErrorMessage(job);
|
||||
|
||||
|
@ -233,7 +233,7 @@ export function jobsProvider(client: IScopedClusterClient, mlClient: MlClient) {
|
|||
|
||||
const jobs = fullJobsList.map((job) => {
|
||||
jobsMap[job.job_id] = job.groups || [];
|
||||
const hasDatafeed = isRecord(job.datafeed_config);
|
||||
const hasDatafeed = isPopulatedObject(job.datafeed_config);
|
||||
const timeRange: { to?: number; from?: number } = {};
|
||||
|
||||
const dataCounts = job.data_counts;
|
||||
|
|
|
@ -20,7 +20,7 @@ import type {
|
|||
import type { SavedSearchQuery } from '../hooks/use_search_items';
|
||||
import type { StepDefineExposedState } from '../sections/create_transform/components/step_define';
|
||||
import type { StepDetailsExposedState } from '../sections/create_transform/components/step_details/step_details_form';
|
||||
import { isRecord } from './utils/record_utils';
|
||||
import { isPopulatedObject } from './utils/object_utils';
|
||||
import { RuntimeField } from '../../../../../../src/plugins/data/common/index_patterns';
|
||||
|
||||
export interface SimpleQuery {
|
||||
|
@ -66,7 +66,7 @@ export function getCombinedRuntimeMappings(
|
|||
let combinedRuntimeMappings = {};
|
||||
|
||||
// Use runtime field mappings defined inline from API
|
||||
if (isRecord(runtimeMappings)) {
|
||||
if (isPopulatedObject(runtimeMappings)) {
|
||||
combinedRuntimeMappings = { ...combinedRuntimeMappings, ...runtimeMappings };
|
||||
}
|
||||
|
||||
|
@ -76,7 +76,7 @@ export function getCombinedRuntimeMappings(
|
|||
combinedRuntimeMappings = { ...combinedRuntimeMappings, ...ipRuntimeMappings };
|
||||
}
|
||||
|
||||
if (isRecord(combinedRuntimeMappings)) {
|
||||
if (isPopulatedObject(combinedRuntimeMappings)) {
|
||||
return combinedRuntimeMappings;
|
||||
}
|
||||
return undefined;
|
||||
|
@ -94,7 +94,7 @@ export function getPreviewTransformRequestBody(
|
|||
source: {
|
||||
index,
|
||||
...(!isDefaultQuery(query) && !isMatchAllQuery(query) ? { query } : {}),
|
||||
...(isRecord(runtimeMappings) ? { runtime_mappings: runtimeMappings } : {}),
|
||||
...(isPopulatedObject(runtimeMappings) ? { runtime_mappings: runtimeMappings } : {}),
|
||||
},
|
||||
...(partialRequest ?? {}),
|
||||
};
|
||||
|
|
|
@ -5,6 +5,6 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
export const isRecord = <T = Record<string, any>>(arg: any): arg is T => {
|
||||
export const isPopulatedObject = <T = Record<string, any>>(arg: any): arg is T => {
|
||||
return typeof arg === 'object' && arg !== null && Object.keys(arg).length > 0;
|
||||
};
|
|
@ -47,7 +47,7 @@ import {
|
|||
PutTransformsPivotRequestSchema,
|
||||
} from '../../../../../../common/api_schemas/transforms';
|
||||
import type { RuntimeField } from '../../../../../../../../../src/plugins/data/common/index_patterns';
|
||||
import { isRecord } from '../../../../common/utils/record_utils';
|
||||
import { isPopulatedObject } from '../../../../common/utils/object_utils';
|
||||
|
||||
export interface StepDetailsExposedState {
|
||||
created: boolean;
|
||||
|
@ -201,7 +201,7 @@ export const StepCreateForm: FC<StepCreateFormProps> = React.memo(
|
|||
{
|
||||
title: indexPatternName,
|
||||
timeFieldName,
|
||||
...(isRecord(runtimeMappings) ? { runtimeFieldMap: runtimeMappings } : {}),
|
||||
...(isPopulatedObject(runtimeMappings) ? { runtimeFieldMap: runtimeMappings } : {}),
|
||||
},
|
||||
false,
|
||||
true
|
||||
|
|
|
@ -16,7 +16,7 @@ import { getFilterAggTypeConfig } from '../config';
|
|||
import type { FilterAggType, PivotAggsConfigFilter } from '../types';
|
||||
import type { RuntimeMappings } from '../../types';
|
||||
import { getKibanaFieldTypeFromEsType } from '../../get_pivot_dropdown_options';
|
||||
import { isRecord } from '../../../../../../../common/utils/record_utils';
|
||||
import { isPopulatedObject } from '../../../../../../../common/utils/object_utils';
|
||||
|
||||
/**
|
||||
* Resolves supported filters for provided field.
|
||||
|
@ -31,7 +31,7 @@ export function getSupportedFilterAggs(
|
|||
if (indexPatternField !== undefined) {
|
||||
return [...commonFilterAggs, ...filterAggsFieldSupport[indexPatternField.type]];
|
||||
}
|
||||
if (isRecord(runtimeMappings) && runtimeMappings.hasOwnProperty(fieldName)) {
|
||||
if (isPopulatedObject(runtimeMappings) && runtimeMappings.hasOwnProperty(fieldName)) {
|
||||
const runtimeField = runtimeMappings[fieldName];
|
||||
return [
|
||||
...commonFilterAggs,
|
||||
|
|
|
@ -26,7 +26,7 @@ import {
|
|||
import { getDefaultAggregationConfig } from './get_default_aggregation_config';
|
||||
import { getDefaultGroupByConfig } from './get_default_group_by_config';
|
||||
import type { Field, StepDefineExposedState } from './types';
|
||||
import { isRecord } from '../../../../../common/utils/record_utils';
|
||||
import { isPopulatedObject } from '../../../../../common/utils/object_utils';
|
||||
|
||||
const illegalEsAggNameChars = /[[\]>]/g;
|
||||
|
||||
|
@ -77,7 +77,7 @@ export function getPivotDropdownOptions(
|
|||
|
||||
// Support for runtime_mappings that are defined by queries
|
||||
let runtimeFields: Field[] = [];
|
||||
if (isRecord(runtimeMappings)) {
|
||||
if (isPopulatedObject(runtimeMappings)) {
|
||||
runtimeFields = Object.keys(runtimeMappings).map((fieldName) => {
|
||||
const field = runtimeMappings[fieldName];
|
||||
return { name: fieldName, type: getKibanaFieldTypeFromEsType(field.type) };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue