From 35b1c8c3cbbef9ee25de52e5454bcbf4d93a4327 Mon Sep 17 00:00:00 2001 From: Dmitrii Arnautov Date: Thu, 1 Oct 2020 13:52:43 +0200 Subject: [PATCH] [ML] refactor date_utils --- .../application => common}/util/date_utils.test.ts | 0 .../application => common}/util/date_utils.ts | 11 ++++++++--- x-pack/plugins/ml/common/util/time_formatter.ts | 13 ------------- .../annotation_description_list/index.tsx | 2 +- .../annotations_table/annotations_table.js | 14 ++++---------- .../anomalies_table/anomalies_table_columns.js | 2 +- .../components/anomalies_table/anomaly_details.js | 2 +- .../components/anomalies_table/links_menu.js | 2 +- .../application/components/data_grid/common.ts | 2 +- .../components/job_messages/job_messages.tsx | 7 +++---- .../model_snapshots/model_snapshots_table.tsx | 11 +++-------- .../revert_model_snapshot_flyout.tsx | 5 ++--- .../components/analytics_list/expanded_row.tsx | 2 +- .../components/models_management/expanded_row.tsx | 2 +- .../components/models_management/models_list.tsx | 7 +++---- .../explorer_charts/explorer_chart_distribution.js | 2 +- .../explorer_chart_single_metric.js | 2 +- .../application/explorer/explorer_swimlane.tsx | 2 +- .../explorer/reducers/explorer_reducer/reducer.ts | 2 +- .../job_details/forecasts_table/forecasts_table.js | 14 +++++++------- .../components/job_details/format_values.js | 5 ++--- .../charts/event_rate_chart/overlay_range.tsx | 8 ++------ .../overview/components/analytics_panel/table.tsx | 2 +- .../components/anomaly_detection_panel/table.tsx | 2 +- .../ml/public/application/services/job_service.js | 2 +- .../components/forecasting_modal/forecasts_list.js | 2 +- .../timeseries_chart/timeseries_chart.js | 2 +- x-pack/plugins/ml/public/shared.ts | 2 +- 28 files changed, 51 insertions(+), 78 deletions(-) rename x-pack/plugins/ml/{public/application => common}/util/date_utils.test.ts (100%) rename x-pack/plugins/ml/{public/application => common}/util/date_utils.ts (78%) delete mode 100644 x-pack/plugins/ml/common/util/time_formatter.ts diff --git a/x-pack/plugins/ml/public/application/util/date_utils.test.ts b/x-pack/plugins/ml/common/util/date_utils.test.ts similarity index 100% rename from x-pack/plugins/ml/public/application/util/date_utils.test.ts rename to x-pack/plugins/ml/common/util/date_utils.test.ts diff --git a/x-pack/plugins/ml/public/application/util/date_utils.ts b/x-pack/plugins/ml/common/util/date_utils.ts similarity index 78% rename from x-pack/plugins/ml/public/application/util/date_utils.ts rename to x-pack/plugins/ml/common/util/date_utils.ts index 21adc0b4b9c66..73ac68b2493f3 100644 --- a/x-pack/plugins/ml/public/application/util/date_utils.ts +++ b/x-pack/plugins/ml/common/util/date_utils.ts @@ -6,10 +6,11 @@ // utility functions for handling dates -// @ts-ignore -import { formatDate } from '@elastic/eui/lib/services/format'; import dateMath from '@elastic/datemath'; -import { TimeRange } from '../../../../../../src/plugins/data/common'; +import { formatDate } from '@elastic/eui'; +import { TimeRange } from '../../../../../src/plugins/data/common'; +import { TIME_FORMAT } from '../constants/time_format'; + export function formatHumanReadableDate(ts: number) { return formatDate(ts, 'MMMM Do YYYY'); } @@ -28,3 +29,7 @@ export function validateTimeRange(time?: TimeRange): boolean { const momentDateTo = dateMath.parse(time.to); return !!(momentDateFrom && momentDateFrom.isValid() && momentDateTo && momentDateTo.isValid()); } + +export const timeFormatter = (value: number) => { + return formatDate(value, TIME_FORMAT); +}; diff --git a/x-pack/plugins/ml/common/util/time_formatter.ts b/x-pack/plugins/ml/common/util/time_formatter.ts deleted file mode 100644 index 905237d0954ec..0000000000000 --- a/x-pack/plugins/ml/common/util/time_formatter.ts +++ /dev/null @@ -1,13 +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; - * you may not use this file except in compliance with the Elastic License. - */ - -// @ts-ignore -import { formatDate } from '@elastic/eui/lib/services/format'; -import { TIME_FORMAT } from '../constants/time_format'; - -export const timeFormatter = (value: number) => { - return formatDate(value, TIME_FORMAT); -}; diff --git a/x-pack/plugins/ml/public/application/components/annotations/annotation_description_list/index.tsx b/x-pack/plugins/ml/public/application/components/annotations/annotation_description_list/index.tsx index eee2f8dca244d..403d836dd9c67 100644 --- a/x-pack/plugins/ml/public/application/components/annotations/annotation_description_list/index.tsx +++ b/x-pack/plugins/ml/public/application/components/annotations/annotation_description_list/index.tsx @@ -15,7 +15,7 @@ import { EuiDescriptionList } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import { Annotation } from '../../../../../common/types/annotations'; -import { formatHumanReadableDateTimeSeconds } from '../../../util/date_utils'; +import { formatHumanReadableDateTimeSeconds } from '../../../../../common/util/date_utils'; interface Props { annotation: Annotation; diff --git a/x-pack/plugins/ml/public/application/components/annotations/annotations_table/annotations_table.js b/x-pack/plugins/ml/public/application/components/annotations/annotations_table/annotations_table.js index 0527b8f6d9f60..7eb280c6247c2 100644 --- a/x-pack/plugins/ml/public/application/components/annotations/annotations_table/annotations_table.js +++ b/x-pack/plugins/ml/public/application/components/annotations/annotations_table/annotations_table.js @@ -31,8 +31,6 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { RIGHT_ALIGNMENT } from '@elastic/eui/lib/services'; -import { formatDate } from '@elastic/eui/lib/services/format'; - import { addItemToRecentlyAccessed } from '../../../util/recently_accessed'; import { ml } from '../../../services/ml_api_service'; import { mlJobService } from '../../../services/job_service'; @@ -42,7 +40,6 @@ import { getLatestDataOrBucketTimestamp, isTimeSeriesViewJob, } from '../../../../../common/util/job_utils'; -import { TIME_FORMAT } from '../../../../../common/constants/time_format'; import { annotation$, @@ -56,6 +53,7 @@ import { import { withKibana } from '../../../../../../../../src/plugins/kibana_react/public'; import { ML_APP_URL_GENERATOR, ML_PAGES } from '../../../../../common/constants/ml_url_generator'; import { PLUGIN_ID } from '../../../../../common/constants/app'; +import { timeFormatter } from '../../../../../common/util/date_utils'; const CURRENT_SERIES = 'current_series'; /** @@ -377,10 +375,6 @@ class AnnotationsTableUI extends Component { ); } - function renderDate(date) { - return formatDate(date, TIME_FORMAT); - } - const columns = [ { field: 'annotation', @@ -397,7 +391,7 @@ class AnnotationsTableUI extends Component { defaultMessage: 'From', }), dataType: 'date', - render: renderDate, + render: timeFormatter, sortable: true, }, { @@ -406,7 +400,7 @@ class AnnotationsTableUI extends Component { defaultMessage: 'To', }), dataType: 'date', - render: renderDate, + render: timeFormatter, sortable: true, }, { @@ -415,7 +409,7 @@ class AnnotationsTableUI extends Component { defaultMessage: 'Last modified date', }), dataType: 'date', - render: renderDate, + render: timeFormatter, sortable: true, }, { diff --git a/x-pack/plugins/ml/public/application/components/anomalies_table/anomalies_table_columns.js b/x-pack/plugins/ml/public/application/components/anomalies_table/anomalies_table_columns.js index 1f8c8633afa47..d2c4122bc1b57 100644 --- a/x-pack/plugins/ml/public/application/components/anomalies_table/anomalies_table_columns.js +++ b/x-pack/plugins/ml/public/application/components/anomalies_table/anomalies_table_columns.js @@ -16,7 +16,7 @@ import { formatHumanReadableDate, formatHumanReadableDateTime, formatHumanReadableDateTimeSeconds, -} from '../../util/date_utils'; +} from '../../../../common/util/date_utils'; import { DescriptionCell } from './description_cell'; import { DetectorCell } from './detector_cell'; diff --git a/x-pack/plugins/ml/public/application/components/anomalies_table/anomaly_details.js b/x-pack/plugins/ml/public/application/components/anomalies_table/anomaly_details.js index cd3875f8cbd2a..a2a3aea5988aa 100644 --- a/x-pack/plugins/ml/public/application/components/anomalies_table/anomaly_details.js +++ b/x-pack/plugins/ml/public/application/components/anomalies_table/anomaly_details.js @@ -26,7 +26,7 @@ import { EuiTabbedContent, EuiText, } from '@elastic/eui'; -import { formatHumanReadableDateTimeSeconds } from '../../util/date_utils'; +import { formatHumanReadableDateTimeSeconds } from '../../../../common/util/date_utils'; import { EntityCell } from '../entity_cell'; import { diff --git a/x-pack/plugins/ml/public/application/components/anomalies_table/links_menu.js b/x-pack/plugins/ml/public/application/components/anomalies_table/links_menu.js index d898734f34c93..079d56da60e5e 100644 --- a/x-pack/plugins/ml/public/application/components/anomalies_table/links_menu.js +++ b/x-pack/plugins/ml/public/application/components/anomalies_table/links_menu.js @@ -26,7 +26,7 @@ import { getFieldTypeFromMapping } from '../../services/mapping_service'; import { ml } from '../../services/ml_api_service'; import { mlJobService } from '../../services/job_service'; import { getUrlForRecord, openCustomUrlWindow } from '../../util/custom_url_utils'; -import { formatHumanReadableDateTimeSeconds } from '../../util/date_utils'; +import { formatHumanReadableDateTimeSeconds } from '../../../../common/util/date_utils'; import { getIndexPatternIdFromName } from '../../util/index_utils'; import { replaceStringTokens } from '../../util/string_utils'; import { ML_APP_URL_GENERATOR, ML_PAGES } from '../../../../common/constants/ml_url_generator'; diff --git a/x-pack/plugins/ml/public/application/components/data_grid/common.ts b/x-pack/plugins/ml/public/application/components/data_grid/common.ts index f252729cc20cd..36b0573d609d8 100644 --- a/x-pack/plugins/ml/public/application/components/data_grid/common.ts +++ b/x-pack/plugins/ml/public/application/components/data_grid/common.ts @@ -37,7 +37,7 @@ import { OUTLIER_SCORE, TOP_CLASSES, } from '../../data_frame_analytics/common/constants'; -import { formatHumanReadableDateTimeSeconds } from '../../util/date_utils'; +import { formatHumanReadableDateTimeSeconds } from '../../../../common/util/date_utils'; import { getNestedProperty } from '../../util/object_utils'; import { mlFieldFormatService } from '../../services/field_format_service'; diff --git a/x-pack/plugins/ml/public/application/components/job_messages/job_messages.tsx b/x-pack/plugins/ml/public/application/components/job_messages/job_messages.tsx index 798ceae0f0732..f60cd61b25cd4 100644 --- a/x-pack/plugins/ml/public/application/components/job_messages/job_messages.tsx +++ b/x-pack/plugins/ml/public/application/components/job_messages/job_messages.tsx @@ -7,14 +7,13 @@ import React, { FC } from 'react'; import { EuiSpacer, EuiInMemoryTable, EuiButtonIcon, EuiToolTip } from '@elastic/eui'; -// @ts-ignore -import { formatDate } from '@elastic/eui/lib/services/format'; + import { i18n } from '@kbn/i18n'; import theme from '@elastic/eui/dist/eui_theme_light.json'; import { JobMessage } from '../../../../common/types/audit_message'; -import { TIME_FORMAT } from '../../../../common/constants/time_format'; import { JobIcon } from '../job_message_icon'; +import { timeFormatter } from '../../../../common/util/date_utils'; interface JobMessagesProps { messages: JobMessage[]; @@ -55,7 +54,7 @@ export const JobMessages: FC = ({ messages, loading, error, re name: i18n.translate('xpack.ml.jobMessages.timeLabel', { defaultMessage: 'Time', }), - render: (timestamp: number) => formatDate(timestamp, TIME_FORMAT), + render: timeFormatter, width: '120px', sortable: true, }, diff --git a/x-pack/plugins/ml/public/application/components/model_snapshots/model_snapshots_table.tsx b/x-pack/plugins/ml/public/application/components/model_snapshots/model_snapshots_table.tsx index 64fdd97903b60..5b175eb06a4a3 100644 --- a/x-pack/plugins/ml/public/application/components/model_snapshots/model_snapshots_table.tsx +++ b/x-pack/plugins/ml/public/application/components/model_snapshots/model_snapshots_table.tsx @@ -13,7 +13,6 @@ import { EuiInMemoryTable, EuiLoadingSpinner, EuiBasicTableColumn, - formatDate, } from '@elastic/eui'; import { checkPermission } from '../../capabilities/check_capabilities'; @@ -21,12 +20,12 @@ import { EditModelSnapshotFlyout } from './edit_model_snapshot_flyout'; import { RevertModelSnapshotFlyout } from './revert_model_snapshot_flyout'; import { ml } from '../../services/ml_api_service'; import { JOB_STATE, DATAFEED_STATE } from '../../../../common/constants/states'; -import { TIME_FORMAT } from '../../../../common/constants/time_format'; import { CloseJobConfirm } from './close_job_confirm'; import { ModelSnapshot, CombinedJobWithStats, } from '../../../../common/types/anomaly_detection_jobs'; +import { timeFormatter } from '../../../../common/util/date_utils'; interface Props { job: CombinedJobWithStats; @@ -138,7 +137,7 @@ export const ModelSnapshotTable: FC = ({ job, refreshJobList }) => { defaultMessage: 'Date created', }), dataType: 'date', - render: renderDate, + render: timeFormatter, sortable: true, }, { @@ -147,7 +146,7 @@ export const ModelSnapshotTable: FC = ({ job, refreshJobList }) => { defaultMessage: 'Latest timestamp', }), dataType: 'date', - render: renderDate, + render: timeFormatter, sortable: true, }, { @@ -246,10 +245,6 @@ export const ModelSnapshotTable: FC = ({ job, refreshJobList }) => { ); }; -function renderDate(date: number) { - return formatDate(date, TIME_FORMAT); -} - async function getCombinedJobState(jobId: string) { const jobs = await ml.jobs.jobs([jobId]); 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 e37efe60f8018..62f5623f67964 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 @@ -32,7 +32,6 @@ import { EuiHorizontalRule, EuiSuperSelect, EuiText, - formatDate, } from '@elastic/eui'; import { @@ -47,8 +46,8 @@ import { LineChartPoint } from '../../../jobs/new_job/common/chart_loader'; import { EventRateChart } from '../../../jobs/new_job/pages/components/charts/event_rate_chart/event_rate_chart'; import { Anomaly } from '../../../jobs/new_job/common/results_loader/results_loader'; import { parseInterval } from '../../../../../common/util/parse_interval'; -import { TIME_FORMAT } from '../../../../../common/constants/time_format'; import { CreateCalendar, CalendarEvent } from './create_calendar'; +import { timeFormatter } from '../../../../../common/util/date_utils'; interface Props { snapshot: ModelSnapshot; @@ -255,7 +254,7 @@ export const RevertModelSnapshotFlyout: FC = ({ snapshot, snapshots, job, diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/expanded_row.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/expanded_row.tsx index 95204f9ba09fc..a0bd437a667a2 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/expanded_row.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/analytics_list/expanded_row.tsx @@ -11,7 +11,7 @@ import { EuiIcon, EuiLoadingSpinner, EuiTabbedContent } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { formatHumanReadableDateTimeSeconds } from '../../../../../util/date_utils'; +import { formatHumanReadableDateTimeSeconds } from '../../../../../../../common/util/date_utils'; import { DataFrameAnalyticsListRow } from './common'; import { ExpandedRowDetailsPane, SectionConfig, SectionItem } from './expanded_row_details_pane'; diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/models_management/expanded_row.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/models_management/expanded_row.tsx index fc820c145270c..803a2523a55e0 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/models_management/expanded_row.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/models_management/expanded_row.tsx @@ -26,7 +26,7 @@ import { import { EuiDescriptionListProps } from '@elastic/eui/src/components/description_list/description_list'; import { ModelItemFull } from './models_list'; import { useMlKibana } from '../../../../../contexts/kibana'; -import { timeFormatter } from '../../../../../../../common/util/time_formatter'; +import { timeFormatter } from '../../../../../../../common/util/date_utils'; interface ExpandedRowProps { item: ModelItemFull; diff --git a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/models_management/models_list.tsx b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/models_management/models_list.tsx index fddb90e53ccd6..11923bf03236b 100644 --- a/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/models_management/models_list.tsx +++ b/x-pack/plugins/ml/public/application/data_frame_analytics/pages/analytics_management/components/models_management/models_list.tsx @@ -19,15 +19,13 @@ import { EuiBadge, SearchFilterConfig, } from '@elastic/eui'; -// @ts-ignore -import { formatDate } from '@elastic/eui/lib/services/format'; + import { EuiBasicTableColumn } from '@elastic/eui/src/components/basic_table/basic_table'; import { EuiTableSelectionType } from '@elastic/eui/src/components/basic_table/table_types'; import { Action } from '@elastic/eui/src/components/basic_table/action_types'; import { StatsBar, ModelsBarStats } from '../../../../../components/stats_bar'; import { useInferenceApiService } from '../../../../../services/ml_api_service/inference'; import { ModelsTableToConfigMapping } from './index'; -import { TIME_FORMAT } from '../../../../../../../common/constants/time_format'; import { DeleteModelsModal } from './delete_models_modal'; import { useMlKibana, useMlUrlGenerator, useNotifications } from '../../../../../contexts/kibana'; import { ExpandedRow } from './expanded_row'; @@ -46,6 +44,7 @@ import { useTableSettings } from '../analytics_list/use_table_settings'; import { filterAnalyticsModels, AnalyticsSearchBar } from '../analytics_search_bar'; import { ML_PAGES } from '../../../../../../../common/constants/ml_url_generator'; import { DataFrameAnalysisConfigType } from '../../../../../../../common/types/data_frame_analytics'; +import { timeFormatter } from '../../../../../../../common/util/date_utils'; type Stats = Omit; @@ -376,7 +375,7 @@ export const ModelsList: FC = () => { defaultMessage: 'Created at', }), dataType: 'date', - render: (date: string) => formatDate(date, TIME_FORMAT), + render: timeFormatter, sortable: true, }, { diff --git a/x-pack/plugins/ml/public/application/explorer/explorer_charts/explorer_chart_distribution.js b/x-pack/plugins/ml/public/application/explorer/explorer_charts/explorer_chart_distribution.js index 00aca5d43be85..994975912cd6f 100644 --- a/x-pack/plugins/ml/public/application/explorer/explorer_charts/explorer_chart_distribution.js +++ b/x-pack/plugins/ml/public/application/explorer/explorer_charts/explorer_chart_distribution.js @@ -17,7 +17,7 @@ import d3 from 'd3'; import $ from 'jquery'; import moment from 'moment'; -import { formatHumanReadableDateTime } from '../../util/date_utils'; +import { formatHumanReadableDateTime } from '../../../../common/util/date_utils'; import { formatValue } from '../../formatters/format_value'; import { getSeverityColor, getSeverityWithLow } from '../../../../common/util/anomaly_utils'; import { diff --git a/x-pack/plugins/ml/public/application/explorer/explorer_charts/explorer_chart_single_metric.js b/x-pack/plugins/ml/public/application/explorer/explorer_charts/explorer_chart_single_metric.js index 0a76211f2e330..606d1c0690422 100644 --- a/x-pack/plugins/ml/public/application/explorer/explorer_charts/explorer_chart_single_metric.js +++ b/x-pack/plugins/ml/public/application/explorer/explorer_charts/explorer_chart_single_metric.js @@ -17,7 +17,7 @@ import $ from 'jquery'; import moment from 'moment'; import { i18n } from '@kbn/i18n'; -import { formatHumanReadableDateTime } from '../../util/date_utils'; +import { formatHumanReadableDateTime } from '../../../../common/util/date_utils'; import { formatValue } from '../../formatters/format_value'; import { getSeverityColor, diff --git a/x-pack/plugins/ml/public/application/explorer/explorer_swimlane.tsx b/x-pack/plugins/ml/public/application/explorer/explorer_swimlane.tsx index 359dc11ca08d1..569709d648b3c 100644 --- a/x-pack/plugins/ml/public/application/explorer/explorer_swimlane.tsx +++ b/x-pack/plugins/ml/public/application/explorer/explorer_swimlane.tsx @@ -19,7 +19,7 @@ import { i18n } from '@kbn/i18n'; import { Subject, Subscription } from 'rxjs'; import { TooltipValue } from '@elastic/charts'; import { htmlIdGenerator } from '@elastic/eui'; -import { formatHumanReadableDateTime } from '../util/date_utils'; +import { formatHumanReadableDateTime } from '../../../common/util/date_utils'; import { numTicksForDateFormat } from '../util/chart_utils'; import { getSeverityColor } from '../../../common/util/anomaly_utils'; import { mlEscape } from '../util/string_utils'; diff --git a/x-pack/plugins/ml/public/application/explorer/reducers/explorer_reducer/reducer.ts b/x-pack/plugins/ml/public/application/explorer/reducers/explorer_reducer/reducer.ts index a38044a8b3425..c5fb0175c54e9 100644 --- a/x-pack/plugins/ml/public/application/explorer/reducers/explorer_reducer/reducer.ts +++ b/x-pack/plugins/ml/public/application/explorer/reducers/explorer_reducer/reducer.ts @@ -4,7 +4,7 @@ * you may not use this file except in compliance with the Elastic License. */ -import { formatHumanReadableDateTime } from '../../../util/date_utils'; +import { formatHumanReadableDateTime } from '../../../../../common/util/date_utils'; import { getDefaultChartsData } from '../../explorer_charts/explorer_charts_container_service'; import { EXPLORER_ACTION, VIEW_BY_JOB_LABEL } from '../../explorer_constants'; diff --git a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/job_details/forecasts_table/forecasts_table.js b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/job_details/forecasts_table/forecasts_table.js index b32070fff73aa..44ebde634714c 100644 --- a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/job_details/forecasts_table/forecasts_table.js +++ b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/job_details/forecasts_table/forecasts_table.js @@ -16,10 +16,9 @@ import { EuiLink, EuiLoadingSpinner, } from '@elastic/eui'; -import { formatDate, formatNumber } from '@elastic/eui/lib/services/format'; +import { formatNumber } from '@elastic/eui/lib/services/format'; import { FORECAST_REQUEST_STATE } from '../../../../../../../common/constants/states'; -import { TIME_FORMAT } from '../../../../../../../common/constants/time_format'; import { addItemToRecentlyAccessed } from '../../../../../util/recently_accessed'; import { mlForecastService } from '../../../../../services/forecast_service'; import { i18n } from '@kbn/i18n'; @@ -34,6 +33,7 @@ import { ML_PAGES, } from '../../../../../../../common/constants/ml_url_generator'; import { PLUGIN_ID } from '../../../../../../../common/constants/app'; +import { timeFormatter } from '../../../../../../../common/util/date_utils'; const MAX_FORECASTS = 500; @@ -218,7 +218,7 @@ export class ForecastsTableUI extends Component { defaultMessage: 'Created', }), dataType: 'date', - render: (date) => formatDate(date, TIME_FORMAT), + render: timeFormatter, textOnly: true, sortable: true, scope: 'row', @@ -229,7 +229,7 @@ export class ForecastsTableUI extends Component { defaultMessage: 'From', }), dataType: 'date', - render: (date) => formatDate(date, TIME_FORMAT), + render: timeFormatter, textOnly: true, sortable: true, }, @@ -239,7 +239,7 @@ export class ForecastsTableUI extends Component { defaultMessage: 'To', }), dataType: 'date', - render: (date) => formatDate(date, TIME_FORMAT), + render: timeFormatter, textOnly: true, sortable: true, }, @@ -277,7 +277,7 @@ export class ForecastsTableUI extends Component { name: i18n.translate('xpack.ml.jobsList.jobDetails.forecastsTable.expiresLabel', { defaultMessage: 'Expires', }), - render: (date) => formatDate(date, TIME_FORMAT), + render: timeFormatter, textOnly: true, sortable: true, }, @@ -309,7 +309,7 @@ export class ForecastsTableUI extends Component { { defaultMessage: 'View forecast created at {createdDate}', values: { - createdDate: formatDate(forecast.forecast_create_timestamp, TIME_FORMAT), + createdDate: timeFormatter(forecast.forecast_create_timestamp), }, } ); diff --git a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/job_details/format_values.js b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/job_details/format_values.js index 3fe4f0e5477a2..eff407a41fb0d 100644 --- a/x-pack/plugins/ml/public/application/jobs/jobs_list/components/job_details/format_values.js +++ b/x-pack/plugins/ml/public/application/jobs/jobs_list/components/job_details/format_values.js @@ -5,10 +5,9 @@ */ import numeral from '@elastic/numeral'; -import { formatDate } from '@elastic/eui/lib/services/format'; import { roundToDecimalPlace } from '../../../../formatters/round_to_decimal_place'; import { toLocaleString } from '../../../../util/string_utils'; -import { TIME_FORMAT } from '../../../../../../common/constants/time_format'; +import { timeFormatter } from '../../../../../../common/util/date_utils'; const DATA_FORMAT = '0.0 b'; @@ -29,7 +28,7 @@ export function formatValues([key, value]) { case 'latest_empty_bucket_timestamp': case 'latest_sparse_bucket_timestamp': case 'latest_bucket_timestamp': - value = formatDate(value, TIME_FORMAT); + value = timeFormatter(value); break; // data diff --git a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/charts/event_rate_chart/overlay_range.tsx b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/charts/event_rate_chart/overlay_range.tsx index a35c2d9c833a8..8ad359251b029 100644 --- a/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/charts/event_rate_chart/overlay_range.tsx +++ b/x-pack/plugins/ml/public/application/jobs/new_job/pages/components/charts/event_rate_chart/overlay_range.tsx @@ -5,12 +5,10 @@ */ import React, { FC } from 'react'; -// @ts-ignore -import { formatDate } from '@elastic/eui/lib/services/format'; import { EuiIcon } from '@elastic/eui'; import { RectAnnotation, LineAnnotation, AnnotationDomainTypes } from '@elastic/charts'; import { LineChartPoint } from '../../../../common/chart_loader'; -import { TIME_FORMAT } from '../../../../../../../../common/constants/time_format'; +import { timeFormatter } from '../../../../../../../../common/util/date_utils'; interface Props { overlayKey: number; @@ -70,9 +68,7 @@ export const OverlayRange: FC = ({
-
- {formatDate(start, TIME_FORMAT)} -
+
{timeFormatter(start)}
) : undefined diff --git a/x-pack/plugins/ml/public/application/overview/components/analytics_panel/table.tsx b/x-pack/plugins/ml/public/application/overview/components/analytics_panel/table.tsx index fc0645a0e9498..4b469a0f5874d 100644 --- a/x-pack/plugins/ml/public/application/overview/components/analytics_panel/table.tsx +++ b/x-pack/plugins/ml/public/application/overview/components/analytics_panel/table.tsx @@ -23,7 +23,7 @@ import { getTaskStateBadge, progressColumn, } from '../../../data_frame_analytics/pages/analytics_management/components/analytics_list/use_columns'; -import { formatHumanReadableDateTimeSeconds } from '../../../util/date_utils'; +import { formatHumanReadableDateTimeSeconds } from '../../../../../common/util/date_utils'; import { ViewLink } from './actions'; diff --git a/x-pack/plugins/ml/public/application/overview/components/anomaly_detection_panel/table.tsx b/x-pack/plugins/ml/public/application/overview/components/anomaly_detection_panel/table.tsx index 8515431d49b17..b95aed01ebae8 100644 --- a/x-pack/plugins/ml/public/application/overview/components/anomaly_detection_panel/table.tsx +++ b/x-pack/plugins/ml/public/application/overview/components/anomaly_detection_panel/table.tsx @@ -20,7 +20,7 @@ import { EuiToolTip, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import { formatHumanReadableDateTimeSeconds } from '../../../util/date_utils'; +import { formatHumanReadableDateTimeSeconds } from '../../../../../common/util/date_utils'; import { ExplorerLink } from './actions'; import { getJobsFromGroup } from './utils'; import { GroupsDictionary, Group } from './anomaly_detection_panel'; 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 939ad34e77a39..0971b47605135 100644 --- a/x-pack/plugins/ml/public/application/services/job_service.js +++ b/x-pack/plugins/ml/public/application/services/job_service.js @@ -15,7 +15,7 @@ import { isWebUrl } from '../util/url_utils'; import { ML_DATA_PREVIEW_COUNT } from '../../../common/util/job_utils'; import { TIME_FORMAT } from '../../../common/constants/time_format'; import { parseInterval } from '../../../common/util/parse_interval'; -import { validateTimeRange } from '../util/date_utils'; +import { validateTimeRange } from '../../../common/util/date_utils'; let jobs = []; let datafeedIds = {}; diff --git a/x-pack/plugins/ml/public/application/timeseriesexplorer/components/forecasting_modal/forecasts_list.js b/x-pack/plugins/ml/public/application/timeseriesexplorer/components/forecasting_modal/forecasts_list.js index cbc2c324a8bc6..2378d8c835ce9 100644 --- a/x-pack/plugins/ml/public/application/timeseriesexplorer/components/forecasting_modal/forecasts_list.js +++ b/x-pack/plugins/ml/public/application/timeseriesexplorer/components/forecasting_modal/forecasts_list.js @@ -13,7 +13,7 @@ import React from 'react'; import { EuiButtonIcon, EuiIcon, EuiInMemoryTable, EuiText, EuiToolTip } from '@elastic/eui'; -import { formatHumanReadableDateTimeSeconds } from '../../../util/date_utils'; +import { formatHumanReadableDateTimeSeconds } from '../../../../../common/util/date_utils'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n/react'; diff --git a/x-pack/plugins/ml/public/application/timeseriesexplorer/components/timeseries_chart/timeseries_chart.js b/x-pack/plugins/ml/public/application/timeseriesexplorer/components/timeseries_chart/timeseries_chart.js index 1d166b7be9bc1..4c87c3b374ff3 100644 --- a/x-pack/plugins/ml/public/application/timeseriesexplorer/components/timeseries_chart/timeseries_chart.js +++ b/x-pack/plugins/ml/public/application/timeseriesexplorer/components/timeseries_chart/timeseries_chart.js @@ -33,7 +33,7 @@ import { showMultiBucketAnomalyMarker, showMultiBucketAnomalyTooltip, } from '../../../util/chart_utils'; -import { formatHumanReadableDateTimeSeconds } from '../../../util/date_utils'; +import { formatHumanReadableDateTimeSeconds } from '../../../../../common/util/date_utils'; import { getTimeBucketsFromCache } from '../../../util/time_buckets'; import { mlTableService } from '../../../services/table_service'; import { ContextChartMask } from '../context_chart_mask'; diff --git a/x-pack/plugins/ml/public/shared.ts b/x-pack/plugins/ml/public/shared.ts index ec884bfac5351..62b8179c9d5b2 100644 --- a/x-pack/plugins/ml/public/shared.ts +++ b/x-pack/plugins/ml/public/shared.ts @@ -20,4 +20,4 @@ export * from '../common/util/validators'; export * from './application/formatters/metric_change_description'; export * from './application/components/data_grid'; export * from './application/data_frame_analytics/common'; -export * from './application/util/date_utils'; +export * from '../common/util/date_utils';