-
Notifications
You must be signed in to change notification settings - Fork 13
Add a ScopeLink component #35
Add a ScopeLink component #35
Conversation
In the docs, there are various guides that are entirely irrelevant for a user of a particular scope. In these cases, we usually include a warning at the top of each guide that indicates that the guide is only relevant for Cloud, Open Source, or Enterprise users. Rather than force the user to guess that they need to change the value of the scope picker, the ScopeLink component enables us to add an inline link that changes the scope of the page. For example: ```html <Notice type="warning" scope={["oss"]} > This guide requires Teleport Cloud or Teleport Enterprise. View this guide as a <ScopeLink scope="cloud">Teleport Cloud user</ScopeLink> or <ScopeLink scope="enterprise">Teleport Enterprise user</ScopeLink>. </Notice> ```
@ptgott is attempting to deploy a commit to the gravitational Team on Vercel. A member of the Team first needs to authorize it. |
Demo video: scopelink.mp4 |
Hi @iAdramelk @Alqanar @C-STYR, I was wondering if you had any thoughts on this draft PR or #33 for handling situations where a user with one scope may need to switch scopes in order to see a particular page. I was working on using the Are there other solutions that would work better here? Thanks! |
@ptgott hi Paul,sorry for the late answer. I have two suggestions here:
How I would approach it: I would update normal E. g. |
Hi @iAdramelk, thanks for the feedback. I did some more digging, and it looks like it might be enough to make the following change to This way, we can add a link Currently, diff --git a/components/Link/hooks.ts b/components/Link/hooks.ts
index eb231f0..894ed38 100644
--- a/components/Link/hooks.ts
+++ b/components/Link/hooks.ts
@@ -25,13 +25,28 @@ export const useCurrentHref = () => {
*/
export const useNormalizedHref = (href: string) => {
+
const { asPath, basePath } = useRouter();
const noBaseHref = href.startsWith(basePath)
? href.substring(basePath.length)
: href;
- const { scope } = useContext(DocsContext);
+ const scopes = {
+ "oss":true,
+ "cloud":true,
+ "enterprise": true
+ }
+
+ let scope: "oss"|"cloud"|"enterprise" = "oss"
+
+ const { query } = splitPath(href)
+ if(query.hasOwnProperty("scope") && scopes[query.scope] == true ){
+ scope = query["scope"] as "oss"|"cloud"|"enterprise"
+ } else {
+ scope = useContext(DocsContext).scope;
+ }
+
if (
isHash(noBaseHref) || I've tested this out with a file called ---
title: sample page
---
[Cloud](../sample?scope=cloud)
[Enterprise](../sample?scope=enterprise) |
@ptgott Good idea! This will be more universal. |
Closes gravitational#35 Closes gravitational#33 See gravitational/teleport#11383 Previously, the Link component would always set the "scope" query parameter in its href to the current value of DocsContext.scope. I wanted to make it possible to link to other scopes, allowing readers who are interested in another edition of Teleport to read content intended for that edition. We could add explicit links to different scopes in, for example, warnings at the top of scope-irrelevant pages or in introduction pages to sections that are only helpful for a specific Teleport edition (e.g., the Enterprise section). This change edits useNormalizedHref to add a "scope" value to the href's query if the input href has a "scope" key and the value is a valid scope name ("oss", "cloud", or "enterprise").
Closes gravitational#35 Closes gravitational#33 See gravitational/teleport#11383 Previously, the Link component would always set the "scope" query parameter in its href to the current value of DocsContext.scope. I wanted to make it possible to link to other scopes, allowing readers who are interested in another edition of Teleport to read content intended for that edition. We could add explicit links to different scopes in, for example, warnings at the top of scope-irrelevant pages or in introduction pages to sections that are only helpful for a specific Teleport edition (e.g., the Enterprise section). This change edits useNormalizedHref to add a "scope" value to the href's query if the input href has a "scope" key and the value is a valid scope name ("oss", "cloud", or "enterprise").
Closes gravitational#35 Closes gravitational#33 See gravitational/teleport#11383 Previously, the Link component would always set the "scope" query parameter in its href to the current value of DocsContext.scope. I wanted to make it possible to link to other scopes, allowing readers who are interested in another edition of Teleport to read content intended for that edition. We could add explicit links to different scopes in, for example, warnings at the top of scope-irrelevant pages or in introduction pages to sections that are only helpful for a specific Teleport edition (e.g., the Enterprise section). This change edits useNormalizedHref to add a "scope" value to the href's query if the input href has a "scope" key and the value is a valid scope name ("oss", "cloud", or "enterprise").
Closes gravitational#35 Closes gravitational#33 See gravitational/teleport#11383 Previously, the Link component would always set the "scope" query parameter in its href to the current value of DocsContext.scope. I wanted to make it possible to link to other scopes, allowing readers who are interested in another edition of Teleport to read content intended for that edition. We could add explicit links to different scopes in, for example, warnings at the top of scope-irrelevant pages or in introduction pages to sections that are only helpful for a specific Teleport edition (e.g., the Enterprise section). This change edits useNormalizedHref to add a "scope" value to the href's query if the input href has a "scope" key and the value is a valid scope name ("oss", "cloud", or "enterprise").
Closes #35 Closes #33 See gravitational/teleport#11383 Previously, the Link component would always set the "scope" query parameter in its href to the current value of DocsContext.scope. I wanted to make it possible to link to other scopes, allowing readers who are interested in another edition of Teleport to read content intended for that edition. We could add explicit links to different scopes in, for example, warnings at the top of scope-irrelevant pages or in introduction pages to sections that are only helpful for a specific Teleport edition (e.g., the Enterprise section). This change edits useNormalizedHref to add a "scope" value to the href's query if the input href has a "scope" key and the value is a valid scope name ("oss", "cloud", or "enterprise").
In the docs, there are various guides that are entirely irrelevant for
a user of a particular scope. In these cases, we usually include a
warning at the top of each guide that indicates that the guide is only
relevant for Cloud, Open Source, or Enterprise users. Rather than force
the user to guess that they need to change the value of the scope
picker, the ScopeLink component enables us to add an inline link that
changes the scope of the page. For example: