-
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
Use documentation links service provided by the core directly. #88158
Use documentation links service provided by the core directly. #88158
Conversation
@@ -220,7 +220,7 @@ export class DocLinksService { | |||
}, | |||
apis: { | |||
createIndex: `${ELASTICSEARCH_DOCS}indices-create-index.html`, | |||
createSnapshotLifecylePolicy: `${ELASTICSEARCH_DOCS}slm-api-put-policy.html`, | |||
createSnapshotLifecyclePolicy: `${ELASTICSEARCH_DOCS}slm-api-put-policy.html`, |
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.
note: looks like nobody is using this yet.
@@ -344,12 +344,38 @@ export interface DocLinksStart { | |||
readonly ml: Record<string, string>; | |||
readonly transforms: Record<string, string>; | |||
readonly visualize: Record<string, string>; | |||
readonly apis: Record<string, string>; | |||
readonly apis: { |
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.
note: it's very easy to make a typo in a link name and with Record<string, string>
signature it may go unnoticed. Changing signatures only for those that we use in Security for now.
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.
This is much better! Makes it easier to know what links are available as well with autocomplete.
The properties you've added don't have the readonly flag. Might be worth just wrapping the whole interface in Readonly<T>
utility type since literally everything should be marked as readonly.
https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype
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, good catch! Will do
b885ec5
to
9cca1c8
Compare
Pinging @elastic/kibana-security (Team:Security) |
Ah nice, I didn't know we were able to extend the links available through I have created a I am trying to move us away from having to manually pass down global services like this through our render tree. Could be useful for this PR as well and includes the correct styling for external links. ComponentI personally prefer linking directly, instead of maintaining a list of all possible links via doc links service. These links are not dynamic and hardly ever change so having that indirection doesn't really solve anything that a simple search-replace can't handle. It also means that it's very easy to end up with unused URLs in the service when the link is removed from our components but the service still has them registered. Having said that, using predefined links like you do is possible via the <DocLink app="elasticsearch" doc="built-in-roles.html">
Learn what privileges individual roles grant.
</DocLink> Hookconst [docs] = useDocLinks();
<EuiLink href={docs.dashboard.guide} target="_blank" external>
Learn how to get started with dashboards.
</EuiLink> |
Yes, it's a valid point. But I can imagine that having those in a single place for such a large product can make life of our Docs team easier: same approach across all plugins + search-replace may not catch typos in attributes like these
Awesome, didn't see this one! Let me check if we have hooks-ready components where I can use |
@@ -344,12 +344,38 @@ export interface DocLinksStart { | |||
readonly ml: Record<string, string>; | |||
readonly transforms: Record<string, string>; | |||
readonly visualize: Record<string, string>; | |||
readonly apis: Record<string, string>; | |||
readonly apis: { |
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.
This is much better! Makes it easier to know what links are available as well with autocomplete.
The properties you've added don't have the readonly flag. Might be worth just wrapping the whole interface in Readonly<T>
utility type since literally everything should be marked as readonly.
https://www.typescriptlang.org/docs/handbook/utility-types.html#readonlytype
apiKeysAPIClient: apiClientMock, | ||
}; | ||
return mountWithIntl( | ||
<KibanaContextProvider services={{ application, docLinks }}> |
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 would pass in the entire coreStart
object into the kibana context provider here so that we don't get errors when a child component starts using e.g. notification or http service.
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 usually like to pass only what we use that makes it much easier to analyze affected code if we migrate/deprecate/remove anything (and we do this constantly). But in case of Core services I agree that's handy and tolerable, will change.
defaultMessage="You can create an {link} from Console." | ||
values={{ | ||
link: ( | ||
<EuiLink href={`${docLinks.links.apis.createApiKey}`} target="_blank"> |
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: Shouldn't the doc link be a string in itself? I don't think we need to wrap it in template literals
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 should, just kept it as it was before - will fix.
apiKeysAPIClient={new APIKeysAPIClient(http)} | ||
/> | ||
</i18nStart.Context>, | ||
<KibanaContextProvider services={{ application, docLinks }}> |
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 as other context provider, it would be safer to pass through the entire coreStart
object.
<APIKeysGridPage | ||
navigateToApp={application.navigateToApp} | ||
notifications={notifications} | ||
docLinks={new DocumentationLinksService(docLinks)} |
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.
Yesss! 🙏
defaultMessage="Role mappings will not be applied to any users. Contact your system administrator and refer to the {link} for more information." | ||
values={{ | ||
link: ( | ||
<EuiLink href={docLinks.links.security.mappingRoles} external={true} target="_blank"> |
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: boolean props don't require ={true}
Yes, we're hoping that using the doc link service will make it easier for us to keep links up-to-date as content moves and changes. We've found quite a few broken links so far sprinkled across the code, so it doesn't seem like there is distributed link-checking. Whereas we're working on getting all the links in the service automatically checked. |
💚 Build SucceededMetrics [docs]Module Count
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
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.
LGTM! 🎉
7.x/7.12.0: 69e3111 |
Summary
Since core now provides all the necessary links directly there is no reason to build our own abstractions around
DocLinks
service. Less code === less bugs and it's also easier to find all places that use a particular link, just in case.cc @lcawl