Skip to content

[ResponseOps][MaintenanceWindows] Move recurring schedule form to dedicated package#220535

Merged
umbopepato merged 10 commits intoelastic:mainfrom
umbopepato:219454-move-recurring-schedule-form-to-package
Jun 10, 2025
Merged

[ResponseOps][MaintenanceWindows] Move recurring schedule form to dedicated package#220535
umbopepato merged 10 commits intoelastic:mainfrom
umbopepato:219454-move-recurring-schedule-form-to-package

Conversation

@umbopepato
Copy link
Member

@umbopepato umbopepato commented May 8, 2025

Summary

Moves the recurring schedule (rrule) form from the Maintenance Windows form to a dedicated package.

Implementation details

Because of the tight time constraints we have for this epic, I tried to change the recurring schedule form as little as possible, keeping the existing form-lib-based implementation and adding an intermediate layer to embed the editing UI in larger forms (i.e. MW form). While this is not particularly elegant, it allows us to build on top of an existing, tested codebase and to leverage form-lib's validation and state management capabilities.

In the context of the MW form, the recurring schedule editor is treated as a single field. Value and error updates are synced through form-lib's field hook API:

<UseField<RecurringSchedule, FormProps> path={path}>
{({ value, setValue, setErrors }) => (
<RecurringScheduleForm
recurringSchedule={value}
onRecurringScheduleChange={setValue}
onErrorsChange={(errors) => {
setErrors(errors.map((message) => ({ path, message })));
}}
startDate={startDate}
endDate={endDate}
timezone={timezone}
/>
)}
</UseField>

Errors are handled internally by the schedule editor, but must still be surfaced up to the parent form in order to have a consistent validity state (otherwise submits are not prevented even if errors are shown in the UI).

The recurring schedule form schema and form fields are exported to be reused in larger form-lib forms.

References

Closes #219454

Checklist

@umbopepato umbopepato added release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// backport:version Backport to applied version labels v9.1.0 v8.19.0 labels May 8, 2025
@umbopepato umbopepato marked this pull request as ready for review May 27, 2025 15:35
@umbopepato umbopepato requested a review from a team as a code owner May 27, 2025 15:35
@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops (Team:ResponseOps)

