Skip to content

Commit

Permalink
Remove the Teleport Team scope (#439)
Browse files Browse the repository at this point in the history
This reverts commit f710f07.

This change also hides the "Available for" list at the top of each docs
page if there are no valid scopes. This allows for compatibility with
docs pages configured with a `forScopes` field that includes `team`.
  • Loading branch information
ptgott authored Mar 4, 2024
1 parent 26c9593 commit fe3d288
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 28 deletions.
1 change: 0 additions & 1 deletion components/Icon/icons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ export { default as success } from "./svg/success.svg?react";
export { default as thumbsUp } from "./svg/thumbs-up.svg?react";
export { default as thumbsDown } from "./svg/thumbs-down.svg?react";
export { default as wand } from "./svg/magic-wand.svg?react";
export { default as users } from "./svg/users.svg?react";
export { default as warning } from "./svg/warning.svg?react";
export { default as window } from "./svg/window.svg?react";
export { default as wrench } from "./svg/wrench.svg?react";
5 changes: 0 additions & 5 deletions components/Icon/svg/users.svg

This file was deleted.

5 changes: 2 additions & 3 deletions layouts/DocsPage/Navigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ const SCOPELESS_HREF_REGEX = /\?|\#/;

const SCOPE_DICTIONARY: Record<string, ScopeType> = {
code3: "oss",
users: "team",
cloud2: "cloud",
building2: "enterprise",
cloud2: "cloud",
};

const getScopeIcons = (scopes: ScopesInMeta) => {
Expand All @@ -28,7 +27,7 @@ const getScopeIcons = (scopes: ScopesInMeta) => {
}

const scopeIcons = Object.keys(SCOPE_DICTIONARY).map(
(scope: "code3" | "building2" | "cloud2" | "users") => {
(scope: "code3" | "building2" | "cloud2") => {
const hideScope = !scopes.includes(SCOPE_DICTIONARY[scope]);
const ariaLabel = hideScope ? "" : SCOPE_DICTIONARY[scope];

Expand Down
37 changes: 22 additions & 15 deletions layouts/DocsPage/Scopes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ interface ScopeDescription {
}

const SCOPE_DESCRIPTIONS: Record<
"oss" | "enterprise" | "cloud" | "team",
"oss" | "enterprise" | "cloud",
ScopeDescription
> = {
oss: {
Expand All @@ -29,19 +29,13 @@ const SCOPE_DESCRIPTIONS: Record<
icon: "building2",
value: "enterprise",
title: "Enterprise",
color: "gray",
color: "green",
},
cloud: {
icon: "cloud2",
value: "cloud",
title: "Cloud",
color: "gray",
},
team: {
icon: "users",
value: "team",
title: "Team",
color: "gray",
color: "blue",
},
};

Expand Down Expand Up @@ -72,12 +66,25 @@ interface ScopesProps {
export const Scopes = ({ scopes, className }: ScopesProps) => {
if (scopes[0] === "noScope" || scopes[0] === "") return <></>;

const scopeItems = scopes?.map((item) => (
<ScopesItem
key={SCOPE_DESCRIPTIONS[item].value}
scopeFeatures={SCOPE_DESCRIPTIONS[item]}
/>
));
// When initializing a ScopesItem from the scopes prop, filter out any scopes
// that are invalid. This way, we retain compatibility with docs pages that
// have a forScopes setting that includes a deprecated scope.
const scopeItems = scopes?.reduce((accum, item) => {
if (SCOPE_DESCRIPTIONS[item] !== undefined) {
accum.push(
<ScopesItem
key={SCOPE_DESCRIPTIONS[item].value}
scopeFeatures={SCOPE_DESCRIPTIONS[item]}
/>
);
}

return accum;
}, []);

if (scopeItems.length === 0) {
return <></>;
}

return (
<ul className={cn(styles.list, className)}>
Expand Down
20 changes: 18 additions & 2 deletions layouts/DocsPage/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,27 @@
import type { IconName } from "components/Icon/types";
import { VideoBarProps } from "components/VideoBar/types";

export const scopeValues = ["oss", "enterprise", "cloud", "team"] as const;
export const scopeValues = ["oss", "enterprise", "cloud"] as const;

export type ScopeType = (typeof scopeValues)[number];
export type ScopesType = ScopeType | ScopeType[];

export type ComplexScopesConfig =
| "oss,cloud"
| "oss,enterprise"
| "enterprise,oss"
| "enterprise,cloud"
| "cloud,oss"
| "cloud,enterprise"
| "oss,enterprise,cloud"
| "oss,cloud,enterprise"
| "enterprise,oss,cloud"
| "enterprise,cloud,oss"
| "cloud,enterprise,oss"
| "cloud,oss,enterprise";

type ScopesConfig = ScopeType | ComplexScopesConfig;

export type ScopesInMeta = [""] | ["noScope"] | ScopeType[];

interface BaseNavigationItem {
Expand All @@ -16,7 +32,7 @@ interface BaseNavigationItem {
entries?: NavigationItem[];
}
export interface RawNavigationItem extends BaseNavigationItem {
forScopes?: ScopeType[];
forScopes?: ScopesConfig | ScopeType[];
}

export interface NavigationItem extends BaseNavigationItem {
Expand Down
22 changes: 20 additions & 2 deletions server/docs-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import type {
NavigationItem,
NavigationCategory,
ScopesInMeta,
ComplexScopesConfig,
} from "layouts/DocsPage/types";

import { getStaticPathsForDocs, getDocsPagesMap } from "./paths";
Expand Down Expand Up @@ -79,6 +80,10 @@ const findNavItem = (
return undefined;
};

function isComplexScopesConfig(smth: string): smth is ComplexScopesConfig {
return smth.includes(",");
}

type AnyNavItem = RawNavigationItem | NavigationItem;
type AnyNav = NavigationCategory | AnyNavItem;
type CookedNav = NavigationCategory | NavigationItem;
Expand All @@ -97,11 +102,24 @@ function addScopesToNavigation(nav: AnyNav[]) {
const transformedNav: CookedNav[] = [];

for (let i = 0; i < nav.length; i++) {
let scopes: ScopesInMeta = ["oss", "team", "cloud", "enterprise"];
let scopes: ScopesInMeta = ["oss", "enterprise", "cloud"];
const item = Object.assign({}, nav[i]);

if ("forScopes" in item) {
scopes = item.forScopes;
if (typeof item.forScopes === "string") {
const itemScopes = item.forScopes;

if (isComplexScopesConfig(itemScopes)) {
const parsedScopes = itemScopes
.split(",")
.map((scope) => scope.trim()) as ScopesInMeta;
scopes = parsedScopes;
} else {
scopes = [itemScopes];
}
} else {
scopes = item.forScopes;
}
} else if (item.entries) {
scopes = ["noScope"];

Expand Down

0 comments on commit fe3d288

Please sign in to comment.