-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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][Connectors] Add support of additional fields for ServiceNow ITSM and SecOps #184023
Merged
Merged
Changes from 28 commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
1439aba
Share Jira validators
cnasikas abf152e
Use shared validators for ITSM and SIR
cnasikas f367b32
Create additional fields component
cnasikas ee8c47d
Create validateJSON util function
cnasikas 88d4ad2
Use additional fields component in ITSM and SIR
cnasikas b85060c
Validate additional fields using validateJSON in ITSM and SIR
cnasikas 835a290
Merge branch 'main' into itsm_additional_fields
cnasikas 742cc75
Add tests
cnasikas 3defe90
Merge branch 'main' into itsm_additional_fields
cnasikas b466ac6
Improve helptext
cnasikas 1e897fd
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine 432c0ed
Fix bug where the errors was showing twice
cnasikas 21924ac
Merge branch 'itsm_additional_fields' of github.com:cnasikas/kibana i…
cnasikas 4f7fb22
Hide additional fields from recovered action
cnasikas 517079b
Fix i18n
cnasikas 829e196
Fix types
cnasikas 0911772
PR feedback
cnasikas 5b9ad7b
Fix tests
cnasikas b326d8f
Merge branch 'main' into itsm_additional_fields
cnasikas 5c10313
Merge branch 'main' into itsm_additional_fields
cnasikas 7cad3d7
PR feedback
cnasikas 9cdd19f
Fix actions snapshot
cnasikas c5cc337
Fix o11y types
cnasikas 7a9451b
Merge branch 'main' into itsm_additional_fields
kibanamachine aa71f73
Merge branch 'main' into itsm_additional_fields
cnasikas 65df354
Fix test
cnasikas aecce0f
Merge branch 'itsm_additional_fields' of github.com:cnasikas/kibana i…
cnasikas 1259aa5
Merge branch 'main' into itsm_additional_fields
kibanamachine 8faa537
Merge branch 'main' into itsm_additional_fields
cnasikas 854a83a
Merge branch 'main' into itsm_additional_fields
cnasikas 95813fd
Merge branch 'main' into itsm_additional_fields
cnasikas 6a593e9
Add feature flag for the intermediate release process
cnasikas 896f3fa
Merge branch 'itsm_additional_fields' of github.com:cnasikas/kibana i…
cnasikas 21909ec
Fix tests
cnasikas 2f79482
Merge branch 'main' into itsm_additional_fields
kibanamachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
158 changes: 158 additions & 0 deletions
158
x-pack/plugins/actions/server/integration_tests/__snapshots__/connector_types.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
x-pack/plugins/stack_connectors/common/servicenow/constants.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export const MAX_ADDITIONAL_FIELDS_LENGTH = 20; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...plugins/stack_connectors/public/connector_types/lib/servicenow/additional_fields.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { render, screen, waitFor } from '@testing-library/react'; | ||
import { __IntlProvider as IntlProvider } from '@kbn/i18n-react'; | ||
import { AdditionalFields } from './additional_fields'; | ||
import userEvent from '@testing-library/user-event'; | ||
|
||
describe('Credentials', () => { | ||
const onChange = jest.fn(); | ||
const value = JSON.stringify({ foo: 'test' }); | ||
const props = { value, errors: [], onChange }; | ||
|
||
it('renders the additional fields correctly', async () => { | ||
render( | ||
<IntlProvider locale="en"> | ||
<AdditionalFields {...props} /> | ||
</IntlProvider> | ||
); | ||
|
||
expect(await screen.findByTestId('additionalFields')).toBeInTheDocument(); | ||
}); | ||
|
||
it('sets the value correctly', async () => { | ||
render( | ||
<IntlProvider locale="en"> | ||
<AdditionalFields {...props} /> | ||
</IntlProvider> | ||
); | ||
|
||
expect(await screen.findByText(value)).toBeInTheDocument(); | ||
}); | ||
|
||
it('changes the value correctly', async () => { | ||
const newValue = JSON.stringify({ bar: 'test' }); | ||
|
||
render( | ||
<IntlProvider locale="en"> | ||
<AdditionalFields {...props} value={undefined} /> | ||
</IntlProvider> | ||
); | ||
|
||
userEvent.paste(await screen.findByTestId('additional_fieldsJsonEditor'), newValue); | ||
|
||
await waitFor(() => { | ||
expect(onChange).toHaveBeenCalledWith(newValue); | ||
}); | ||
|
||
expect(await screen.findByText(newValue)).toBeInTheDocument(); | ||
}); | ||
|
||
it('updating wth an empty string sets its value to null', async () => { | ||
const newValue = JSON.stringify({ bar: 'test' }); | ||
|
||
render( | ||
<IntlProvider locale="en"> | ||
<AdditionalFields {...props} value={undefined} /> | ||
</IntlProvider> | ||
); | ||
|
||
const editor = await screen.findByTestId('additional_fieldsJsonEditor'); | ||
|
||
userEvent.paste(editor, newValue); | ||
userEvent.clear(editor); | ||
|
||
await waitFor(() => { | ||
expect(onChange).toHaveBeenCalledWith(null); | ||
}); | ||
}); | ||
}); |
54 changes: 54 additions & 0 deletions
54
x-pack/plugins/stack_connectors/public/connector_types/lib/servicenow/additional_fields.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { EuiIconTip } from '@elastic/eui'; | ||
import { JsonEditorWithMessageVariables } from '@kbn/triggers-actions-ui-plugin/public'; | ||
import React from 'react'; | ||
import { ActionVariable } from '@kbn/alerting-types'; | ||
import { isEmpty } from 'lodash'; | ||
import * as i18n from './translations'; | ||
|
||
interface AdditionalFieldsProps { | ||
value?: string | null; | ||
errors?: string[]; | ||
messageVariables?: ActionVariable[]; | ||
onChange: (value: string | null) => void; | ||
} | ||
|
||
export const AdditionalFieldsComponent: React.FC<AdditionalFieldsProps> = ({ | ||
cnasikas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
value, | ||
errors, | ||
messageVariables, | ||
onChange, | ||
}) => { | ||
return ( | ||
<JsonEditorWithMessageVariables | ||
messageVariables={messageVariables} | ||
paramsProperty={'additional_fields'} | ||
inputTargetValue={value} | ||
errors={errors ?? []} | ||
dataTestSubj="additionalFields" | ||
label={ | ||
<> | ||
{i18n.ADDITIONAL_FIELDS} | ||
<EuiIconTip | ||
size="s" | ||
color="subdued" | ||
type="questionInCircle" | ||
className="eui-alignTop" | ||
data-test-subj="otherFieldsHelpTooltip" | ||
aria-label={i18n.ADDITIONAL_FIELDS_HELP} | ||
content={i18n.ADDITIONAL_FIELDS_HELP_TEXT} | ||
/> | ||
</> | ||
} | ||
onDocumentsChange={(json: string) => onChange(isEmpty(json) ? null : json)} | ||
/> | ||
); | ||
}; | ||
|
||
export const AdditionalFields = React.memo(AdditionalFieldsComponent); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: It is not this PRs fault(maybe I caused it in the past?) but it annoys me so much that we call this
otherFields
in the code when in practice it should beadditionalFields
everywhere 😄There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same 🙂 but unfortunately we cannot change it now because it is a backend field and the feature is already released.