Skip to content

Commit

Permalink
[8.x] [ML] Fixes link to anomaly explorer from anomaly embeddables wh…
Browse files Browse the repository at this point in the history
…en viewing by job group (#198256) (#198515)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[ML] Fixes link to anomaly explorer from anomaly embeddables when
viewing by job group
(#198256)](#198256)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Robert
Jaszczurek","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-10-31T11:56:50Z","message":"[ML]
Fixes link to anomaly explorer from anomaly embeddables when viewing by
job group (#198256)\n\n## Summary\r\n\r\nFix for:
[#196509](https://github.com/elastic/kibana/issues/196509)\r\n\r\nAfter
fix:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/9d731676-fd47-41fe-8843-8b8e6c6e153d","sha":"9eb8b885148ba8fb5f22a1c64c02452eba5dfca9","branchLabelMapping":{"^v9.0.0$":"main","^v8.17.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:fix",":ml","Feature:Anomaly
Detection","v9.0.0","Team:ML","v8.16.0","backport:version","v8.17.0"],"title":"[ML]
Fixes link to anomaly explorer from anomaly embeddables when viewing by
job
group","number":198256,"url":"https://github.com/elastic/kibana/pull/198256","mergeCommit":{"message":"[ML]
Fixes link to anomaly explorer from anomaly embeddables when viewing by
job group (#198256)\n\n## Summary\r\n\r\nFix for:
[#196509](https://github.com/elastic/kibana/issues/196509)\r\n\r\nAfter
fix:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/9d731676-fd47-41fe-8843-8b8e6c6e153d","sha":"9eb8b885148ba8fb5f22a1c64c02452eba5dfca9"}},"sourceBranch":"main","suggestedTargetBranches":["8.16","8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/198256","number":198256,"mergeCommit":{"message":"[ML]
Fixes link to anomaly explorer from anomaly embeddables when viewing by
job group (#198256)\n\n## Summary\r\n\r\nFix for:
[#196509](https://github.com/elastic/kibana/issues/196509)\r\n\r\nAfter
fix:\r\n\r\n\r\nhttps://github.com/user-attachments/assets/9d731676-fd47-41fe-8843-8b8e6c6e153d","sha":"9eb8b885148ba8fb5f22a1c64c02452eba5dfca9"}},{"branch":"8.16","label":"v8.16.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"8.x","label":"v8.17.0","branchLabelMappingKey":"^v8.17.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Robert Jaszczurek <[email protected]>
  • Loading branch information
kibanamachine and rbrtj authored Oct 31, 2024
1 parent 0f6fd23 commit 1f6547b
Showing 1 changed file with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ function getInvalidJobIds(jobs: MlJobWithTimeRange[], ids: string[]) {
});
}

// This is useful when redirecting from dashboards where groupIds are treated as jobIds
const getJobIdsFromGroups = (jobIds: string[], jobs: MlJobWithTimeRange[]) => {
const result = new Set<string>();

jobIds.forEach((id) => {
const jobsInGroup = jobs.filter((job) => job.groups?.includes(id));

if (jobsInGroup.length > 0) {
jobsInGroup.forEach((job) => result.add(job.job_id));
} else {
// If it's not a group ID, keep it (regardless of whether it's valid or not)
result.add(id);
}
});

return Array.from(result);
};

export interface JobSelection {
jobIds: string[];
selectedGroups: string[];
Expand All @@ -37,9 +55,9 @@ export const useJobSelection = (jobs: MlJobWithTimeRange[]) => {
const getJobSelection = useJobSelectionFlyout();

const tmpIds = useMemo(() => {
const ids = globalState?.ml?.jobIds || [];
const ids = getJobIdsFromGroups(globalState?.ml?.jobIds || [], jobs);
return (typeof ids === 'string' ? [ids] : ids).map((id: string) => String(id));
}, [globalState?.ml?.jobIds]);
}, [globalState?.ml?.jobIds, jobs]);

const invalidIds = useMemo(() => {
return getInvalidJobIds(jobs, tmpIds);
Expand Down

0 comments on commit 1f6547b

Please sign in to comment.