Skip to content

Commit

Permalink
[ResponseOps][Cases] Allow users to create case using templates (elas…
Browse files Browse the repository at this point in the history
…tic#187138)

## Summary

Fixes elastic#181309

This PR 
- allows users to create, edit or delete templates via cases > settings
page
- allows users to create case using templates


https://github.com/elastic/kibana/assets/117571355/39226aa4-9d9a-41a8-a900-ca765ed98e1b

## 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.

- [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)
- [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))

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

### 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)


## Release notes
Allow users to create case using templates.

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Christos Nasikas <christos.nasikas@elastic.co>
Co-authored-by: adcoelho <antonio.coelho@elastic.co>
  • Loading branch information
4 people committed Jul 2, 2024
1 parent e73eb1d commit 8bf9aa5
Show file tree
Hide file tree
Showing 148 changed files with 11,701 additions and 2,521 deletions.
6 changes: 6 additions & 0 deletions x-pack/plugins/cases/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@ export const MAX_CUSTOM_FIELDS_PER_CASE = 10 as const;
export const MAX_CUSTOM_FIELD_KEY_LENGTH = 36 as const; // uuidv4 length
export const MAX_CUSTOM_FIELD_LABEL_LENGTH = 50 as const;
export const MAX_CUSTOM_FIELD_TEXT_VALUE_LENGTH = 160 as const;
export const MAX_TEMPLATE_KEY_LENGTH = 36 as const; // uuidv4 length
export const MAX_TEMPLATE_NAME_LENGTH = 50 as const;
export const MAX_TEMPLATE_DESCRIPTION_LENGTH = 1000 as const;
export const MAX_TEMPLATES_LENGTH = 10 as const;
export const MAX_TEMPLATE_TAG_LENGTH = 50 as const;
export const MAX_TAGS_PER_TEMPLATE = 10 as const;

/**
* Cases features
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/cases/common/constants/owners.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ export const OWNER_INFO: Record<Owner, RouteInfo> = {
[GENERAL_CASES_OWNER]: {
id: GENERAL_CASES_OWNER,
appId: 'management',
label: 'Stack',
iconType: 'casesApp',
label: 'Management',
iconType: 'managementApp',
appRoute: '/app/management/insightsAndAlerting',
validRuleConsumers: [AlertConsumers.ML, AlertConsumers.STACK_ALERTS, AlertConsumers.EXAMPLE],
},
Expand Down
141 changes: 76 additions & 65 deletions x-pack/plugins/cases/common/types/api/case/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,81 @@ export const CaseRequestCustomFieldsRt = limitedArraySchema({
max: MAX_CUSTOM_FIELDS_PER_CASE,
});

export const CaseBaseOptionalFieldsRequestRt = rt.exact(
rt.partial({
/**
* The description of the case
*/
description: limitedStringSchema({
fieldName: 'description',
min: 1,
max: MAX_DESCRIPTION_LENGTH,
}),
/**
* The identifying strings for filter a case
*/
tags: limitedArraySchema({
codec: limitedStringSchema({ fieldName: 'tag', min: 1, max: MAX_LENGTH_PER_TAG }),
min: 0,
max: MAX_TAGS_PER_CASE,
fieldName: 'tags',
}),
/**
* The title of a case
*/
title: limitedStringSchema({ fieldName: 'title', min: 1, max: MAX_TITLE_LENGTH }),
/**
* The external system that the case can be synced with
*/
connector: CaseConnectorRt,
/**
* The severity of the case
*/
severity: CaseSeverityRt,
/**
* The users assigned to this case
*/
assignees: limitedArraySchema({
codec: CaseUserProfileRt,
fieldName: 'assignees',
min: 0,
max: MAX_ASSIGNEES_PER_CASE,
}),
/**
* The category of the case.
*/
category: rt.union([
limitedStringSchema({ fieldName: 'category', min: 1, max: MAX_CATEGORY_LENGTH }),
rt.null,
]),
/**
* Custom fields of the case
*/
customFields: CaseRequestCustomFieldsRt,
/**
* The alert sync settings
*/
settings: CaseSettingsRt,
})
);

export const CaseRequestFieldsRt = rt.intersection([
CaseBaseOptionalFieldsRequestRt,
rt.exact(
rt.partial({
/**
* The current status of the case (open, closed, in-progress)
*/
status: CaseStatusRt,

/**
* The plugin owner of the case
*/
owner: rt.string,
})
),
]);

/**
* Create case
*/
Expand Down Expand Up @@ -356,71 +431,7 @@ export const CasesBulkGetResponseRt = rt.strict({
* Update cases
*/
export const CasePatchRequestRt = rt.intersection([
rt.exact(
rt.partial({
/**
* The description of the case
*/
description: limitedStringSchema({
fieldName: 'description',
min: 1,
max: MAX_DESCRIPTION_LENGTH,
}),
/**
* The current status of the case (open, closed, in-progress)
*/
status: CaseStatusRt,
/**
* The identifying strings for filter a case
*/
tags: limitedArraySchema({
codec: limitedStringSchema({ fieldName: 'tag', min: 1, max: MAX_LENGTH_PER_TAG }),
min: 0,
max: MAX_TAGS_PER_CASE,
fieldName: 'tags',
}),
/**
* The title of a case
*/
title: limitedStringSchema({ fieldName: 'title', min: 1, max: MAX_TITLE_LENGTH }),
/**
* The external system that the case can be synced with
*/
connector: CaseConnectorRt,
/**
* The alert sync settings
*/
settings: CaseSettingsRt,
/**
* The plugin owner of the case
*/
owner: rt.string,
/**
* The severity of the case
*/
severity: CaseSeverityRt,
/**
* The users assigned to this case
*/
assignees: limitedArraySchema({
codec: CaseUserProfileRt,
fieldName: 'assignees',
min: 0,
max: MAX_ASSIGNEES_PER_CASE,
}),
/**
* The category of the case.
*/
category: rt.union([
limitedStringSchema({ fieldName: 'category', min: 1, max: MAX_CATEGORY_LENGTH }),
rt.null,
]),
/**
* Custom fields of the case
*/
customFields: CaseRequestCustomFieldsRt,
})
),
CaseRequestFieldsRt,
/**
* The saved object ID and version
*/
Expand Down
Loading

0 comments on commit 8bf9aa5

Please sign in to comment.