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

[ML] AIOps: Improves table hovering for log rate analysis #162941

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -5,8 +5,8 @@
* 2.0.
*/

import React, { FC, useCallback, useMemo, useState } from 'react';
import { orderBy } from 'lodash';
import React, { FC, useCallback, useEffect, useMemo, useState } from 'react';
import { orderBy, isEqual } from 'lodash';
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';

import {
Expand Down Expand Up @@ -336,6 +336,46 @@ export const LogRateAnalysisResultsTable: FC<LogRateAnalysisResultsTableProps> =
};
}, [pageIndex, pageSize, sortField, sortDirection, significantTerms]);

useEffect(() => {
// If no row is hovered or pinned or the user switched to a new page,
// fall back to set the first row into a hovered state to make the
// main document count chart show a comparison view by default.
if (
(selectedSignificantTerm === null ||
!pageOfItems.some((item) => isEqual(item, selectedSignificantTerm))) &&
pinnedSignificantTerm === null &&
pageOfItems.length > 0
) {
setSelectedSignificantTerm(pageOfItems[0]);
}

// If a user switched pages and a pinned row is no longer visible
// on the current page, set the status of pinned rows back to `null`.
if (
pinnedSignificantTerm !== null &&
!pageOfItems.some((item) => isEqual(item, pinnedSignificantTerm))
) {
setPinnedSignificantTerm(null);
}
}, [
selectedSignificantTerm,
setSelectedSignificantTerm,
setPinnedSignificantTerm,
pageOfItems,
pinnedSignificantTerm,
]);

// When the analysis results table unmounts,
// make sure to reset any hovered or pinned rows.
useEffect(
() => () => {
setSelectedSignificantTerm(null);
setPinnedSignificantTerm(null);
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[]
);

const getRowStyle = (significantTerm: SignificantTerm) => {
if (
pinnedSignificantTerm &&
Expand Down Expand Up @@ -393,7 +433,9 @@ export const LogRateAnalysisResultsTable: FC<LogRateAnalysisResultsTableProps> =
}
},
onMouseEnter: () => {
setSelectedSignificantTerm(significantTerm);
if (pinnedSignificantTerm === null) {
setSelectedSignificantTerm(significantTerm);
}
},
onMouseLeave: () => {
setSelectedSignificantTerm(null);
Expand Down
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { FC, useCallback, useMemo, useState } from 'react';
import React, { FC, useCallback, useEffect, useMemo, useState } from 'react';
import { orderBy } from 'lodash';

import {
Expand Down Expand Up @@ -423,6 +423,26 @@ export const LogRateAnalysisResultsGroupsTable: FC<LogRateAnalysisResultsTablePr
};
}, [pageIndex, pageSize, sortField, sortDirection, groupTableItems]);

// If no row is hovered or pinned, fall back to set the first row
// into a hovered state to make the main document count chart
// show a comparison view by default.
useEffect(() => {
peteharverson marked this conversation as resolved.
Show resolved Hide resolved
if (selectedGroup === null && pinnedGroup === null && pageOfItems.length > 0) {
setSelectedGroup(pageOfItems[0]);
}
}, [selectedGroup, setSelectedGroup, pageOfItems, pinnedGroup]);

// When the analysis results table unmounts,
// make sure to reset any hovered or pinned rows.
useEffect(
() => () => {
setSelectedGroup(null);
setPinnedGroup(null);
},
// eslint-disable-next-line react-hooks/exhaustive-deps
[]
);

const getRowStyle = (group: GroupTableItem) => {
if (pinnedGroup && pinnedGroup.id === group.id) {
return {
Expand Down Expand Up @@ -464,7 +484,9 @@ export const LogRateAnalysisResultsGroupsTable: FC<LogRateAnalysisResultsTablePr
}
},
onMouseEnter: () => {
setSelectedGroup(group);
if (pinnedGroup === null) {
setSelectedGroup(group);
}
},
onMouseLeave: () => {
setSelectedGroup(null);
Expand Down