target: { value: Frequency.MONTHLY },
}
);
await waitFor(() => expect(screen.getByTestId('bymonth-field')).toBeInTheDocument());
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
await waitFor(() => expect(screen.getByTestId('bymonth-field')).toBeInTheDocument());
expect(await screen.findByTestId('bymonth-field')).toBeInTheDocument();
return (
<UseField<RecurringSchedule, FormProps> path={path}>
{({ value, setValue, setErrors }) => (
<RecurringScheduleForm
Copy link
Contributor

@adcoelho adcoelho Jun 3, 2025

Choose a reason for hiding this comment

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

I tried to change the recurring schedule form as little as possible, keeping the existing form-lib-based implementation and adding an intermediate layer to embed the editing UI in larger forms (i.e., MW form). While this is not particularly elegant, it allows us to build on top of an existing, tested codebase and to leverage form-lib's validation and state management capabilities.

I am still a bit unsure about this.

I'll up my conclusions after reading the code, and let me know if they are right:

  1. RecurringSchedule was previously used in MW
  2. RecurringSchedule used to be just a wrapper around multiple UseFields.
  3. RecurringSchedule was moved to a package and wrapped in <Form>.

Now, in MW we have something like:

<Form> // <CreateMaintenanceWindowForm>
    ...
    <ABunchOfOtherFields>
    ...
    <UseField> // <RecurringScheduleField> 
        <Form> // <RecurringScheduleForm> 
            <UseField> // the same as the previous RecurringSchedule implementation
            ...

I'm not sure I like the Form > UseField > Form approach, or rather, I'm unsure what to expect in its behavior.

For example, the recurringSchedule schema was removed from maintenance_windows/components/schema.ts, which now comes from RecurringScheduleForm. What should be expected when submitting CreateMaintenanceWindowForm?

Validation appears to be working fine(I tested the PR a bit), but maybe there is a simpler solution.

Why not split RecurringScheduleForm in the package into Form and Fields, and import here only the fields(similar to what was done before)?

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 not sure I like the Form > UseField > Form approach, I'm unsure what to expect in its behavior.

+1 on that. This would be a simpler solution to have Fields (frequency, interval etc.) as one component which could be used in RecurringScheduleForm and imported to MW and used directly in CreateMaintenanceWindowForm.

Copy link
Member Author

@umbopepato umbopepato Jun 9, 2025

Choose a reason for hiding this comment

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

Although not very elegant, the intention was to hide the form lib editing functionality inside the schedule component and just expose a value/onChange prop API to the exterior so the same component could be used in other types of forms or editing UIs too. Since all the forms that use this schedule fields are currently all form-lib-based, and you too have doubts on the encapsulated solution, I switched to exporting the schema and the fields separately. We can always move to a more generic solution later if needed.

Copy link
Contributor

@js-jankisalvi js-jankisalvi left a comment

Choose a reason for hiding this comment

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

Verified locally, works as expected. Had only one concern about wrapping a form inside field mentioned above

@umbopepato umbopepato force-pushed the 219454-move-recurring-schedule-form-to-package branch from b1f975d to 55c5526 Compare June 9, 2025 13:09
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
alerting 216 219 +3

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
alerting 91.2KB 91.4KB +181.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
@kbn/response-ops-recurring-schedule-form - 1 +1

Total ESLint disabled count

id before after diff
@kbn/response-ops-recurring-schedule-form - 1 +1

History

@umbopepato umbopepato merged commit 664a435 into elastic:main Jun 10, 2025
12 checks passed
@kibanamachine
Copy link
Contributor

Starting backport for target branches: 8.19

https://github.com/elastic/kibana/actions/runs/15554987050

@kibanamachine
Copy link
Contributor

💔 All backports failed

Status Branch Result
8.19 Backport failed because of merge conflicts

Manual backport

To create the backport manually run:

node scripts/backport --pr 220535

Questions ?

Please refer to the Backport tool documentation

@umbopepato
Copy link
Member Author

💚 All backports created successfully

Status Branch Result
8.19

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

umbopepato added a commit to umbopepato/kibana that referenced this pull request Jun 10, 2025
…icated package (elastic#220535)

## Summary

Moves the recurring schedule (rrule) form from the Maintenance Windows
form to a dedicated package.

## Implementation details

~~Because of the tight time constraints we have for this epic, I tried
to change the recurring schedule form as little as possible, keeping the
existing form-lib-based implementation and adding an intermediate layer
to embed the editing UI in larger forms (i.e. MW form). While this is
not particularly elegant, it allows us to build on top of an existing,
tested codebase and to leverage form-lib's validation and state
management capabilities.~~

~~In the context of the MW form, the recurring schedule editor is
treated as a single field. Value and error updates are synced through
form-lib's field hook API:~~

https://github.com/elastic/kibana/blob/acd6a4823e5b9c53ae7cbed59a246972ab32cfe0/x-pack/platform/plugins/shared/alerting/public/pages/maintenance_windows/components/recurring_schedule_field.tsx#L21-L34

~~Errors are handled internally by the schedule editor, but must still
be surfaced up to the parent form in order to have a consistent validity
state (otherwise submits are not prevented even if errors are shown in
the UI).~~

The recurring schedule form schema and form fields are exported to be
reused in larger form-lib forms.

## References

Closes elastic#219454

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
(cherry picked from commit 664a435)

# Conflicts:
#	src/platform/packages/shared/response-ops/recurring-schedule-form/utils/convert_to_rrule.ts
#	src/platform/packages/shared/response-ops/recurring-schedule-form/utils/parse_schedule.ts
#	src/platform/packages/shared/response-ops/recurring-schedule-form/utils/recurring_summary.ts
#	x-pack/platform/plugins/shared/alerting/public/pages/maintenance_windows/components/recurring_schedule_form/custom_recurring_schedule.test.tsx
#	x-pack/platform/plugins/shared/alerting/public/pages/maintenance_windows/components/recurring_schedule_form/custom_recurring_schedule.tsx
#	x-pack/platform/plugins/shared/alerting/public/pages/maintenance_windows/components/recurring_schedule_form/recurring_schedule.test.tsx
#	x-pack/platform/plugins/shared/alerting/public/pages/maintenance_windows/components/recurring_schedule_form/recurring_schedule.tsx
#	x-pack/platform/plugins/shared/alerting/public/pages/maintenance_windows/constants.ts
umbopepato added a commit that referenced this pull request Jun 10, 2025
… to dedicated package (#220535) (#223203)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[ResponseOps][MaintenanceWindows] Move recurring schedule form to
dedicated package
(#220535)](#220535)

<!--- Backport version: 10.0.0 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Umberto
Pepato","email":"umbopepato@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-06-10T08:50:22Z","message":"[ResponseOps][MaintenanceWindows]
Move recurring schedule form to dedicated package (#220535)\n\n##
Summary\n\nMoves the recurring schedule (rrule) form from the
Maintenance Windows\nform to a dedicated package.\n\n## Implementation
details\n\n~~Because of the tight time constraints we have for this
epic, I tried\nto change the recurring schedule form as little as
possible, keeping the\nexisting form-lib-based implementation and adding
an intermediate layer\nto embed the editing UI in larger forms (i.e. MW
form). While this is\nnot particularly elegant, it allows us to build on
top of an existing,\ntested codebase and to leverage form-lib's
validation and state\nmanagement capabilities.~~\n\n~~In the context of
the MW form, the recurring schedule editor is\ntreated as a single
field. Value and error updates are synced through\nform-lib's field hook
API:~~\n\n\nhttps://github.com/elastic/kibana/blob/acd6a4823e5b9c53ae7cbed59a246972ab32cfe0/x-pack/platform/plugins/shared/alerting/public/pages/maintenance_windows/components/recurring_schedule_field.tsx#L21-L34\n\n~~Errors
are handled internally by the schedule editor, but must still\nbe
surfaced up to the parent form in order to have a consistent
validity\nstate (otherwise submits are not prevented even if errors are
shown in\nthe UI).~~\n\nThe recurring schedule form schema and form
fields are exported to be\nreused in larger form-lib forms.\n\n##
References\n\nCloses #219454\n\n### Checklist\n\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common
scenarios\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"664a435e6c20444217c9215bfa280c3f8fe9320e","branchLabelMapping":{"^v9.1.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","Team:ResponseOps","backport:version","v9.1.0","v8.19.0"],"title":"[ResponseOps][MaintenanceWindows]
Move recurring schedule form to dedicated
package","number":220535,"url":"https://github.com/elastic/kibana/pull/220535","mergeCommit":{"message":"[ResponseOps][MaintenanceWindows]
Move recurring schedule form to dedicated package (#220535)\n\n##
Summary\n\nMoves the recurring schedule (rrule) form from the
Maintenance Windows\nform to a dedicated package.\n\n## Implementation
details\n\n~~Because of the tight time constraints we have for this
epic, I tried\nto change the recurring schedule form as little as
possible, keeping the\nexisting form-lib-based implementation and adding
an intermediate layer\nto embed the editing UI in larger forms (i.e. MW
form). While this is\nnot particularly elegant, it allows us to build on
top of an existing,\ntested codebase and to leverage form-lib's
validation and state\nmanagement capabilities.~~\n\n~~In the context of
the MW form, the recurring schedule editor is\ntreated as a single
field. Value and error updates are synced through\nform-lib's field hook
API:~~\n\n\nhttps://github.com/elastic/kibana/blob/acd6a4823e5b9c53ae7cbed59a246972ab32cfe0/x-pack/platform/plugins/shared/alerting/public/pages/maintenance_windows/components/recurring_schedule_field.tsx#L21-L34\n\n~~Errors
are handled internally by the schedule editor, but must still\nbe
surfaced up to the parent form in order to have a consistent
validity\nstate (otherwise submits are not prevented even if errors are
shown in\nthe UI).~~\n\nThe recurring schedule form schema and form
fields are exported to be\nreused in larger form-lib forms.\n\n##
References\n\nCloses #219454\n\n### Checklist\n\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common
scenarios\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"664a435e6c20444217c9215bfa280c3f8fe9320e"}},"sourceBranch":"main","suggestedTargetBranches":["8.19"],"targetPullRequestStates":[{"branch":"main","label":"v9.1.0","branchLabelMappingKey":"^v9.1.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/220535","number":220535,"mergeCommit":{"message":"[ResponseOps][MaintenanceWindows]
Move recurring schedule form to dedicated package (#220535)\n\n##
Summary\n\nMoves the recurring schedule (rrule) form from the
Maintenance Windows\nform to a dedicated package.\n\n## Implementation
details\n\n~~Because of the tight time constraints we have for this
epic, I tried\nto change the recurring schedule form as little as
possible, keeping the\nexisting form-lib-based implementation and adding
an intermediate layer\nto embed the editing UI in larger forms (i.e. MW
form). While this is\nnot particularly elegant, it allows us to build on
top of an existing,\ntested codebase and to leverage form-lib's
validation and state\nmanagement capabilities.~~\n\n~~In the context of
the MW form, the recurring schedule editor is\ntreated as a single
field. Value and error updates are synced through\nform-lib's field hook
API:~~\n\n\nhttps://github.com/elastic/kibana/blob/acd6a4823e5b9c53ae7cbed59a246972ab32cfe0/x-pack/platform/plugins/shared/alerting/public/pages/maintenance_windows/components/recurring_schedule_field.tsx#L21-L34\n\n~~Errors
are handled internally by the schedule editor, but must still\nbe
surfaced up to the parent form in order to have a consistent
validity\nstate (otherwise submits are not prevented even if errors are
shown in\nthe UI).~~\n\nThe recurring schedule form schema and form
fields are exported to be\nreused in larger form-lib forms.\n\n##
References\n\nCloses #219454\n\n### Checklist\n\n- [x] [Unit or
functional\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\nwere
updated or added to match the most common
scenarios\n\n---------\n\nCo-authored-by: kibanamachine
<42973632+kibanamachine@users.noreply.github.com>","sha":"664a435e6c20444217c9215bfa280c3f8fe9320e"}},{"branch":"8.19","label":"v8.19.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
pmuellr pushed a commit to pmuellr/kibana that referenced this pull request Jun 11, 2025
…icated package (elastic#220535)

## Summary

Moves the recurring schedule (rrule) form from the Maintenance Windows
form to a dedicated package.

## Implementation details

~~Because of the tight time constraints we have for this epic, I tried
to change the recurring schedule form as little as possible, keeping the
existing form-lib-based implementation and adding an intermediate layer
to embed the editing UI in larger forms (i.e. MW form). While this is
not particularly elegant, it allows us to build on top of an existing,
tested codebase and to leverage form-lib's validation and state
management capabilities.~~

~~In the context of the MW form, the recurring schedule editor is
treated as a single field. Value and error updates are synced through
form-lib's field hook API:~~


https://github.com/elastic/kibana/blob/acd6a4823e5b9c53ae7cbed59a246972ab32cfe0/x-pack/platform/plugins/shared/alerting/public/pages/maintenance_windows/components/recurring_schedule_field.tsx#L21-L34

~~Errors are handled internally by the schedule editor, but must still
be surfaced up to the parent form in order to have a consistent validity
state (otherwise submits are not prevented even if errors are shown in
the UI).~~

The recurring schedule form schema and form fields are exported to be
reused in larger form-lib forms.

## References

Closes elastic#219454

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
nickpeihl pushed a commit to nickpeihl/kibana that referenced this pull request Jun 12, 2025
…icated package (elastic#220535)

## Summary

Moves the recurring schedule (rrule) form from the Maintenance Windows
form to a dedicated package.

## Implementation details

~~Because of the tight time constraints we have for this epic, I tried
to change the recurring schedule form as little as possible, keeping the
existing form-lib-based implementation and adding an intermediate layer
to embed the editing UI in larger forms (i.e. MW form). While this is
not particularly elegant, it allows us to build on top of an existing,
tested codebase and to leverage form-lib's validation and state
management capabilities.~~

~~In the context of the MW form, the recurring schedule editor is
treated as a single field. Value and error updates are synced through
form-lib's field hook API:~~


https://github.com/elastic/kibana/blob/acd6a4823e5b9c53ae7cbed59a246972ab32cfe0/x-pack/platform/plugins/shared/alerting/public/pages/maintenance_windows/components/recurring_schedule_field.tsx#L21-L34

~~Errors are handled internally by the schedule editor, but must still
be surfaced up to the parent form in order to have a consistent validity
state (otherwise submits are not prevented even if errors are shown in
the UI).~~

The recurring schedule form schema and form fields are exported to be
reused in larger form-lib forms.

## References

Closes elastic#219454

### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
umbopepato added a commit that referenced this pull request Jun 23, 2025
## Summary

> [!IMPORTANT]
> This PR is targeting the `scheduled-reports-ui` feature branch, where
the backend changes from the `scheduled-reports` branch are temporarily
integrated while waiting for
#221028 to be merged (see the
squashed `[TMP] ...` commit message).

Implements the flyout UI for the creation and read-only viewing of
scheduled reports (exports).

<img height="500" alt="image"
src="https://github.com/user-attachments/assets/6bbd274b-1bbb-481f-ac40-4d7131be6d85"
/>

<details>

<summary>

## Known issues

</summary>

- Console error due to `compressed` attribute wrongly forwarded by
form-hook-lib to DOM element (this is likely a form lib issue):
<img width="916" alt="image"
src="https://github.com/user-attachments/assets/09d20ba9-8781-46d6-bcfa-862d8a4cbf90"
/>

- Email validation errors accumulate instead of replacing the previous
one (again looks like a fom lib issue):

https://github.com/user-attachments/assets/f2dc7a46-a3a9-465d-b8a1-3187b200f9b9

</details>

<details>

<summary>

## Screenshots

</summary>

Health API error:
<img height="500" alt="Screenshot 2025-05-31 at 10 48 40"
src="https://github.com/user-attachments/assets/dd069597-971c-489f-9c07-eb5edfd7bede"
/>

Health API loading state:
<img height="500" alt="Screenshot 2025-05-31 at 10 49 04"
src="https://github.com/user-attachments/assets/27d95bf3-bf7d-42c7-9a40-2826f38aa837"
/>

Health API success with some missing prerequisites:
<img width="449" alt="Screenshot 2025-06-17 at 16 59 57"
src="https://github.com/user-attachments/assets/c44afa97-70ff-4618-8b73-41b816514459"
/>

Form validation:
<img height="500" alt="image"
src="https://github.com/user-attachments/assets/a8d4cae1-2819-4f71-a911-9300a6cf81f8"
/>

Success toast:
<img width="480" alt="image"
src="https://github.com/user-attachments/assets/a87c3af5-dbb0-40e8-915a-fc9d7e1d97f2"
/>

Failure toast:
<img width="518" alt="image"
src="https://github.com/user-attachments/assets/908f9dea-b5cb-4da9-b4a5-76e313837f18"
/>

Print format toggle:
<img width="502" alt="image"
src="https://github.com/user-attachments/assets/602f3ab9-07ef-4689-a305-dc1b2b5495cd"
/>

Missing notifications email connector callout:
<img width="499" alt="image"
src="https://github.com/user-attachments/assets/fe4997a5-75e6-4450-85e5-7d853049e085"
/>

</details>

## References

Closes #216321
Stacked on #220535

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Eyo O. Eyo <7893459+eokoneyo@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:version Backport to applied version labels release_note:skip Skip the PR/issue when compiling release notes Team:ResponseOps Platform ResponseOps team (formerly the Cases and Alerting teams) t// v8.19.0 v9.1.0

5 participants