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

[RAM][Maintenance Window] Fix maintenance window category ID edit UI not initializing correctly. #170352

Merged
merged 2 commits into from
Nov 2, 2023
Merged
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
Expand Up @@ -189,6 +189,43 @@ describe('CreateMaintenanceWindowForm', () => {
expect(managementInput).toBeChecked();
});

it('should initialize MWs with selected category ids properly', async () => {
const result = appMockRenderer.render(
<CreateMaintenanceWindowForm
{...formProps}
initialValue={{
title: 'test',
startDate: '2023-03-24',
endDate: '2023-03-26',
timezone: ['America/Los_Angeles'],
recurring: true,
categoryIds: ['observability', 'management'],
}}
maintenanceWindowId="test"
/>
);

await waitFor(() => {
expect(
result.queryByTestId('maintenanceWindowCategorySelectionLoading')
).not.toBeInTheDocument();
});

const observabilityInput = within(
result.getByTestId('maintenanceWindowCategorySelection')
).getByTestId('checkbox-observability');
const securityInput = within(
result.getByTestId('maintenanceWindowCategorySelection')
).getByTestId('checkbox-securitySolution');
const managementInput = within(
result.getByTestId('maintenanceWindowCategorySelection')
).getByTestId('checkbox-management');

expect(observabilityInput).toBeChecked();
expect(managementInput).toBeChecked();
expect(securityInput).not.toBeChecked();
});

it('can select category IDs', async () => {
const result = appMockRenderer.render(<CreateMaintenanceWindowForm {...formProps} />);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export const CreateMaintenanceWindowForm = React.memo<CreateMaintenanceWindowFor
onSubmit: submitMaintenanceWindow,
});

const [{ recurring, timezone, categoryIds }] = useFormData<FormProps>({
const [{ recurring, timezone, categoryIds }, _, mounted] = useFormData<FormProps>({
form,
watch: ['recurring', 'timezone', 'categoryIds'],
});
Expand Down Expand Up @@ -188,6 +188,9 @@ export const CreateMaintenanceWindowForm = React.memo<CreateMaintenanceWindowFor
if (isEditMode) {
return;
}
if (!mounted) {
return;
}
if (hasSetInitialCategories.current) {
return;
}
Expand All @@ -197,7 +200,7 @@ export const CreateMaintenanceWindowForm = React.memo<CreateMaintenanceWindowFor
setFieldValue('categoryIds', [...new Set(ruleTypes.map((ruleType) => ruleType.category))]);
hasSetInitialCategories.current = true;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isEditMode, ruleTypes]);
}, [isEditMode, ruleTypes, mounted]);

// For edit mode, if a maintenance window => category_ids is not an array, this means
// the maintenance window was created before the introduction of category filters.
Expand All @@ -206,6 +209,9 @@ export const CreateMaintenanceWindowForm = React.memo<CreateMaintenanceWindowFor
if (!isEditMode) {
return;
}
if (!mounted) {
return;
}
if (hasSetInitialCategories.current) {
return;
}
Expand All @@ -219,7 +225,7 @@ export const CreateMaintenanceWindowForm = React.memo<CreateMaintenanceWindowFor
]);
hasSetInitialCategories.current = true;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isEditMode, categoryIds]);
}, [isEditMode, categoryIds, mounted]);

return (
<Form form={form}>
Expand Down
Loading