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

docs: prototype partials DOC-1159 #2820

Closed
wants to merge 14 commits into from
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,7 @@ screenshots/
tests/screenshot.spec.ts-snapshots/
test-results/
playwright-report/
artifact.zip
artifact.zip

# Ignore _partials/index.ts
_partials/index.ts
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ init: ## Initialize npm dependencies
npx husky install

start: ## Start a local development server
make generate-partials
npm run start

build: ## Run npm build
Expand Down Expand Up @@ -203,6 +204,11 @@ format-images: ## Format images
@echo "formatting images in /static/assets/docs/images/ folder"
./scripts/compress-convert-images.sh

###@ Generate _partials/index.ts required to automatic partials usage.

generate-partials: ## Generate
./scripts/generate-partials.sh

###@ Aloglia Indexing

update-dev-index: ## Update the Algolia index for the dev environment
Expand Down
6 changes: 6 additions & 0 deletions _partials/clusters/_cluster-profile.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
partial_category: clusters
partial_name: cluster-profile
---

This is the second import {props.cloud} {props.version}.
8 changes: 8 additions & 0 deletions _partials/getting-started/_palette-setup.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{/* ---
partial_category: getting-started
partial_name: palette-setup
--- */}

This is how we set up Palette with {props.cloud} {props.version}.

[Test](/getting-started/additional-capabilities)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is how we set up Palette with {props.cloud} {props.version}.
50 changes: 49 additions & 1 deletion docs/docs-content/getting-started/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,54 @@ sidebar_custom_props:
tags: ["getting-started"]
---

### Partials test

#### Approach 1

<!-- import Setup from '../_partials/_getting-started_aws_palette-setup.mdx';

<Setup cloud="AWS" version="2.0"/> -->

#### Approach 2

<!-- import Setup2 from '../../../_partials/getting-started/_palette-setup.mdx';

<Setup2 cloud="AWS" version="2.0"/> -->

#### Approach 3

<!-- <PartialsComponent
category="GETTING-STARTED"
name="PaletteSetup"
props={[
{
key:"cloud",
value:"AWS",
},
{
key:"version",
value:"2.0",
}
]}
/> -->

#### Approach 4

<!-- <PartialsComponentFrontMatter
category="clusters"
name="cluster-profile"
props={[
{
key:"cloud",
value:"AWS",
},
{
key:"version",
value:"2.0",
}
]}
/> -->

This page gives you an overview of how to get started with Spectro Cloud Palette and begin leveraging its Kubernetes
full-stack management at scale. Palette's unique capabilities provide end-to-end declarative cluster management, cluster
monitoring and reconciliation, as well as enterprise-grade security.
Expand All @@ -33,7 +81,7 @@ The first step towards adopting Palette in your organization is to
We have curated the pages in the Getting Started section to give you a gradual introduction to the fundamental concepts
and workflows you need to deploy and manage Kubernetes clusters through Palette.

<div class="desktop-only-display">
<div className="desktop-only-display">

![Overview of the getting started journey rocket](/getting-started/getting-started_getting-started_journey-overview.webp)

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"docusaurus": "docusaurus",
"start": "docusaurus start --host 0.0.0.0 --port 9000",
"build": "npm run generate-api-docs && docusaurus build",
"build": "npm run generate-api-docs && npm run generate-partials && docusaurus build",
"swizzle": "docusaurus swizzle",
"deploy": "docusaurus deploy",
"clear": "docusaurus clear",
Expand All @@ -18,6 +18,7 @@
"generate-api-docs": "npm run run-api-parser && docusaurus gen-api-docs palette && docusaurus gen-api-docs emc",
"clean-api-docs": "docusaurus clean-api-docs palette && docusaurus clean-api-docs emc",
"run-api-parser": "node utils/api-parser/index.js",
"generate-partials": "./scripts/generate-partials.sh",
"lint": "eslint . --ext .js,.ts,.jsx,.tsx",
"lint:fix": "npm run lint -- --fix",
"format": "prettier --write \"**/*.{js,jsx,json,ts,tsx,md,mdx,css}\"",
Expand Down
22 changes: 22 additions & 0 deletions scripts/generate-partials.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

# Enable error handling
set -e

echo "Starting generation of _partials/index.ts."

# # Remove the index.ts file if it exists already.
rm -f _partials/index.ts

# Create the file and add the generated warning.
echo "// This file is generated. DO NOT EDIT!" >> _partials/index.ts

# Find all the MDX files recursively in the _partials folder.
# Loop through each file.
find _partials -name "*.mdx" -print0 | while read -d $'\0' path
do
module_name=$(basename ${path} .mdx | tr -d '_' | tr -d '-')
echo "export * as ${module_name}${RANDOM} from '@site/${path}';" >> _partials/index.ts
done

echo "Completed generation of _partials/index.ts."
26 changes: 26 additions & 0 deletions src/components/PartialsComponent/PartialsCategories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { ClusterPartials } from "./maps/ClustersPartials"
import { GettingStartedPartials } from "./maps/GettingStartedPartials"
import { PartialsMap } from "./maps/PartialsMap"

export interface PartialsCategory {
category: string;
map: PartialsMap;
}

interface PartialsMapCategories {
maps: PartialsCategory[]
}

// Maintain a map of existing partials
export const AllPartials: PartialsMapCategories = {
maps: [
{
category: "GETTING-STARTED",
map: GettingStartedPartials
},
{
category: "CLUSTERS",
map: ClusterPartials
}
]
};
50 changes: 50 additions & 0 deletions src/components/PartialsComponent/PartialsComponent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from "react";
import { AllPartials, PartialsCategory } from "./PartialsCategories"

interface InputProperty {
key: string,
value: string,
}

interface PartialsComponentDetails {
category: string;
name: string;
// Pass the key-value property pairs
props: InputProperty[];
}

export default function PartialsComponent(details : PartialsComponentDetails) : React.ReactElement {

var foundCategoryMap = null;
AllPartials.maps.forEach((val) => {
if (val.category == details.category) {
foundCategoryMap = val;
return
}
})

if (!foundCategoryMap) {
throw new Error("No partial found for category".
concat(details.name).
concat("."));
}

const partialsMap = foundCategoryMap as PartialsCategory;
if (!partialsMap.map[details.name]) {
throw new Error("No partial found for name ".
concat(details.name).
concat("in category ").
concat(details.category).
concat(".="));
}

// Map elements to index signatures
var propAttribute: {[key: string] : string} = {}
details.props.map((val) => {
propAttribute[val.key] = val.value
})

var cloned = React.cloneElement(partialsMap.map[details.name], propAttribute)
return cloned;
}

3 changes: 3 additions & 0 deletions src/components/PartialsComponent/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import PartialsComponent from "./PartialsComponent";

export default PartialsComponent;
9 changes: 9 additions & 0 deletions src/components/PartialsComponent/maps/ClustersPartials.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from "react";
// Import each partial here
import ClusterProfiles from "@site/_partials/clusters/_cluster-profile.mdx"
import { PartialsMap } from "./PartialsMap"

// Maintain a map of existing partials
export const ClusterPartials: PartialsMap = {
"ClusterProfile": <ClusterProfiles />,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import React from "react";
// Import each partial here
import PaletteSetup from "@site/_partials/getting-started/_palette-setup.mdx"
import { PartialsMap } from "./PartialsMap"

// Maintain a map of existing partials
export const GettingStartedPartials: PartialsMap = {
"PaletteSetup": <PaletteSetup />,
};
8 changes: 8 additions & 0 deletions src/components/PartialsComponent/maps/PartialsMap.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from "react";

export interface PartialsMap {
[key: string]: React.ReactElement;
}

// {key: x, value: y}
// {x : y}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import React, { FunctionComponent } from "react";
// Import all the partials as one module.
import * as PartialModules from "@site/_partials";

export interface PartialsMap {
[key: string]: FunctionComponent;
}

interface InputProperty {
key: string,
value: string,
}

interface PartialsComponentDetails {
category: string;
name: string;
// Pass the key-value property pairs
props: InputProperty[];
}

// !!!!! DISABLED ONLY FOR TEAM DEMO !!!!
// const AllPartials = importPartials()
const AllPartials = {}

export default function PartialsComponentFrontMatter(details : PartialsComponentDetails) : React.ReactElement {
var mapKey = getMapKey(details.category, details.name)

if (!AllPartials[mapKey]) {
throw new Error("No partial found for name ".
concat(details.name).
concat(" in category ").
concat(details.category).
concat(".="));
}

// Map elements to index signatures
var propAttribute: {[key: string] : string} = {}
details.props.map((val) => {
propAttribute[val.key] = val.value
})

return React.createElement(AllPartials[mapKey], propAttribute);
}

function importPartials() : PartialsMap {
const pmap : PartialsMap = {}

// The keys are the names of each exported module in _partials/index.ts
const partialKeys = Object.keys(PartialModules);

for (const pkey of partialKeys) {
var currentPartial = PartialModules[pkey];
var catFrontMatter = currentPartial["frontMatter"]["partial_category"];
var nameFrontMatter = currentPartial["frontMatter"]["partial_name"];

if (!catFrontMatter || !nameFrontMatter) {
throw new Error("Please specify partial_category and partial_name for ".
concat(pkey).
concat("."));
}

var mapKey = getMapKey(catFrontMatter, nameFrontMatter)
if (pmap[mapKey]) {
throw new Error("Duplicate partial defined for name ".
concat(nameFrontMatter).
concat(" in category ").
concat(catFrontMatter).
concat("."));
}

pmap[mapKey] = currentPartial.default as FunctionComponent;
}
return pmap
}

function getMapKey(category: string, name: string): string {
return category.concat('#').concat(name)
}
3 changes: 3 additions & 0 deletions src/components/PartialsComponentFrontMatter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import PartialsComponentFrontMatter from "./PartialsComponent";

export default PartialsComponentFrontMatter;
4 changes: 4 additions & 0 deletions src/theme/MDXComponents/MDXComponents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import TOCInline from "@theme/TOCInline";
import { TechnicalPreviewReleaseNote as TpBadge } from "@site/src/components/Badges";
import SimpleCardGrid from "@site/src/components/SimpleCardGrid/index";
import ReleaseNotesVersions from "@site/src/components/ReleaseNotesVersions/index";
import PartialsComponent from "@site/src/components/PartialsComponent";
import PartialsComponentFrontMatter from "@site/src/components/PartialsComponentFrontMatter";

export default {
...MDXComponents,
Expand All @@ -28,4 +30,6 @@ export default {
TpBadge,
SimpleCardGrid,
ReleaseNotesVersions,
PartialsComponent,
PartialsComponentFrontMatter: PartialsComponentFrontMatter,
};
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
// This file is not used in compilation. It is here just for a nice editor experience.
"extends": "@tsconfig/docusaurus/tsconfig.json",
"include": ["src", "declarations.d.ts", "utils"],
"include": ["src", "declarations.d.ts", "utils", "**/*.mdx",],
"exclude": ["src/deprecated"],
"compilerOptions": {
"types": ["node", "jest", "@testing-library/jest-dom"],
"types": ["node", "jest", "@testing-library/jest-dom", "mdx"],
"esModuleInterop": true,
"target": "es6",
"module": "Node16",
Expand Down