-
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
[Endpoint] Integrate the Policy list with ingest datasources api #60548
[Endpoint] Integrate the Policy list with ingest datasources api #60548
Conversation
Pinging @elastic/endpoint-management (Team:Endpoint Management) |
Pinging @elastic/endpoint-app-team (Feature:Endpoint) |
* @param http | ||
* @param options | ||
*/ | ||
export const sendGetEndpoingDatasources = ( |
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.
style suggestion: Endpoint
is misspelled. Also, I'm not clear on the name of this function. Based on the doc comment, I would think endpointSpecificDatasource
might be a good candidate for the name. Also, for clarity, would you consider adding an explicit return type?
I think Promise GetDatasourcesResponse>
would be correct
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.
Sounds good. I'll change the name to fetchEndpointSpecificDatasources()
.
FYI - These are in fact Endpoint datasources - we will define them in the endpoint package and when creating a new one, the package.name
will be set to endpoint
and tie back to the package from where it was defined.
total, | ||
}, | ||
}); | ||
dispatch({ |
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.
would you consider moving the dispatch
call outside the try
block? If the reducer throws a runtime error, it'll be treated the same as if the HTTP call returned an error code.
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.
ahh - yes. good point. I personally like to keep the code inside of try {}
blocks to a minimum since (I think) the JS compilers are not able to optimize that code. will move it out.
total, | ||
}, | ||
}); | ||
} catch (err) { |
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.
I can't just pass the err
through because the ApiServerError
structure is in the body
property of the error object returned by http.*
methods, thus why I do the check below. I test this by adding a kuery
param on the fetch above to make it fail 😞
} | ||
|
||
if (action.type === 'userShownPolicyListServerFailedMessage') { | ||
// Make sure that the apiError currently stored is the one the user was shown |
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.
Trying to understand the flow here. If an error is stored in state, the react view uses the toast services to show info about it, then dispatches this. If the error matches the one in state, we clear it.
What is the point of keeping track of that in state?
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 trying to protect against showing the same error multiple times - example: during a quick paginations. That being said, I just realized that useEffect()
has the error set as the dependency, so it will not fire multiple times unless it changes. Will look at it a little closer and remove it is not needed (will change API fetching middleware/reducer to clear error on fetch)
// eslint-disable-next-line @elastic/eui/href-or-on-click | ||
<EuiLink | ||
href={`${services.application.getUrlForApp('ingestManager')}#/configs/${version}`} | ||
onClick={(ev: SyntheticEvent) => { |
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.
What is the reason for having the onClick here?
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.
It prevents a full browser refresh.
This might be avoidable - a few weeks ago one of the updates from the kibana-platform team was a change required by Plugins for how to use react-router. Mainly, I think they are now passing down to us an instance of their history
which we should use in initializing our router (or just use react-router's sub-routes - maybe?). If we do use their history
instance, then doing getting the history object from react-router (using the hook) and then doing a history.push
might do the same thing as this code below.
I don't recall if we have an issue open to look into that routing change.
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.
BTW - @oatkiller question: I pinged the EUI team on why the @elastic/eui/href-or-on-click
was enable, especially since we are mostly all using a router with history push. They said it was ok to turn it off. My question: should we turn it off across our plugin? (by introducing a .eslingrc.js
file)
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.
Gotcha. Looking through the code I see a few places that are using a similar pattern.
I wrote this up a while ago, but would like your thoughts: oatkiller@d6861d8
Seeing that you're doing navigateToApp
, instead of history.push
, I don't think the commit would work for you out of the box. But I would like to have an easy way to reuse the logic that guards event.preventDefault
also @parkiino cause I was talking to her as well.
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.
re : changing lint rules. I've been contemplating changing lint rules since day 0. @stacey-gammon argued that having consistent rules across all of Kibana is worthwhile because it allows developers to contribute across the app with the same standards (and allows code to be theoretically copy-pasted around the app as well.)
In the past I used lint rules (and other forms of static analysis) heavily as a way to enforce consistency across the app, so it's something I still think about.
With that in mind, I think we should try to argue for the lint rules changes to happen Kibana-wide. If Kibana contributors at large disagree'd with our change, we could reevaluate then.
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 we should try to argue for the lint rules changes to happen Kibana-wide. If Kibana contributors at large disagree'd with our change, we could reevaluate then.
💯
For this particular issue, I think this should be a moot point once everything is converted to NP, there will no longer be the full page refresh navigating among apps. Though I'm surprised using navigateToApp
somehow gets around the full page refresh. So maybe I am missing something else. cc @joshdover
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.
Maybe we're hitting the issue because we have not implemented the recent change in the NP to use the history
instance provided by plugin mount()
(this change #56705 )???
Will try that out to see if that is 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.
Ok, I tried it by using history.push()
instead of navigateToApp()
after making changes in our router to use the history
instance passed by mount()
, but still got full page refresh. Perhaps I'm missing something as to how we should interop with the core top-level router ( @joshdover ?? 😃 )
I'm laving in the code that uses navigateToApp()
for now and will refactor if there is a better pattern to follow.
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.
From platform team:
Yea, we have an open issue to discuss about the best way to avoid that, and to allow 'plain' links to have the same behavior as navigateToApp . The onClick workaround used in the PR is the way to go for now unfortunately
Sorry for the extra work!
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.
@stacey-gammon no problem at all - appreciate the feedback.
Good to know that the platform team has this on their list of items to address in the future. The ability to "just handle it" is exactly what @chandlerprall suggested on Slack when I first approach the EUI team about possibly turning this ESLint rule off -
"...I recommend having an onClick at the document.body level that can programmatically interact with the router...."
…-policy-list-api-integration
@@ -25,14 +24,16 @@ export default function({ getPageObjects, getService }: FtrProviderContext) { | |||
const policyTitle = await testSubjects.getVisibleText('policyViewTitle'); | |||
expect(policyTitle).to.equal('Policies'); | |||
}); | |||
it('shows policy count total', async () => { | |||
// FIXME: Skipped until we can figure out how to load data for Ingest | |||
it.skip('shows policy count total', async () => { |
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.
perhaps just remove these tests? they'll be available in git history
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 thinking these will come right back in the not too far future.
…-policy-list-api-integration
@elasticmachine merge upstream |
…-policy-list-api-integration
💚 Build SucceededHistory
To update your PR or re-run it, just comment with: |
Friendly reminder: Looks like this PR hasn’t been backported yet. |
1 similar comment
Friendly reminder: Looks like this PR hasn’t been backported yet. |
Looks like this PR has a backport PR but it still hasn't been merged. Please merge it ASAP to keep the branches relatively in sync. |
) (#60904) * Use ingest API to get endpoint datasources * Add `application` service to `KibanaContextProvider` * Adjust Policy list to show data available from API * Added ingest service + refactored middleware * handle api failures/errors * Removed policy list fake_data generator * Fix typing * Rename method + added explicit return type * move dispatch outside of try block * Removed unnecessary action * Added FIXME comments with link to issue * Skip some functional tests * added tests for ingest service * Policy list tests - turn it all off Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com> # Conflicts: # x-pack/plugins/endpoint/public/applications/endpoint/index.tsx # x-pack/plugins/endpoint/public/applications/endpoint/view/policy/policy_list.tsx
Summary
datasources
REST API to retrieve a list of endpoint datasources (filters bydatasource.package.name === 'endpoint'
)datasources/{id}
REST API to get details of a datasourceChecklist
Delete any items that are not applicable to this PR.