Skip to content

Commit

Permalink
[ML] Removes duplicated service code used in Single Metric Viewer (#1…
Browse files Browse the repository at this point in the history
…78566)

## Summary

Related meta issue: #176651

This PR removes duplicates created in the initial PR for adding SMV as
an embeddable in dashboards:

- `ml/public/application/services/forecast_service_provider.ts` replaces
`ml/public/application/services/forecast_service.js`

- `ml/public/application/timeseriesexplorer/timeseriesexplorer_utils/time_series_search_service.ts`
replaces `ml/public/application/timeseriesexplorer/timeseries_search_service.ts`

- removes `ml/public/application/timeseriesexplorer/timeseriesexplorer_utils/timeseriesexplorer_utils.js`


### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
  • Loading branch information
alvarezmelissa87 authored Mar 20, 2024
1 parent 55b3d0f commit 8c85463
Show file tree
Hide file tree
Showing 21 changed files with 809 additions and 2,006 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import {

import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { withKibana } from '@kbn/kibana-react-plugin/public';
import { context } from '@kbn/kibana-react-plugin/public';
import { timeFormatter } from '@kbn/ml-date-utils';

import { FORECAST_REQUEST_STATE } from '../../../../../../../common/constants/states';
import { addItemToRecentlyAccessed } from '../../../../../util/recently_accessed';
import { mlForecastService } from '../../../../../services/forecast_service';
import { forecastServiceFactory } from '../../../../../services/forecast_service';
import {
getLatestDataOrBucketTimestamp,
isTimeSeriesViewJob,
Expand All @@ -38,20 +38,27 @@ const MAX_FORECASTS = 500;
/**
* Table component for rendering the lists of forecasts run on an ML job.
*/
export class ForecastsTableUI extends Component {
export class ForecastsTable extends Component {
constructor(props) {
super(props);
this.state = {
isLoading: props.job.data_counts.processed_record_count !== 0,
forecasts: [],
};
this.mlForecastService;
}

/**
* Access ML services in react context.
*/
static contextType = context;

componentDidMount() {
this.mlForecastService = forecastServiceFactory(this.context.services.mlServices.mlApiServices);
const dataCounts = this.props.job.data_counts;
if (dataCounts.processed_record_count > 0) {
// Get the list of all the forecasts with results at or later than the specified 'from' time.
mlForecastService
this.mlForecastService
.getForecastsSummary(
this.props.job,
null,
Expand Down Expand Up @@ -86,7 +93,7 @@ export class ForecastsTableUI extends Component {
application: { navigateToUrl },
share,
},
} = this.props.kibana;
} = this.context;

// Creates the link to the Single Metric Viewer.
// Set the total time range from the start of the job data to the end of the forecast,
Expand Down Expand Up @@ -337,8 +344,6 @@ export class ForecastsTableUI extends Component {
);
}
}
ForecastsTableUI.propTypes = {
ForecastsTable.propTypes = {
job: PropTypes.object.isRequired,
};

export const ForecastsTable = withKibana(ForecastsTableUI);
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ jest.mock('../../contexts/kibana/kibana_context', () => {
timefilter: getMockedTimefilter(),
},
},
mlServices: { mlApiServices: {} },
notifications: {
toasts: {
addDanger: () => {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,14 @@ import {
useUiSettings,
} from '../../contexts/kibana';
import type { MlJobWithTimeRange } from '../../../../common/types/anomaly_detection_jobs';
import { isTimeSeriesViewJob } from '../../../../common/util/job_utils';
import { TimeSeriesExplorer } from '../../timeseriesexplorer';
import { getDateFormatTz } from '../../explorer/explorer_utils';
import { mlJobService } from '../../services/job_service';
import { mlForecastService } from '../../services/forecast_service';
import { useForecastService } from '../../services/forecast_service';
import { useTimeSeriesExplorerService } from '../../util/time_series_explorer_service';
import { APP_STATE_ACTION } from '../../timeseriesexplorer/timeseriesexplorer_constants';
import {
createTimeSeriesJobData,
getAutoZoomDuration,
validateJobSelection,
} from '../../timeseriesexplorer/timeseriesexplorer_utils';
import { validateJobSelection } from '../../timeseriesexplorer/timeseriesexplorer_utils';
import { TimeSeriesExplorerPage } from '../../timeseriesexplorer/timeseriesexplorer_page';
import { TimeseriesexplorerNoJobsFound } from '../../timeseriesexplorer/components/timeseriesexplorer_no_jobs_found';
import { useTableInterval } from '../../components/controls/select_interval';
Expand Down Expand Up @@ -117,6 +115,7 @@ export const TimeSeriesExplorerUrlStateManager: FC<TimeSeriesExplorerUrlStateMan
},
} = useMlKibana();
const { toasts } = useNotifications();
const mlForecastService = useForecastService();
const toastNotificationService = useToastNotificationService();
const [timeSeriesExplorerUrlState, setTimeSeriesExplorerUrlState] =
useTimeSeriesExplorerUrlState();
Expand All @@ -127,6 +126,7 @@ export const TimeSeriesExplorerUrlStateManager: FC<TimeSeriesExplorerUrlStateMan

const refresh = useRefresh();
const previousRefresh = usePrevious(refresh?.lastRefresh ?? 0);
const timeSeriesExplorerService = useTimeSeriesExplorerService();

// We cannot simply infer bounds from the globalState's `time` attribute
// with `moment` since it can contain custom strings such as `now-15m`.
Expand Down Expand Up @@ -176,7 +176,7 @@ export const TimeSeriesExplorerUrlStateManager: FC<TimeSeriesExplorerUrlStateMan
: timeSeriesExplorerUrlState?.mlTimeSeriesExplorer?.zoom;

const selectedJob = selectedJobId !== undefined ? mlJobService.getJob(selectedJobId) : undefined;
const timeSeriesJobs = createTimeSeriesJobData(mlJobService.jobs);
const timeSeriesJobs = mlJobService.jobs.filter(isTimeSeriesViewJob);

const viewableDetector = selectedJob ? getViewableDetectors(selectedJob)[0]?.index ?? 0 : 0;

Expand All @@ -189,7 +189,7 @@ export const TimeSeriesExplorerUrlStateManager: FC<TimeSeriesExplorerUrlStateMan

let autoZoomDuration: number | undefined;
if (selectedJobId !== undefined && selectedJob !== undefined) {
autoZoomDuration = getAutoZoomDuration(timeSeriesJobs, selectedJob);
autoZoomDuration = timeSeriesExplorerService.getAutoZoomDuration(selectedJob);
}

const appStateHandler = useCallback(
Expand Down

This file was deleted.

Loading

0 comments on commit 8c85463

Please sign in to comment.