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

Increase category field limit from 2 to 5 for time series splitting #982

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
@@ -0,0 +1,14 @@
.categoryFieldComboBox {
// Ensure the combo box can handle multiple selections
.euiComboBoxPill {
max-width: 100%;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}

.euiComboBox__inputWrap {
max-height: 150px; // Adjust height to accommodate more selections
overflow-y: auto;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
validateCategoryField,
} from '../../../../utils/utils';
import { ModelConfigurationFormikValues } from '../../models/interfaces';
import './CategoryField.module.scss';

interface CategoryFieldProps {
isEdit: boolean;
Expand Down Expand Up @@ -74,7 +75,7 @@ export function CategoryField(props: CategoryFieldProps) {
style={{ lineHeight: 'normal' }}
>
Split a single time series into multiple time series based on
categorical fields. You can select up to 2.{' '}
categorical fields. You can select up to 5.{' '}
<EuiLink href={`${BASE_DOCS_LINK}/ad`} target="_blank">
Learn more
</EuiLink>
Expand Down Expand Up @@ -155,7 +156,7 @@ export function CategoryField(props: CategoryFieldProps) {
onChange={(options) => {
const selection = options.map((option) => option.label);
if (!isEmpty(selection)) {
if (selection.length <= 2) {
if (selection.length <= 5) {
Copy link
Member

Choose a reason for hiding this comment

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

would it be possible that we base this number on our plugin setting and we change the default to 5 there as max?
https://github.com/opensearch-project/anomaly-detection/blob/main/src/main/java/org/opensearch/ad/settings/ADNumericSetting.java#L40

form.setFieldValue('categoryField', selection);
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,64 @@ describe('<CategoryField /> spec', () => {
expect(queryByText('b')).not.toBeNull();
expect(queryByText('c')).toBeNull();
});
test(`limits selection to a maximum of 5 entities`, () => {
const { getAllByRole, getByTestId, queryByText } = render(
<Fragment>
<Formik
initialValues={{
categoryField: [],
}}
onSubmit={() => {}}
>
<Fragment>
<Form>
<CategoryField
isEdit={false}
isHCDetector={true}
categoryFieldOptions={['a', 'b', 'c', 'd', 'e', 'f']}
setIsHCDetector={(isHCDetector: boolean) => {
return;
}}
isLoading={false}
formikProps={{
values: {
categoryFieldEnabled: true,
},
}}
/>
</Form>
</Fragment>
</Formik>
</Fragment>
);
// open combo box
fireEvent.click(getByTestId('comboBoxToggleListButton'));
expect(queryByText('a')).not.toBeNull();
expect(queryByText('b')).not.toBeNull();
expect(queryByText('c')).not.toBeNull();
expect(queryByText('d')).not.toBeNull();
expect(queryByText('e')).not.toBeNull();
expect(queryByText('f')).not.toBeNull();

// select top 6 options (a, b, c, d, e, f)
fireEvent.click(getAllByRole('option')[0]);
fireEvent.click(getAllByRole('option')[0]);
fireEvent.click(getAllByRole('option')[0]);
fireEvent.click(getAllByRole('option')[0]);
fireEvent.click(getAllByRole('option')[0]);
fireEvent.click(getAllByRole('option')[0]);

// close combo box
fireEvent.click(getByTestId('comboBoxToggleListButton'));

// the last selection (f) is still not selected
expect(queryByText('a')).not.toBeNull();
expect(queryByText('b')).not.toBeNull();
expect(queryByText('c')).not.toBeNull();
expect(queryByText('d')).not.toBeNull();
expect(queryByText('e')).not.toBeNull();
expect(queryByText('f')).toBeNull();
});
test(`fields are readonly if editing`, () => {
const { getByTestId, queryByText } = render(
<Fragment>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ exports[`<CategoryField /> spec renders the component when disabled 1`] = `
class="euiText euiText--medium content-panel-subTitle"
style="line-height: normal;"
>
Split a single time series into multiple time series based on categorical fields. You can select up to 2.
Split a single time series into multiple time series based on categorical fields. You can select up to 5.

<a
class="euiLink euiLink--primary"
Expand Down Expand Up @@ -170,7 +170,7 @@ exports[`<CategoryField /> spec renders the component when enabled 1`] = `
class="euiText euiText--medium content-panel-subTitle"
style="line-height: normal;"
>
Split a single time series into multiple time series based on categorical fields. You can select up to 2.
Split a single time series into multiple time series based on categorical fields. You can select up to 5.

<a
class="euiLink euiLink--primary"
Expand Down