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

[ResponseOps][Cases] Allow users to create case using templates #187138

Merged
merged 21 commits into from
Jul 2, 2024

Conversation

js-jankisalvi
Copy link
Contributor

@js-jankisalvi js-jankisalvi commented Jun 28, 2024

Summary

Fixes #181309

This PR

  • allows users to create, edit or delete templates via cases > settings page
  • allows users to create case using templates
template.demo.mov

Testing

  1. Go to all solutions and create cases with all fields (including all fields of all supported connectors) without using templates. Verify that everything is working as expected.
  2. Go to all solutions and create and edit templates with various fields. Verify that everything is working as expected.
  3. Go to all solutions, create different templates on each solution, and verify that when creating a case you can use templates and everything is working as expected.
  4. Go to the alerts table of o11y and security and attach alerts to a new case. Verify that in the flyout the templates are working as expected.
  5. Go to ML and try to attach an ML visualization to a new case. Verify that the solution picker is working as expected and it resets the form when changing solutions.
  6. Create a template with custom fields. Delete one of the custom fields from the settings page. Verify that it is also deleted from the template.

Checklist

Delete any items that are not applicable to this PR.

Flaky test runner: https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/6425

For maintainers

Release notes

Allow users to create case using templates.

js-jankisalvi and others added 13 commits May 14, 2024 14:42
## Summary

Implements #181573

This PR allows users to create, update and delete templates using
existing configure API

Flaky test runner:
https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/5846

Test via Postman: 
- Can create the template 
- Can update the template
- Can delete the template
- Maximum 10 templates allowed
- Template cases fields are validated as per the existing schema
- custom fields within templates are validated as per the existing
schema

### 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
- [x] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
## Summary

Parent issue: #181309

This PR adds optional tags field in template. 

### 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: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
## Summary
Merging into feature branch.

Implements create functionality
#181864

Add template from case settings page.

<img width="1728" alt="image"
src="https://github.com/elastic/kibana/assets/117571355/4a4565e5-3ca8-4a7c-a5c9-0ac15b72a0d0">

**How to test**
- Go to Cases > Settings
- Click on add templates
- Fill the form
- Save

Scenarios: 
- Create template with different custom fields
- Create template  with connector

Flaky test runner
[here](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/6213)

### Checklist

Delete any items that are not applicable to this PR.

- [x] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [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
- [x] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [x] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [x] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
## Summary

Merging into feature branch.

Implements edit and delete functionality
#181864

Edit or delete template from case settings page.


https://github.com/elastic/kibana/assets/117571355/f6fd45fa-c1eb-45ab-8936-02c764dbadc4


**How to test**
- Go to Cases > Settings
- Add a template
- Click on edit template icon
- Update the fields
- Click save

- Click on delete template icon
- Click on confirm modal
- Click save

**Scenarios:** 
- Edit template with different custom fields
- Edit template  with connector
- Delete template

**Flaky Test**
[here](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/6331)

### 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
- [x] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
- [x] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
… template's custom fields via API (#186608)

## Summary

Parent issue: #181309

This PR takes care of below scenario:
When user deletes custom fields via API, those custom fields need to be
removed from templates as well.

[Flaky test
runner](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/6377)

**Testing**

- create a custom field in settings page
- create a template with that custom field in settings page
- Get configuration via postman for same owner, should have customFields
and templates attribute similar to this:
```
[
    {
        "customFields": [
            {
                  "key": "new_custom_field_key_2",
                  "type": "toggle",
                  "label": "My toggle custom field",
                  "required": "false",
            }
         ],
        "templates": [
            {
                "key": "template_key_1",
                "name": "Template with CF1",
                "caseFields": {
                     "customFields": [
                        {
                            "key": "new_custom_field_key_2",
                            "type": "toggle",
                            "value": false
                        }
                    ]
                },
            
            },
        ],
        "version": ${config_version}
        "id": ${config_id}
    }
]
```
- run the patch request via postman to delete the custom field, e.g:
```
path: https://localhost:5601/api/cases/configure/config_id

body: 
{
        "customFields": [],
        "templates": [
            {
                "key": "new_template_key_1",
                "name": "New template",
                "caseFields": {
                    "customFields": [
                        {
                            "key": "new_custom_field_key_2",
                            "type": "toggle",
                            "value": true
                        }
                    ]
                }
            }
        ],
    "version": "test-version"
}
```
- validate that custom field is removed from templates as well

### 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: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
@js-jankisalvi js-jankisalvi added Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) Feature:Cases Cases feature release_note:feature Makes this part of the condensed release notes v8.15.0 labels Jun 28, 2024
@js-jankisalvi js-jankisalvi self-assigned this Jun 28, 2024
@js-jankisalvi js-jankisalvi requested review from a team as code owners June 28, 2024 10:44
@elasticmachine
Copy link
Contributor

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

