Skip to content
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

Merged
merged 5 commits into from
Jan 15, 2021

Conversation

azasypkin
Copy link
Member

@azasypkin azasypkin commented Jan 13, 2021

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

@azasypkin azasypkin added chore Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v8.0.0 release_note:skip Skip the PR/issue when compiling release notes v7.12.0 labels Jan 13, 2021
@@ -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`,
Copy link
Member Author

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: {
Copy link
Member Author

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.

Copy link
Contributor

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

Copy link
Member Author

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

@azasypkin azasypkin requested review from a team as code owners January 13, 2021 14:22
@azasypkin azasypkin marked this pull request as ready for review January 13, 2021 14:22
@elasticmachine
Copy link
Contributor

Pinging @elastic/kibana-security (Team:Security)

@thomheymann
Copy link
Contributor

thomheymann commented Jan 14, 2021

Ah nice, I didn't know we were able to extend the links available through DocLinksService.

I have created a DocLink component (and hook) that uses that service and allows developers to create links to documentation: https://github.com/elastic/kibana/blob/99906a0b08e5ad77f8d04fb1eb338d1b7ede8036/x-pack/plugins/security/public/components/doc_link.tsx

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.

Component

I 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 useDocLinks hook (See Hook example).

<DocLink app="elasticsearch" doc="built-in-roles.html">
  Learn what privileges individual roles grant.
</DocLink>

Hook

const [docs] = useDocLinks();

<EuiLink href={docs.dashboard.guide} target="_blank" external>
  Learn how to get started with dashboards.
</EuiLink>

@azasypkin
Copy link
Member Author

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.

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 doc=buitl-ni-rols.htlm".

Having said that, using predefined links like you do is possible via the useDocLinks hook (See Hook example).

Awesome, didn't see this one! Let me check if we have hooks-ready components where I can use useDocLinks.

@@ -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: {
Copy link
Contributor

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 }}>
Copy link
Contributor

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.

Copy link
Member Author

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">
Copy link
Contributor

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

Copy link
Member Author

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 }}>
Copy link
Contributor

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)}
Copy link
Contributor

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">
Copy link
Contributor

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}

@lcawl
Copy link
Contributor

lcawl commented Jan 14, 2021

... 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 doc=buitl-ni-rols.htlm".

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.

@kibanamachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

Module Count

Fewer modules leads to a faster build time

id before after diff
security 472 468 -4

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
security 786.5KB 786.9KB +374.0B

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
core 564.6KB 564.6KB +1.0B
security 164.9KB 161.5KB -3.5KB
total -3.5KB

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

Copy link
Contributor

@thomheymann thomheymann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🎉

@azasypkin azasypkin merged commit abfd8bb into elastic:master Jan 15, 2021
@azasypkin azasypkin deleted the issue-xxx-doc-services-clean branch January 15, 2021 12:31
azasypkin added a commit to azasypkin/kibana that referenced this pull request Jan 15, 2021
@azasypkin
Copy link
Member Author

7.x/7.12.0: 69e3111

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backported chore release_note:skip Skip the PR/issue when compiling release notes Team:Security Team focused on: Auth, Users, Roles, Spaces, Audit Logging, and more! v7.12.0 v8.0.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants