Skip to content

Commit

Permalink
[ML] Fixes link to anomaly explorer from anomaly embeddables when vie…
Browse files Browse the repository at this point in the history
…wing by job group (#198256)

## Summary

Fix for: [#196509](#196509)

After fix:

https://github.com/user-attachments/assets/9d731676-fd47-41fe-8843-8b8e6c6e153d
(cherry picked from commit 9eb8b88)
  • Loading branch information
rbrtj committed Oct 31, 2024
1 parent 52651e7 commit e3c6e56
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 e3c6e56

Please sign in to comment.