[8.14] [Connectors] [Jira] Fixed bug in additional fields (#183285) (#183359)

# Backport

This will backport the following commits from `main` to `8.14`:
- [[Connectors] [Jira] Fixed bug in additional fields
(#183285)](https://github.com/elastic/kibana/pull/183285)

<!--- Backport version: 9.4.3 -->

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

<!--BACKPORT
[{"author":{"name":"Antonio","email":"antonio.coelho@elastic.co"},"sourceCommit":{"committedDate":"2024-05-14T07:41:08Z","message":"[Connectors]
[Jira] Fixed bug in additional fields (#183285)\n\nFixes
#183163\r\n\r\n## Summary\r\n\r\nIn this scenario, the API was being
called with `otherFields: ''`.\r\n\r\nThe backend expects
`otherFields:\r\nschema.nullable(schema.recordOf(...))`.\r\n\r\nInitially,
I thought about setting the value to `{}` when the user\r\ncleared the
form but we had that behavior in the past in another field\r\nand I had
to change it. 😅\r\n\r\nNow I set the value to `null` and the API is
called with valid
values.","sha":"4ba10f02d37093966391958b1f77e708afa7372f","branchLabelMapping":{"^v8.15.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","release_note:skip","Team:ResponseOps","Feature:Actions/ConnectorTypes","v8.14.0","v8.15.0"],"title":"[Connectors]
[Jira] Fixed bug in additional fields
","number":183285,"url":"https://github.com/elastic/kibana/pull/183285","mergeCommit":{"message":"[Connectors]
[Jira] Fixed bug in additional fields (#183285)\n\nFixes
#183163\r\n\r\n## Summary\r\n\r\nIn this scenario, the API was being
called with `otherFields: ''`.\r\n\r\nThe backend expects
`otherFields:\r\nschema.nullable(schema.recordOf(...))`.\r\n\r\nInitially,
I thought about setting the value to `{}` when the user\r\ncleared the
form but we had that behavior in the past in another field\r\nand I had
to change it. 😅\r\n\r\nNow I set the value to `null` and the API is
called with valid
values.","sha":"4ba10f02d37093966391958b1f77e708afa7372f"}},"sourceBranch":"main","suggestedTargetBranches":["8.14"],"targetPullRequestStates":[{"branch":"8.14","label":"v8.14.0","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.15.0","branchLabelMappingKey":"^v8.15.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/183285","number":183285,"mergeCommit":{"message":"[Connectors]
[Jira] Fixed bug in additional fields (#183285)\n\nFixes
#183163\r\n\r\n## Summary\r\n\r\nIn this scenario, the API was being
called with `otherFields: ''`.\r\n\r\nThe backend expects
`otherFields:\r\nschema.nullable(schema.recordOf(...))`.\r\n\r\nInitially,
I thought about setting the value to `{}` when the user\r\ncleared the
form but we had that behavior in the past in another field\r\nand I had
to change it. 😅\r\n\r\nNow I set the value to `null` and the API is
called with valid
values.","sha":"4ba10f02d37093966391958b1f77e708afa7372f"}}]}]
BACKPORT-->

Co-authored-by: Antonio <antonio.coelho@elastic.co>
This commit is contained in:
Kibana Machine 2024-05-14 05:07:00 -04:00 committed by GitHub
parent 19b599c6e7
commit b1f978ea67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 12 additions and 2 deletions

View file

@ -12,7 +12,7 @@ import { useGetFieldsByIssueType } from './use_get_fields_by_issue_type';
import { useGetIssues } from './use_get_issues';
import { useGetSingleIssue } from './use_get_single_issue';
import { ActionConnector } from '@kbn/triggers-actions-ui-plugin/public/types';
import { act, fireEvent, render, waitFor, within } from '@testing-library/react';
import { act, fireEvent, render, waitFor, within, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
jest.mock('@kbn/triggers-actions-ui-plugin/public/common/lib/kibana');
@ -489,6 +489,16 @@ describe('JiraParamsFields renders', () => {
expect(editAction.mock.calls[0][1].incident.otherFields).toEqual(TEST_VALUE);
});
it('updating additional fields with an empty string sets its value to null', async () => {
render(<JiraParamsFields {...defaultProps} />);
const otherFields = await screen.findByTestId('otherFieldsJsonEditor');
userEvent.paste(otherFields, 'foobar');
userEvent.clear(otherFields);
expect(editAction.mock.calls[1][1].incident.otherFields).toEqual(null);
});
it('Clears any left behind priority when issueType changes and hasPriority becomes false', async () => {
useGetFieldsByIssueTypeMock
.mockReturnValueOnce(useGetFieldsByIssueTypeResponse)

View file

@ -424,7 +424,7 @@ const JiraParamsFields: React.FunctionComponent<ActionParamsProps<JiraActionPara
</>
}
onDocumentsChange={(json: string) => {
editSubActionProperty('otherFields', json);
editSubActionProperty('otherFields', json === '' ? null : json);
}}
/>
</EuiFormRow>