-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Cases] Case action UI implementation (#179409)
## Summary Implements #179433 This PR adds case connector with params fields in the UI for case action ### 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] 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: kibanamachine <[email protected]>
- Loading branch information
1 parent
b8765aa
commit 3453cb9
Showing
27 changed files
with
1,223 additions
and
14 deletions.
There are no files selected for viewing
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
86 changes: 86 additions & 0 deletions
86
x-pack/plugins/cases/public/components/system_actions/cases/cases.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,86 @@ | ||
/* | ||
* 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 type { ActionTypeModel } from '@kbn/triggers-actions-ui-plugin/public/types'; | ||
import { getConnectorType } from './cases'; | ||
const CONNECTOR_TYPE_ID = '.cases'; | ||
let connectorTypeModel: ActionTypeModel; | ||
|
||
beforeAll(() => { | ||
connectorTypeModel = getConnectorType(); | ||
}); | ||
|
||
describe('has correct connector id', () => { | ||
test('connector type static data is as expected', () => { | ||
expect(connectorTypeModel.id).toEqual(CONNECTOR_TYPE_ID); | ||
}); | ||
}); | ||
|
||
describe('action params validation', () => { | ||
test('action params validation succeeds when action params is valid', async () => { | ||
const actionParams = { | ||
subActionParams: { | ||
timeWindow: '7d', | ||
reopenClosedCases: false, | ||
groupingBy: [], | ||
owner: 'cases', | ||
}, | ||
}; | ||
|
||
expect(await connectorTypeModel.validateParams(actionParams)).toEqual({ | ||
errors: { timeWindow: [] }, | ||
}); | ||
}); | ||
|
||
test('params validation succeeds when valid timeWindow', async () => { | ||
const actionParams = { subActionParams: { timeWindow: '17w' } }; | ||
|
||
expect(await connectorTypeModel.validateParams(actionParams)).toEqual({ | ||
errors: { timeWindow: [] }, | ||
}); | ||
}); | ||
|
||
test('params validation fails when timeWindow is empty', async () => { | ||
const actionParams = { subActionParams: { timeWindow: '' } }; | ||
|
||
expect(await connectorTypeModel.validateParams(actionParams)).toEqual({ | ||
errors: { timeWindow: ['Invalid time window.'] }, | ||
}); | ||
}); | ||
|
||
test('params validation fails when timeWindow is undefined', async () => { | ||
const actionParams = { subActionParams: { timeWindow: undefined } }; | ||
|
||
expect(await connectorTypeModel.validateParams(actionParams)).toEqual({ | ||
errors: { timeWindow: ['Invalid time window.'] }, | ||
}); | ||
}); | ||
|
||
test('params validation fails when timeWindow is null', async () => { | ||
const actionParams = { subActionParams: { timeWindow: null } }; | ||
|
||
expect(await connectorTypeModel.validateParams(actionParams)).toEqual({ | ||
errors: { timeWindow: ['Invalid time window.'] }, | ||
}); | ||
}); | ||
|
||
test('params validation fails when timeWindow size is 0', async () => { | ||
const actionParams = { subActionParams: { timeWindow: '0d' } }; | ||
|
||
expect(await connectorTypeModel.validateParams(actionParams)).toEqual({ | ||
errors: { timeWindow: ['Invalid time window.'] }, | ||
}); | ||
}); | ||
|
||
test('params validation fails when timeWindow size is negative', async () => { | ||
const actionParams = { subActionParams: { timeWindow: '-5w' } }; | ||
|
||
expect(await connectorTypeModel.validateParams(actionParams)).toEqual({ | ||
errors: { timeWindow: ['Invalid time window.'] }, | ||
}); | ||
}); | ||
}); |
57 changes: 57 additions & 0 deletions
57
x-pack/plugins/cases/public/components/system_actions/cases/cases.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,57 @@ | ||
/* | ||
* 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 { lazy } from 'react'; | ||
import type { | ||
GenericValidationResult, | ||
ActionTypeModel as ConnectorTypeModel, | ||
} from '@kbn/triggers-actions-ui-plugin/public'; | ||
|
||
import { | ||
CASES_CONNECTOR_ID, | ||
CASES_CONNECTOR_TITLE, | ||
CASES_CONNECTOR_TIME_WINDOW_REGEX, | ||
} from '../../../../common/constants'; | ||
import type { CasesActionParams } from './types'; | ||
import * as i18n from './translations'; | ||
|
||
interface ValidationErrors { | ||
timeWindow: string[]; | ||
} | ||
|
||
export function getConnectorType(): ConnectorTypeModel<{}, {}, CasesActionParams> { | ||
return { | ||
id: CASES_CONNECTOR_ID, | ||
iconClass: 'casesApp', | ||
selectMessage: i18n.CASE_ACTION_DESC, | ||
actionTypeTitle: CASES_CONNECTOR_TITLE, | ||
actionConnectorFields: null, | ||
isExperimental: true, | ||
validateParams: async ( | ||
actionParams: CasesActionParams | ||
): Promise<GenericValidationResult<unknown>> => { | ||
const errors: ValidationErrors = { | ||
timeWindow: [], | ||
}; | ||
const validationResult = { | ||
errors, | ||
}; | ||
const timeWindowRegex = new RegExp(CASES_CONNECTOR_TIME_WINDOW_REGEX, 'g'); | ||
|
||
if ( | ||
actionParams.subActionParams && | ||
(!actionParams.subActionParams.timeWindow || | ||
!actionParams.subActionParams.timeWindow.length || | ||
!timeWindowRegex.test(actionParams.subActionParams.timeWindow)) | ||
) { | ||
errors.timeWindow.push(i18n.TIME_WINDOW_SIZE_ERROR); | ||
} | ||
return validationResult; | ||
}, | ||
actionParamsFields: lazy(() => import('./cases_params')), | ||
}; | ||
} |
Oops, something went wrong.