@elasticmachine
Copy link
Contributor

Pinging @elastic/response-ops-cases (Feature:Cases)

js-jankisalvi and others added 4 commits June 28, 2024 13:41
## Summary

This PR adds the ability for users to select a template when creating a
case. When a user selects a template the cases form fields are populated
with the values from the template. The solution picker in the flyout
changed as:

<img width="1281" alt="Screenshot 2024-06-20 at 1 26 14 PM"
src="https://github.com/elastic/kibana/assets/7871006/30859c61-94e7-4f0a-97d1-cb081bd72c36">

## Bug fixes

1. Changing the solution through the solution picket in the flyout would
not respect the connector's configuration.
2. Bug where the lazy loading of connectors' icons was causing the
flyout to open and close when you selected a solution picket. This bug
appeared when the first bug was fixed.

## Testing

1. Go to all solutions and create cases setting all fields (including
all fields of all supported connectors) without using templates. Verify
that everything is working as expected.
2. Go to all solutions, create different templates on each solution, and
verify that when creating a case you can use templates and everything is
working as expected.
3. Go to the alerts table of o11y and security and attach alerts to a
new case. Verify that in the flyout the templates are working as
expected.
4. Go to ML and try to attach an ML visualization to a new case. Verify
that the solution picker is working as expected and it resets the form
when changing solutions.

Fixes: #181871
Depends on: #185877

### Checklist

Delete any items that are not applicable to this PR.

