-
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
[Response Ops] [Rule Form] Add Show Request and Add Action screens to flyout #206154
Merged
Merged
Changes from 18 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
3cdd3d0
Genericize request code block and add show request to flyout
Zacqary 4851aa2
Hide close button when show request is open
Zacqary 514200a
Decouple actions modal from body
Zacqary 0a414f8
Add in-flyout actio rule form screen context and in-flyout connectors…
Zacqary 4b1adac
Remove horizontal rule from horizontal step display
Zacqary 1f73a1f
Add filter dropdown for smaller containers
Zacqary 7a07955
Add EuiSpacer above code block
Zacqary 3980df1
Use screen context for show request modal
Zacqary 8521048
Fix missing ruleflyout showrequest changes
Zacqary 4575262
Fix missing deps
Zacqary e8743f6
Remove stylelint disable
Zacqary 3bfcfdb
Update tests
Zacqary 6e0d535
Add actions connectors body test
Zacqary 59091f7
Update all test suites to pass
Zacqary e4a0a24
Fix stylelint
Zacqary fd0a82b
Restore RulePage to create rule form
Zacqary fb3027e
Remove waitFor in flyout tests
Zacqary 8d58b28
Use EUI breakpoint variables for container breakpoints
Zacqary f906fd1
Revert "Use EUI breakpoint variables for container breakpoints"
Zacqary e20a68b
Merge branch 'main' into 195211-demodalize-flyout
elasticmachine 4f38926
Remove unused selectconnector hook
Zacqary 97a8bd2
Merge branch '195211-demodalize-flyout' of https://github.com/Zacqary…
Zacqary acf8def
Merge remote-tracking branch 'upstream/main' into 195211-demodalize-f…
Zacqary 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
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
67 changes: 67 additions & 0 deletions
67
src/platform/packages/shared/response-ops/rule_form/src/hooks/use_on_select_connector.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,67 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { ActionConnector } from '@kbn/alerts-ui-shared'; | ||
import { useCallback } from 'react'; | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import { useRuleFormDispatch, useRuleFormState } from '.'; | ||
import { RuleFormParamsErrors } from '../common/types'; | ||
import { DEFAULT_FREQUENCY } from '../constants'; | ||
import { getDefaultParams } from '../utils'; | ||
|
||
export const useOnSelectConnector = ({ onClose }: { onClose: () => void }) => { | ||
const { | ||
plugins: { actionTypeRegistry }, | ||
selectedRuleType, | ||
} = useRuleFormState(); | ||
|
||
const dispatch = useRuleFormDispatch(); | ||
return useCallback( | ||
async (connector: ActionConnector) => { | ||
const { id, actionTypeId } = connector; | ||
const uuid = uuidv4(); | ||
const group = selectedRuleType.defaultActionGroupId; | ||
const actionTypeModel = actionTypeRegistry.get(actionTypeId); | ||
|
||
const params = | ||
getDefaultParams({ | ||
group, | ||
ruleType: selectedRuleType, | ||
actionTypeModel, | ||
}) || {}; | ||
|
||
dispatch({ | ||
type: 'addAction', | ||
payload: { | ||
id, | ||
actionTypeId, | ||
uuid, | ||
params, | ||
group, | ||
frequency: DEFAULT_FREQUENCY, | ||
}, | ||
}); | ||
|
||
const res: { errors: RuleFormParamsErrors } = await actionTypeRegistry | ||
.get(actionTypeId) | ||
?.validateParams(params); | ||
|
||
dispatch({ | ||
type: 'setActionParamsError', | ||
payload: { | ||
uuid, | ||
errors: res.errors, | ||
}, | ||
}); | ||
|
||
onClose(); | ||
}, | ||
[dispatch, onClose, selectedRuleType, actionTypeRegistry] | ||
); | ||
}; |
15 changes: 15 additions & 0 deletions
15
...platform/packages/shared/response-ops/rule_form/src/hooks/use_rule_form_screen_context.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,15 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { useContext } from 'react'; | ||
import { RuleFormScreenContext } from '../rule_form_screen_context'; | ||
|
||
export const useRuleFormScreenContext = () => { | ||
return useContext(RuleFormScreenContext); | ||
}; |
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
10 changes: 10 additions & 0 deletions
10
src/platform/packages/shared/response-ops/rule_form/src/request_code_block/index.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,10 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
export * from './request_code_block'; |
67 changes: 67 additions & 0 deletions
67
...form/packages/shared/response-ops/rule_form/src/request_code_block/request_code_block.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,67 @@ | ||
/* | ||
* 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", the "GNU Affero General Public License v3.0 only", and the "Server Side | ||
* Public License v 1"; you may not use this file except in compliance with, at | ||
* your election, the "Elastic License 2.0", the "GNU Affero General Public | ||
* License v3.0 only", or the "Server Side Public License, v 1". | ||
*/ | ||
|
||
import { omit, pick } from 'lodash'; | ||
import React, { useMemo } from 'react'; | ||
import { EuiCodeBlock } from '@elastic/eui'; | ||
import { | ||
CreateRuleBody, | ||
UPDATE_FIELDS_WITH_ACTIONS, | ||
UpdateRuleBody, | ||
transformCreateRuleBody, | ||
transformUpdateRuleBody, | ||
} from '../common/apis'; | ||
import { BASE_ALERTING_API_PATH } from '../constants'; | ||
import { useRuleFormState } from '../hooks'; | ||
import { SHOW_REQUEST_MODAL_ERROR } from '../translations'; | ||
import { RuleFormData } from '../types'; | ||
|
||
const stringifyBodyRequest = ({ | ||
formData, | ||
isEdit, | ||
}: { | ||
formData: RuleFormData; | ||
isEdit: boolean; | ||
}): string => { | ||
try { | ||
const request = isEdit | ||
? transformUpdateRuleBody(pick(formData, UPDATE_FIELDS_WITH_ACTIONS) as UpdateRuleBody) | ||
: transformCreateRuleBody(omit(formData, 'id') as CreateRuleBody); | ||
return JSON.stringify(request, null, 2); | ||
} catch { | ||
return SHOW_REQUEST_MODAL_ERROR; | ||
} | ||
}; | ||
|
||
interface RequestCodeBlockProps { | ||
isEdit: boolean; | ||
'data-test-subj'?: string; | ||
} | ||
export const RequestCodeBlock = (props: RequestCodeBlockProps) => { | ||
const { isEdit, 'data-test-subj': dataTestSubj } = props; | ||
const { formData, id, multiConsumerSelection } = useRuleFormState(); | ||
|
||
const formattedRequest = useMemo(() => { | ||
return stringifyBodyRequest({ | ||
formData: { | ||
...formData, | ||
...(multiConsumerSelection ? { consumer: multiConsumerSelection } : {}), | ||
}, | ||
isEdit, | ||
}); | ||
}, [formData, isEdit, multiConsumerSelection]); | ||
|
||
return ( | ||
<EuiCodeBlock language="json" isCopyable data-test-subj={dataTestSubj}> | ||
{`${isEdit ? 'PUT' : 'POST'} kbn:${BASE_ALERTING_API_PATH}/rule${ | ||
isEdit ? `/${id}` : '' | ||
}\n${formattedRequest}`} | ||
</EuiCodeBlock> | ||
); | ||
}; |
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
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.
Seems like it's not being used anywhere
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.
Was trying something here and I forgot to remove it