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

[Cases] Delete custom field #167167

Conversation

js-jankisalvi
Copy link
Contributor

Summary

This PR allows users to delete custom fields in settings page.

Screen.Recording.2023-09-25.at.17.41.24.mov

Checklist

Delete any items that are not applicable to this PR.

@js-jankisalvi js-jankisalvi added release_note:skip Skip the PR/issue when compiling release notes Team:Endpoint Response Endpoint Response Team Feature:Cases Cases feature v8.11.0 labels Sep 25, 2023
@js-jankisalvi js-jankisalvi self-assigned this Sep 25, 2023
@js-jankisalvi js-jankisalvi requested a review from a team as a code owner September 25, 2023 15:44
@elasticmachine
Copy link
Contributor

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


if (configCustomField) {
const fieldValue =
configCustomField.type === CustomFieldTypes.TEXT && isEmpty(value) ? null : [value];
Copy link
Contributor Author

@js-jankisalvi js-jankisalvi Sep 25, 2023

Choose a reason for hiding this comment

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

There was a bug where you switch the toggle field as on during create case and it still remained off in case view page.
Because it was set to null here.

Copy link
Member

@cnasikas cnasikas Sep 26, 2023

Choose a reason for hiding this comment

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

Instead of checking specifically for a custom field type we can do isEmpty(value) && value !== false ? null : [value]

Copy link
Contributor Author

@js-jankisalvi js-jankisalvi Sep 26, 2023

Choose a reason for hiding this comment

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

This check still have issue when toggle field value is true when creating a case, I updated it to isEmpty(value) && typeof value !== 'boolean' ? null : [value];

When we have more custom fields in future, we can create some util function to handle different types.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, you are right. Ok!

font-weight: ${euiTheme.font.weight.bold};
`}
>
{i18n.ADDITIONAL_FIELDS}
Copy link
Contributor Author

@js-jankisalvi js-jankisalvi Sep 25, 2023

Choose a reason for hiding this comment

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

Missed this header from the designs.

Copy link
Member

Choose a reason for hiding this comment

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

What about using an h3 or h4 and playing with the size instead of using CSS?

@@ -41,6 +45,17 @@ const CustomFieldsComponent: React.FC<Props> = ({ isLoading, customFieldsConfigu

return (
<EuiFlexGroup direction="column" gutterSize="s">
{customFieldsComponents.length ? (
Copy link
Member

Choose a reason for hiding this comment

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

It seems to me that the whole component should not be returned if the are no custom fields configured. Maybe we can either return null for the whole component ({customFieldsComponents.length ? ( <EuiFlexGroup direction="column" gutterSize="s">....) or in x-pack/plugins/cases/public/components/create/form.tsx check if customFieldsConfiguration and not render CustomFields if they are empty.


userEvent.click(screen.getByText('Cancel'));
await waitFor(() => {
expect(onDeleteCustomField).not.toHaveBeenCalledWith();
Copy link
Member

Choose a reason for hiding this comment

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

I think is better to wait here so that the confirm-delete-custom-field-modal is not shown anymore. This way we can be sure that expect(onDeleteCustomField).not.toHaveBeenCalledWith(); is not true because it has not been called yet.

const { customFields } = props;
const { customFields, onDeleteCustomField } = props;
const { euiTheme } = useEuiTheme();
const [showDeletionModal, setShowDeletionModal] = useState<{
Copy link
Member

Choose a reason for hiding this comment

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

nit: if you want to simplify a bit the code you can do const [selectedItem, setSelectedItem] = useState<CustomFieldsConfiguration[number] | null>(null). Then you can do const showModal = Boolean(selectedItem). Also,

onClick={() =>
  setSelectedItem(customFields)
}

Copy link
Member

@cnasikas cnasikas Sep 26, 2023

Choose a reason for hiding this comment

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

I noticed that above we have customFields.length === 5. Let's use MAX_CUSTOM_FIELDS_PER_CASE.

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.

LGTM! I left some comments.

{i18n.ADDITIONAL_FIELDS}
</EuiText>
) : null}
<h3
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, what I meant was

<EuiText size="m">
    <h3>{i18n.ADDITIONAL_FIELDS}</h3>
</EuiText>

Copy link
Member

Choose a reason for hiding this comment

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

By size I mean the size of the EuiText.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

oh okay 😄

@js-jankisalvi js-jankisalvi merged commit 608038d into elastic:cases-custom-fields-feature-branch Sep 26, 2023
1 check passed
@kibana-ci
Copy link
Collaborator

kibana-ci commented Sep 26, 2023

💔 Build Failed

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #43 / Cases Configure Closure options change closure option successfully
  • [job] [logs] FTR Configs #43 / Cases Configure Closure options change closure option successfully
  • [job] [logs] Cases Cypress Tests on Security Solution / Cases connector incident fields Correct incident fields show when connector is changed Correct incident fields show when connector is changed
  • [job] [logs] Cases Cypress Tests on Security Solution / Cases connector incident fields Correct incident fields show when connector is changed Correct incident fields show when connector is changed
  • [job] [logs] Serverless Security Explore Cypress Tests #1 / Cases connectors Configures a new connector Configures a new connector
  • [job] [logs] Cases Cypress Tests on Security Solution / Cases connectors Configures a new connector Configures a new connector
  • [job] [logs] Serverless Security Explore Cypress Tests #1 / Cases connectors Configures a new connector Configures a new connector
  • [job] [logs] Cases Cypress Tests on Security Solution / Cases connectors Configures a new connector Configures a new connector
  • [job] [logs] FTR Configs #3 / cases security and spaces enabled: basic Common patch_cases happy path should patch a case with customFields
  • [job] [logs] FTR Configs #3 / cases security and spaces enabled: basic Common patch_cases happy path should patch a case with customFields
  • [job] [logs] FTR Configs #12 / cases security and spaces enabled: trial Common patch_cases happy path should patch a case with customFields
  • [job] [logs] FTR Configs #12 / cases security and spaces enabled: trial Common patch_cases happy path should patch a case with customFields
  • [job] [logs] Jest Integration Tests #5 / checking migration metadata changes on all registered SO types detecting migration related changes in registered types
  • [job] [logs] FTR Configs #18 / serverless common UI Index Management Index Templates "before all" hook for "renders the index templates tab"
  • [job] [logs] FTR Configs #23 / Serverless observability API Cases get_case should return a case
  • [job] [logs] FTR Configs #23 / Serverless observability API Cases get_case should return a case
  • [job] [logs] FTR Configs #58 / Serverless security API Cases get_case should return a case
  • [job] [logs] FTR Configs #58 / Serverless security API Cases get_case should return a case
  • [job] [logs] FTR Configs #15 / uptime uptime REST endpoints with real-world data UptimeIntegrationDeprecation should return hasIntegrationMonitors true when there are zip url policies
  • [job] [logs] FTR Configs #15 / uptime uptime REST endpoints with real-world data UptimeIntegrationDeprecation should return hasIntegrationMonitors true when there are zip url policies

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
cases 698 699 +1

Async chunks

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

id before after diff
cases 441.7KB 443.5KB +1.8KB

History

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

cc @js-jankisalvi

js-jankisalvi added a commit that referenced this pull request Oct 2, 2023
## Summary

This PR implements an MPV for custom fields in Cases. Specifically:

- Users can add, delete, or edit custom fields from the configuration
page
- Users can set custom fields when creating a case
- Users can set custom fields when editing a case
- Only the `Text` custom field type is supported. The `Toggle` is
implemented to test the framework.
- Users with a basic license can enter the configuration page and set
custom fields
- The configuration page header changed to "Settings"
- The "Edit external connection" button changed to "Settings"
- APIs:
    - Users cannot post custom fields with duplicate keys
    - Users cannot change the type of the custom field
    - Users cannot add custom fields that are not configured
    - Required fields should be present
- If some of the custom fields are omitted from the request the backend
will fill them with `null` values
- Limits:
    - Maximum 10 custom fields configured
    - Maximum 50 chars in custom field labels
    - Maximum 160 chars for the value of the `Text` custom field type
    - Users cannot change the type of a custom field
- The key of the custom fields should contain only lowercase letters
(a-z), numbers (0-9), '_', and '-'
    - Required fields needs a value

## Testing
- Cases created before custom fields are working as expected (create
some on `main` before switching to the feature branch)
- Environments without configuration are working as expected (clear ES
data)
- Environments with existing configurations are working as expected
- Try to create cases with custom fields (required & optional) and
delete some of them
- Try to create cases with custom fields (required & optional) and then
configure new custom fields. Existing cases with old custom fields
should work as expected
- User actions are working as expected especially with the combinations
described in the previous two bullets
- Users with a basic license can configure custom fields but cannot
configure connectors
- Users with a gold+ license can configure custom fields and connectors
- Users with read access cannot configure or edit custom fields

Resolves: #160236

PRs:

- #165671
- #166353
- #166439
- #166483
- #166815
- #166940
- #166962
- #166969
- #166975
- #167029
- #167047
- #167105
- #167131
- #167144
- #167166
- #167167
- #167310
- #167386
- #167481
- #167495
- #167398
- #167472

### 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]
[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

### 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 configure custom fields in Cases. Supported field types:
Text. Coming soon: Multi-text, List, Number, Toggle, Date, IP, Email,
etc.

---------

Co-authored-by: adcoelho <[email protected]>
Co-authored-by: kibanamachine <[email protected]>
Co-authored-by: Christos Nasikas <[email protected]>
Co-authored-by: Julian Gernun <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature:Cases Cases feature release_note:skip Skip the PR/issue when compiling release notes Team:Endpoint Response Endpoint Response Team v8.11.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants