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 Log Rate Analysis: adds controls for controlling which columns will be visible #184262

Merged
Show file tree
Hide file tree
Changes from 7 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 @@ -17,7 +17,7 @@ interface FieldFilterApplyButtonProps {
tooltipContent?: string;
}

export const FieldFilterApplyButton: FC<FieldFilterApplyButtonProps> = ({
export const ItemFilterApplyButton: FC<FieldFilterApplyButtonProps> = ({
disabled,
onClick,
tooltipContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,38 @@ import {
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';

import { FieldFilterApplyButton } from './field_filter_apply_button';
import { ItemFilterApplyButton } from './item_filter_apply_button';

interface FieldFilterPopoverProps {
interface ItemFilterPopoverProps {
disabled?: boolean;
disabledApplyButton?: boolean;
uniqueFieldNames: string[];
onChange: (skippedFields: string[]) => void;
disabledApplyTooltipContent?: string;
helpText: string;
itemSearchAriaLabel: string;
initialSkippedItems?: string[];
popoverButtonTitle: string;
selectedItemLimit?: number;
uniqueItemNames: string[];
onChange: (skippedItems: string[]) => void;
}

// This component is mostly inspired by EUI's Data Grid Column Selector
// https://github.com/elastic/eui/blob/main/src/components/datagrid/controls/column_selector.tsx
export const FieldFilterPopover: FC<FieldFilterPopoverProps> = ({
export const ItemFilterPopover: FC<ItemFilterPopoverProps> = ({
disabled,
disabledApplyButton,
uniqueFieldNames,
disabledApplyTooltipContent,
helpText,
itemSearchAriaLabel,
initialSkippedItems = [],
popoverButtonTitle,
selectedItemLimit = 2,
uniqueItemNames,
onChange,
}) => {
const euiThemeContext = useEuiTheme();
// Inspired by https://github.com/elastic/eui/blob/main/src/components/datagrid/controls/_data_grid_column_selector.scss
const fieldSelectPopover = useMemo(
const itemSelectPopover = useMemo(
() => css`
${euiYScrollWithShadows(euiThemeContext, {})}
max-height: 400px;
Expand All @@ -55,97 +67,91 @@ export const FieldFilterPopover: FC<FieldFilterPopoverProps> = ({
);

const [isTouched, setIsTouched] = useState(false);
const [fieldSearchText, setFieldSearchText] = useState('');
const [skippedFields, setSkippedFields] = useState<string[]>([]);
const setFieldsFilter = (fieldNames: string[], checked: boolean) => {
let updatedSkippedFields = [...skippedFields];
const [itemSearchText, setItemSearchText] = useState('');
const [skippedItems, setSkippedItems] = useState<string[]>(initialSkippedItems);
const setItemsFilter = (itemNames: string[], checked: boolean) => {
let updatedSkippedItems = [...skippedItems];
if (!checked) {
updatedSkippedFields.push(...fieldNames);
updatedSkippedItems.push(...itemNames);
} else {
updatedSkippedFields = skippedFields.filter((d) => !fieldNames.includes(d));
updatedSkippedItems = skippedItems.filter((d) => !itemNames.includes(d));
}
setSkippedFields(updatedSkippedFields);
// Ensure there are no duplicates
setSkippedItems([...new Set(updatedSkippedItems)]);
setIsTouched(true);
};

const [isFieldSelectionPopoverOpen, setIsFieldSelectionPopoverOpen] = useState(false);
const onFieldSelectionButtonClick = () => setIsFieldSelectionPopoverOpen((isOpen) => !isOpen);
const closePopover = () => setIsFieldSelectionPopoverOpen(false);
const [isItemSelectionPopoverOpen, setIsItemSelectionPopoverOpen] = useState(false);
const onItemSelectionButtonClick = () => setIsItemSelectionPopoverOpen((isOpen) => !isOpen);
const closePopover = () => setIsItemSelectionPopoverOpen(false);

const filteredUniqueFieldNames = useMemo(() => {
return uniqueFieldNames.filter(
(d) => d.toLowerCase().indexOf(fieldSearchText.toLowerCase()) !== -1
const filteredUniqueItemNames = useMemo(() => {
return uniqueItemNames.filter(
(d) => d.toLowerCase().indexOf(itemSearchText.toLowerCase()) !== -1
);
}, [fieldSearchText, uniqueFieldNames]);
}, [itemSearchText, uniqueItemNames]);

// If the supplied list of unique field names changes, do a sanity check to only
// keep field names in the list of skipped fields that still are in the list of unique fields.
useEffect(() => {
setSkippedFields((previousSkippedFields) =>
previousSkippedFields.filter((d) => uniqueFieldNames.includes(d))
setSkippedItems((previousSkippedItems) =>
previousSkippedItems.filter((d) => uniqueItemNames.includes(d))
);
}, [uniqueFieldNames]);
}, [uniqueItemNames]);

const selectedFieldCount = uniqueFieldNames.length - skippedFields.length;
const selectedItemCount = uniqueItemNames.length - skippedItems.length;

return (
<EuiPopover
data-test-subj="aiopsFieldFilterPopover"
anchorPosition="downLeft"
panelPaddingSize="s"
panelStyle={{ minWidth: '20%' }}
button={
<EuiButton
data-test-subj="aiopsFieldFilterButton"
onClick={onFieldSelectionButtonClick}
onClick={onItemSelectionButtonClick}
disabled={disabled}
size="s"
iconType="arrowDown"
iconSide="right"
iconSize="s"
color="text"
>
<FormattedMessage
id="xpack.aiops.logRateAnalysis.page.fieldFilterButtonLabel"
defaultMessage="Filter fields"
/>
{popoverButtonTitle}
</EuiButton>
}
isOpen={isFieldSelectionPopoverOpen}
isOpen={isItemSelectionPopoverOpen}
closePopover={closePopover}
>
<EuiPopoverTitle>
<EuiText size="xs" color="subdued" style={{ maxWidth: '400px' }}>
<FormattedMessage
id="xpack.aiops.logRateAnalysis.page.fieldFilterHelpText"
defaultMessage="Deselect non-relevant fields to remove them from groups and click the Apply button to rerun the grouping. Use the search bar to filter the list, then select/deselect multiple fields with the actions below."
/>
{helpText}
</EuiText>
<EuiSpacer size="s" />
<EuiFieldText
compressed
placeholder={i18n.translate('xpack.aiops.analysis.fieldSelectorPlaceholder', {
defaultMessage: 'Search',
})}
aria-label={i18n.translate('xpack.aiops.analysis.fieldSelectorAriaLabel', {
defaultMessage: 'Filter fields',
})}
value={fieldSearchText}
onChange={(e: ChangeEvent<HTMLInputElement>) => setFieldSearchText(e.currentTarget.value)}
aria-label={itemSearchAriaLabel}
value={itemSearchText}
onChange={(e: ChangeEvent<HTMLInputElement>) => setItemSearchText(e.currentTarget.value)}
data-test-subj="aiopsFieldSelectorSearch"
/>
</EuiPopoverTitle>
<div css={fieldSelectPopover} data-test-subj="aiopsFieldSelectorFieldNameList">
{filteredUniqueFieldNames.map((fieldName) => (
<div css={itemSelectPopover} data-test-subj="aiopsFieldSelectorFieldNameList">
{filteredUniqueItemNames.map((fieldName) => (
<div key={fieldName} css={{ padding: '4px' }}>
<EuiSwitch
data-test-subj={`aiopsFieldSelectorFieldNameListItem${
!skippedFields.includes(fieldName) ? ' checked' : ''
!skippedItems.includes(fieldName) ? ' checked' : ''
}`}
className="euiSwitch--mini"
compressed
label={fieldName}
onChange={(e) => setFieldsFilter([fieldName], e.target.checked)}
checked={!skippedFields.includes(fieldName)}
onChange={(e) => setItemsFilter([fieldName], e.target.checked)}
checked={!skippedItems.includes(fieldName)}
/>
</div>
))}
Expand All @@ -162,19 +168,19 @@ export const FieldFilterPopover: FC<FieldFilterPopoverProps> = ({
<EuiButtonEmpty
size="xs"
flush="left"
onClick={() => setFieldsFilter(filteredUniqueFieldNames, true)}
disabled={fieldSearchText.length > 0 && filteredUniqueFieldNames.length === 0}
onClick={() => setItemsFilter(filteredUniqueItemNames, true)}
disabled={itemSearchText.length > 0 && filteredUniqueItemNames.length === 0}
data-test-subj="aiopsFieldSelectorSelectAllFieldsButton"
>
{fieldSearchText.length > 0 ? (
{itemSearchText.length > 0 ? (
<FormattedMessage
id="xpack.aiops.logRateAnalysis.page.fieldSelector.selectAllSearchedFields"
defaultMessage="Select filtered fields"
id="xpack.aiops.logRateAnalysis.page.fieldSelector.selectAllSearchedItems"
defaultMessage="Select filtered"
/>
) : (
<FormattedMessage
id="xpack.aiops.logRateAnalysis.page.fieldSelector.selectAllFields"
defaultMessage="Select all fields"
id="xpack.aiops.logRateAnalysis.page.fieldSelector.selectAllItems"
defaultMessage="Select all"
/>
)}
</EuiButtonEmpty>
Expand All @@ -183,39 +189,35 @@ export const FieldFilterPopover: FC<FieldFilterPopoverProps> = ({
<EuiButtonEmpty
size="xs"
flush="right"
onClick={() => setFieldsFilter(filteredUniqueFieldNames, false)}
disabled={fieldSearchText.length > 0 && filteredUniqueFieldNames.length === 0}
onClick={() => setItemsFilter(filteredUniqueItemNames, false)}
disabled={itemSearchText.length > 0 && filteredUniqueItemNames.length === 0}
data-test-subj="aiopsFieldSelectorDeselectAllFieldsButton"
>
{fieldSearchText.length > 0 ? (
{itemSearchText.length > 0 ? (
<FormattedMessage
id="xpack.aiops.logRateAnalysis.page.fieldSelector.deselectAllSearchedFields"
defaultMessage="Deselect filtered fields"
id="xpack.aiops.logRateAnalysis.page.fieldSelector.deselectAllSearchedItems"
defaultMessage="Deselect filtered"
/>
) : (
<FormattedMessage
id="xpack.aiops.logRateAnalysis.page.fieldSelector.deselectAllFields"
defaultMessage="Deselect all fields"
id="xpack.aiops.logRateAnalysis.page.fieldSelector.deselectAllItems"
defaultMessage="Deselect all"
/>
)}
</EuiButtonEmpty>
</EuiFlexItem>
</>
<EuiFlexItem grow={false}>
<FieldFilterApplyButton
<ItemFilterApplyButton
onClick={() => {
onChange(skippedFields);
setFieldSearchText('');
setIsFieldSelectionPopoverOpen(false);
onChange(skippedItems);
setItemSearchText('');
setIsItemSelectionPopoverOpen(false);
closePopover();
}}
disabled={disabledApplyButton || selectedFieldCount < 2 || !isTouched}
disabled={disabledApplyButton || selectedItemCount < selectedItemLimit || !isTouched}
tooltipContent={
selectedFieldCount < 2
? i18n.translate('xpack.aiops.analysis.fieldSelectorNotEnoughFieldsSelected', {
defaultMessage: 'Grouping requires at least 2 fields to be selected.',
})
: undefined
selectedItemCount < selectedItemLimit ? disabledApplyTooltipContent : undefined
}
/>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@ import { useLogRateAnalysisStateContext } from '@kbn/aiops-components';

import { useAiopsAppContext } from '../../hooks/use_aiops_app_context';
import { useDataSource } from '../../hooks/use_data_source';
import {
commonColumns,
significantItemColumns,
} from '../log_rate_analysis_results_table/use_columns';

import {
getGroupTableItems,
LogRateAnalysisResultsTable,
LogRateAnalysisResultsGroupsTable,
} from '../log_rate_analysis_results_table';

import { FieldFilterPopover } from './field_filter_popover';
import { ItemFilterPopover as FieldFilterPopover } from './item_filter_popover';
import { ItemFilterPopover as ColumnFilterPopover } from './item_filter_popover';
import { LogRateAnalysisTypeCallOut } from './log_rate_analysis_type_callout';

const groupResultsMessage = i18n.translate(
Expand Down Expand Up @@ -77,6 +82,37 @@ const groupResultsOnMessage = i18n.translate(
);
const resultsGroupedOffId = 'aiopsLogRateAnalysisGroupingOff';
const resultsGroupedOnId = 'aiopsLogRateAnalysisGroupingOn';
const fieldFilterHelpText = i18n.translate('xpack.aiops.logRateAnalysis.page.fieldFilterHelpText', {
defaultMessage:
'Deselect non-relevant fields to remove them from groups and click the Apply button to rerun the grouping. Use the search bar to filter the list, then select/deselect multiple fields with the actions below.',
});
const columnsFilterHelpText = i18n.translate(
'xpack.aiops.logRateAnalysis.page.columnsFilterHelpText',
{
defaultMessage: 'Configure visible columns.',
}
);
const disabledFieldFilterApplyButtonTooltipContent = i18n.translate(
'xpack.aiops.analysis.fieldSelectorNotEnoughFieldsSelected',
{
defaultMessage: 'Grouping requires at least 2 fields to be selected.',
}
);
const disabledColumnFilterApplyButtonTooltipContent = i18n.translate(
'xpack.aiops.analysis.columnSelectorNotEnoughColumnsSelected',
{
defaultMessage: 'At least one column must be selected.',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the 'at least one' correct? It seems to require at least two columns.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch - fixed in 72f120e

}
);
const columnSearchAriaLabel = i18n.translate('xpack.aiops.analysis.columnSelectorAriaLabel', {
defaultMessage: 'Filter columns',
});
const columnsButton = i18n.translate('xpack.aiops.logRateAnalysis.page.columnsFilterButtonLabel', {
defaultMessage: 'Columns',
});
const fieldsButton = i18n.translate('xpack.aiops.analysis.fieldFilterButtonLabel', {
defaultMessage: 'Filter fields',
});

/**
* Interface for log rate analysis results data.
Expand Down Expand Up @@ -157,6 +193,7 @@ export const LogRateAnalysisResults: FC<LogRateAnalysisResultsProps> = ({
);
const [shouldStart, setShouldStart] = useState(false);
const [toggleIdSelected, setToggleIdSelected] = useState(resultsGroupedOffId);
const [skippedColumns, setSkippedColumns] = useState<string[]>(['p-value']);
Copy link
Member

@jgowdyelastic jgowdyelastic Jun 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice if this could be ColumnNames[] rather than string. It'll probably mean changing all places where they are stored as a string array, but it'd be useful to use the types to enforce that only the correct values are used.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in c1876b9


const onGroupResultsToggle = (optionId: string) => {
setToggleIdSelected(optionId);
Expand All @@ -179,6 +216,10 @@ export const LogRateAnalysisResults: FC<LogRateAnalysisResultsProps> = ({
startHandler(true, false);
};

const onVisibleColumnsChange = (columns: string[]) => {
setSkippedColumns(columns);
};

const {
cancel,
start,
Expand Down Expand Up @@ -380,10 +421,32 @@ export const LogRateAnalysisResults: FC<LogRateAnalysisResultsProps> = ({
<FieldFilterPopover
disabled={!groupResults || isRunning}
disabledApplyButton={isRunning}
uniqueFieldNames={uniqueFieldNames}
disabledApplyTooltipContent={disabledFieldFilterApplyButtonTooltipContent}
helpText={fieldFilterHelpText}
itemSearchAriaLabel={fieldsButton}
popoverButtonTitle={fieldsButton}
uniqueItemNames={uniqueFieldNames}
onChange={onFieldsFilterChange}
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<ColumnFilterPopover
disabled={isRunning}
disabledApplyButton={isRunning}
disabledApplyTooltipContent={disabledColumnFilterApplyButtonTooltipContent}
helpText={columnsFilterHelpText}
itemSearchAriaLabel={columnSearchAriaLabel}
initialSkippedItems={skippedColumns}
popoverButtonTitle={columnsButton}
selectedItemLimit={1}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm seeing a weird issue where if I open the popover, hit 'Deselect all', I then have to select 2 items (or sometimes more) to get the Apply button enabled:

Screenshot 2024-06-06 at 10 40 43

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Fixed this issue in 7f58298
It now takes into account the incoming skipped items 👍

uniqueItemNames={
qn895 marked this conversation as resolved.
Show resolved Hide resolved
(groupResults
? Object.values(commonColumns)
: Object.values(significantItemColumns)) as string[]
}
onChange={onVisibleColumnsChange}
/>
</EuiFlexItem>
</ProgressControls>
{showLogRateAnalysisResultsTable && currentAnalysisType !== undefined && (
<>
Expand Down Expand Up @@ -481,6 +544,7 @@ export const LogRateAnalysisResults: FC<LogRateAnalysisResultsProps> = ({
>
{showLogRateAnalysisResultsTable && groupResults ? (
<LogRateAnalysisResultsGroupsTable
skippedColumns={skippedColumns}
significantItems={data.significantItems}
groupTableItems={groupTableItems}
loading={isRunning}
Expand All @@ -493,6 +557,7 @@ export const LogRateAnalysisResults: FC<LogRateAnalysisResultsProps> = ({
) : null}
{showLogRateAnalysisResultsTable && !groupResults ? (
<LogRateAnalysisResultsTable
skippedColumns={skippedColumns}
significantItems={data.significantItems}
loading={isRunning}
timeRangeMs={timeRangeMs}
Expand Down
Loading