Skip to content

Commit 959a0e5

Browse files
[ML] Listing global calendars on the job management page (#63124)
* [ML] Listing global calendars on the job management page * tiny refactor Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent a4464c2 commit 959a0e5

File tree

1 file changed

+12
-3
lines changed
  • x-pack/plugins/ml/server/models/job_service

1 file changed

+12
-3
lines changed

x-pack/plugins/ml/server/models/job_service/jobs.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
DatafeedWithStats,
1717
CombinedJobWithStats,
1818
} from '../../../common/types/anomaly_detection_jobs';
19+
import { GLOBAL_CALENDAR } from '../../../common/constants/calendars';
1920
import { datafeedsProvider, MlDatafeedsResponse, MlDatafeedsStatsResponse } from './datafeeds';
2021
import { jobAuditMessagesProvider } from '../job_audit_messages';
2122
import { resultsServiceProvider } from '../results_service';
@@ -227,6 +228,8 @@ export function jobsProvider(callAsCurrentUser: APICaller) {
227228
const groups: { [jobId: string]: string[] } = {};
228229
const datafeeds: { [id: string]: DatafeedWithStats } = {};
229230
const calendarsByJobId: { [jobId: string]: string[] } = {};
231+
const globalCalendars: string[] = [];
232+
230233
const requests: [
231234
Promise<MlJobsResponse>,
232235
Promise<MlJobsStatsResponse>,
@@ -298,7 +301,9 @@ export function jobsProvider(callAsCurrentUser: APICaller) {
298301
if (calendarResults) {
299302
calendarResults.forEach(cal => {
300303
cal.job_ids.forEach(id => {
301-
if (groups[id]) {
304+
if (id === GLOBAL_CALENDAR) {
305+
globalCalendars.push(cal.calendar_id);
306+
} else if (groups[id]) {
302307
groups[id].forEach(jId => {
303308
if (calendarsByJobId[jId] !== undefined) {
304309
calendarsByJobId[jId].push(cal.calendar_id);
@@ -325,8 +330,12 @@ export function jobsProvider(callAsCurrentUser: APICaller) {
325330
jobResults.jobs.forEach(job => {
326331
const tempJob = job as CombinedJobWithStats;
327332

328-
if (calendarsByJobId[tempJob.job_id].length) {
329-
tempJob.calendars = calendarsByJobId[tempJob.job_id];
333+
const calendars: string[] = [
334+
...(calendarsByJobId[tempJob.job_id] || []),
335+
...(globalCalendars || []),
336+
];
337+
if (calendars.length) {
338+
tempJob.calendars = calendars;
330339
}
331340

332341
if (jobStatsResults && jobStatsResults.jobs) {

0 commit comments

Comments
 (0)