- [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
- [ ] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed

### For maintainers

- [x] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

---------

Co-authored-by: Janki Salvi <117571355+js-jankisalvi@users.noreply.github.com>
Co-authored-by: adcoelho <antonio.coelho@elastic.co>
@@ -65,6 +65,7 @@ export const attachTimeline = (newCase: TestCase) => {
cy.get('body').type('{esc}');
cy.get(INSERT_TIMELINE_BTN).click();
cy.get(LOADING_INDICATOR).should('not.exist');
cy.get('[data-test-subj="selectable-input"]').click();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This test was failing due to tooltip on the search_box.
This click is added to get past tooltip and let search_box be visible:
image

Copy link
Contributor

@angorayc angorayc left a comment

Choose a reason for hiding this comment

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

@js-jankisalvi some questions for you.

  1. I created a template and saved it. Does it means I have to always apply the template when creating a new case? Would I be able to create a new case without a template applied?
Screen.Recording.2024-07-01.at.11.05.00.mov
  1. I deleted the case template from settings, then go back to case and create a new case. The new case had an empty template input that I had no options in as the first step. At the same time, the template information I deleted seemed still applying to my new case. Could you please double check this behaviour? Thanks.
Screen.Recording.2024-07-01.at.11.08.43.mov

@adcoelho
Copy link
Contributor

adcoelho commented Jul 1, 2024

@angorayc

Does it means I have to always apply the template when creating a new case?

You don't have to pick any template in that dropdown. It is supposed to serve as a way to prefill fields when creating cases but it is totally optional. You can always create a case without a template applied 🙂

However, your video makes me think we could have a no template option in the templates dropdown. I don't like that after we select a template there is no going back besides leaving the page 🤔 What do you think @js-jankisalvi ?

  1. [...] At the same time, the template information I deleted seemed still applying to my new case.

I managed to reproduce this but I am not sure it is connected to templates. I get the same behaviour if I manually populate the description. (I'll check if we already have an issue for this.)

When you were initially in the Create Case page did you leave by pressing back to cases or cancel?

Screenshot 2024-07-01 at 12 15 51

@angorayc
Copy link
Contributor

angorayc commented Jul 1, 2024

@angorayc

Does it means I have to always apply the template when creating a new case?

You don't have to pick any template in that dropdown. It is supposed to serve as a way to prefill fields when creating cases but it is totally optional. You can always create a case without a template applied 🙂

However, your video makes me think we could have a no template option in the templates dropdown. I don't like that after we select a template there is no going back besides leaving the page 🤔 What do you think @js-jankisalvi ?

In the first video, I wasn't able to unselected the template after selecting one, adding an option No template might be useful here.

  1. [...] At the same time, the template information I deleted seemed still applying to my new case.

I managed to reproduce this but I am not sure it is connected to templates. I get the same behaviour if I manually populate the description. (I'll check if we already have an issue for this.)

When you were initially in the Create Case page did you leave by pressing back to cases or cancel?

Screenshot 2024-07-01 at 12 15 51

I think I clicked back to cases

@js-jankisalvi
Copy link
Contributor Author

js-jankisalvi commented Jul 1, 2024

However, your video makes me think we could have a no template option in the templates dropdown. I don't like that after we select a template there is no going back besides leaving the page 🤔 What do you think @js-jankisalvi ?

Yes, agree. no template option makes sense. created an issue for it: #187233

Copy link
Contributor

@angorayc angorayc left a comment

Choose a reason for hiding this comment

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

Code change for threat hunting ✅

@js-jankisalvi
Copy link
Contributor Author

  1. [...] At the same time, the template information I deleted seemed still applying to my new case.

I managed to reproduce this but I am not sure it is connected to templates. I get the same behaviour if I manually populate the description. (I'll check if we already have an issue for this.)
When you were initially in the Create Case page did you leave by pressing back to cases or cancel?

I think I clicked back to cases

Created a bug for case description: #187236

@adcoelho
Copy link
Contributor

adcoelho commented Jul 1, 2024

In the case configuration page, the ui gets broken if we have too many tags.

Screenshot 2024-07-01 at 14 51 50

connectors={connectors}
isLoading={isLoadingConnectors || isLoadingCaseConfiguration}
withSteps={withSteps}
draftStorageKey={draftStorageKey}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this line is the source of this bug.

We could make the draftStorageKey optional and not include it in the creation form. What do you guys think?

The draft was originally implemented for the comments in the edit case page.

Copy link
Contributor Author

@js-jankisalvi js-jankisalvi Jul 1, 2024

Choose a reason for hiding this comment

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

yes it's fine to not have description storage while creating a case. It is more useful for edit description scenario.

Copy link
Member

Choose a reason for hiding this comment

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

What is the current behavior on main? What if you spent a lot of time writing the description on the case and you made a mistake (refresh the browser, etc)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Currently in main, we save session for description while creating a case. It is removed when we cancel the create case. But stays when we use back to cases button.

What if you spent a lot of time writing the description on the case and you made a mistake (refresh the browser, etc)?

That is a good point. Maybe we can keep the session but it should be removed when we click Back to cases?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, let's do this! It can be done on another PR.

@adcoelho
Copy link
Contributor

adcoelho commented Jul 1, 2024

If I have a default External Incident Management System in the configuration and try to create a template I get the following error.

Screenshot 2024-07-01 at 15 10 25

I am aware of this issue but I don't think it is the same.

Does it make sense to have "required" fields in the template?

@js-jankisalvi
Copy link
Contributor Author

In the case configuration page, the ui gets broken if we have too many tags.

Fixed here 6319822

Now it looks like this: image

@adcoelho
Copy link
Contributor

adcoelho commented Jul 1, 2024

I was messing around with custom field default values and whatnot.

If I:

  1. Create a template(named X, whatever 😄 )
  2. Create a toggle custom field with true as the default value
  3. Go straight to the case creation page and select my template the toggle will be true with that template selected
  4. If I go back to the case configuration page and edit the template, the toggle will have value false.

I am having trouble uploading the screen recording so ping me offline if the description above is not clear 😅

@js-jankisalvi
Copy link
Contributor Author

I am aware of this issue but I don't think it is the same.

yup, it's different.

Does it make sense to have "required" fields in the template?

No, every field should be optional in templates. I quickly checked the code and it seems only Jira connector's issueTypes field has this validation. Maybe we can ignore this validation for templates. I could update this issue to handle it.

@kibanamachine
Copy link
Contributor

Flaky Test Runner Stats

🎉 All tests passed! - kibana-flaky-test-suite-runner#6425

[✅] x-pack/test_serverless/functional/test_suites/security/config.ts: 25/25 tests passed.
[✅] x-pack/test_serverless/functional/test_suites/observability/config.ts: 25/25 tests passed.
[✅] x-pack/test/functional_with_es_ssl/apps/cases/group2/config.ts: 25/25 tests passed.
[✅] x-pack/test/functional_with_es_ssl/apps/cases/group1/config.ts: 25/25 tests passed.
[✅] x-pack/test/cases_api_integration/security_and_spaces/config_basic.ts: 25/25 tests passed.

see run history

@cnasikas
Copy link
Member

cnasikas commented Jul 1, 2024

I found another issue with the toggle custom field. If I create a custom field with the default value set to true (toggle on) and go to create a template the default value is not populated correctly. The text field is working as expected.

@cnasikas
Copy link
Member

cnasikas commented Jul 1, 2024

No, every field should be optional in templates. I quickly checked the code and it seems only Jira connector's issueTypes field has this validation. Maybe we can ignore this validation for templates. I could update #187087 to handle it.

Yes, let's handle it on another PR and update the issue as you said.

@cnasikas
Copy link
Member

cnasikas commented Jul 1, 2024

I found another issue with the toggle custom field. If I create a custom field with the default value set to true (toggle on) and go to create a template the default value is not populated correctly. The text field is working as expected.

I cannot reproduce it. Probably a mistake on my part.

Copy link
Contributor

@adcoelho adcoelho left a comment

Choose a reason for hiding this comment

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

As discussed offline a couple of bugs will be fixed after. Besides that I tested it and it works as expected.

Nice work! 🔥

@js-jankisalvi
Copy link
Contributor Author

Created an issue for custom fields bugs

@kibana-ci
Copy link
Collaborator

💛 Build succeeded, but was flaky

Failed CI Steps

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
cases 755 772 +17

Async chunks

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

id before after diff
cases 479.4KB 497.7KB +18.3KB

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
cases 151.7KB 153.4KB +1.8KB
Unknown metric groups

ESLint disabled in files

id before after diff
cases 16 17 +1

ESLint disabled line counts

id before after diff
cases 61 62 +1

Total ESLint disabled count

id before after diff
cases 77 79 +2

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

cc @js-jankisalvi

Copy link
Member

@cnasikas cnasikas left a comment

Choose a reason for hiding this comment

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

I tested all possible scenarions with connectors, custom fields, case fields, etc in different solutions. I also tested the case flyout in solutions and outside of solutions. Everything is working as expected. I found two small bugs but we can fix them on another PR:

  1. When selecting template tags I can see duplicates
Screenshot 2024-07-02 at 1 03 28 PM
  1. When I delete a connector and I edit a template the selection is empty. I think we should set it to the none connector when the user views the template. On the backend we can leave it as it is with the connector. We do the same with cases.
Screenshot 2024-07-02 at 1 14 46 PM

Great work!! 🚀

@js-jankisalvi js-jankisalvi merged commit 8bf9aa5 into main Jul 2, 2024
40 checks passed
@js-jankisalvi js-jankisalvi deleted the feat/case_templates branch July 2, 2024 10:45
@kibanamachine kibanamachine added the backport:skip This commit does not require backporting label Jul 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting Feature:Cases Cases feature release_note:feature Makes this part of the condensed release notes Team:ResponseOps Label for the ResponseOps team (formerly the Cases and Alerting teams) v8.15.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Cases] Allow users to create case using template
7 participants