Skip to content

Commit b09c92e

Browse files
committed
feat: extend CloudPlan type and update TOC handling for premium plan
- Added 'premium' option to the CloudPlan type for enhanced plan support. - Updated getTidbCloudFilesFromTocs function to include premium in the TOC type determination and file mapping logic. - Enhanced the handling of TOC nodes to accommodate the new premium plan, ensuring accurate categorization of documentation files.
1 parent 10aa7c9 commit b09c92e

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

gatsby/cloud-plan.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { mdxAstToToc, TocQueryData } from "./toc";
22
import { generateConfig } from "./path";
33
import { extractFilesFromToc } from "./toc-filter";
4+
import { CloudPlan } from "shared/useCloudPlan";
45

56
/**
67
* Get files from different TOC types for tidbcloud
@@ -40,7 +41,12 @@ export async function getTidbCloudFilesFromTocs(
4041
const tocNodes = tocQuery.data!.allMdx.nodes;
4142
const tidbCloudTocFilesMap = new Map<
4243
string,
43-
{ dedicated: Set<string>; starter: Set<string>; essential: Set<string> }
44+
{
45+
dedicated: Set<string>;
46+
starter: Set<string>;
47+
essential: Set<string>;
48+
premium: Set<string>;
49+
}
4450
>();
4551

4652
tocNodes.forEach((node: TocQueryData["allMdx"]["nodes"][0]) => {
@@ -55,12 +61,14 @@ export async function getTidbCloudFilesFromTocs(
5561

5662
// Determine TOC type based on filename
5763
const relativePath = node.parent.relativePath;
58-
let tocType: "dedicated" | "starter" | "essential" = "dedicated";
64+
let tocType: CloudPlan = "dedicated";
5965

6066
if (relativePath.includes("TOC-tidb-cloud-starter")) {
6167
tocType = "starter";
6268
} else if (relativePath.includes("TOC-tidb-cloud-essential")) {
6369
tocType = "essential";
70+
} else if (relativePath.includes("TOC-tidb-cloud-premium")) {
71+
tocType = "premium";
6472
}
6573

6674
// Initialize the entry if it doesn't exist
@@ -69,6 +77,7 @@ export async function getTidbCloudFilesFromTocs(
6977
dedicated: new Set(),
7078
starter: new Set(),
7179
essential: new Set(),
80+
premium: new Set(),
7281
});
7382
}
7483

src/shared/useCloudPlan.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@ import { Repo } from "./interface";
1212
export const CLOUD_MODE_KEY = "plan";
1313
export const CLOUD_MODE_VALUE_STARTER = "starter";
1414
export const CLOUD_MODE_VALUE_ESSENTIAL = "essential";
15+
export const CLOUD_MODE_VALUE_PREMIUM = "premium";
1516

16-
export type CloudPlan = "dedicated" | "starter" | "essential";
17+
export type CloudPlan = "dedicated" | "starter" | "essential" | "premium";
1718

1819
const CloudPlanContext = createContext<{
1920
repo: Repo;
@@ -35,6 +36,7 @@ export const useCloudPlan = () => {
3536
const isTidbcloud = repo === Repo.tidbcloud;
3637
const [isStarter, setIsStarter] = useState<boolean>(false);
3738
const [isEssential, setIsEssential] = useState<boolean>(false);
39+
const [isPremium, setIsPremium] = useState<boolean>(false);
3840
const [isClassic, setIsClassic] = useState<boolean>(true);
3941

4042
const setCloudPlan = (cloudPlan: CloudPlan) => {
@@ -50,12 +52,14 @@ export const useCloudPlan = () => {
5052
_cloudPlan) as CloudPlan;
5153
const isStarter = isTidbcloud && cloudPlan === CLOUD_MODE_VALUE_STARTER;
5254
const isEssential = isTidbcloud && cloudPlan === CLOUD_MODE_VALUE_ESSENTIAL;
55+
const isPremium = isTidbcloud && cloudPlan === CLOUD_MODE_VALUE_PREMIUM;
5356
const isClassic =
5457
!isTidbcloud || !cloudPlan || (!isStarter && !isEssential);
5558

5659
_setCloudPlan(cloudPlan);
5760
setIsStarter(isStarter);
5861
setIsEssential(isEssential);
62+
setIsPremium(isPremium);
5963
setIsClassic(isClassic);
6064
}, []);
6165

@@ -64,6 +68,7 @@ export const useCloudPlan = () => {
6468
setCloudPlan,
6569
isStarter,
6670
isEssential,
71+
isPremium,
6772
isClassic,
6873
};
6974
};

0 commit comments

Comments
 (0)