-
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
[Cases] Update UI to use the new connector's API #149276
[Cases] Update UI to use the new connector's API #149276
Conversation
e4efb8f
to
71e543d
Compare
x-pack/plugins/cases/public/components/case_action_bar/index.tsx
Outdated
Show resolved
Hide resolved
@@ -127,16 +132,12 @@ export const CaseViewActivity = ({ | |||
[assignees, onUpdateField] | |||
); | |||
|
|||
const { isLoading: isLoadingConnectors, data: connectors = [] } = useGetConnectors(); | |||
|
|||
const [connectorName, isValidConnector] = useMemo(() => { |
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.
Moved the logic inside the EditConnector
component
|
||
const onSubmitConnector = useCallback( | ||
(connectorId, connectorFields, onError, onSuccess) => { | ||
const connector = getConnectorById(connectorId, connectors); |
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.
Moved the logic inside the EditConnector
component
onSubmit={onSubmitConnector} | ||
userActions={userActionsData.caseUserActions} | ||
key={caseData.connector.id} |
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.
We need to reset the state of the EditConnector
component every time the current connector changes. We use the key
do to that. This helps to remove all unnecessary useEffect
s that update the state when the caseData
changes.
@@ -20,12 +19,6 @@ interface ConnectorCardProps { | |||
isLoading: boolean; | |||
} | |||
|
|||
const StyledText = styled.span` |
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.
Removed all styles. I converted the component to use EuiFlex*
instead of EuiCard
. The result is the same as before.
} | ||
|
||
const MyFlexGroup = styled(EuiFlexGroup)` |
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.
I moved the styling of the text inside x-pack/plugins/cases/public/components/connectors/card.tsx
. The result is the same as before.
{ | ||
...initialState, | ||
fields: caseFields, | ||
currentConnector: getConnectorById(caseData.connector.id, allAvailableConnectors), |
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.
We init the state with data from the caseData
. The use of key
in https://github.com/elastic/kibana/pull/149276/files#r1083999611 resets the initial state of the reducer every time the caseData.connector.id
changes.
connectors={connectors} | ||
hasDataToPush={userActionsData.hasDataToPush} | ||
isLoading={isLoadingConnectors || (isLoading && loadingKey === 'connector')} | ||
isValidConnector={isLoadingConnectors ? true : isValidConnector} |
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.
Moved the logic inside the EditConnector
component
<EditConnector | ||
caseData={caseData} | ||
caseServices={userActionsData.caseServices} | ||
connectorName={connectorName} |
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.
Moved the logic inside the EditConnector
component
caseServices={userActionsData.caseServices} | ||
connectorName={connectorName} | ||
connectors={connectors} | ||
hasDataToPush={userActionsData.hasDataToPush} |
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.
Moved the logic inside the usePushToService
hook which is used by the EditConnector
component
x-pack/test/cases_api_integration/security_and_spaces/tests/trial/internal/get_connectors.ts
Outdated
Show resolved
Hide resolved
x-pack/test/cases_api_integration/security_and_spaces/tests/trial/internal/get_connectors.ts
Show resolved
Hide resolved
x-pack/test/cases_api_integration/security_and_spaces/tests/trial/internal/get_connectors.ts
Outdated
Show resolved
Hide resolved
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.
Tested locally. Looks good 👍
Added couple of minor comments.
x-pack/plugins/cases/public/components/edit_connector/push_button.tsx
Outdated
Show resolved
Hide resolved
{!isLoading && !editConnector && pushCallouts && actionsReadCapabilities && ( | ||
<EuiFlexItem data-test-subj="push-callouts">{pushCallouts}</EuiFlexItem> | ||
)} | ||
<DisappearingFlexItem $isHidden={!editConnector}> |
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.
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.
Great work! Left some suggestions, still need to test it. I'll do that shortly.
return [connector?.name ?? '', !!connector]; | ||
}, [connectors, caseData.connector]); | ||
const { isLoading: isLoadingAllAvailableConnectors, data: allAvailableConnectors } = | ||
useGetConnectors(); |
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: maybe rename this hook to something like useGetConnectorsList
or useGetConfiguredConnectors
. At first glance I couldn't remember why we needed this one and the new useGetCaseConnectors
.
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.
@jonathan-buttner What about getAllConnectors
or getAllActionConnectors
? useGetConfiguredConnectors
is also fine.
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.
I looked at the API a little more, this one is retrieving all case allowed action connectors right? Maybe getSupportedActionConnectors
? The term all
doesn't really tell us what's happening beyond it's getting all of something but I'd say getAllActionConnectors
is better than getAllConnectors
.
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.
useGetSupportedActionConnectors
sounds good to me.
x-pack/plugins/cases/public/components/case_view/components/case_view_activity.tsx
Outdated
Show resolved
Hide resolved
x-pack/plugins/cases/public/components/case_view/components/case_view_activity.tsx
Outdated
Show resolved
Hide resolved
@@ -88,7 +87,7 @@ export const usePushToService = ({ | |||
* By priority of importance: | |||
* 1. Show license error. | |||
* 2. Show configuration error. | |||
* 3. Show connector configuration error if the connector is set to none or no connectors have been created. | |||
* 3. Show connector configuration error if the connector is set to none or no allAvailableConnectors have been created. |
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.
I'm not sure what we mean by allAvailableConnectors
should this just be connectors
?
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.
I wanted to distinguish between the case connectors returned from the new API and the action connectors returned by configure/_find
. What about supportedActionConnectors
? Any other ideas?
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.
Ah I see, what part of the boolean expression indicates that there were no connectors returned by configure/_find
?
connector.id === 'none' && !isLoadingLicense && !hasLicenseError
Basically are we actually checking for that? If not, I'd say we just remove that part of the comment. If I'm misunderstanding it and we are checking then I'd vote for ...or no action connectors have been created that are supported by cases
.
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.
I think you are right. Effectively we only check if the connector is set to none
. If hasLicenseError=true
then the first check (license error) will return. What about "Show connector missing information if the connector is set to none" ?
x-pack/plugins/cases/public/containers/use_get_case_connectors.test.tsx
Outdated
Show resolved
Hide resolved
x-pack/plugins/cases/public/containers/use_get_case_user_actions.test.tsx
Outdated
Show resolved
Hide resolved
Did some testing! Parity with the previous functionality looks good 👍 I tested the things you suggested in the PR description. I did notice a couple weird rerendering things, I'm not sure if they existed already though. Let me know what you think. Last user activity jumpsWhen switching between connectors the last user activity appears, then disappears, then reappears. Not sure if that is how it was before though.rerender.after.switch.connectors.movRenders two push sections for a connectorWhen pushing new activity to a connector that had already had some portion pushed, the activity view shows the old push arrows, the new push arrows for a short time and then removes them to only be the up down arrow. Renders this for a very short periodEventually renders thisrenders.two.push.sections.mov |
Thanks @js-jankisalvi! Yes, this is the current behavior. I opened an issue to improve it #149692. |
I can't reproduce the jumping or double arrows bugs so removing the connector id must have fixed it 👍 |
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.
Thanks for the changes, looks good 👍
Yes, @adcoelho awesome suggestion fixed the bug without me even realizing it 🙂 |
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.
Tested and lgtm! Should have approved it before, sorry 🙌
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.
Looks good 👍
💚 Build Succeeded
Metrics [docs]Module Count
Async chunks
Page load bundle
Unknown metric groupsESLint disabled in files
ESLint disabled line counts
Total ESLint disabled count
History
To update your PR or re-run it, just comment with: cc @cnasikas |
## Summary This PR updates the UI to use the new connector's API introduced by this PR elastic#147295. In this PR I refactor a bit some of the logic we have for the connectors. I left comments to explain the reasoning. ## Testing Please test the following: - The fields of each connector are preserved correctly when changing connectors - The following callout is shown when you do not have selected any connector <img width="784" alt="Screenshot 2023-01-23 at 2 21 33 PM" src="https://user-images.githubusercontent.com/7871006/214534706-5d447472-a40b-4fb4-aa4f-733bdcc76d9e.png"> - The edit connector button (pencil) is not shown if you do not have access to use connectors. Also, the following text should be shown. <img width="784" alt="Screenshot 2023-01-23 at 2 20 30 PM" src="https://user-images.githubusercontent.com/7871006/214535027-4b6b17a6-9d2c-4634-b78a-e966d70ae966.png"> - You see the following callout if a) select a connector to a case and b) then delete the connector <img width="778" alt="Screenshot 2023-01-23 at 2 11 49 PM" src="https://user-images.githubusercontent.com/7871006/214535408-ad72ed87-d9ea-4449-8340-4b17d63ed7b4.png"> - The text of the connector's push button is shown correctly. It should be `Push <connector_nane>` for the first push and `Updated Push <connector_nane>` for any other push. <img width="214" alt="Screenshot 2023-01-25 at 12 09 29 PM" src="https://user-images.githubusercontent.com/7871006/214536143-72e8f5f7-bb9d-4e4f-b2e7-66186ac76cdb.png"> <img width="292" alt="Screenshot 2023-01-25 at 12 09 17 PM" src="https://user-images.githubusercontent.com/7871006/214536169-765a682f-f4d9-4389-ad25-ec8184f99040.png"> - The connector's push button is disabled correctly. - When the connector's push button is disabled a tooltip is shown <img width="291" alt="Screenshot 2023-01-25 at 12 11 27 PM" src="https://user-images.githubusercontent.com/7871006/214536498-4058f1bd-2548-4a87-8e7c-589e1717e0a2.png"> - The push user action label is displayed correctly. It should be `pushed as new incident...` for the first push and `updated incident...` for any other push. <img width="630" alt="Screenshot 2023-01-25 at 9 54 23 AM" src="https://user-images.githubusercontent.com/7871006/214533317-ed29f938-298c-4d5f-94f9-9f11821f9365.png"> <img width="614" alt="Screenshot 2023-01-25 at 11 56 56 AM" src="https://user-images.githubusercontent.com/7871006/214533604-5be88d51-a021-4095-ab70-1938d82c6bdc.png"> - The push arrow indicators are shown correctly. The top arrow should be displayed only if it is the latest push. The bottom arrow should be displayed only if it is the latest push and new changes need to be pushed. Changes are considered the update of text or description, the addition or edit of a comment, and the addition or removal of a case. <img width="371" alt="Screenshot 2023-01-11 at 1 38 37 PM" src="https://user-images.githubusercontent.com/7871006/214534308-29da895a-2dff-4ae7-ace5-31ff7574feac.png"> <img width="322" alt="Screenshot 2023-01-11 at 1 37 31 PM" src="https://user-images.githubusercontent.com/7871006/214534312-9e28a398-ae64-4cc2-9f07-0ed72546e337.png"> - The "View <incident_name>" shows the latest push incident of each connector when changing connectors. <img width="229" alt="Screenshot 2023-01-23 at 2 25 30 PM" src="https://user-images.githubusercontent.com/7871006/214039111-0d4692c3-e7c3-4b7b-825b-bd86a0f03a96.png"> Depends on: elastic#149451, elastic#149535 ### Checklist Delete any items that are not applicable to this PR. - [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) --------- Co-authored-by: Jonathan Buttner <[email protected]>
Summary
This PR updates the UI to use the new connector's API introduced by this PR #147295. In this PR I refactor a bit some of the logic we have for the connectors. I left comments to explain the reasoning.
Testing
Please test the following:
Push <connector_nane>
for the first push andUpdated Push <connector_nane>
for any other push.pushed as new incident...
for the first push andupdated incident...
for any other push.Depends on: #149451, #149535
Checklist
Delete any items that are not applicable to this PR.
For maintainers