diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index df5562fad8a32..9684643d7eed1 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -609,6 +609,7 @@ x-pack/packages/ml/data_view_utils @elastic/ml-ui x-pack/packages/ml/date_picker @elastic/ml-ui x-pack/packages/ml/date_utils @elastic/ml-ui x-pack/packages/ml/error_utils @elastic/ml-ui +x-pack/packages/ml/field_stats_flyout @elastic/ml-ui x-pack/packages/ml/in_memory_table @elastic/ml-ui x-pack/packages/ml/is_defined @elastic/ml-ui x-pack/packages/ml/is_populated_object @elastic/ml-ui @@ -616,6 +617,7 @@ x-pack/packages/ml/kibana_theme @elastic/ml-ui x-pack/packages/ml/local_storage @elastic/ml-ui x-pack/packages/ml/nested_property @elastic/ml-ui x-pack/packages/ml/number_utils @elastic/ml-ui +x-pack/packages/ml/parse_interval @elastic/ml-ui x-pack/plugins/ml @elastic/ml-ui x-pack/packages/ml/query_utils @elastic/ml-ui x-pack/packages/ml/random_sampler_utils @elastic/ml-ui @@ -627,6 +629,7 @@ x-pack/packages/ml/time_buckets @elastic/ml-ui x-pack/packages/ml/trained_models_utils @elastic/ml-ui x-pack/packages/ml/ui_actions @elastic/ml-ui x-pack/packages/ml/url_state @elastic/ml-ui +x-pack/packages/ml/validators @elastic/ml-ui packages/kbn-mock-idp-plugin @elastic/kibana-security packages/kbn-mock-idp-utils @elastic/kibana-security packages/kbn-monaco @elastic/appex-sharedux diff --git a/package.json b/package.json index 08ff2379c8572..06076e3178bbc 100644 --- a/package.json +++ b/package.json @@ -644,6 +644,7 @@ "@kbn/ml-date-picker": "link:x-pack/packages/ml/date_picker", "@kbn/ml-date-utils": "link:x-pack/packages/ml/date_utils", "@kbn/ml-error-utils": "link:x-pack/packages/ml/error_utils", + "@kbn/ml-field-stats-flyout": "link:x-pack/packages/ml/field_stats_flyout", "@kbn/ml-in-memory-table": "link:x-pack/packages/ml/in_memory_table", "@kbn/ml-is-defined": "link:x-pack/packages/ml/is_defined", "@kbn/ml-is-populated-object": "link:x-pack/packages/ml/is_populated_object", @@ -651,6 +652,7 @@ "@kbn/ml-local-storage": "link:x-pack/packages/ml/local_storage", "@kbn/ml-nested-property": "link:x-pack/packages/ml/nested_property", "@kbn/ml-number-utils": "link:x-pack/packages/ml/number_utils", + "@kbn/ml-parse-interval": "link:x-pack/packages/ml/parse_interval", "@kbn/ml-plugin": "link:x-pack/plugins/ml", "@kbn/ml-query-utils": "link:x-pack/packages/ml/query_utils", "@kbn/ml-random-sampler-utils": "link:x-pack/packages/ml/random_sampler_utils", @@ -662,6 +664,7 @@ "@kbn/ml-trained-models-utils": "link:x-pack/packages/ml/trained_models_utils", "@kbn/ml-ui-actions": "link:x-pack/packages/ml/ui_actions", "@kbn/ml-url-state": "link:x-pack/packages/ml/url_state", + "@kbn/ml-validators": "link:x-pack/packages/ml/validators", "@kbn/monaco": "link:packages/kbn-monaco", "@kbn/monitoring-collection-plugin": "link:x-pack/plugins/monitoring_collection", "@kbn/monitoring-plugin": "link:x-pack/plugins/monitoring", diff --git a/tsconfig.base.json b/tsconfig.base.json index 53930a4a57f24..3e586dfa14a4d 100644 --- a/tsconfig.base.json +++ b/tsconfig.base.json @@ -1212,6 +1212,8 @@ "@kbn/ml-date-utils/*": ["x-pack/packages/ml/date_utils/*"], "@kbn/ml-error-utils": ["x-pack/packages/ml/error_utils"], "@kbn/ml-error-utils/*": ["x-pack/packages/ml/error_utils/*"], + "@kbn/ml-field-stats-flyout": ["x-pack/packages/ml/field_stats_flyout"], + "@kbn/ml-field-stats-flyout/*": ["x-pack/packages/ml/field_stats_flyout/*"], "@kbn/ml-in-memory-table": ["x-pack/packages/ml/in_memory_table"], "@kbn/ml-in-memory-table/*": ["x-pack/packages/ml/in_memory_table/*"], "@kbn/ml-is-defined": ["x-pack/packages/ml/is_defined"], @@ -1226,6 +1228,8 @@ "@kbn/ml-nested-property/*": ["x-pack/packages/ml/nested_property/*"], "@kbn/ml-number-utils": ["x-pack/packages/ml/number_utils"], "@kbn/ml-number-utils/*": ["x-pack/packages/ml/number_utils/*"], + "@kbn/ml-parse-interval": ["x-pack/packages/ml/parse_interval"], + "@kbn/ml-parse-interval/*": ["x-pack/packages/ml/parse_interval/*"], "@kbn/ml-plugin": ["x-pack/plugins/ml"], "@kbn/ml-plugin/*": ["x-pack/plugins/ml/*"], "@kbn/ml-query-utils": ["x-pack/packages/ml/query_utils"], @@ -1248,6 +1252,8 @@ "@kbn/ml-ui-actions/*": ["x-pack/packages/ml/ui_actions/*"], "@kbn/ml-url-state": ["x-pack/packages/ml/url_state"], "@kbn/ml-url-state/*": ["x-pack/packages/ml/url_state/*"], + "@kbn/ml-validators": ["x-pack/packages/ml/validators"], + "@kbn/ml-validators/*": ["x-pack/packages/ml/validators/*"], "@kbn/mock-idp-plugin": ["packages/kbn-mock-idp-plugin"], "@kbn/mock-idp-plugin/*": ["packages/kbn-mock-idp-plugin/*"], "@kbn/mock-idp-utils": ["packages/kbn-mock-idp-utils"], diff --git a/x-pack/.i18nrc.json b/x-pack/.i18nrc.json index 8082fa6f8ede2..97aa05deb4a42 100644 --- a/x-pack/.i18nrc.json +++ b/x-pack/.i18nrc.json @@ -79,6 +79,7 @@ "packages/ml/data_grid", "packages/ml/data_view_utils", "packages/ml/date_picker", + "packages/ml/field_stats_flyout", "packages/ml/inference_integration_flyout", "packages/ml/trained_models_utils", "packages/ml/category_validator", diff --git a/x-pack/packages/ml/field_stats_flyout/README.md b/x-pack/packages/ml/field_stats_flyout/README.md new file mode 100644 index 0000000000000..23a8462c96491 --- /dev/null +++ b/x-pack/packages/ml/field_stats_flyout/README.md @@ -0,0 +1,3 @@ +# @kbn/ml-field-stats-flyout + +This package provides a field statistics flyout component. It is used in the Machine Learning and Transforms plugin. diff --git a/x-pack/plugins/ml/public/application/components/field_stats_flyout/eui_combo_box_with_field_stats.tsx b/x-pack/packages/ml/field_stats_flyout/eui_combo_box_with_field_stats.tsx similarity index 68% rename from x-pack/plugins/ml/public/application/components/field_stats_flyout/eui_combo_box_with_field_stats.tsx rename to x-pack/packages/ml/field_stats_flyout/eui_combo_box_with_field_stats.tsx index 8bb04b7597dd8..a09710da8e398 100644 --- a/x-pack/plugins/ml/public/application/components/field_stats_flyout/eui_combo_box_with_field_stats.tsx +++ b/x-pack/packages/ml/field_stats_flyout/eui_combo_box_with_field_stats.tsx @@ -25,9 +25,25 @@ export const optionCss = css` } `; -export const EuiComboBoxWithFieldStats: FC< - EuiComboBoxProps -> = ({ options, ...restProps }) => { +/** + * Props for the EuiComboBoxWithFieldStats component. + */ +export type EuiComboBoxWithFieldStatsProps = EuiComboBoxProps< + string | number | string[] | undefined +>; + +/** + * React component that wraps the EuiComboBox component and adds field statistics functionality. + * + * @component + * @example + * ```tsx + * + * ``` + * @param {EuiComboBoxWithFieldStatsProps} props - The component props. + */ +export const EuiComboBoxWithFieldStats: FC = (props) => { + const { options, ...restProps } = props; const { renderOption } = useFieldStatsTrigger(); const comboBoxOptions: EuiComboBoxOptionOption[] = useMemo( () => diff --git a/x-pack/plugins/ml/public/application/components/field_stats_flyout/field_stats_content.tsx b/x-pack/packages/ml/field_stats_flyout/field_stats_content.tsx similarity index 73% rename from x-pack/plugins/ml/public/application/components/field_stats_flyout/field_stats_content.tsx rename to x-pack/packages/ml/field_stats_flyout/field_stats_content.tsx index 8e48370c9c785..a649ed778d157 100644 --- a/x-pack/plugins/ml/public/application/components/field_stats_flyout/field_stats_content.tsx +++ b/x-pack/packages/ml/field_stats_flyout/field_stats_content.tsx @@ -15,20 +15,42 @@ import { FieldStats } from '@kbn/unified-field-list/src/components/field_stats'; import { isDefined } from '@kbn/ml-is-defined'; import type { DataView } from '@kbn/data-plugin/common'; import type { TimeRange as TimeRangeMs } from '@kbn/ml-date-picker'; +import { getDefaultDSLQuery } from '@kbn/ml-query-utils'; import moment from 'moment'; import { euiPaletteColorBlind } from '@elastic/eui'; -import { getDefaultDatafeedQuery } from '../../jobs/new_job/utils/new_job_utils'; -import { useFieldStatsFlyoutContext } from './use_field_stats_flytout_context'; +import { useFieldStatsFlyoutContext } from './use_field_stats_flyout_context'; -const DEFAULT_DSL_QUERY = getDefaultDatafeedQuery(); const DEFAULT_COLOR = euiPaletteColorBlind()[0]; -export const FieldStatsContent: FC<{ +/** + * Represents the props for the FieldStatsFlyout component. + */ +export interface FieldStatsFlyoutProps { + /** + * The data view object. + */ dataView: DataView; + /** + * Services required for field statistics. + */ fieldStatsServices: FieldStatsServices; + /** + * Optional time range in milliseconds. + */ timeRangeMs?: TimeRangeMs; + /** + * Optional DSL query for filtering field statistics. + */ dslQuery?: FieldStatsProps['dslQuery']; -}> = ({ dataView: selectedDataView, fieldStatsServices, timeRangeMs, dslQuery }) => { +} + +/** + * Renders the content for the field statistics flyout. + * @param props - The props for the FieldStatsContent component. + * @returns The rendered FieldStatsContent component. + */ +export const FieldStatsContent: FC = (props) => { + const { dataView: selectedDataView, fieldStatsServices, timeRangeMs, dslQuery } = props; const { fieldName } = useFieldStatsFlyoutContext(); // Format timestamp to ISO formatted date strings @@ -58,7 +80,7 @@ export const FieldStatsContent: FC<{ = ({ dataView, fieldStatsServices, timeRangeMs, dslQuery }) => { +} + +/** + * Renders a flyout component for displaying field statistics. + * + * @component + * @example + * ```tsx + * + * ``` + * + * @param {Object} props - The component props. + */ +export const FieldStatsFlyout: FC = (props) => { + const { dataView, fieldStatsServices, timeRangeMs, dslQuery } = props; const { setIsFlyoutVisible, isFlyoutVisible, fieldName } = useFieldStatsFlyoutContext(); const closeFlyout = useCallback(() => setIsFlyoutVisible(false), []); // eslint-disable-line react-hooks/exhaustive-deps diff --git a/x-pack/plugins/ml/public/application/components/field_stats_flyout/field_stats_flyout_provider.tsx b/x-pack/packages/ml/field_stats_flyout/field_stats_flyout_provider.tsx similarity index 72% rename from x-pack/plugins/ml/public/application/components/field_stats_flyout/field_stats_flyout_provider.tsx rename to x-pack/packages/ml/field_stats_flyout/field_stats_flyout_provider.tsx index 9b23ac89afcdb..9dd947f0872f3 100644 --- a/x-pack/plugins/ml/public/application/components/field_stats_flyout/field_stats_flyout_provider.tsx +++ b/x-pack/packages/ml/field_stats_flyout/field_stats_flyout_provider.tsx @@ -7,7 +7,9 @@ import type { PropsWithChildren, FC } from 'react'; import React, { useCallback, useState } from 'react'; +import type { CoreStart } from '@kbn/core/public'; import type { DataView } from '@kbn/data-plugin/common'; +import type { DataPublicPluginStart } from '@kbn/data-plugin/public'; import type { FieldStatsServices } from '@kbn/unified-field-list/src/components/field_stats'; import type { TimeRange as TimeRangeMs } from '@kbn/ml-date-picker'; import type { FieldStatsProps } from '@kbn/unified-field-list/src/components/field_stats'; @@ -16,33 +18,73 @@ import { getProcessedFields } from '@kbn/ml-data-grid'; import { stringHash } from '@kbn/ml-string-hash'; import { lastValueFrom } from 'rxjs'; import { useRef } from 'react'; +import { useKibana } from '@kbn/kibana-react-plugin/public'; import { getMergedSampleDocsForPopulatedFieldsQuery } from './populated_fields/get_merged_populated_fields_query'; -import { useMlKibana } from '../../contexts/kibana'; import { FieldStatsFlyout } from './field_stats_flyout'; -import { MLFieldStatsFlyoutContext } from './use_field_stats_flytout_context'; +import { MLFieldStatsFlyoutContext } from './use_field_stats_flyout_context'; import { PopulatedFieldsCacheManager } from './populated_fields/populated_fields_cache_manager'; -export const FieldStatsFlyoutProvider: FC< - PropsWithChildren<{ - dataView: DataView; - fieldStatsServices: FieldStatsServices; - timeRangeMs?: TimeRangeMs; - dslQuery?: FieldStatsProps['dslQuery']; - disablePopulatedFields?: boolean; - }> -> = ({ - dataView, - fieldStatsServices, - timeRangeMs, - dslQuery, - disablePopulatedFields = false, - children, -}) => { +type Services = CoreStart & { + data: DataPublicPluginStart; +}; + +function useDataSearch() { + const { data } = useKibana().services; + + if (!data) { + throw new Error('Kibana data service not available.'); + } + + return data.search; +} + +/** + * Props for the FieldStatsFlyoutProvider component. + * + * @typedef {Object} FieldStatsFlyoutProviderProps + * @property dataView - The data view object. + * @property fieldStatsServices - Services required for field statistics. + * @property [timeRangeMs] - Optional time range in milliseconds. + * @property [dslQuery] - Optional DSL query for filtering field statistics. + * @property [disablePopulatedFields] - Optional flag to disable populated fields. + */ +export type FieldStatsFlyoutProviderProps = PropsWithChildren<{ + dataView: DataView; + fieldStatsServices: FieldStatsServices; + timeRangeMs?: TimeRangeMs; + dslQuery?: FieldStatsProps['dslQuery']; + disablePopulatedFields?: boolean; +}>; + +/** + * Provides field statistics in a flyout component. + * + * @component + * @example + * ```tsx + * + * {children} + * + * ``` + * + * @param {FieldStatsFlyoutProviderProps} props - The component props. + */ +export const FieldStatsFlyoutProvider: FC = (props) => { const { - services: { - data: { search }, - }, - } = useMlKibana(); + dataView, + fieldStatsServices, + timeRangeMs, + dslQuery, + disablePopulatedFields = false, + children, + } = props; + const search = useDataSearch(); const [isFieldStatsFlyoutVisible, setFieldStatsIsFlyoutVisible] = useState(false); const [fieldName, setFieldName] = useState(); const [fieldValue, setFieldValue] = useState(); diff --git a/x-pack/plugins/ml/public/application/components/field_stats_flyout/field_stats_info_button.tsx b/x-pack/packages/ml/field_stats_flyout/field_stats_info_button.tsx similarity index 66% rename from x-pack/plugins/ml/public/application/components/field_stats_flyout/field_stats_info_button.tsx rename to x-pack/packages/ml/field_stats_flyout/field_stats_info_button.tsx index 0bdd1613a5d5d..936f9550cdda1 100644 --- a/x-pack/plugins/ml/public/application/components/field_stats_flyout/field_stats_info_button.tsx +++ b/x-pack/packages/ml/field_stats_flyout/field_stats_info_button.tsx @@ -7,30 +7,81 @@ import { EuiButtonIcon, EuiFlexGroup, EuiFlexItem, EuiToolTip, EuiText } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import React from 'react'; +import React, { type FC } from 'react'; import { FieldIcon } from '@kbn/react-field'; import { type Field } from '@kbn/ml-anomaly-utils'; -import { useCurrentThemeVars } from '../../contexts/kibana'; -import { getKbnFieldIconType } from '../../../../common/util/get_field_icon_types'; +import { useKibana } from '@kbn/kibana-react-plugin/public'; +import { useCurrentEuiThemeVars } from '@kbn/ml-kibana-theme'; +import { getKbnFieldIconType } from './get_kbn_field_icon_types'; + +function useThemeVars() { + const { theme } = useKibana().services; + + if (!theme) { + throw new TypeError('theme service not available in kibana-react context.'); + } + + return useCurrentEuiThemeVars(theme); +} + +/** + * Represents a field used for statistics. + */ export type FieldForStats = Pick; -export const FieldStatsInfoButton = ({ - field, - label, - onButtonClick, - disabled, - isEmpty = false, - hideTrigger = false, -}: { + +/** + * Represents the props for the FieldStatsInfoButton component. + */ +export interface FieldStatsInfoButtonProps { + /** + * The field for which to display statistics. + */ field: FieldForStats; + /** + * The label for the field. + */ label: string; - searchValue?: string; + /** + * Button click callback function. + * @param field - The field for which to display statistics. + * @returns void + */ + onButtonClick?: (field: FieldForStats) => void; + /** + * If true, the button is disabled. + */ disabled?: boolean; + /** + * If true, the field is empty. + */ isEmpty?: boolean; - onButtonClick?: (field: FieldForStats) => void; + /** + * If true, the trigger is hidden. + */ hideTrigger?: boolean; -}) => { - const themeVars = useCurrentThemeVars(); +} + +/** + * Renders a button component for field statistics information. + * + * @component + * @example + * ```tsx + * + * ``` + * @param {FieldStatsInfoButtonProps} props - The props for the FieldStatsInfoButton component. + */ +export const FieldStatsInfoButton: FC = (props) => { + const { field, label, onButtonClick, disabled, isEmpty, hideTrigger } = props; + const themeVars = useThemeVars(); const emptyFieldMessage = isEmpty ? ' ' + i18n.translate('xpack.ml.newJob.wizard.fieldContextPopover.emptyFieldInSampleDocsMsg', { diff --git a/x-pack/packages/ml/field_stats_flyout/get_kbn_field_icon_types.test.ts b/x-pack/packages/ml/field_stats_flyout/get_kbn_field_icon_types.test.ts new file mode 100644 index 0000000000000..5f930750ae8a8 --- /dev/null +++ b/x-pack/packages/ml/field_stats_flyout/get_kbn_field_icon_types.test.ts @@ -0,0 +1,44 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { getKbnFieldIconType } from './get_kbn_field_icon_types'; +import { ES_FIELD_TYPES } from '@kbn/field-types'; + +describe('getKbnFieldIconType', () => { + it('should return "number" for numeric field types', () => { + const numericTypes = [ + ES_FIELD_TYPES.FLOAT, + ES_FIELD_TYPES.HALF_FLOAT, + ES_FIELD_TYPES.SCALED_FLOAT, + ES_FIELD_TYPES.DOUBLE, + ES_FIELD_TYPES.INTEGER, + ES_FIELD_TYPES.LONG, + ES_FIELD_TYPES.SHORT, + ES_FIELD_TYPES.UNSIGNED_LONG, + ]; + + numericTypes.forEach((type) => { + expect(getKbnFieldIconType(type)).toBe('number'); + }); + }); + + it('should return "date" for date field types', () => { + const dateTypes = [ES_FIELD_TYPES.DATE, ES_FIELD_TYPES.DATE_NANOS]; + + dateTypes.forEach((type) => { + expect(getKbnFieldIconType(type)).toBe('date'); + }); + }); + + it('should return the same type for other field types', () => { + const otherTypes = ['keyword', 'text', 'boolean', 'geo_point', 'geo_shape']; + + otherTypes.forEach((type) => { + expect(getKbnFieldIconType(type)).toBe(type); + }); + }); +}); diff --git a/x-pack/plugins/ml/common/util/get_field_icon_types.ts b/x-pack/packages/ml/field_stats_flyout/get_kbn_field_icon_types.ts similarity index 79% rename from x-pack/plugins/ml/common/util/get_field_icon_types.ts rename to x-pack/packages/ml/field_stats_flyout/get_kbn_field_icon_types.ts index 517089d6b0fa6..7ae82d0c28ca8 100644 --- a/x-pack/plugins/ml/common/util/get_field_icon_types.ts +++ b/x-pack/packages/ml/field_stats_flyout/get_kbn_field_icon_types.ts @@ -8,6 +8,12 @@ import { ES_FIELD_TYPES } from '@kbn/field-types'; import type { FieldIconProps } from '@kbn/react-field'; +/** + * Returns the Kibana field icon type based on the provided field type. + * + * @param fieldType - The type of the field for which the icon type is needed. + * @returns The icon type corresponding to the provided field type. + */ export function getKbnFieldIconType(type: string): FieldIconProps['type'] { switch (type) { case ES_FIELD_TYPES.FLOAT: diff --git a/x-pack/packages/ml/field_stats_flyout/index.ts b/x-pack/packages/ml/field_stats_flyout/index.ts new file mode 100644 index 0000000000000..db4d3c5ee7b15 --- /dev/null +++ b/x-pack/packages/ml/field_stats_flyout/index.ts @@ -0,0 +1,27 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export { FieldStatsFlyout } from './field_stats_flyout'; +export { FieldStatsContent, type FieldStatsFlyoutProps } from './field_stats_content'; +export { + FieldStatsFlyoutProvider, + type FieldStatsFlyoutProviderProps, +} from './field_stats_flyout_provider'; +export { + MLFieldStatsFlyoutContext, + useFieldStatsFlyoutContext, +} from './use_field_stats_flyout_context'; +export { + FieldStatsInfoButton, + type FieldForStats, + type FieldStatsInfoButtonProps, +} from './field_stats_info_button'; +export { useFieldStatsTrigger } from './use_field_stats_trigger'; +export { + EuiComboBoxWithFieldStats, + type EuiComboBoxWithFieldStatsProps, +} from './eui_combo_box_with_field_stats'; diff --git a/x-pack/plugins/transform/public/__mocks__/shared_imports.ts b/x-pack/packages/ml/field_stats_flyout/jest.config.js similarity index 51% rename from x-pack/plugins/transform/public/__mocks__/shared_imports.ts rename to x-pack/packages/ml/field_stats_flyout/jest.config.js index ac4b7fe49a38c..92a117be85f1b 100644 --- a/x-pack/plugins/transform/public/__mocks__/shared_imports.ts +++ b/x-pack/packages/ml/field_stats_flyout/jest.config.js @@ -5,10 +5,8 @@ * 2.0. */ -// actual mocks -export const expandLiteralStrings = jest.fn(); -export const XJsonMode = jest.fn(); -export const getSavedSearch = jest.fn(); - -// just passing through the reimports -export { getMlSharedImports } from '@kbn/ml-plugin/public'; +module.exports = { + preset: '@kbn/test', + rootDir: '../../../..', + roots: ['/x-pack/packages/ml/field_stats_flyout'], +}; diff --git a/x-pack/packages/ml/field_stats_flyout/kibana.jsonc b/x-pack/packages/ml/field_stats_flyout/kibana.jsonc new file mode 100644 index 0000000000000..4c362fcc84e05 --- /dev/null +++ b/x-pack/packages/ml/field_stats_flyout/kibana.jsonc @@ -0,0 +1,5 @@ +{ + "type": "shared-browser", + "id": "@kbn/ml-field-stats-flyout", + "owner": "@elastic/ml-ui" +} diff --git a/x-pack/packages/ml/field_stats_flyout/package.json b/x-pack/packages/ml/field_stats_flyout/package.json new file mode 100644 index 0000000000000..effef071413a1 --- /dev/null +++ b/x-pack/packages/ml/field_stats_flyout/package.json @@ -0,0 +1,6 @@ +{ + "name": "@kbn/ml-field-stats-flyout", + "private": true, + "version": "1.0.0", + "license": "Elastic License 2.0" +} \ No newline at end of file diff --git a/x-pack/plugins/ml/public/application/components/field_stats_flyout/populated_fields/get_merged_populated_fields_query.test.ts b/x-pack/packages/ml/field_stats_flyout/populated_fields/get_merged_populated_fields_query.test.ts similarity index 100% rename from x-pack/plugins/ml/public/application/components/field_stats_flyout/populated_fields/get_merged_populated_fields_query.test.ts rename to x-pack/packages/ml/field_stats_flyout/populated_fields/get_merged_populated_fields_query.test.ts diff --git a/x-pack/plugins/ml/public/application/components/field_stats_flyout/populated_fields/get_merged_populated_fields_query.ts b/x-pack/packages/ml/field_stats_flyout/populated_fields/get_merged_populated_fields_query.ts similarity index 100% rename from x-pack/plugins/ml/public/application/components/field_stats_flyout/populated_fields/get_merged_populated_fields_query.ts rename to x-pack/packages/ml/field_stats_flyout/populated_fields/get_merged_populated_fields_query.ts diff --git a/x-pack/plugins/ml/public/application/components/field_stats_flyout/populated_fields/index.ts b/x-pack/packages/ml/field_stats_flyout/populated_fields/index.ts similarity index 100% rename from x-pack/plugins/ml/public/application/components/field_stats_flyout/populated_fields/index.ts rename to x-pack/packages/ml/field_stats_flyout/populated_fields/index.ts diff --git a/x-pack/plugins/ml/public/application/components/field_stats_flyout/populated_fields/populated_fields_cache_manager.ts b/x-pack/packages/ml/field_stats_flyout/populated_fields/populated_fields_cache_manager.ts similarity index 100% rename from x-pack/plugins/ml/public/application/components/field_stats_flyout/populated_fields/populated_fields_cache_manager.ts rename to x-pack/packages/ml/field_stats_flyout/populated_fields/populated_fields_cache_manager.ts diff --git a/x-pack/packages/ml/field_stats_flyout/tsconfig.json b/x-pack/packages/ml/field_stats_flyout/tsconfig.json new file mode 100644 index 0000000000000..b0920fac0ad2a --- /dev/null +++ b/x-pack/packages/ml/field_stats_flyout/tsconfig.json @@ -0,0 +1,36 @@ +{ + "extends": "../../../../tsconfig.base.json", + "compilerOptions": { + "outDir": "target/types", + "types": [ + "jest", + "node", + "react" + ] + }, + "include": [ + "**/*.ts", + "**/*.tsx", + ], + "exclude": [ + "target/**/*" + ], + "kbn_references": [ + "@kbn/i18n-react", + "@kbn/data-plugin", + "@kbn/unified-field-list", + "@kbn/ml-date-picker", + "@kbn/i18n", + "@kbn/react-field", + "@kbn/ml-anomaly-utils", + "@kbn/kibana-react-plugin", + "@kbn/ml-kibana-theme", + "@kbn/core", + "@kbn/ml-data-grid", + "@kbn/ml-string-hash", + "@kbn/ml-is-populated-object", + "@kbn/ml-query-utils", + "@kbn/ml-is-defined", + "@kbn/field-types", + ] +} diff --git a/x-pack/plugins/ml/public/application/components/field_stats_flyout/use_field_stats_flytout_context.ts b/x-pack/packages/ml/field_stats_flyout/use_field_stats_flyout_context.ts similarity index 82% rename from x-pack/plugins/ml/public/application/components/field_stats_flyout/use_field_stats_flytout_context.ts rename to x-pack/packages/ml/field_stats_flyout/use_field_stats_flyout_context.ts index 76b7be8d22f86..ec6c28873011c 100644 --- a/x-pack/plugins/ml/public/application/components/field_stats_flyout/use_field_stats_flytout_context.ts +++ b/x-pack/packages/ml/field_stats_flyout/use_field_stats_flyout_context.ts @@ -7,6 +7,10 @@ import { createContext, useContext } from 'react'; import type { TimeRange as TimeRangeMs } from '@kbn/ml-date-picker'; + +/** + * Represents the properties for the MLJobWizardFieldStatsFlyout component. + */ interface MLJobWizardFieldStatsFlyoutProps { isFlyoutVisible: boolean; setIsFlyoutVisible: (v: boolean) => void; @@ -18,6 +22,10 @@ interface MLJobWizardFieldStatsFlyoutProps { timeRangeMs?: TimeRangeMs; populatedFields?: Set; } + +/** + * Context for the ML Field Stats Flyout. + */ export const MLFieldStatsFlyoutContext = createContext({ isFlyoutVisible: false, setIsFlyoutVisible: () => {}, @@ -28,6 +36,10 @@ export const MLFieldStatsFlyoutContext = createContext { field: Field; } +/** + * Custom hook for managing field statistics trigger functionality. + * + * @returns An object containing the following properties and functions: + * - `renderOption`: A callback function for rendering options in a combo box. + * - `setIsFlyoutVisible`: A function for setting the visibility of the flyout. + * - `setFieldName`: A function for setting the field name. + * - `handleFieldStatsButtonClick`: A callback function for handling field stats button click. + * - `closeFlyout`: A callback function for closing the flyout. + * - `optionCss`: CSS styles for the options in the combo box. + * - `populatedFields`: A set of populated fields. + */ export const useFieldStatsTrigger = () => { const { setIsFlyoutVisible, setFieldName, populatedFields } = useFieldStatsFlyoutContext(); diff --git a/x-pack/packages/ml/parse_interval/README.md b/x-pack/packages/ml/parse_interval/README.md new file mode 100644 index 0000000000000..7fb1fc37db18f --- /dev/null +++ b/x-pack/packages/ml/parse_interval/README.md @@ -0,0 +1,14 @@ +# @kbn/ml-parse-interval + +The `parse_interval` package provides the `parseInterval` utility function for parsing time intervals in various formats. + +## Usage + +```javascript +import { parseInterval } = from '@kbn/ml-parse-interval'; + +const intervalString = '1d'; +const intervalInMs = parseInterval(intervalString); + +console.log(intervalInMs); // Output: 86400000 +``` diff --git a/x-pack/plugins/transform/common/shared_imports.ts b/x-pack/packages/ml/parse_interval/index.ts similarity index 76% rename from x-pack/plugins/transform/common/shared_imports.ts rename to x-pack/packages/ml/parse_interval/index.ts index 953e4a3431035..67aca45bab202 100644 --- a/x-pack/plugins/transform/common/shared_imports.ts +++ b/x-pack/packages/ml/parse_interval/index.ts @@ -5,4 +5,4 @@ * 2.0. */ -export { composeValidators, patternValidator } from '@kbn/ml-plugin/common'; +export { parseInterval } from './parse_interval'; diff --git a/x-pack/packages/ml/parse_interval/jest.config.js b/x-pack/packages/ml/parse_interval/jest.config.js new file mode 100644 index 0000000000000..01fc21724c5bf --- /dev/null +++ b/x-pack/packages/ml/parse_interval/jest.config.js @@ -0,0 +1,12 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +module.exports = { + preset: '@kbn/test/jest_node', + rootDir: '../../../..', + roots: ['/x-pack/packages/ml/parse_interval'], +}; diff --git a/x-pack/packages/ml/parse_interval/kibana.jsonc b/x-pack/packages/ml/parse_interval/kibana.jsonc new file mode 100644 index 0000000000000..6d8398c29b1cc --- /dev/null +++ b/x-pack/packages/ml/parse_interval/kibana.jsonc @@ -0,0 +1,5 @@ +{ + "type": "shared-common", + "id": "@kbn/ml-parse-interval", + "owner": "@elastic/ml-ui" +} diff --git a/x-pack/packages/ml/parse_interval/package.json b/x-pack/packages/ml/parse_interval/package.json new file mode 100644 index 0000000000000..7c2eb0c2de1fa --- /dev/null +++ b/x-pack/packages/ml/parse_interval/package.json @@ -0,0 +1,6 @@ +{ + "name": "@kbn/ml-parse-interval", + "private": true, + "version": "1.0.0", + "license": "Elastic License 2.0" +} \ No newline at end of file diff --git a/x-pack/plugins/ml/common/util/parse_interval.test.ts b/x-pack/packages/ml/parse_interval/parse_interval.test.ts similarity index 100% rename from x-pack/plugins/ml/common/util/parse_interval.test.ts rename to x-pack/packages/ml/parse_interval/parse_interval.test.ts diff --git a/x-pack/plugins/ml/common/util/parse_interval.ts b/x-pack/packages/ml/parse_interval/parse_interval.ts similarity index 55% rename from x-pack/plugins/ml/common/util/parse_interval.ts rename to x-pack/packages/ml/parse_interval/parse_interval.ts index 7ae00ab25a52a..ea84f4ba2e467 100644 --- a/x-pack/plugins/ml/common/util/parse_interval.ts +++ b/x-pack/packages/ml/parse_interval/parse_interval.ts @@ -11,30 +11,43 @@ import dateMath from '@kbn/datemath'; type SupportedUnits = unitOfTime.Base; -// Assume interval is in the form (value)(unit), such as "1h" +/** + * Assume interval is in the form (value)(unit), such as "1h" + */ const INTERVAL_STRING_RE = new RegExp('^([0-9]*)\\s*(' + dateMath.units.join('|') + ')$'); -// moment.js is only designed to allow fractional values between 0 and 1 -// for units of hour or less. +/** + * moment.js is only designed to allow fractional values between 0 and 1 + * for units of hour or less. + */ const SUPPORT_ZERO_DURATION_UNITS: SupportedUnits[] = ['ms', 's', 'm', 'h']; -// List of time units which are supported for use in Elasticsearch durations -// (such as anomaly detection job bucket spans) -// See https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-units +/** + * List of time units which are supported for use in Elasticsearch durations + * (such as anomaly detection job bucket spans) + * See https://www.elastic.co/guide/en/elasticsearch/reference/current/common-options.html#time-units + */ const SUPPORT_ES_DURATION_UNITS: SupportedUnits[] = ['ms', 's', 'm', 'h', 'd']; -// Parses an interval String, such as 7d, 1h or 30m to a moment duration. -// Optionally carries out an additional check that the interval is supported as a -// time unit by Elasticsearch, as units greater than 'd' for example cannot be used -// for anomaly detection job bucket spans. -// Differs from the Kibana ui/utils/parse_interval in the following ways: -// 1. A value-less interval such as 'm' is not allowed - in line with the ML back-end -// not accepting such interval Strings for the bucket span of a job. -// 2. Zero length durations 0ms, 0s, 0m and 0h are accepted as-is. -// Note that when adding or subtracting fractional durations, moment is only designed -// to work with units less than 'day'. -// 3. Fractional intervals e.g. 1.5h or 4.5d are not allowed, in line with the behaviour -// of the Elasticsearch date histogram aggregation. +/** + * Parses an interval string, such as 7d, 1h, or 30m to a moment duration. + * Optionally carries out an additional check that the interval is supported as a + * time unit by Elasticsearch, as units greater than 'd' for example cannot be used + * for anomaly detection job bucket spans. + * + * Differs from the Kibana ui/utils/parse_interval in the following ways: + * 1. A value-less interval such as 'm' is not allowed - in line with the ML back-end + * not accepting such interval strings for the bucket span of a job. + * 2. Zero length durations 0ms, 0s, 0m, and 0h are accepted as-is. + * Note that when adding or subtracting fractional durations, moment is only designed + * to work with units less than 'day'. + * 3. Fractional intervals e.g. 1.5h or 4.5d are not allowed, in line with the behaviour + * of the Elasticsearch date histogram aggregation. + * + * @param interval - The interval to parse. + * @param checkValidEsUnit - Optional. Specifies whether to check if the unit is a valid Elasticsearch duration unit. Default is false. + * @returns The parsed Duration object, or null if the interval is invalid. + */ export function parseInterval( interval: string | number, checkValidEsUnit = false diff --git a/x-pack/packages/ml/parse_interval/tsconfig.json b/x-pack/packages/ml/parse_interval/tsconfig.json new file mode 100644 index 0000000000000..e1bbb08bab509 --- /dev/null +++ b/x-pack/packages/ml/parse_interval/tsconfig.json @@ -0,0 +1,19 @@ +{ + "extends": "../../../../tsconfig.base.json", + "compilerOptions": { + "outDir": "target/types", + "types": [ + "jest", + "node" + ] + }, + "include": [ + "**/*.ts", + ], + "exclude": [ + "target/**/*" + ], + "kbn_references": [ + "@kbn/datemath", + ] +} diff --git a/x-pack/packages/ml/query_utils/index.ts b/x-pack/packages/ml/query_utils/index.ts index dfd7f6c08ca0c..9ddcaad02d78c 100644 --- a/x-pack/packages/ml/query_utils/index.ts +++ b/x-pack/packages/ml/query_utils/index.ts @@ -20,4 +20,4 @@ export type { SearchQueryVariant, SimpleQuery, } from './src/types'; -export { getDefaultDSLQuery } from './src/get_default_query'; +export { getDefaultDSLQuery } from './src/get_default_dsl_query'; diff --git a/x-pack/packages/ml/query_utils/src/get_default_query.ts b/x-pack/packages/ml/query_utils/src/get_default_dsl_query.ts similarity index 63% rename from x-pack/packages/ml/query_utils/src/get_default_query.ts rename to x-pack/packages/ml/query_utils/src/get_default_dsl_query.ts index f17746ddd2929..08ed5bb94ddaa 100644 --- a/x-pack/packages/ml/query_utils/src/get_default_query.ts +++ b/x-pack/packages/ml/query_utils/src/get_default_dsl_query.ts @@ -6,9 +6,10 @@ */ import { cloneDeep } from 'lodash'; -import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; -const DEFAULT_QUERY = { +import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; + +const DEFAULT_DSL_QUERY: estypes.QueryDslQueryContainer = { bool: { must: [ { @@ -21,6 +22,6 @@ const DEFAULT_QUERY = { /** * Default DSL query which matches all the results */ -export function getDefaultDSLQuery(): QueryDslQueryContainer { - return cloneDeep(DEFAULT_QUERY); +export function getDefaultDSLQuery(): estypes.QueryDslQueryContainer { + return cloneDeep(DEFAULT_DSL_QUERY); } diff --git a/x-pack/packages/ml/time_buckets/time_buckets.js b/x-pack/packages/ml/time_buckets/time_buckets.js index c70e7962f4250..d2e52fa475178 100644 --- a/x-pack/packages/ml/time_buckets/time_buckets.js +++ b/x-pack/packages/ml/time_buckets/time_buckets.js @@ -149,7 +149,7 @@ TimeBuckets.prototype.getDuration = function () { * * Input can be one of the following: * - "auto" - * - an interval String, such as 7d, 1h or 30m which can be parsed to a moment duration using ml/common/util/parse_interval + * - an interval String, such as 7d, 1h or 30m which can be parsed to a moment duration using @kbn/ml-parse-interval * - a moment.duration object. * * @param {string|moment.duration} input - see desc diff --git a/x-pack/packages/ml/validators/README.md b/x-pack/packages/ml/validators/README.md new file mode 100644 index 0000000000000..1aee8908113f1 --- /dev/null +++ b/x-pack/packages/ml/validators/README.md @@ -0,0 +1,3 @@ +# @kbn/ml-validators + +This package provides a set of validators for machine learning and transform related functionality in Kibana. diff --git a/x-pack/plugins/ml/common/constants/validation.ts b/x-pack/packages/ml/validators/constants.ts similarity index 52% rename from x-pack/plugins/ml/common/constants/validation.ts rename to x-pack/packages/ml/validators/constants.ts index eec37506c9597..6d6151a151ce7 100644 --- a/x-pack/plugins/ml/common/constants/validation.ts +++ b/x-pack/packages/ml/validators/constants.ts @@ -5,16 +5,40 @@ * 2.0. */ +/** + * Interface for a callout message. + */ export interface CalloutMessage { + /** + * Unique identifier for the callout message. + */ id: string; + /** + * Heading of the callout message. + */ heading: string; + /** + * Status of the callout message. + */ status: VALIDATION_STATUS; + /** + * Text of the callout message. + */ text: string; + /** + * Optional URL for the callout message. + */ url?: string; } +/** + * Type for the response of the validate analytics job API. + */ export type ValidateAnalyticsJobResponse = CalloutMessage[]; +/** + * Enum for the validation status. + */ export enum VALIDATION_STATUS { ERROR = 'error', INFO = 'info', @@ -22,17 +46,54 @@ export enum VALIDATION_STATUS { WARNING = 'warning', } +/** + * Boolean const for skipping the bucket span estimation. + */ export const SKIP_BUCKET_SPAN_ESTIMATION = true; +/** + * Const for allowed data units. + */ export const ALLOWED_DATA_UNITS = ['B', 'KB', 'MB', 'GB', 'TB', 'PB']; +/** + * Const for the maximum length of a job ID. + */ export const JOB_ID_MAX_LENGTH = 64; // Data Frame Analytics + +/** + * Const for the upper limit of training documents. + */ export const TRAINING_DOCS_UPPER = 200000; + +/** + * Const for the lower limit of training documents. + */ export const TRAINING_DOCS_LOWER = 200; + +/** + * Const for the threshold of included fields. + */ export const INCLUDED_FIELDS_THRESHOLD = 100; + +/** + * Const for the minimum number of fields for check. + */ export const MINIMUM_NUM_FIELD_FOR_CHECK = 25; + +/** + * Const for the fraction empty limit. + */ export const FRACTION_EMPTY_LIMIT = 0.3; + +/** + * Const for the maximum length of categories. + */ export const NUM_CATEGORIES_THRESHOLD = 10; + +/** + * Const for all categories. + */ export const ALL_CATEGORIES = -1; diff --git a/x-pack/packages/ml/validators/index.ts b/x-pack/packages/ml/validators/index.ts new file mode 100644 index 0000000000000..da982fec00f33 --- /dev/null +++ b/x-pack/packages/ml/validators/index.ts @@ -0,0 +1,32 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +export { + ALL_CATEGORIES, + ALLOWED_DATA_UNITS, + FRACTION_EMPTY_LIMIT, + INCLUDED_FIELDS_THRESHOLD, + JOB_ID_MAX_LENGTH, + MINIMUM_NUM_FIELD_FOR_CHECK, + NUM_CATEGORIES_THRESHOLD, + SKIP_BUCKET_SPAN_ESTIMATION, + TRAINING_DOCS_LOWER, + TRAINING_DOCS_UPPER, + VALIDATION_STATUS, + type CalloutMessage, + type ValidateAnalyticsJobResponse, +} from './constants'; +export { + composeValidators, + dictionaryValidator, + maxLengthValidator, + memoryInputValidator, + patternValidator, + requiredValidator, + timeIntervalInputValidator, + type MemoryInputValidatorResult, +} from './validators'; diff --git a/x-pack/packages/ml/validators/jest.config.js b/x-pack/packages/ml/validators/jest.config.js new file mode 100644 index 0000000000000..67f28da8589d9 --- /dev/null +++ b/x-pack/packages/ml/validators/jest.config.js @@ -0,0 +1,12 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +module.exports = { + preset: '@kbn/test/jest_node', + rootDir: '../../../..', + roots: ['/x-pack/packages/ml/validators'], +}; diff --git a/x-pack/packages/ml/validators/kibana.jsonc b/x-pack/packages/ml/validators/kibana.jsonc new file mode 100644 index 0000000000000..e747549d8e33c --- /dev/null +++ b/x-pack/packages/ml/validators/kibana.jsonc @@ -0,0 +1,5 @@ +{ + "type": "shared-common", + "id": "@kbn/ml-validators", + "owner": "@elastic/ml-ui" +} diff --git a/x-pack/packages/ml/validators/package.json b/x-pack/packages/ml/validators/package.json new file mode 100644 index 0000000000000..958c085a4d3d5 --- /dev/null +++ b/x-pack/packages/ml/validators/package.json @@ -0,0 +1,6 @@ +{ + "name": "@kbn/ml-validators", + "private": true, + "version": "1.0.0", + "license": "Elastic License 2.0" +} \ No newline at end of file diff --git a/x-pack/packages/ml/validators/tsconfig.json b/x-pack/packages/ml/validators/tsconfig.json new file mode 100644 index 0000000000000..ca25f09b5cd50 --- /dev/null +++ b/x-pack/packages/ml/validators/tsconfig.json @@ -0,0 +1,19 @@ +{ + "extends": "../../../../tsconfig.base.json", + "compilerOptions": { + "outDir": "target/types", + "types": [ + "jest", + "node" + ] + }, + "include": [ + "**/*.ts", + ], + "exclude": [ + "target/**/*" + ], + "kbn_references": [ + "@kbn/ml-parse-interval", + ] +} diff --git a/x-pack/plugins/ml/common/util/validators.test.ts b/x-pack/packages/ml/validators/validators.test.ts similarity index 100% rename from x-pack/plugins/ml/common/util/validators.test.ts rename to x-pack/packages/ml/validators/validators.test.ts diff --git a/x-pack/plugins/ml/common/util/validators.ts b/x-pack/packages/ml/validators/validators.ts similarity index 66% rename from x-pack/plugins/ml/common/util/validators.ts rename to x-pack/packages/ml/validators/validators.ts index 9ceeac4b29e82..39db75cd3dfce 100644 --- a/x-pack/plugins/ml/common/util/validators.ts +++ b/x-pack/packages/ml/validators/validators.ts @@ -5,8 +5,9 @@ * 2.0. */ -import { ALLOWED_DATA_UNITS } from '../constants/validation'; -import { parseInterval } from './parse_interval'; +import { parseInterval } from '@kbn/ml-parse-interval'; + +import { ALLOWED_DATA_UNITS } from './constants'; /** * Provides a validator function for maximum allowed input length. @@ -27,8 +28,9 @@ export function maxLengthValidator( } /** - * Provides a validator function for checking against pattern. - * @param pattern + * Factory that provides a validator function for checking against pattern. + * @param pattern Pattern to check against. + * @returns A validator function that checks if the value matches the pattern. */ export function patternValidator( pattern: RegExp @@ -44,8 +46,10 @@ export function patternValidator( } /** - * Composes multiple validators into a single function - * @param validators + * Factory that composes multiple validators into a single function. + * + * @param validators List of validators to compose. + * @returns A validator function that runs all the validators. */ export function composeValidators( ...validators: Array<(value: any) => { [key: string]: any } | null> @@ -58,16 +62,32 @@ export function composeValidators( }; } +/** + * Factory to create a required validator function. + * @returns A validator function that checks if the value is empty. + */ export function requiredValidator() { return (value: T) => { return value === '' || value === undefined || value === null ? { required: true } : null; }; } +/** + * Type for the result of a validation. + */ export type ValidationResult = Record | null; +/** + * Type for the result of a memory input validation. + */ export type MemoryInputValidatorResult = { invalidUnits: { allowedUnits: string } } | null; +/** + * Factory for creating a memory input validator function. + * + * @param allowedUnits Allowed units for the memory input. + * @returns A validator function that checks if the value is a valid memory input. + */ export function memoryInputValidator(allowedUnits = ALLOWED_DATA_UNITS) { return (value: T) => { if (typeof value !== 'string' || value === '') { @@ -80,6 +100,11 @@ export function memoryInputValidator(allowedUnits = ALLOWED_DATA_UNITS) { }; } +/** + * Factory for creating a time interval input validator function. + * + * @returns A validator function that checks if the value is a valid time interval. + */ export function timeIntervalInputValidator() { return (value: string) => { if (value === '') { @@ -97,6 +122,12 @@ export function timeIntervalInputValidator() { }; } +/** + * Factory to create a dictionary validator function. + * @param dict Dictionary to check against. + * @param shouldInclude Whether the value should be included in the dictionary. + * @returns A validator function that checks if the value is in the dictionary. + */ export function dictionaryValidator(dict: string[], shouldInclude: boolean = false) { const dictSet = new Set(dict); return (value: string) => { diff --git a/x-pack/plugins/ml/common/constants/messages.ts b/x-pack/plugins/ml/common/constants/messages.ts index 8eafbccc9bee9..57d6e51cd7b55 100644 --- a/x-pack/plugins/ml/common/constants/messages.ts +++ b/x-pack/plugins/ml/common/constants/messages.ts @@ -10,7 +10,7 @@ import { i18n } from '@kbn/i18n'; import type { DocLinksStart } from '@kbn/core/public'; -import { JOB_ID_MAX_LENGTH, VALIDATION_STATUS } from './validation'; +import { JOB_ID_MAX_LENGTH, VALIDATION_STATUS } from '@kbn/ml-validators'; import { renderTemplate } from '../util/string_utils'; diff --git a/x-pack/plugins/ml/common/index.ts b/x-pack/plugins/ml/common/index.ts index ac0da68923e52..bc53fc4247f2d 100644 --- a/x-pack/plugins/ml/common/index.ts +++ b/x-pack/plugins/ml/common/index.ts @@ -5,7 +5,6 @@ * 2.0. */ -export { composeValidators, patternValidator } from './util/validators'; export { getDefaultCapabilities as getDefaultMlCapabilities } from './types/capabilities'; export { DATAFEED_STATE, JOB_STATE } from './constants/states'; export type { MlSummaryJob, SummaryJobState } from './types/anomaly_detection_jobs'; diff --git a/x-pack/plugins/ml/common/util/alerts.ts b/x-pack/plugins/ml/common/util/alerts.ts index b4be94ec93da5..c73c5a3ede39f 100644 --- a/x-pack/plugins/ml/common/util/alerts.ts +++ b/x-pack/plugins/ml/common/util/alerts.ts @@ -6,10 +6,12 @@ */ import { pick } from 'lodash'; + import { isDefined } from '@kbn/ml-is-defined'; +import { parseInterval } from '@kbn/ml-parse-interval'; + import type { CombinedJobWithStats, Datafeed, Job } from '../types/anomaly_detection_jobs'; import { resolveMaxTimeInterval } from './job_utils'; -import { parseInterval } from './parse_interval'; import type { JobsHealthRuleTestsConfig, JobsHealthTests } from '../types/alerts'; const narrowBucketLength = 60; diff --git a/x-pack/plugins/ml/common/util/job_utils.ts b/x-pack/plugins/ml/common/util/job_utils.ts index eb89fe695522f..cdde803a482e5 100644 --- a/x-pack/plugins/ml/common/util/job_utils.ts +++ b/x-pack/plugins/ml/common/util/job_utils.ts @@ -9,14 +9,15 @@ import { cloneDeep, each, isEmpty, isEqual, pick } from 'lodash'; import semverGte from 'semver/functions/gte'; import type { Duration } from 'moment'; import moment from 'moment'; + import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import numeral from '@elastic/numeral'; + import { i18n } from '@kbn/i18n'; import type { Filter } from '@kbn/es-query'; import { isPopulatedObject } from '@kbn/ml-is-populated-object'; import type { SerializableRecord } from '@kbn/utility-types'; import { FilterStateStore } from '@kbn/es-query'; -import type { QueryDslQueryContainer } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { isDefined } from '@kbn/ml-is-defined'; import { type MlEntityField, @@ -24,9 +25,9 @@ import { ML_JOB_AGGREGATION, MLCATEGORY, } from '@kbn/ml-anomaly-utils'; -import { ALLOWED_DATA_UNITS, JOB_ID_MAX_LENGTH } from '../constants/validation'; -import { parseInterval } from './parse_interval'; -import { maxLengthValidator } from './validators'; +import { maxLengthValidator, ALLOWED_DATA_UNITS, JOB_ID_MAX_LENGTH } from '@kbn/ml-validators'; +import { parseInterval } from '@kbn/ml-parse-interval'; + import { CREATED_BY_LABEL } from '../constants/new_job'; import type { CombinedJob, @@ -875,7 +876,7 @@ export function resolveMaxTimeInterval(timeIntervals: estypes.Duration[]): numbe } export function getFiltersForDSLQuery( - datafeedQuery: QueryDslQueryContainer, + datafeedQuery: estypes.QueryDslQueryContainer, dataViewId: string | undefined, alias?: string, store = FilterStateStore.APP_STATE @@ -903,7 +904,7 @@ export function getFiltersForDSLQuery( } // check to see if the query is a known "empty" shape -export function isKnownEmptyQuery(query: QueryDslQueryContainer) { +export function isKnownEmptyQuery(query: estypes.QueryDslQueryContainer) { const queries = [ // the default query used by the job wizards { bool: { must: [{ match_all: {} }] } }, diff --git a/x-pack/plugins/ml/common/util/validation_utils.ts b/x-pack/plugins/ml/common/util/validation_utils.ts index b31431cdb7d0d..ab5838be86ee9 100644 --- a/x-pack/plugins/ml/common/util/validation_utils.ts +++ b/x-pack/plugins/ml/common/util/validation_utils.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { VALIDATION_STATUS } from '../constants/validation'; +import { VALIDATION_STATUS } from '@kbn/ml-validators'; // get the most severe status level from a list of messages const contains = (arr: string[], str: string) => arr.indexOf(str) >= 0; diff --git a/x-pack/plugins/ml/public/alerting/anomaly_detection_rule/config_validator.tsx b/x-pack/plugins/ml/public/alerting/anomaly_detection_rule/config_validator.tsx index 88b1502ac3b99..d37583a0de697 100644 --- a/x-pack/plugins/ml/public/alerting/anomaly_detection_rule/config_validator.tsx +++ b/x-pack/plugins/ml/public/alerting/anomaly_detection_rule/config_validator.tsx @@ -10,7 +10,7 @@ import React from 'react'; import { FormattedMessage } from '@kbn/i18n-react'; import { EuiCallOut, EuiSpacer } from '@elastic/eui'; -import { parseInterval } from '../../../common/util/parse_interval'; +import { parseInterval } from '@kbn/ml-parse-interval'; import { type CombinedJobWithStats } from '../../../common/types/anomaly_detection_jobs'; import { DATAFEED_STATE } from '../../../common/constants/states'; import { type MlAnomalyDetectionAlertParams } from '../../../common/types/alerts'; diff --git a/x-pack/plugins/ml/public/alerting/anomaly_detection_rule/ml_anomaly_alert_trigger.tsx b/x-pack/plugins/ml/public/alerting/anomaly_detection_rule/ml_anomaly_alert_trigger.tsx index 7404646db7195..3d70b4bbdc16d 100644 --- a/x-pack/plugins/ml/public/alerting/anomaly_detection_rule/ml_anomaly_alert_trigger.tsx +++ b/x-pack/plugins/ml/public/alerting/anomaly_detection_rule/ml_anomaly_alert_trigger.tsx @@ -14,6 +14,7 @@ import type { RuleTypeParamsExpressionProps } from '@kbn/triggers-actions-ui-plu import { isDefined } from '@kbn/ml-is-defined'; import { ML_ANOMALY_RESULT_TYPE, ML_ANOMALY_THRESHOLD } from '@kbn/ml-anomaly-utils'; import { useKibana } from '@kbn/kibana-react-plugin/public'; +import { parseInterval } from '@kbn/ml-parse-interval'; import type { MlCapabilities } from '../../../common/types/capabilities'; import { ML_PAGES } from '../../../common/constants/locator'; import type { MlCoreSetup } from '../../plugin'; @@ -34,7 +35,6 @@ import { ConfigValidator } from './config_validator'; import { type CombinedJobWithStats } from '../../../common/types/anomaly_detection_jobs'; import { AdvancedSettings } from './advanced_settings'; import { getLookbackInterval, getTopNBuckets } from '../../../common/util/alerts'; -import { parseInterval } from '../../../common/util/parse_interval'; export type MlAnomalyAlertTriggerProps = RuleTypeParamsExpressionProps & { diff --git a/x-pack/plugins/ml/public/alerting/anomaly_detection_rule/preview_alert_condition.tsx b/x-pack/plugins/ml/public/alerting/anomaly_detection_rule/preview_alert_condition.tsx index e9e9c38940d61..4da8f5e63e075 100644 --- a/x-pack/plugins/ml/public/alerting/anomaly_detection_rule/preview_alert_condition.tsx +++ b/x-pack/plugins/ml/public/alerting/anomaly_detection_rule/preview_alert_condition.tsx @@ -24,10 +24,13 @@ import { EuiSpacer, EuiText, } from '@elastic/eui'; +import { + composeValidators, + requiredValidator, + timeIntervalInputValidator, +} from '@kbn/ml-validators'; import type { AlertingApiService } from '../../application/services/ml_api_service/alerting'; import type { MlAnomalyDetectionAlertParams, PreviewResponse } from '../../../common/types/alerts'; -import { composeValidators } from '../../../common'; -import { requiredValidator, timeIntervalInputValidator } from '../../../common/util/validators'; import { invalidTimeIntervalMessage } from '../../application/jobs/new_job/common/job_validator/util'; import { ALERT_PREVIEW_SAMPLE_SIZE } from '../../../common/constants/alerts'; diff --git a/x-pack/plugins/ml/public/alerting/time_interval_control.tsx b/x-pack/plugins/ml/public/alerting/time_interval_control.tsx index 43eafe7acaedc..6ec4e251ee136 100644 --- a/x-pack/plugins/ml/public/alerting/time_interval_control.tsx +++ b/x-pack/plugins/ml/public/alerting/time_interval_control.tsx @@ -5,13 +5,15 @@ * 2.0. */ -import type { EuiFieldTextProps } from '@elastic/eui'; -import { EuiFieldText, EuiFormRow } from '@elastic/eui'; import type { FC, ReactNode } from 'react'; import React, { useMemo } from 'react'; + +import type { EuiFieldTextProps } from '@elastic/eui'; +import { EuiFieldText, EuiFormRow } from '@elastic/eui'; + +import { composeValidators, timeIntervalInputValidator } from '@kbn/ml-validators'; + import { invalidTimeIntervalMessage } from '../application/jobs/new_job/common/job_validator/util'; -import { composeValidators } from '../../common'; -import { timeIntervalInputValidator } from '../../common/util/validators'; type TimeIntervalControlProps = Omit & { label: string | ReactNode; diff --git a/x-pack/plugins/ml/public/alerting/validators.ts b/x-pack/plugins/ml/public/alerting/validators.ts index 4999c8bf45a8f..283e5d473fe3d 100644 --- a/x-pack/plugins/ml/public/alerting/validators.ts +++ b/x-pack/plugins/ml/public/alerting/validators.ts @@ -6,6 +6,7 @@ */ import { numberValidator } from '@kbn/ml-agg-utils'; -import { timeIntervalInputValidator } from '../../common/util/validators'; +import { timeIntervalInputValidator } from '@kbn/ml-validators'; + export const validateLookbackInterval = timeIntervalInputValidator(); export const validateTopNBucket = numberValidator({ min: 1, integerOnly: true }); diff --git a/x-pack/plugins/ml/public/application/aiops/change_point_detection.tsx b/x-pack/plugins/ml/public/application/aiops/change_point_detection.tsx index 386210cc02d25..cbfb7fa3024c3 100644 --- a/x-pack/plugins/ml/public/application/aiops/change_point_detection.tsx +++ b/x-pack/plugins/ml/public/application/aiops/change_point_detection.tsx @@ -13,9 +13,9 @@ import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; import { ChangePointDetection } from '@kbn/aiops-plugin/public'; +import { useFieldStatsTrigger, FieldStatsFlyoutProvider } from '@kbn/ml-field-stats-flyout'; import { useDataSource } from '../contexts/ml/data_source_context'; -import { useFieldStatsTrigger, FieldStatsFlyoutProvider } from '../components/field_stats_flyout'; import { useMlKibana } from '../contexts/kibana'; import { HelpMenu } from '../components/help_menu'; import { TechnicalPreviewBadge } from '../components/technical_preview_badge'; diff --git a/x-pack/plugins/ml/public/application/components/anomalies_table/links_menu.tsx b/x-pack/plugins/ml/public/application/components/anomalies_table/links_menu.tsx index 42cf24b52cac4..89bb4b800eb91 100644 --- a/x-pack/plugins/ml/public/application/components/anomalies_table/links_menu.tsx +++ b/x-pack/plugins/ml/public/application/components/anomalies_table/links_menu.tsx @@ -45,10 +45,10 @@ import { escapeQuotes } from '@kbn/es-query'; import { isQuery } from '@kbn/data-plugin/public'; import type { TimeRangeBounds } from '@kbn/ml-time-buckets'; +import { parseInterval } from '@kbn/ml-parse-interval'; import { PLUGIN_ID } from '../../../../common/constants/app'; import { findMessageField } from '../../util/index_utils'; import { getInitialAnomaliesLayers, getInitialSourceIndexFieldLayers } from '../../../maps/util'; -import { parseInterval } from '../../../../common/util/parse_interval'; import { ML_APP_LOCATOR, ML_PAGES } from '../../../../common/constants/locator'; import { getFiltersForDSLQuery } from '../../../../common/util/job_utils'; diff --git a/x-pack/plugins/ml/public/application/components/callout/callout.tsx b/x-pack/plugins/ml/public/application/components/callout/callout.tsx index 8c60f87ef2427..e0ad8952057f3 100644 --- a/x-pack/plugins/ml/public/application/components/callout/callout.tsx +++ b/x-pack/plugins/ml/public/application/components/callout/callout.tsx @@ -9,8 +9,8 @@ import type { FC } from 'react'; import React from 'react'; import { EuiCallOut, EuiLink, EuiSpacer } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; -import type { CalloutMessage } from '../../../../common/constants/validation'; -import { VALIDATION_STATUS } from '../../../../common/constants/validation'; +import type { CalloutMessage } from '@kbn/ml-validators'; +import { VALIDATION_STATUS } from '@kbn/ml-validators'; export const defaultIconType = 'questionInCircle'; diff --git a/x-pack/plugins/ml/public/application/components/custom_urls/custom_url_editor/list.tsx b/x-pack/plugins/ml/public/application/components/custom_urls/custom_url_editor/list.tsx index bb913b8ecec34..e76b55a6f2369 100644 --- a/x-pack/plugins/ml/public/application/components/custom_urls/custom_url_editor/list.tsx +++ b/x-pack/plugins/ml/public/application/components/custom_urls/custom_url_editor/list.tsx @@ -28,13 +28,13 @@ import { type DataFrameAnalyticsConfig, } from '@kbn/ml-data-frame-analytics-utils'; import { parseUrlState } from '@kbn/ml-url-state'; +import { parseInterval } from '@kbn/ml-parse-interval'; import { useMlApi, useMlKibana } from '../../../contexts/kibana'; import { useToastNotificationService } from '../../../services/toast_notification_service'; import { isValidLabel, openCustomUrlWindow } from '../../../util/custom_url_utils'; import { getTestUrl } from './utils'; -import { parseInterval } from '../../../../../common/util/parse_interval'; import { TIME_RANGE_TYPE } from './constants'; import type { Job } from '../../../../../common/types/anomaly_detection_jobs'; diff --git a/x-pack/plugins/ml/public/application/components/custom_urls/custom_url_editor/utils.ts b/x-pack/plugins/ml/public/application/components/custom_urls/custom_url_editor/utils.ts index 0fc2a7b514b2d..c154abb6f5f69 100644 --- a/x-pack/plugins/ml/public/application/components/custom_urls/custom_url_editor/utils.ts +++ b/x-pack/plugins/ml/public/application/components/custom_urls/custom_url_editor/utils.ts @@ -25,8 +25,9 @@ import { type DataFrameAnalyticsConfig, DEFAULT_RESULTS_FIELD, } from '@kbn/ml-data-frame-analytics-utils'; - import { isDefined } from '@kbn/ml-is-defined'; +import { parseInterval } from '@kbn/ml-parse-interval'; + import type { DashboardItems } from '../../../services/dashboard_service'; import { categoryFieldTypes } from '../../../../../common/util/fields_utils'; import { TIME_RANGE_TYPE, URL_TYPE } from './constants'; @@ -35,7 +36,6 @@ import { getPartitioningFieldNames, getFiltersForDSLQuery, } from '../../../../../common/util/job_utils'; -import { parseInterval } from '../../../../../common/util/parse_interval'; import { replaceStringTokens } from '../../../util/string_utils'; import { replaceTokensInUrlValue, diff --git a/x-pack/plugins/ml/public/application/components/field_stats_flyout/index.ts b/x-pack/plugins/ml/public/application/components/field_stats_flyout/index.ts deleted file mode 100644 index d844dd037bd5b..0000000000000 --- a/x-pack/plugins/ml/public/application/components/field_stats_flyout/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export { FieldStatsFlyout } from './field_stats_flyout'; -export { FieldStatsContent } from './field_stats_content'; -export { FieldStatsFlyoutProvider } from './field_stats_flyout_provider'; -export { - MLFieldStatsFlyoutContext, - useFieldStatsFlyoutContext, -} from './use_field_stats_flytout_context'; -export { FieldStatsInfoButton } from './field_stats_info_button'; -export { useFieldStatsTrigger } from './use_field_stats_trigger'; -export { EuiComboBoxWithFieldStats } from './eui_combo_box_with_field_stats'; diff --git a/x-pack/plugins/ml/public/application/components/import_export_jobs/import_jobs_flyout/validate.ts b/x-pack/plugins/ml/public/application/components/import_export_jobs/import_jobs_flyout/validate.ts index 235c3d7b5ffe0..0431addf4b6fa 100644 --- a/x-pack/plugins/ml/public/application/components/import_export_jobs/import_jobs_flyout/validate.ts +++ b/x-pack/plugins/ml/public/application/components/import_export_jobs/import_jobs_flyout/validate.ts @@ -6,11 +6,13 @@ */ import { useCallback } from 'react'; + import { i18n } from '@kbn/i18n'; +import { JOB_ID_MAX_LENGTH } from '@kbn/ml-validators'; + import type { JobType } from '../../../../../common/types/saved_objects'; import { isValidIndexName } from '../../../../../common/util/es_utils'; import { isJobIdValid } from '../../../../../common/util/job_utils'; -import { JOB_ID_MAX_LENGTH } from '../../../../../common/constants/validation'; import type { JobIdObject } from './jobs_import_service'; import { useMlApi } from '../../../contexts/kibana'; diff --git a/x-pack/plugins/ml/public/application/components/model_snapshots/revert_model_snapshot_flyout/revert_model_snapshot_flyout.tsx b/x-pack/plugins/ml/public/application/components/model_snapshots/revert_model_snapshot_flyout/revert_model_snapshot_flyout.tsx index 639c101e7be6f..4cb7df0894899 100644 --- a/x-pack/plugins/ml/public/application/components/model_snapshots/revert_model_snapshot_flyout/revert_model_snapshot_flyout.tsx +++ b/x-pack/plugins/ml/public/application/components/model_snapshots/revert_model_snapshot_flyout/revert_model_snapshot_flyout.tsx @@ -31,6 +31,7 @@ import { import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import { timeFormatter } from '@kbn/ml-date-utils'; +import { parseInterval } from '@kbn/ml-parse-interval'; import type { ModelSnapshot, @@ -42,7 +43,6 @@ import { mlResultsServiceProvider } from '../../../services/results_service'; import type { LineChartPoint } from '../../../jobs/new_job/common/chart_loader'; import { EventRateChart } from '../../../jobs/new_job/pages/components/charts/event_rate_chart/event_rate_chart'; import type { Anomaly } from '../../../jobs/new_job/common/results_loader/results_loader'; -import { parseInterval } from '../../../../../common/util/parse_interval'; import type { CalendarEvent } from './create_calendar'; import { CreateCalendar } from './create_calendar'; diff --git a/x-pack/plugins/ml/public/application/components/validate_job/validate_job_view.js b/x-pack/plugins/ml/public/application/components/validate_job/validate_job_view.js index a959208fe0c31..4701937a272ed 100644 --- a/x-pack/plugins/ml/public/application/components/validate_job/validate_job_view.js +++ b/x-pack/plugins/ml/public/application/components/validate_job/validate_job_view.js @@ -25,9 +25,9 @@ import { } from '@elastic/eui'; import { FormattedMessage } from '@kbn/i18n-react'; +import { VALIDATION_STATUS } from '@kbn/ml-validators'; import { parseMessages } from '../../../../common/constants/messages'; -import { VALIDATION_STATUS } from '../../../../common/constants/validation'; import { Callout, statusToEuiIconType } from '../callout'; import { getMostSevereMessageStatus } from '../../../../common/util/validation_utils'; import { toastNotificationServiceProvider } from '../../services/toast_notification_service'; diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/configuration_step/analysis_fields_table.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/configuration_step/analysis_fields_table.tsx index 82582e9b913bf..3ddd02d0052f9 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/configuration_step/analysis_fields_table.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/configuration_step/analysis_fields_table.tsx @@ -21,9 +21,12 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import type { ES_FIELD_TYPES } from '@kbn/field-types'; import type { FieldSelectionItem } from '@kbn/ml-data-frame-analytics-utils'; -import { useFieldStatsTrigger } from '../../../../../components/field_stats_flyout/use_field_stats_trigger'; -import type { FieldForStats } from '../../../../../components/field_stats_flyout/field_stats_info_button'; -import { FieldStatsInfoButton } from '../../../../../components/field_stats_flyout/field_stats_info_button'; +import { + useFieldStatsTrigger, + FieldStatsInfoButton, + type FieldForStats, +} from '@kbn/ml-field-stats-flyout'; + // @ts-ignore could not find declaration file import { CustomSelectionTable } from '../../../../../components/custom_selection_table'; diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/configuration_step/configuration_step_form.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/configuration_step/configuration_step_form.tsx index c0920b39d47fc..b2b60e95dceda 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/configuration_step/configuration_step_form.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/configuration_step/configuration_step_form.tsx @@ -29,12 +29,13 @@ import { } from '@kbn/ml-data-frame-analytics-utils'; import { DataGrid } from '@kbn/ml-data-grid'; import { SEARCH_QUERY_LANGUAGE } from '@kbn/ml-query-utils'; -import { useMlApi, useMlKibana } from '../../../../../contexts/kibana'; import { EuiComboBoxWithFieldStats, FieldStatsFlyoutProvider, -} from '../../../../../components/field_stats_flyout'; -import type { FieldForStats } from '../../../../../components/field_stats_flyout/field_stats_info_button'; + type FieldForStats, +} from '@kbn/ml-field-stats-flyout'; + +import { useMlApi, useMlKibana } from '../../../../../contexts/kibana'; import { useNewJobCapsServiceAnalytics } from '../../../../../services/new_job_capabilities/new_job_capabilities_service_analytics'; import { useDataSource } from '../../../../../contexts/ml'; diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/details_step/details_step_form.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/details_step/details_step_form.tsx index f43ce7bd2fb9b..7c40b121aa5fa 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/details_step/details_step_form.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/details_step/details_step_form.tsx @@ -13,10 +13,10 @@ import { i18n } from '@kbn/i18n'; import { extractErrorMessage } from '@kbn/ml-error-utils'; import { CreateDataViewForm } from '@kbn/ml-data-view-utils/components/create_data_view_form_row'; import { DestinationIndexForm } from '@kbn/ml-creation-wizard-utils/components/destination_index_form'; +import { JOB_ID_MAX_LENGTH } from '@kbn/ml-validators'; import { useMlApi, useMlKibana } from '../../../../../contexts/kibana'; import type { CreateAnalyticsStepProps } from '../../../analytics_management/hooks/use_create_analytics_form'; -import { JOB_ID_MAX_LENGTH } from '../../../../../../../common/constants/validation'; import { ContinueButton } from '../continue_button'; import { ANALYTICS_STEPS } from '../../page'; import { useCanCreateDataView } from '../../hooks/use_can_create_data_view'; diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/validation_step/validation_step.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/validation_step/validation_step.tsx index 81e4f20dac2ba..b080eacc43424 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/validation_step/validation_step.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/validation_step/validation_step.tsx @@ -9,7 +9,8 @@ import type { FC } from 'react'; import React from 'react'; import { EuiLoadingSpinner, EuiSpacer } from '@elastic/eui'; -import type { CalloutMessage } from '../../../../../../../common/constants/validation'; +import type { CalloutMessage } from '@kbn/ml-validators'; + import { Callout } from '../../../../../components/callout'; import { ANALYTICS_STEPS } from '../../page'; import { ContinueButton } from '../continue_button'; diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/validation_step/validation_step_wrapper.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/validation_step/validation_step_wrapper.tsx index 3c8cba36458a2..4dbce9dffd632 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/validation_step/validation_step_wrapper.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_creation/components/validation_step/validation_step_wrapper.tsx @@ -13,6 +13,8 @@ import { EuiForm } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { extractErrorMessage } from '@kbn/ml-error-utils'; +import type { CalloutMessage, ValidateAnalyticsJobResponse } from '@kbn/ml-validators'; +import { VALIDATION_STATUS } from '@kbn/ml-validators'; import type { CreateAnalyticsStepProps } from '../../../analytics_management/hooks/use_create_analytics_form'; import { ValidationStep } from './validation_step'; @@ -20,11 +22,6 @@ import { ValidationStepDetails } from './validation_step_details'; import { ANALYTICS_STEPS } from '../../page'; import { useMlApi } from '../../../../../contexts/kibana'; import { getJobConfigFromFormState } from '../../../analytics_management/hooks/use_create_analytics_form/state'; -import type { - CalloutMessage, - ValidateAnalyticsJobResponse, -} from '../../../../../../../common/constants/validation'; -import { VALIDATION_STATUS } from '../../../../../../../common/constants/validation'; export interface ValidationSummary { warning: number; diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/expandable_section/expandable_section_results.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/expandable_section/expandable_section_results.tsx index 212c0fa6d2cf7..cc296a42afbae 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/expandable_section/expandable_section_results.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_exploration/components/expandable_section/expandable_section_results.tsx @@ -39,6 +39,7 @@ import { import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { SEARCH_QUERY_LANGUAGE } from '@kbn/ml-query-utils'; +import { parseInterval } from '@kbn/ml-parse-interval'; import type { useColorRange } from '../../../../../components/color_range_legend'; import { ColorRangeLegend } from '../../../../../components/color_range_legend'; @@ -51,7 +52,6 @@ import { openCustomUrlWindow, } from '../../../../../util/custom_url_utils'; import { replaceStringTokens } from '../../../../../util/string_utils'; -import { parseInterval } from '../../../../../../../common/util/parse_interval'; import type { ExpandableSectionProps } from '.'; import { ExpandableSection, HEADER_ITEMS_LOADING } from '.'; diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/action_edit/edit_action_flyout.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/action_edit/edit_action_flyout.tsx index 77aa8b669011c..4922ae35e81d5 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/action_edit/edit_action_flyout.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/action_edit/edit_action_flyout.tsx @@ -35,11 +35,11 @@ import { type DataFrameAnalyticsConfig, type UpdateDataFrameAnalyticsConfig, } from '@kbn/ml-data-frame-analytics-utils'; +import type { MemoryInputValidatorResult } from '@kbn/ml-validators'; +import { memoryInputValidator } from '@kbn/ml-validators'; import { useMlKibana, useMlApi } from '../../../../../contexts/kibana'; import { useToastNotificationService } from '../../../../../services/toast_notification_service'; -import type { MemoryInputValidatorResult } from '../../../../../../../common/util/validators'; -import { memoryInputValidator } from '../../../../../../../common/util/validators'; import { useRefreshAnalyticsList } from '../../../../common/analytics'; import type { EditAction } from './use_edit_action'; diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/reducer.ts b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/reducer.ts index 8181b6b6360c4..2fd395a5e20c5 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/reducer.ts +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/hooks/use_create_analytics_form/reducer.ts @@ -24,6 +24,14 @@ import { TRAINING_PERCENT_MIN, TRAINING_PERCENT_MAX, } from '@kbn/ml-data-frame-analytics-utils'; +import { + composeValidators, + maxLengthValidator, + memoryInputValidator, + requiredValidator, + JOB_ID_MAX_LENGTH, + ALLOWED_DATA_UNITS, +} from '@kbn/ml-validators'; import { isValidIndexName } from '../../../../../../../common/util/es_utils'; @@ -35,16 +43,6 @@ import { isJobIdValid, validateModelMemoryLimitUnits, } from '../../../../../../../common/util/job_utils'; -import { - composeValidators, - maxLengthValidator, - memoryInputValidator, - requiredValidator, -} from '../../../../../../../common/util/validators'; -import { - JOB_ID_MAX_LENGTH, - ALLOWED_DATA_UNITS, -} from '../../../../../../../common/constants/validation'; import { isAdvancedConfig } from '../../components/action_clone/clone_action_name'; const { collapseLiteralStrings } = XJson; diff --git a/x-pack/plugins/ml/public/application/explorer/explorer_utils.ts b/x-pack/plugins/ml/public/application/explorer/explorer_utils.ts index 90182b07152ad..abe921ee4352e 100644 --- a/x-pack/plugins/ml/public/application/explorer/explorer_utils.ts +++ b/x-pack/plugins/ml/public/application/explorer/explorer_utils.ts @@ -27,6 +27,7 @@ import { import type { InfluencersFilterQuery } from '@kbn/ml-anomaly-utils'; import type { TimeRangeBounds } from '@kbn/ml-time-buckets'; import type { IUiSettingsClient } from '@kbn/core/public'; +import { parseInterval } from '@kbn/ml-parse-interval'; import { ANNOTATIONS_TABLE_DEFAULT_QUERY_SIZE, @@ -39,7 +40,6 @@ import { isModelPlotEnabled, isTimeSeriesViewJob, } from '../../../common/util/job_utils'; -import { parseInterval } from '../../../common/util/parse_interval'; import type { MlJobService } from '../services/job_service'; import type { SwimlaneType } from './explorer_constants'; diff --git a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/datafeed.js b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/datafeed.js index c62907052773c..5f6ba8f6c89be 100644 --- a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/datafeed.js +++ b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/edit_job_flyout/tabs/datafeed.js @@ -17,11 +17,12 @@ import { EuiCallOut, } from '@elastic/eui'; +import { FormattedMessage } from '@kbn/i18n-react'; +import { parseInterval } from '@kbn/ml-parse-interval'; + import { calculateDatafeedFrequencyDefaultSeconds } from '../../../../../../../common/util/job_utils'; import { getNewJobDefaults } from '../../../../../services/ml_server_info'; -import { parseInterval } from '../../../../../../../common/util/parse_interval'; import { MLJobEditor, ML_EDITOR_MODE } from '../../ml_job_editor'; -import { FormattedMessage } from '@kbn/i18n-react'; function getDefaults(bucketSpan, jobDefaults) { const bucketSpanSeconds = bucketSpan !== undefined ? parseInterval(bucketSpan).asSeconds() : ''; diff --git a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/utils.js b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/utils.js index 8e457e8b1e800..57ee1e5f3ef5f 100644 --- a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/utils.js +++ b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/utils.js @@ -6,13 +6,14 @@ */ import { each } from 'lodash'; + import { i18n } from '@kbn/i18n'; +import { parseInterval } from '@kbn/ml-parse-interval'; import { toastNotificationServiceProvider } from '../../../services/toast_notification_service'; import { stringMatch } from '../../../util/string_utils'; import { JOB_STATE, DATAFEED_STATE } from '../../../../../common/constants/states'; import { JOB_ACTION } from '../../../../../common/constants/job_actions'; -import { parseInterval } from '../../../../../common/util/parse_interval'; import { mlCalendarService } from '../../../services/calendar_service'; import { jobCloningService } from '../../../services/job_cloning_service'; import { ML_PAGES } from '../../../../../common/constants/locator'; diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/common/job_creator/job_creator.ts b/x-pack/plugins/ml/public/application/jobs/new_job/common/job_creator/job_creator.ts index 103b789fe66b6..f43fa93368447 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/common/job_creator/job_creator.ts +++ b/x-pack/plugins/ml/public/application/jobs/new_job/common/job_creator/job_creator.ts @@ -7,6 +7,7 @@ import { BehaviorSubject } from 'rxjs'; import { cloneDeep } from 'lodash'; + import { ES_FIELD_TYPES } from '@kbn/field-types'; import type { Query } from '@kbn/es-query'; import type { DataView } from '@kbn/data-views-plugin/public'; @@ -22,6 +23,8 @@ import { import type { RuntimeMappings } from '@kbn/ml-runtime-field-utils'; import type { SavedSearch } from '@kbn/saved-search-plugin/public'; import { isPopulatedObject } from '@kbn/ml-is-populated-object'; +import { parseInterval } from '@kbn/ml-parse-interval'; + import { createDatafeedId } from '../../../../../../common/util/job_utils'; import type { MlApi } from '../../../../services/ml_api_service'; import type { IndexPatternTitle } from '../../../../../../common/types/kibana'; @@ -42,7 +45,6 @@ import type { CREATED_BY_LABEL } from '../../../../../../common/constants/new_jo import { JOB_TYPE, SHARED_RESULTS_INDEX_NAME } from '../../../../../../common/constants/new_job'; import { collectAggs } from './util/general'; import { filterRuntimeMappings } from './util/filter_runtime_mappings'; -import { parseInterval } from '../../../../../../common/util/parse_interval'; import type { Calendar } from '../../../../../../common/types/calendars'; import { mlCalendarService } from '../../../../services/calendar_service'; import { getDatafeedAggregations } from '../../../../../../common/util/datafeed_utils'; diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/common/job_creator/single_metric_job_creator.ts b/x-pack/plugins/ml/public/application/jobs/new_job/common/job_creator/single_metric_job_creator.ts index a90cca5153069..29ce6de6e54d7 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/common/job_creator/single_metric_job_creator.ts +++ b/x-pack/plugins/ml/public/application/jobs/new_job/common/job_creator/single_metric_job_creator.ts @@ -15,8 +15,9 @@ import { ES_AGGREGATION, } from '@kbn/ml-anomaly-utils'; import type { SavedSearch } from '@kbn/saved-search-plugin/public'; +import { parseInterval } from '@kbn/ml-parse-interval'; + import type { MlApi } from '../../../../services/ml_api_service'; -import { parseInterval } from '../../../../../../common/util/parse_interval'; import { JobCreator } from './job_creator'; import type { Job, diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/common/job_validator/util.ts b/x-pack/plugins/ml/public/application/jobs/new_job/common/job_validator/util.ts index 91de9a04043e3..340ab047d6582 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/common/job_validator/util.ts +++ b/x-pack/plugins/ml/public/application/jobs/new_job/common/job_validator/util.ts @@ -5,14 +5,13 @@ * 2.0. */ -import { i18n } from '@kbn/i18n'; import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; + +import { i18n } from '@kbn/i18n'; +import { ALLOWED_DATA_UNITS, JOB_ID_MAX_LENGTH } from '@kbn/ml-validators'; + import type { BasicValidations } from './job_validator'; import type { Job, Datafeed } from '../../../../../../common/types/anomaly_detection_jobs'; -import { - ALLOWED_DATA_UNITS, - JOB_ID_MAX_LENGTH, -} from '../../../../../../common/constants/validation'; import { getNewJobLimits } from '../../../../services/ml_server_info'; import type { ValidationResults } from '../../../../../../common/util/job_utils'; diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/common/results_loader/results_loader.ts b/x-pack/plugins/ml/public/application/jobs/new_job/common/results_loader/results_loader.ts index 0492cb49ebedd..f3d1803415f10 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/common/results_loader/results_loader.ts +++ b/x-pack/plugins/ml/public/application/jobs/new_job/common/results_loader/results_loader.ts @@ -10,8 +10,8 @@ import { BehaviorSubject, lastValueFrom } from 'rxjs'; import type { ML_ANOMALY_SEVERITY } from '@kbn/ml-anomaly-utils'; import { getSeverityType, ES_AGGREGATION } from '@kbn/ml-anomaly-utils'; import type { TimeBuckets } from '@kbn/ml-time-buckets'; +import { parseInterval } from '@kbn/ml-parse-interval'; -import { parseInterval } from '../../../../../../common/util/parse_interval'; import { JOB_TYPE } from '../../../../../../common/constants/new_job'; import type { ModelPlotOutputResults } from '../../../../services/results_service'; diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/advanced_detector_modal/advanced_detector_modal.tsx b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/advanced_detector_modal/advanced_detector_modal.tsx index fbfaceafde822..667840a6ca486 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/advanced_detector_modal/advanced_detector_modal.tsx +++ b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/advanced_detector_modal/advanced_detector_modal.tsx @@ -8,6 +8,7 @@ import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import type { FC } from 'react'; import React, { Fragment, useState, useContext, useEffect } from 'react'; + import type { EuiComboBoxOptionOption } from '@elastic/eui'; import { EuiComboBox, @@ -17,13 +18,15 @@ import { EuiHorizontalRule, EuiTextArea, } from '@elastic/eui'; + import { type Field, type Aggregation, EVENT_RATE_FIELD_ID, mlCategory, } from '@kbn/ml-anomaly-utils'; -import { useFieldStatsTrigger } from '../../../../../../../components/field_stats_flyout/use_field_stats_trigger'; +import { useFieldStatsTrigger } from '@kbn/ml-field-stats-flyout'; + import { JobCreatorContext } from '../../../job_creator_context'; import type { AdvancedJobCreator } from '../../../../../common/job_creator'; import { diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/agg_select/agg_select.tsx b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/agg_select/agg_select.tsx index 4ac460d997e43..257b075ed4511 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/agg_select/agg_select.tsx +++ b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/agg_select/agg_select.tsx @@ -11,9 +11,8 @@ import type { EuiComboBoxOptionOption } from '@elastic/eui'; import { EuiComboBox, EuiFormRow } from '@elastic/eui'; import type { Field, Aggregation, AggFieldPair } from '@kbn/ml-anomaly-utils'; import { EVENT_RATE_FIELD_ID } from '@kbn/ml-anomaly-utils'; -import { FieldStatsInfoButton } from '../../../../../../../components/field_stats_flyout/field_stats_info_button'; +import { useFieldStatsTrigger, FieldStatsInfoButton } from '@kbn/ml-field-stats-flyout'; import { JobCreatorContext } from '../../../job_creator_context'; -import { useFieldStatsTrigger } from '../../../../../../../components/field_stats_flyout/use_field_stats_trigger'; // The display label used for an aggregation e.g. sum(bytes). export type Label = string; diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/categorization_field/categorization_field_select.tsx b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/categorization_field/categorization_field_select.tsx index 8ecdd28113e3e..b2eb7a08d93be 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/categorization_field/categorization_field_select.tsx +++ b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/categorization_field/categorization_field_select.tsx @@ -11,7 +11,8 @@ import type { EuiComboBoxOptionOption } from '@elastic/eui'; import { EuiComboBox } from '@elastic/eui'; import type { Field } from '@kbn/ml-anomaly-utils'; -import { useFieldStatsTrigger } from '../../../../../../../components/field_stats_flyout/use_field_stats_trigger'; +import { useFieldStatsTrigger } from '@kbn/ml-field-stats-flyout'; + import { JobCreatorContext } from '../../../job_creator_context'; import { createFieldOptions } from '../../../../../common/job_creator/util/general'; diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/categorization_partition_field/categorization_per_partition_input.tsx b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/categorization_partition_field/categorization_per_partition_input.tsx index 513522c50bee3..237688b215511 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/categorization_partition_field/categorization_per_partition_input.tsx +++ b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/categorization_partition_field/categorization_per_partition_input.tsx @@ -11,7 +11,7 @@ import type { EuiComboBoxOptionOption } from '@elastic/eui'; import { EuiComboBox } from '@elastic/eui'; import type { Field } from '@kbn/ml-anomaly-utils'; -import { useFieldStatsTrigger } from '../../../../../../../components/field_stats_flyout/use_field_stats_trigger'; +import { useFieldStatsTrigger } from '@kbn/ml-field-stats-flyout'; import { JobCreatorContext } from '../../../job_creator_context'; import { createFieldOptions } from '../../../../../common/job_creator/util/general'; diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/geo_field/geo_field_select.tsx b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/geo_field/geo_field_select.tsx index a22b04ea7f4c9..f40e28f2fea28 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/geo_field/geo_field_select.tsx +++ b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/geo_field/geo_field_select.tsx @@ -10,7 +10,7 @@ import React, { useCallback, useMemo } from 'react'; import type { EuiComboBoxOptionOption } from '@elastic/eui'; import { EuiComboBox } from '@elastic/eui'; import type { Field } from '@kbn/ml-anomaly-utils'; -import { useFieldStatsTrigger } from '../../../../../../../components/field_stats_flyout/use_field_stats_trigger'; +import { useFieldStatsTrigger } from '@kbn/ml-field-stats-flyout'; interface DropDownLabel { label: string; diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/influencers/influencers_select.tsx b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/influencers/influencers_select.tsx index 2894072bacce5..4c0946657d8e6 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/influencers/influencers_select.tsx +++ b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/influencers/influencers_select.tsx @@ -11,7 +11,8 @@ import type { EuiComboBoxOptionOption } from '@elastic/eui'; import { EuiComboBox } from '@elastic/eui'; import type { Field } from '@kbn/ml-anomaly-utils'; -import { useFieldStatsTrigger } from '../../../../../../../components/field_stats_flyout/use_field_stats_trigger'; +import { useFieldStatsTrigger } from '@kbn/ml-field-stats-flyout'; + import { JobCreatorContext } from '../../../job_creator_context'; import { createFieldOptions, diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/rare_field/rare_field_select.tsx b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/rare_field/rare_field_select.tsx index 76d9f63aef828..a834a0d3bbdd4 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/rare_field/rare_field_select.tsx +++ b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/rare_field/rare_field_select.tsx @@ -10,7 +10,7 @@ import React from 'react'; import type { EuiComboBoxOptionOption } from '@elastic/eui'; import { EuiComboBox } from '@elastic/eui'; import type { Field, SplitField } from '@kbn/ml-anomaly-utils'; -import { useFieldStatsTrigger } from '../../../../../../../components/field_stats_flyout/use_field_stats_trigger'; +import { useFieldStatsTrigger } from '@kbn/ml-field-stats-flyout'; interface DropDownLabel { label: string; diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/split_field_select/split_field_select.tsx b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/split_field_select/split_field_select.tsx index 20cf8bbc0a195..d621e85b3f56a 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/split_field_select/split_field_select.tsx +++ b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/split_field_select/split_field_select.tsx @@ -11,7 +11,7 @@ import type { EuiComboBoxOptionOption } from '@elastic/eui'; import { EuiComboBox } from '@elastic/eui'; import type { Field, SplitField } from '@kbn/ml-anomaly-utils'; -import { useFieldStatsTrigger } from '../../../../../../../components/field_stats_flyout/use_field_stats_trigger'; +import { useFieldStatsTrigger } from '@kbn/ml-field-stats-flyout'; interface DropDownLabel { label: string; diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/summary_count_field/summary_count_field_select.tsx b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/summary_count_field/summary_count_field_select.tsx index 9a7826533f082..8fc91b74d1a2c 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/summary_count_field/summary_count_field_select.tsx +++ b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/components/summary_count_field/summary_count_field_select.tsx @@ -11,7 +11,8 @@ import type { EuiComboBoxOptionOption } from '@elastic/eui'; import { EuiComboBox } from '@elastic/eui'; import type { Field } from '@kbn/ml-anomaly-utils'; -import { useFieldStatsTrigger } from '../../../../../../../components/field_stats_flyout/use_field_stats_trigger'; +import { useFieldStatsTrigger } from '@kbn/ml-field-stats-flyout'; + import { JobCreatorContext } from '../../../job_creator_context'; import { createFieldOptions, diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/pick_fields.tsx b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/pick_fields.tsx index 76e35e1d5847d..5f85554470258 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/pick_fields.tsx +++ b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/pick_fields_step/pick_fields.tsx @@ -8,7 +8,8 @@ import type { FC } from 'react'; import React, { Fragment, useContext, useEffect, useState } from 'react'; -import { useFieldStatsFlyoutContext } from '../../../../../components/field_stats_flyout'; +import { useFieldStatsFlyoutContext } from '@kbn/ml-field-stats-flyout'; + import { JobCreatorContext } from '../job_creator_context'; import { WizardNav } from '../wizard_nav'; import type { StepProps } from '../step_types'; diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/pages/new_job/wizard_steps.tsx b/x-pack/plugins/ml/public/application/jobs/new_job/pages/new_job/wizard_steps.tsx index e81650e17c646..6c4600be5d25e 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/pages/new_job/wizard_steps.tsx +++ b/x-pack/plugins/ml/public/application/jobs/new_job/pages/new_job/wizard_steps.tsx @@ -13,9 +13,9 @@ import { FormattedMessage } from '@kbn/i18n-react'; import { EuiSpacer, EuiTitle, EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; import type { FieldStatsServices } from '@kbn/unified-field-list/src/components/field_stats'; +import { FieldStatsFlyoutProvider } from '@kbn/ml-field-stats-flyout'; import { JobCreatorContext } from '../components/job_creator_context'; import { useMlKibana } from '../../../../contexts/kibana'; -import { FieldStatsFlyoutProvider } from '../../../../components/field_stats_flyout'; import { WIZARD_STEPS } from '../components/step_types'; import { TimeRangeStep } from '../components/time_range_step'; diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/recognize/components/edit_job.tsx b/x-pack/plugins/ml/public/application/jobs/new_job/recognize/components/edit_job.tsx index ef036b2abb05f..68093350c1de8 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/recognize/components/edit_job.tsx +++ b/x-pack/plugins/ml/public/application/jobs/new_job/recognize/components/edit_job.tsx @@ -7,6 +7,7 @@ import type { FC } from 'react'; import React, { useEffect, useState } from 'react'; + import { EuiButton, EuiButtonEmpty, @@ -21,12 +22,14 @@ import { EuiSpacer, EuiTitle, } from '@elastic/eui'; + import { FormattedMessage } from '@kbn/i18n-react'; +import { composeValidators, maxLengthValidator } from '@kbn/ml-validators'; +import { JOB_ID_MAX_LENGTH } from '@kbn/ml-validators'; + import type { ModuleJobUI } from '../page'; import { usePartialState } from '../../../../components/custom_hooks'; -import { composeValidators, maxLengthValidator } from '../../../../../../common/util/validators'; import { isJobIdValid } from '../../../../../../common/util/job_utils'; -import { JOB_ID_MAX_LENGTH } from '../../../../../../common/constants/validation'; import { JobGroupsInput } from '../../common/components'; import type { JobOverride } from '../../../../../../common/types/modules'; diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/recognize/components/job_settings_form.tsx b/x-pack/plugins/ml/public/application/jobs/new_job/recognize/components/job_settings_form.tsx index a13664e663e5a..db9d8993f0430 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/recognize/components/job_settings_form.tsx +++ b/x-pack/plugins/ml/public/application/jobs/new_job/recognize/components/job_settings_form.tsx @@ -7,6 +7,7 @@ import type { FC } from 'react'; import React, { useEffect, useState, useCallback, useMemo } from 'react'; + import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import { @@ -21,15 +22,16 @@ import { EuiTextAlign, } from '@elastic/eui'; import { getTimeFilterRange, useTimefilter } from '@kbn/ml-date-picker'; -import { useDataSource } from '../../../../contexts/ml/data_source_context'; -import type { ModuleJobUI } from '../page'; -import { SAVE_STATE } from '../page'; import { composeValidators, maxLengthValidator, patternValidator, -} from '../../../../../../common/util/validators'; -import { JOB_ID_MAX_LENGTH } from '../../../../../../common/constants/validation'; + JOB_ID_MAX_LENGTH, +} from '@kbn/ml-validators'; + +import { useDataSource } from '../../../../contexts/ml/data_source_context'; +import type { ModuleJobUI } from '../page'; +import { SAVE_STATE } from '../page'; import type { TimeRange } from '../../common/components'; import { TimeRangePicker } from '../../common/components'; diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/utils/new_job_utils.ts b/x-pack/plugins/ml/public/application/jobs/new_job/utils/new_job_utils.ts index 531b4ad4d0ac4..e96643c7ba6c1 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/utils/new_job_utils.ts +++ b/x-pack/plugins/ml/public/application/jobs/new_job/utils/new_job_utils.ts @@ -18,28 +18,18 @@ import type { Filter, Query, DataViewBase } from '@kbn/es-query'; import type { IUiSettingsClient } from '@kbn/core/public'; import { getEsQueryConfig } from '@kbn/data-plugin/public'; import type { SavedSearch } from '@kbn/saved-search-plugin/public'; -import { SEARCH_QUERY_LANGUAGE } from '@kbn/ml-query-utils'; +import { getDefaultDSLQuery, SEARCH_QUERY_LANGUAGE } from '@kbn/ml-query-utils'; import { getQueryFromSavedSearchObject } from '../../../util/index_utils'; // Provider for creating the items used for searching and job creation. -const DEFAULT_DSL_QUERY: estypes.QueryDslQueryContainer = { - bool: { - must: [ - { - match_all: {}, - }, - ], - }, -}; - export const DEFAULT_QUERY: Query = { query: '', language: 'lucene', }; export function getDefaultDatafeedQuery() { - return cloneDeep(DEFAULT_DSL_QUERY); + return getDefaultDSLQuery(); } export function getDefaultQuery() { diff --git a/x-pack/plugins/ml/public/application/model_management/deployment_setup.tsx b/x-pack/plugins/ml/public/application/model_management/deployment_setup.tsx index 96152e6726ba8..c62a1122c2d0f 100644 --- a/x-pack/plugins/ml/public/application/model_management/deployment_setup.tsx +++ b/x-pack/plugins/ml/public/application/model_management/deployment_setup.tsx @@ -32,12 +32,8 @@ import type { CoreStart, OverlayStart } from '@kbn/core/public'; import { css } from '@emotion/react'; import { numberValidator } from '@kbn/ml-agg-utils'; import { toMountPoint } from '@kbn/react-kibana-mount'; +import { composeValidators, dictionaryValidator, requiredValidator } from '@kbn/ml-validators'; import { getNewJobLimits, isCloudTrial } from '../services/ml_server_info'; -import { - composeValidators, - dictionaryValidator, - requiredValidator, -} from '../../../common/util/validators'; import type { ModelItem } from './models_list'; import { useEnabledFeatures } from '../contexts/ml'; diff --git a/x-pack/plugins/ml/public/application/services/job_service.js b/x-pack/plugins/ml/public/application/services/job_service.js index 936317675fbbb..3c896e5d00a88 100644 --- a/x-pack/plugins/ml/public/application/services/job_service.js +++ b/x-pack/plugins/ml/public/application/services/job_service.js @@ -7,7 +7,8 @@ import { cloneDeep, each, find, get } from 'lodash'; -import { parseInterval } from '../../../common/util/parse_interval'; +import { parseInterval } from '@kbn/ml-parse-interval'; + import { createDatafeedId } from '../../../common/util/job_utils'; import { isWebUrl } from '../util/url_utils'; diff --git a/x-pack/plugins/ml/public/application/services/ml_api_service/data_frame_analytics.ts b/x-pack/plugins/ml/public/application/services/ml_api_service/data_frame_analytics.ts index e9b2e914fabe3..37709b7474978 100644 --- a/x-pack/plugins/ml/public/application/services/ml_api_service/data_frame_analytics.ts +++ b/x-pack/plugins/ml/public/application/services/ml_api_service/data_frame_analytics.ts @@ -16,15 +16,16 @@ import type { DeleteDataFrameAnalyticsWithIndexStatus, UpdateDataFrameAnalyticsConfig, } from '@kbn/ml-data-frame-analytics-utils'; +import type { ValidateAnalyticsJobResponse } from '@kbn/ml-validators'; import { ML_INTERNAL_BASE_PATH } from '../../../../common/constants/app'; -import type { HttpService } from '../http_service'; -import { useMlKibana } from '../../contexts/kibana'; - -import type { ValidateAnalyticsJobResponse } from '../../../../common/constants/validation'; import type { JobMessage } from '../../../../common/types/audit_message'; import type { PutDataFrameAnalyticsResponseSchema } from '../../../../server/routes/schemas/data_frame_analytics_schema'; +import { useMlKibana } from '../../contexts/kibana'; + +import type { HttpService } from '../http_service'; + export interface GetDataFrameAnalyticsStatsResponseOk { node_failures?: object; count: number; diff --git a/x-pack/plugins/ml/public/application/timeseriesexplorer/components/forecasting_modal/forecasting_modal.js b/x-pack/plugins/ml/public/application/timeseriesexplorer/components/forecasting_modal/forecasting_modal.js index fe6b132635301..5ac0dd68700d6 100644 --- a/x-pack/plugins/ml/public/application/timeseriesexplorer/components/forecasting_modal/forecasting_modal.js +++ b/x-pack/plugins/ml/public/application/timeseriesexplorer/components/forecasting_modal/forecasting_modal.js @@ -19,11 +19,11 @@ import { EuiToolTip } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { context } from '@kbn/kibana-react-plugin/public'; import { extractErrorMessage } from '@kbn/ml-error-utils'; +import { parseInterval } from '@kbn/ml-parse-interval'; import { FORECAST_REQUEST_STATE, JOB_STATE } from '../../../../../common/constants/states'; import { MESSAGE_LEVEL } from '../../../../../common/constants/message_levels'; import { isJobVersionGte } from '../../../../../common/util/job_utils'; -import { parseInterval } from '../../../../../common/util/parse_interval'; import { Modal } from './modal'; import { PROGRESS_STATES } from './progress_states'; import { forecastServiceFactory } from '../../../services/forecast_service'; diff --git a/x-pack/plugins/ml/public/application/util/custom_url_utils.ts b/x-pack/plugins/ml/public/application/util/custom_url_utils.ts index 8e9279688e91f..b71c78d466eb3 100644 --- a/x-pack/plugins/ml/public/application/util/custom_url_utils.ts +++ b/x-pack/plugins/ml/public/application/util/custom_url_utils.ts @@ -18,7 +18,8 @@ import type { MlCustomUrlAnomalyRecordDoc, } from '@kbn/ml-anomaly-utils'; import type { DataGridItem } from '@kbn/ml-data-grid'; -import { parseInterval } from '../../../common/util/parse_interval'; +import { parseInterval } from '@kbn/ml-parse-interval'; + import { escapeForElasticsearchQuery, replaceStringTokens } from './string_utils'; // Value of custom_url time_range property indicating drilldown time range is calculated automatically diff --git a/x-pack/plugins/ml/public/application/util/time_series_explorer_service.ts b/x-pack/plugins/ml/public/application/util/time_series_explorer_service.ts index c0c7995f1b310..a89cac8269b6f 100644 --- a/x-pack/plugins/ml/public/application/util/time_series_explorer_service.ts +++ b/x-pack/plugins/ml/public/application/util/time_series_explorer_service.ts @@ -6,18 +6,19 @@ */ import { useMemo } from 'react'; +import moment from 'moment'; +import type { Observable } from 'rxjs'; +import { forkJoin, of, catchError, map } from 'rxjs'; +import { each, get } from 'lodash'; + import type { IUiSettingsClient } from '@kbn/core/public'; import { aggregationTypeTransform } from '@kbn/ml-anomaly-utils'; import { isMultiBucketAnomaly, ML_JOB_AGGREGATION } from '@kbn/ml-anomaly-utils'; import { extractErrorMessage } from '@kbn/ml-error-utils'; -import moment from 'moment'; -import type { Observable } from 'rxjs'; -import { forkJoin, of } from 'rxjs'; -import { each, get } from 'lodash'; -import { catchError, map } from 'rxjs'; import { type MlAnomalyRecordDoc } from '@kbn/ml-anomaly-utils'; import type { TimeRangeBounds, TimeBucketsInterval } from '@kbn/ml-time-buckets'; -import { parseInterval } from '../../../common/util/parse_interval'; +import { parseInterval } from '@kbn/ml-parse-interval'; + import type { GetAnnotationsResponse } from '../../../common/types/annotations'; import { mlFunctionToESAggregation } from '../../../common/util/job_utils'; import { ANNOTATIONS_TABLE_DEFAULT_QUERY_SIZE } from '../../../common/constants/search'; diff --git a/x-pack/plugins/ml/public/embeddables/common/get_jobs_observable.ts b/x-pack/plugins/ml/public/embeddables/common/get_jobs_observable.ts index e1fc6a6d178c1..d050b40458519 100644 --- a/x-pack/plugins/ml/public/embeddables/common/get_jobs_observable.ts +++ b/x-pack/plugins/ml/public/embeddables/common/get_jobs_observable.ts @@ -8,8 +8,10 @@ import { isEqual } from 'lodash'; import type { Observable } from 'rxjs'; import { catchError, distinctUntilChanged, EMPTY, map, switchMap } from 'rxjs'; + +import { parseInterval } from '@kbn/ml-parse-interval'; + import type { JobId } from '../../../common/types/anomaly_detection_jobs'; -import { parseInterval } from '../../../common/util/parse_interval'; import type { ExplorerJob } from '../../application/explorer/explorer_utils'; import type { AnomalyDetectorService } from '../../application/services/anomaly_detector_service'; diff --git a/x-pack/plugins/ml/public/embeddables/job_creation/common/job_details.tsx b/x-pack/plugins/ml/public/embeddables/job_creation/common/job_details.tsx index 3bfa1a0caf799..0e843da22a74b 100644 --- a/x-pack/plugins/ml/public/embeddables/job_creation/common/job_details.tsx +++ b/x-pack/plugins/ml/public/embeddables/job_creation/common/job_details.tsx @@ -31,12 +31,13 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import { extractErrorMessage } from '@kbn/ml-error-utils'; import type { TimeRange } from '@kbn/es-query'; +import { JOB_ID_MAX_LENGTH } from '@kbn/ml-validators'; + import type { QuickLensJobCreator } from '../../../application/jobs/new_job/job_from_lens'; import type { LayerResult } from '../../../application/jobs/new_job/job_from_lens'; import type { CreateState } from '../../../application/jobs/new_job/job_from_dashboard'; import { JOB_TYPE, DEFAULT_BUCKET_SPAN } from '../../../../common/constants/new_job'; import { basicJobValidation } from '../../../../common/util/job_utils'; -import { JOB_ID_MAX_LENGTH } from '../../../../common/constants/validation'; import { invalidTimeIntervalMessage } from '../../../application/jobs/new_job/common/job_validator/util'; import { ML_APP_LOCATOR, ML_PAGES } from '../../../../common/constants/locator'; import { useMlFromLensKibanaContext } from './context'; diff --git a/x-pack/plugins/ml/public/index.ts b/x-pack/plugins/ml/public/index.ts index bf293e2228570..d18b4f60a085f 100755 --- a/x-pack/plugins/ml/public/index.ts +++ b/x-pack/plugins/ml/public/index.ts @@ -41,15 +41,5 @@ export { CONTROLLED_BY_SWIM_LANE_FILTER } from './ui_actions/constants'; export type { MlLocator } from './locator'; export { useMlHref, ML_PAGES, MlLocatorDefinition } from './locator'; -// Bundled shared exports -// Exported this way so the code doesn't end up in ML's page load bundle -export const getMlSharedImports = async () => { - return await import('./shared'); -}; - -// Helper to get Type returned by getMlSharedImports. -type AwaitReturnType = T extends PromiseLike ? U : T; -export type GetMlSharedImportsReturnType = AwaitReturnType>; - export { MLJobsAwaitingNodeWarning } from './application/components/jobs_awaiting_node_warning/new_job_awaiting_node_shared'; export { MlNodeAvailableWarningShared } from './application/components/node_available_warning'; diff --git a/x-pack/plugins/ml/public/shared.ts b/x-pack/plugins/ml/public/shared.ts deleted file mode 100644 index fec15f3181a84..0000000000000 --- a/x-pack/plugins/ml/public/shared.ts +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export { FieldStatsInfoButton } from './application/components/field_stats_flyout/field_stats_info_button'; -export { useFieldStatsTrigger } from './application/components/field_stats_flyout/use_field_stats_trigger'; -export { FieldStatsFlyoutProvider } from './application/components/field_stats_flyout/field_stats_flyout_provider'; -export { useFieldStatsFlyoutContext } from './application/components/field_stats_flyout/use_field_stats_flytout_context'; diff --git a/x-pack/plugins/ml/server/lib/alerts/jobs_health_service.ts b/x-pack/plugins/ml/server/lib/alerts/jobs_health_service.ts index 5e79e0f460b73..1e60dc1aeb3cf 100644 --- a/x-pack/plugins/ml/server/lib/alerts/jobs_health_service.ts +++ b/x-pack/plugins/ml/server/lib/alerts/jobs_health_service.ts @@ -6,11 +6,14 @@ */ import { groupBy, keyBy, memoize, partition } from 'lodash'; + import type { KibanaRequest, Logger, SavedObjectsClientContract } from '@kbn/core/server'; import { i18n } from '@kbn/i18n'; import type { MlJob } from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import { isDefined } from '@kbn/ml-is-defined'; import { ALERT_REASON } from '@kbn/rule-data-utils'; +import { parseInterval } from '@kbn/ml-parse-interval'; + import type { MlClient } from '../ml_client'; import type { JobSelection } from '../../routes/schemas/alerting_schema'; import { datafeedsProvider, type DatafeedsService } from '../../models/job_service/datafeeds'; @@ -39,7 +42,6 @@ import { } from '../../../common/util/alerts'; import type { AnnotationService } from '../../models/annotation_service/annotation'; import { annotationServiceProvider } from '../../models/annotation_service'; -import { parseInterval } from '../../../common/util/parse_interval'; import { jobAuditMessagesProvider, type JobAuditMessagesService, diff --git a/x-pack/plugins/ml/server/models/data_frame_analytics/validation.ts b/x-pack/plugins/ml/server/models/data_frame_analytics/validation.ts index d82b52920dbc6..515de87e79c56 100644 --- a/x-pack/plugins/ml/server/models/data_frame_analytics/validation.ts +++ b/x-pack/plugins/ml/server/models/data_frame_analytics/validation.ts @@ -27,7 +27,7 @@ import { TRAINING_DOCS_LOWER, TRAINING_DOCS_UPPER, VALIDATION_STATUS, -} from '../../../common/constants/validation'; +} from '@kbn/ml-validators'; interface MissingAgg { [key: string]: { diff --git a/x-pack/plugins/ml/server/models/fields_service/fields_service.ts b/x-pack/plugins/ml/server/models/fields_service/fields_service.ts index a7e1812888c2f..95e97ef01e3b3 100644 --- a/x-pack/plugins/ml/server/models/fields_service/fields_service.ts +++ b/x-pack/plugins/ml/server/models/fields_service/fields_service.ts @@ -5,14 +5,16 @@ * 2.0. */ -import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; import Boom from '@hapi/boom'; -import type { IScopedClusterClient } from '@kbn/core/server'; import { duration } from 'moment'; + +import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey'; +import type { IScopedClusterClient } from '@kbn/core/server'; import type { AggCardinality } from '@kbn/ml-agg-utils'; import { isPopulatedObject } from '@kbn/ml-is-populated-object'; import type { RuntimeMappings } from '@kbn/ml-runtime-field-utils'; -import { parseInterval } from '../../../common/util/parse_interval'; +import { parseInterval } from '@kbn/ml-parse-interval'; + import { initCardinalityFieldsCache } from './fields_aggs_cache'; import { isValidAggregationField } from '../../../common/util/validation_utils'; import { getDatafeedAggregations } from '../../../common/util/datafeed_utils'; diff --git a/x-pack/plugins/ml/server/models/job_service/jobs.ts b/x-pack/plugins/ml/server/models/job_service/jobs.ts index 172d5d1b7e582..9c4ea6b1d3307 100644 --- a/x-pack/plugins/ml/server/models/job_service/jobs.ts +++ b/x-pack/plugins/ml/server/models/job_service/jobs.ts @@ -7,9 +7,12 @@ import { uniq } from 'lodash'; import Boom from '@hapi/boom'; + import type { IScopedClusterClient } from '@kbn/core/server'; import type { RulesClient } from '@kbn/alerting-plugin/server'; import { isPopulatedObject } from '@kbn/ml-is-populated-object'; +import { parseInterval } from '@kbn/ml-parse-interval'; + import { getSingleMetricViewerJobErrorMessage, parseTimeIntervalForJob, @@ -52,7 +55,6 @@ import type { MlClient } from '../../lib/ml_client'; import { ML_ALERT_TYPES } from '../../../common/constants/alerts'; import type { MlAnomalyDetectionAlertParams } from '../../routes/schemas/alerting_schema'; import type { AuthorizationHeader } from '../../lib/request_authorization'; -import { parseInterval } from '../../../common/util/parse_interval'; interface Results { [id: string]: { diff --git a/x-pack/plugins/ml/server/models/job_validation/job_validation.ts b/x-pack/plugins/ml/server/models/job_validation/job_validation.ts index da751c9d33be4..fff24e7730f18 100644 --- a/x-pack/plugins/ml/server/models/job_validation/job_validation.ts +++ b/x-pack/plugins/ml/server/models/job_validation/job_validation.ts @@ -6,12 +6,14 @@ */ import Boom from '@hapi/boom'; + import type { IScopedClusterClient } from '@kbn/core/server'; import type { TypeOf } from '@kbn/config-schema'; +import { VALIDATION_STATUS } from '@kbn/ml-validators'; + import { fieldsServiceProvider } from '../fields_service'; import type { MessageId, JobValidationMessage } from '../../../common/constants/messages'; import { getMessages } from '../../../common/constants/messages'; -import { VALIDATION_STATUS } from '../../../common/constants/validation'; import { basicJobValidation, uniqWithIsEqual } from '../../../common/util/job_utils'; import { validateBucketSpan } from './validate_bucket_span'; diff --git a/x-pack/plugins/ml/server/models/job_validation/validate_bucket_span.js b/x-pack/plugins/ml/server/models/job_validation/validate_bucket_span.js index 75b1b98213036..bd3ab7c7e8769 100644 --- a/x-pack/plugins/ml/server/models/job_validation/validate_bucket_span.js +++ b/x-pack/plugins/ml/server/models/job_validation/validate_bucket_span.js @@ -5,9 +5,10 @@ * 2.0. */ +import { SKIP_BUCKET_SPAN_ESTIMATION } from '@kbn/ml-validators'; + import { estimateBucketSpanFactory } from '../bucket_span_estimator'; import { mlFunctionToESAggregation, parseTimeIntervalForJob } from '../../../common/util/job_utils'; -import { SKIP_BUCKET_SPAN_ESTIMATION } from '../../../common/constants/validation'; import { validateJobObject } from './validate_job_object'; diff --git a/x-pack/plugins/ml/server/models/job_validation/validate_bucket_span.test.ts b/x-pack/plugins/ml/server/models/job_validation/validate_bucket_span.test.ts index b660e6f8040c0..c8827be8bad2c 100644 --- a/x-pack/plugins/ml/server/models/job_validation/validate_bucket_span.test.ts +++ b/x-pack/plugins/ml/server/models/job_validation/validate_bucket_span.test.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { SKIP_BUCKET_SPAN_ESTIMATION } from '../../../common/constants/validation'; +import { SKIP_BUCKET_SPAN_ESTIMATION } from '@kbn/ml-validators'; import type { JobValidationMessage } from '../../../common/constants/messages'; // @ts-ignore diff --git a/x-pack/plugins/ml/server/models/job_validation/validate_model_memory_limit.ts b/x-pack/plugins/ml/server/models/job_validation/validate_model_memory_limit.ts index c22c514db73d6..85ce1cd8d3427 100644 --- a/x-pack/plugins/ml/server/models/job_validation/validate_model_memory_limit.ts +++ b/x-pack/plugins/ml/server/models/job_validation/validate_model_memory_limit.ts @@ -6,11 +6,13 @@ */ import numeral from '@elastic/numeral'; + import type { IScopedClusterClient } from '@kbn/core/server'; +import { ALLOWED_DATA_UNITS } from '@kbn/ml-validators'; + import type { CombinedJob } from '../../../common/types/anomaly_detection_jobs'; import { validateJobObject } from './validate_job_object'; import { calculateModelMemoryLimitProvider } from '../calculate_model_memory_limit'; -import { ALLOWED_DATA_UNITS } from '../../../common/constants/validation'; import type { MlClient } from '../../lib/ml_client'; // The minimum value the backend expects is 1MByte diff --git a/x-pack/plugins/ml/server/models/job_validation/validate_time_range.ts b/x-pack/plugins/ml/server/models/job_validation/validate_time_range.ts index 0c6af17a4a069..de9f624485bb7 100644 --- a/x-pack/plugins/ml/server/models/job_validation/validate_time_range.ts +++ b/x-pack/plugins/ml/server/models/job_validation/validate_time_range.ts @@ -7,7 +7,8 @@ import type { IScopedClusterClient } from '@kbn/core/server'; import { ES_FIELD_TYPES } from '@kbn/field-types'; -import { parseInterval } from '../../../common/util/parse_interval'; +import { parseInterval } from '@kbn/ml-parse-interval'; + import type { CombinedJob } from '../../../common/types/anomaly_detection_jobs'; import { validateJobObject } from './validate_job_object'; diff --git a/x-pack/plugins/ml/server/models/results_service/anomaly_charts.ts b/x-pack/plugins/ml/server/models/results_service/anomaly_charts.ts index 7e551b0624261..1690e2db74164 100644 --- a/x-pack/plugins/ml/server/models/results_service/anomaly_charts.ts +++ b/x-pack/plugins/ml/server/models/results_service/anomaly_charts.ts @@ -26,6 +26,8 @@ import { ML_JOB_AGGREGATION, } from '@kbn/ml-anomaly-utils'; import { isRuntimeMappings } from '@kbn/ml-runtime-field-utils'; +import { parseInterval } from '@kbn/ml-parse-interval'; + import type { MlClient } from '../../lib/ml_client'; import type { MetricData, @@ -48,7 +50,6 @@ import { } from '../../../common/util/job_utils'; import type { CriteriaField } from './results_service'; import type { CombinedJob, Datafeed } from '../../shared'; -import { parseInterval } from '../../../common/util/parse_interval'; import { getDatafeedAggregations } from '../../../common/util/datafeed_utils'; import { findAggField } from '../../../common/util/validation_utils'; diff --git a/x-pack/plugins/ml/tsconfig.json b/x-pack/plugins/ml/tsconfig.json index 2f980378de923..b625562ab2674 100644 --- a/x-pack/plugins/ml/tsconfig.json +++ b/x-pack/plugins/ml/tsconfig.json @@ -37,7 +37,6 @@ "@kbn/data-plugin", "@kbn/data-views-plugin", "@kbn/data-visualizer-plugin", - "@kbn/datemath", "@kbn/embeddable-plugin", "@kbn/es-query", "@kbn/es-types", @@ -70,7 +69,6 @@ "@kbn/ml-trained-models-utils", "@kbn/ml-url-state", "@kbn/monaco", - "@kbn/react-field", "@kbn/rison", "@kbn/saved-objects-finder-plugin", "@kbn/saved-objects-management-plugin", @@ -130,6 +128,9 @@ "@kbn/esql-utils", "@kbn/core-lifecycle-browser", "@kbn/observability-ai-assistant-plugin", - "@kbn/json-schemas" + "@kbn/json-schemas", + "@kbn/ml-field-stats-flyout", + "@kbn/ml-parse-interval", + "@kbn/ml-validators" ] } diff --git a/x-pack/plugins/transform/kibana.jsonc b/x-pack/plugins/transform/kibana.jsonc index 499206b4db924..1f8ab0fe72f40 100644 --- a/x-pack/plugins/transform/kibana.jsonc +++ b/x-pack/plugins/transform/kibana.jsonc @@ -40,7 +40,6 @@ "discover", "kibanaUtils", "kibanaReact", - "ml" ], "extraPublicDirs": [ "common" diff --git a/x-pack/plugins/transform/public/app/__mocks__/app_dependencies.tsx b/x-pack/plugins/transform/public/app/__mocks__/app_dependencies.tsx index 6af01088b70db..e0536a3e1b4d6 100644 --- a/x-pack/plugins/transform/public/app/__mocks__/app_dependencies.tsx +++ b/x-pack/plugins/transform/public/app/__mocks__/app_dependencies.tsx @@ -5,7 +5,6 @@ * 2.0. */ -import { useContext } from 'react'; import { of } from 'rxjs'; import type { IKibanaSearchResponse, @@ -25,8 +24,6 @@ import { savedSearchPluginMock } from '@kbn/saved-search-plugin/public/mocks'; import { contentManagementMock } from '@kbn/content-management-plugin/public/mocks'; import type { AppDependencies } from '../app_dependencies'; -import { MlSharedContext } from './shared_context'; -import type { GetMlSharedImportsReturnType } from '../../shared_imports'; import type { SavedObjectsManagementPluginStart } from '@kbn/saved-objects-management-plugin/public'; import { settingsServiceMock } from '@kbn/core-ui-settings-browser-mocks'; import { unifiedSearchPluginMock } from '@kbn/unified-search-plugin/public/mocks'; @@ -88,7 +85,6 @@ const appDependencies: AppDependencies = { http: coreSetup.http, history: {} as ScopedHistory, share: { urlGenerators: { getUrlGenerator: jest.fn() } } as unknown as SharePluginStart, - ml: {} as GetMlSharedImportsReturnType, triggersActionsUi: {} as jest.Mocked, unifiedSearch: unifiedSearchPluginMock.createStartContract(), savedObjectsManagement: {} as jest.Mocked, @@ -98,8 +94,7 @@ const appDependencies: AppDependencies = { }; export const useAppDependencies = () => { - const ml = useContext(MlSharedContext); - return { ...appDependencies, ml }; + return appDependencies; }; export const useToastNotifications = () => { diff --git a/x-pack/plugins/transform/public/app/__mocks__/shared_context.ts b/x-pack/plugins/transform/public/app/__mocks__/shared_context.ts deleted file mode 100644 index 33e43ee54cee7..0000000000000 --- a/x-pack/plugins/transform/public/app/__mocks__/shared_context.ts +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { createContext } from 'react'; - -import type { GetMlSharedImportsReturnType } from '../../shared_imports'; - -// This code is a workaround to provide dependencies that are -// loaded dynamically during runtime. -export const MlSharedContext = createContext({} as GetMlSharedImportsReturnType); diff --git a/x-pack/plugins/transform/public/app/app_dependencies.tsx b/x-pack/plugins/transform/public/app/app_dependencies.tsx index 1f8b2373f0f7d..9033540ee0d4c 100644 --- a/x-pack/plugins/transform/public/app/app_dependencies.tsx +++ b/x-pack/plugins/transform/public/app/app_dependencies.tsx @@ -37,7 +37,6 @@ import type { FieldFormatsStart } from '@kbn/field-formats-plugin/public'; import type { SavedObjectsManagementPluginStart } from '@kbn/saved-objects-management-plugin/public'; import type { SettingsStart } from '@kbn/core-ui-settings-browser'; import type { DataViewEditorStart } from '@kbn/data-view-editor-plugin/public'; -import type { GetMlSharedImportsReturnType } from '../shared_imports'; export interface AppDependencies { analytics: AnalyticsServiceStart; @@ -60,7 +59,6 @@ export interface AppDependencies { theme: ThemeServiceStart; history: ScopedHistory; share: SharePluginStart; - ml: GetMlSharedImportsReturnType; spaces?: SpacesPluginStart; triggersActionsUi: TriggersAndActionsUIPublicPluginStart; unifiedSearch: UnifiedSearchPublicPluginStart; diff --git a/x-pack/plugins/transform/public/app/common/aggregations.ts b/x-pack/plugins/transform/public/app/common/aggregations.ts index 50582d2f278ea..3fd41f1dd4111 100644 --- a/x-pack/plugins/transform/public/app/common/aggregations.ts +++ b/x-pack/plugins/transform/public/app/common/aggregations.ts @@ -5,7 +5,7 @@ * 2.0. */ -import { composeValidators, patternValidator } from '../../../common/shared_imports'; +import { composeValidators, patternValidator } from '@kbn/ml-validators'; import type { AggName } from '../../../common/types/aggregations'; diff --git a/x-pack/plugins/transform/public/app/components/toast_notification_text.test.tsx b/x-pack/plugins/transform/public/app/components/toast_notification_text.test.tsx index f3781bc97b4aa..c058bc521653e 100644 --- a/x-pack/plugins/transform/public/app/components/toast_notification_text.test.tsx +++ b/x-pack/plugins/transform/public/app/components/toast_notification_text.test.tsx @@ -13,7 +13,6 @@ import { themeServiceMock } from '@kbn/core/public/mocks'; import { ToastNotificationText } from './toast_notification_text'; -jest.mock('../../shared_imports'); jest.mock('../app_dependencies'); describe('ToastNotificationText', () => { diff --git a/x-pack/plugins/transform/public/app/hooks/use_index_data.test.tsx b/x-pack/plugins/transform/public/app/hooks/use_index_data.test.tsx index 52fc601db27fc..ee7e2ca1e7256 100644 --- a/x-pack/plugins/transform/public/app/hooks/use_index_data.test.tsx +++ b/x-pack/plugins/transform/public/app/hooks/use_index_data.test.tsx @@ -16,16 +16,11 @@ import { DataGrid, type UseIndexDataReturnType } from '@kbn/ml-data-grid'; import type { RuntimeMappings } from '@kbn/ml-runtime-field-utils'; import type { SimpleQuery } from '@kbn/ml-query-utils'; -import { getMlSharedImports } from '../../shared_imports'; - import type { SearchItems } from './use_search_items'; import { useIndexData } from './use_index_data'; -jest.mock('../../shared_imports'); jest.mock('../app_dependencies'); -import { MlSharedContext } from '../__mocks__/shared_context'; - const query: SimpleQuery = { query_string: { query: '*', @@ -46,12 +41,9 @@ const queryClient = new QueryClient(); describe('Transform: useIndexData()', () => { test('dataView set triggers loading', async () => { - const mlShared = await getMlSharedImports(); const wrapper: FC> = ({ children }) => ( - - {children} - + {children} ); @@ -87,8 +79,6 @@ describe('Transform: with useIndexData()', () => { fields: [] as any[], } as SearchItems['dataView']; - const mlSharedImports = await getMlSharedImports(); - const Wrapper = () => { const props = { ...useIndexData(dataView, { match_all: {} }, runtimeMappings), @@ -105,9 +95,7 @@ describe('Transform: with useIndexData()', () => { render( - - - + ); @@ -129,8 +117,6 @@ describe('Transform: with useIndexData()', () => { fields: [] as any[], } as SearchItems['dataView']; - const mlSharedImports = await getMlSharedImports(); - const Wrapper = () => { const props = { ...useIndexData(dataView, { match_all: {} }, runtimeMappings), @@ -147,9 +133,7 @@ describe('Transform: with useIndexData()', () => { render( - - - + ); diff --git a/x-pack/plugins/transform/public/app/mount_management_section.ts b/x-pack/plugins/transform/public/app/mount_management_section.ts index 8d59c9ce2d0f2..35ae95feb9a44 100644 --- a/x-pack/plugins/transform/public/app/mount_management_section.ts +++ b/x-pack/plugins/transform/public/app/mount_management_section.ts @@ -11,7 +11,6 @@ import { Storage } from '@kbn/kibana-utils-plugin/public'; import { type TransformEnabledFeatures } from './serverless_context'; import type { PluginsDependencies } from '../plugin'; -import { getMlSharedImports } from '../shared_imports'; import type { ExperimentalFeatures } from '../../server/config'; import type { AppDependencies } from './app_dependencies'; @@ -87,7 +86,6 @@ export async function mountManagementSection( history, share, spaces, - ml: await getMlSharedImports(), triggersActionsUi, unifiedSearch, charts, diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/pivot_configuration/pivot_configuration.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/pivot_configuration/pivot_configuration.tsx index ed63b8791be59..798837a1a693f 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/pivot_configuration/pivot_configuration.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/pivot_configuration/pivot_configuration.tsx @@ -11,10 +11,10 @@ import React, { memo, createContext, useMemo } from 'react'; import { EuiFormRow, type EuiComboBoxOptionOption } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; +import { useFieldStatsTrigger, FieldStatsInfoButton } from '@kbn/ml-field-stats-flyout'; import { type DropDownOptionWithField } from '../step_define/common/get_pivot_dropdown_options'; import type { DropDownOption } from '../../../../common'; -import { useAppDependencies } from '../../../../app_dependencies'; import { AggListForm } from '../aggregation_list'; import { DropDown } from '../aggregation_dropdown'; import { GroupByListForm } from '../group_by_list'; @@ -26,9 +26,6 @@ export const PivotConfigurationContext = createContext< export const PivotConfiguration: FC = memo( ({ actions, state }) => { - const { - ml: { useFieldStatsTrigger, FieldStatsInfoButton }, - } = useAppDependencies(); const { handleFieldStatsButtonClick, closeFlyout, renderOption, populatedFields } = useFieldStatsTrigger(); @@ -64,7 +61,7 @@ export const PivotConfiguration: FC = memo( }; return aggOption; }), - [aggOptions, FieldStatsInfoButton, handleFieldStatsButtonClick, populatedFields] + [aggOptions, handleFieldStatsButtonClick, populatedFields] ); return ( diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_create/step_create_form.test.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_create/step_create_form.test.tsx index 6ce8984a8230c..f045d553abb6c 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_create/step_create_form.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_create/step_create_form.test.tsx @@ -12,7 +12,6 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import type { StepCreateFormProps } from './step_create_form'; import { StepCreateForm } from './step_create_form'; -jest.mock('../../../../../shared_imports'); jest.mock('../../../../app_dependencies'); describe('Transform: ', () => { diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/latest_function_form.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/latest_function_form.tsx index f97b6cda583a5..9ded43a82c71a 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/latest_function_form.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/latest_function_form.tsx @@ -10,7 +10,7 @@ import React, { type FC } from 'react'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import { EuiButtonIcon, EuiCallOut, EuiComboBox, EuiCopy, EuiFormRow } from '@elastic/eui'; -import { useAppDependencies } from '../../../../app_dependencies'; +import { useFieldStatsTrigger } from '@kbn/ml-field-stats-flyout'; import type { LatestFunctionService } from './hooks/use_latest_function_config'; interface LatestFunctionFormProps { @@ -24,9 +24,6 @@ export const LatestFunctionForm: FC = ({ copyToClipboardDescription, latestFunctionService, }) => { - const { - ml: { useFieldStatsTrigger }, - } = useAppDependencies(); const { renderOption, closeFlyout } = useFieldStatsTrigger(); return ( <> diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.test.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.test.tsx index fa1ce2f2c7e99..7490493bcfe56 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.test.tsx @@ -25,11 +25,8 @@ import type { SearchItems } from '../../../../hooks/use_search_items'; import { getAggNameConflictToastMessages } from './common'; import { StepDefineForm } from './step_define_form'; -import { MlSharedContext } from '../../../../__mocks__/shared_context'; -import { getMlSharedImports } from '../../../../../shared_imports'; import { unifiedSearchPluginMock } from '@kbn/unified-search-plugin/public/mocks'; -jest.mock('../../../../../shared_imports'); jest.mock('../../../../app_dependencies'); const startMock = coreMock.createStart(); @@ -66,7 +63,6 @@ describe('Transform: ', () => { test('Minimal initialization', async () => { // Arrange const queryClient = new QueryClient(); - const mlSharedImports = await getMlSharedImports(); const searchItems = { dataView: { @@ -90,11 +86,9 @@ describe('Transform: ', () => { - - - - - + + + diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx index ac8ccabc539cb..84ca627904a51 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_form.tsx @@ -35,6 +35,7 @@ import { } from '@kbn/ml-date-picker'; import { useStorage } from '@kbn/ml-local-storage'; import { useUrlState } from '@kbn/ml-url-state'; +import { useFieldStatsFlyoutContext } from '@kbn/ml-field-stats-flyout'; import type { PivotAggDict } from '../../../../../../common/types/pivot_aggs'; import type { PivotGroupByDict } from '../../../../../../common/types/pivot_group_by'; @@ -59,7 +60,7 @@ import { getPreviewTransformRequestBody } from '../../../../common'; import { useDocumentationLinks } from '../../../../hooks/use_documentation_links'; import { useIndexData } from '../../../../hooks/use_index_data'; import { useTransformConfigData } from '../../../../hooks/use_transform_config_data'; -import { useAppDependencies, useToastNotifications } from '../../../../app_dependencies'; +import { useToastNotifications } from '../../../../app_dependencies'; import type { SearchItems } from '../../../../hooks/use_search_items'; import { getAggConfigFromEsAgg } from '../../../../common/pivot_aggs'; @@ -124,11 +125,6 @@ export const StepDefineForm: FC = React.memo((props) => { const { transformConfigQuery } = stepDefineForm.searchBar.state; const { runtimeMappings } = stepDefineForm.runtimeMappingsEditor.state; - const appDependencies = useAppDependencies(); - const { - ml: { useFieldStatsFlyoutContext }, - } = appDependencies; - const fieldStatsContext = useFieldStatsFlyoutContext(); const indexPreviewProps = { ...useIndexData( diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_summary.test.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_summary.test.tsx index 8fef5cf0b934d..28efd40ad03fd 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_summary.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/step_define/step_define_summary.test.tsx @@ -18,18 +18,13 @@ import type { SearchItems } from '../../../../hooks/use_search_items'; import type { StepDefineExposedState } from './common'; import { StepDefineSummary } from './step_define_summary'; -jest.mock('../../../../../shared_imports'); jest.mock('../../../../app_dependencies'); -import { MlSharedContext } from '../../../../__mocks__/shared_context'; -import { getMlSharedImports } from '../../../../../shared_imports'; - describe('Transform: ', () => { // Using the async/await wait()/done() pattern to avoid act() errors. test('Minimal initialization', async () => { // Arrange const queryClient = new QueryClient(); - const mlSharedImports = await getMlSharedImports(); const searchItems = { dataView: { @@ -78,9 +73,7 @@ describe('Transform: ', () => { const { queryByText } = render( - - - + ); diff --git a/x-pack/plugins/transform/public/app/sections/create_transform/components/wizard/wizard.tsx b/x-pack/plugins/transform/public/app/sections/create_transform/components/wizard/wizard.tsx index 606a027f4542a..ab2865b85eb8a 100644 --- a/x-pack/plugins/transform/public/app/sections/create_transform/components/wizard/wizard.tsx +++ b/x-pack/plugins/transform/public/app/sections/create_transform/components/wizard/wizard.tsx @@ -20,6 +20,7 @@ import { UrlStateProvider } from '@kbn/ml-url-state'; import { UI_SETTINGS } from '@kbn/data-plugin/common'; import type { FieldStatsServices } from '@kbn/unified-field-list/src/components/field_stats'; import type { RuntimeMappings } from '@kbn/ml-runtime-field-utils'; +import { FieldStatsFlyoutProvider } from '@kbn/ml-field-stats-flyout'; import { useEnabledFeatures } from '../../../../serverless_context'; import type { TransformConfigUnion } from '../../../../../../common/types/transform'; @@ -110,13 +111,7 @@ export const CreateTransformWizardContext = createContext<{ export const Wizard: FC = React.memo(({ cloneConfig, searchItems }) => { const { showNodeInfo } = useEnabledFeatures(); const appDependencies = useAppDependencies(); - const { - ml: { FieldStatsFlyoutProvider }, - uiSettings, - data, - fieldFormats, - charts, - } = appDependencies; + const { uiSettings, data, fieldFormats, charts } = appDependencies; const { dataView } = searchItems; // The current WIZARD_STEP diff --git a/x-pack/plugins/transform/public/app/sections/transform_management/components/action_delete/delete_action_name.test.tsx b/x-pack/plugins/transform/public/app/sections/transform_management/components/action_delete/delete_action_name.test.tsx index cf4e6aef4e537..d5caa80792b0e 100644 --- a/x-pack/plugins/transform/public/app/sections/transform_management/components/action_delete/delete_action_name.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/transform_management/components/action_delete/delete_action_name.test.tsx @@ -11,7 +11,6 @@ import { render } from '@testing-library/react'; import type { DeleteActionNameProps } from './delete_action_name'; import { DeleteActionName } from './delete_action_name'; -jest.mock('../../../../../shared_imports'); jest.mock('../../../../app_dependencies'); describe('Transform: Transform List Actions ', () => { diff --git a/x-pack/plugins/transform/public/app/sections/transform_management/components/action_discover/discover_action_name.test.tsx b/x-pack/plugins/transform/public/app/sections/transform_management/components/action_discover/discover_action_name.test.tsx index 0717dea8a4d0d..b4dbcad166583 100644 --- a/x-pack/plugins/transform/public/app/sections/transform_management/components/action_discover/discover_action_name.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/transform_management/components/action_discover/discover_action_name.test.tsx @@ -16,7 +16,6 @@ import { isDiscoverActionDisabled, DiscoverActionName } from './discover_action_ import transformListRow from '../../../../common/__mocks__/transform_list_row.json'; import type { TransformListRowWithStats } from '../../../../common/transform_list'; -jest.mock('../../../../../shared_imports'); jest.mock('../../../../app_dependencies'); // @ts-expect-error mock data is too loosely typed diff --git a/x-pack/plugins/transform/public/app/sections/transform_management/components/action_start/start_action_name.test.tsx b/x-pack/plugins/transform/public/app/sections/transform_management/components/action_start/start_action_name.test.tsx index 9a1a7b2e77cb2..4f3bd2a87f919 100644 --- a/x-pack/plugins/transform/public/app/sections/transform_management/components/action_start/start_action_name.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/transform_management/components/action_start/start_action_name.test.tsx @@ -15,7 +15,6 @@ import { StartActionName } from './start_action_name'; import transformListRow from '../../../../common/__mocks__/transform_list_row.json'; -jest.mock('../../../../../shared_imports'); jest.mock('../../../../app_dependencies'); const queryClient = new QueryClient(); diff --git a/x-pack/plugins/transform/public/app/sections/transform_management/components/action_stop/stop_action_name.test.tsx b/x-pack/plugins/transform/public/app/sections/transform_management/components/action_stop/stop_action_name.test.tsx index c7118b9d4150c..0ef47ae51debc 100644 --- a/x-pack/plugins/transform/public/app/sections/transform_management/components/action_stop/stop_action_name.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/transform_management/components/action_stop/stop_action_name.test.tsx @@ -15,7 +15,6 @@ import { StopActionName } from './stop_action_name'; import transformListRow from '../../../../common/__mocks__/transform_list_row.json'; -jest.mock('../../../../../shared_imports'); jest.mock('../../../../app_dependencies'); const queryClient = new QueryClient(); diff --git a/x-pack/plugins/transform/public/app/sections/transform_management/components/create_transform_button/create_transform_button.test.tsx b/x-pack/plugins/transform/public/app/sections/transform_management/components/create_transform_button/create_transform_button.test.tsx index 644971bc32931..fceb52cb0cd4e 100644 --- a/x-pack/plugins/transform/public/app/sections/transform_management/components/create_transform_button/create_transform_button.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/transform_management/components/create_transform_button/create_transform_button.test.tsx @@ -12,8 +12,6 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { CreateTransformButton } from './create_transform_button'; -jest.mock('../../../../../shared_imports'); - const queryClient = new QueryClient(); describe('Transform: Transform List ', () => { diff --git a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/expanded_row.test.tsx b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/expanded_row.test.tsx index 119ce5dd92dba..28c82d11a1c46 100644 --- a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/expanded_row.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/expanded_row.test.tsx @@ -15,12 +15,8 @@ import { ExpandedRow } from './expanded_row'; import transformListRow from '../../../../common/__mocks__/transform_list_row.json'; -jest.mock('../../../../../shared_imports'); jest.mock('../../../../app_dependencies'); -import { MlSharedContext } from '../../../../__mocks__/shared_context'; -import { getMlSharedImports } from '../../../../../shared_imports'; - const queryClient = new QueryClient(); describe('Transform: Transform List ', () => { @@ -35,15 +31,12 @@ describe('Transform: Transform List ', () => { }); test('Minimal initialization', async () => { - const mlShared = await getMlSharedImports(); // @ts-expect-error mock data is too loosely typed const item: TransformListRow = transformListRow; renderReactTestingLibraryWithI18n( - - - + ); diff --git a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/transform_list.test.tsx b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/transform_list.test.tsx index ede0470d917f2..28e2cca179a19 100644 --- a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/transform_list.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/transform_list.test.tsx @@ -25,7 +25,6 @@ const useQueryMock = jest.spyOn(ReactQuery, 'useQuery').mockImplementation((quer const queryClient = new QueryClient(); -jest.mock('../../../../../shared_imports'); jest.mock('../../../../app_dependencies'); describe('Transform: Transform List ', () => { diff --git a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/use_actions.test.tsx b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/use_actions.test.tsx index 02064c76c95ce..5007065113782 100644 --- a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/use_actions.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/use_actions.test.tsx @@ -9,7 +9,6 @@ import React, { type FC, type PropsWithChildren } from 'react'; import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { renderHook } from '@testing-library/react-hooks'; -jest.mock('../../../../../shared_imports'); jest.mock('../../../../app_dependencies'); import { useActions } from './use_actions'; diff --git a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/use_columns.test.tsx b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/use_columns.test.tsx index b1d2b6dcb0d42..dcab70822ecd9 100644 --- a/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/use_columns.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/transform_management/components/transform_list/use_columns.test.tsx @@ -11,7 +11,6 @@ import { renderHook } from '@testing-library/react-hooks'; import { useColumns } from './use_columns'; -jest.mock('../../../../../shared_imports'); jest.mock('../../../../app_dependencies'); describe('Transform: Job List Columns', () => { diff --git a/x-pack/plugins/transform/public/app/sections/transform_management/transform_management_section.test.tsx b/x-pack/plugins/transform/public/app/sections/transform_management/transform_management_section.test.tsx index 20f5f4c27b19f..be4bd374eb673 100644 --- a/x-pack/plugins/transform/public/app/sections/transform_management/transform_management_section.test.tsx +++ b/x-pack/plugins/transform/public/app/sections/transform_management/transform_management_section.test.tsx @@ -11,7 +11,6 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'; import { TransformManagementSection } from './transform_management_section'; -jest.mock('../../../shared_imports'); jest.mock('../../services/navigation'); const queryClient = new QueryClient(); diff --git a/x-pack/plugins/transform/public/shared_imports.ts b/x-pack/plugins/transform/public/shared_imports.ts deleted file mode 100644 index 63276cecc7a86..0000000000000 --- a/x-pack/plugins/transform/public/shared_imports.ts +++ /dev/null @@ -1,15 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -export { XJsonMode } from '@kbn/ace'; - -export type { GetMlSharedImportsReturnType } from '@kbn/ml-plugin/public'; -export { getMlSharedImports } from '@kbn/ml-plugin/public'; - -import { XJson } from '@kbn/es-ui-shared-plugin/public'; -const { expandLiteralStrings, collapseLiteralStrings } = XJson; -export { expandLiteralStrings, collapseLiteralStrings }; diff --git a/x-pack/plugins/transform/tsconfig.json b/x-pack/plugins/transform/tsconfig.json index e3ccb0cc1d403..c04d45922aa40 100644 --- a/x-pack/plugins/transform/tsconfig.json +++ b/x-pack/plugins/transform/tsconfig.json @@ -15,7 +15,6 @@ "@kbn/core", "@kbn/features-plugin", "@kbn/licensing-plugin", - "@kbn/ml-plugin", "@kbn/unified-search-plugin", "@kbn/data-plugin", "@kbn/config-schema", @@ -78,7 +77,9 @@ "@kbn/core-elasticsearch-server-mocks", "@kbn/test-jest-helpers", "@kbn/monaco", - "@kbn/json-schemas" + "@kbn/json-schemas", + "@kbn/ml-field-stats-flyout", + "@kbn/ml-validators" ], "exclude": [ "target/**/*", diff --git a/yarn.lock b/yarn.lock index 3a1a8be457d79..80c2ca108690f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5695,6 +5695,10 @@ version "0.0.0" uid "" +"@kbn/ml-field-stats-flyout@link:x-pack/packages/ml/field_stats_flyout": + version "0.0.0" + uid "" + "@kbn/ml-in-memory-table@link:x-pack/packages/ml/in_memory_table": version "0.0.0" uid "" @@ -5723,6 +5727,10 @@ version "0.0.0" uid "" +"@kbn/ml-parse-interval@link:x-pack/packages/ml/parse_interval": + version "0.0.0" + uid "" + "@kbn/ml-plugin@link:x-pack/plugins/ml": version "0.0.0" uid "" @@ -5767,6 +5775,10 @@ version "0.0.0" uid "" +"@kbn/ml-validators@link:x-pack/packages/ml/validators": + version "0.0.0" + uid "" + "@kbn/mock-idp-plugin@link:packages/kbn-mock-idp-plugin": version "0.0.0" uid ""