Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[8.x] [ML] Fixes link to anomaly explorer from anomaly embeddables when viewing by job group (#198256) #198515

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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