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

[WIP] SiS version POC #1115

Draft
wants to merge 47 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
e8e640f
Initial POC for SiS version exceptions
sfc-gh-dmatthews Jul 15, 2024
4b67c63
Add marker to SiS versions
sfc-gh-dmatthews Jul 15, 2024
b1fbf26
Add original SiS version back in (test)
sfc-gh-dmatthews Jul 15, 2024
9c18468
Revert "Add original SiS version back in (test)"
sfc-gh-dmatthews Jul 15, 2024
2472ed5
Typo in variable name
sfc-gh-dmatthews Jul 15, 2024
139b9d6
Use Snowflake text character
sfc-gh-dmatthews Jul 15, 2024
0098e9c
Merge branch 'main' into test-sis
sfc-gh-dmatthews Oct 15, 2024
15cba30
Add Radix UI
sfc-gh-dmatthews Oct 18, 2024
28e6cfa
Add 1.35.0 exceptions
sfc-gh-dmatthews Oct 18, 2024
cb7bd27
Radix version selector
sfc-gh-dmatthews Oct 18, 2024
72cf6aa
Move version check to sideBar
sfc-gh-dmatthews Nov 7, 2024
d12209a
Keep existing version on relative (versionless) links
sfc-gh-dmatthews Nov 7, 2024
76b3015
Merge branch 'main' into test-sis
sfc-gh-dmatthews Nov 7, 2024
9ceb862
Add na demo data
sfc-gh-dmatthews Nov 8, 2024
c1c6070
Begin platform context
sfc-gh-dmatthews Nov 8, 2024
e05b465
Partial pair programming commit (broken)
sfc-gh-dmatthews Nov 8, 2024
45bf701
Mostly working! Except breadcrumbs and some other silliness.
sfc-gh-tteixeira Nov 9, 2024
7075de2
Fix routing for all versions + platforms
sfc-gh-dmatthews Nov 15, 2024
06197fd
Update null version from context
sfc-gh-dmatthews Nov 18, 2024
d3046c0
Handle versions when function DNE
sfc-gh-dmatthews Nov 20, 2024
678c97c
Precompute platform and version data
sfc-gh-dmatthews Nov 24, 2024
2cbfe9d
Use "latest" instead of null version
sfc-gh-dmatthews Nov 24, 2024
7296e7c
Update runtime.txt
sfc-gh-dmatthews Nov 25, 2024
19f2738
Only load subset of platform notes
sfc-gh-dmatthews Nov 25, 2024
7213ffa
Merge branch 'main' into test-sis
sfc-gh-dmatthews Nov 25, 2024
44582d9
Merge branch 'main' into test-sis
sfc-gh-dmatthews Dec 4, 2024
23b7c47
Merge branch 'main' into test-sis
sfc-gh-dmatthews Dec 7, 2024
c5da45d
Remove redundant platform names
sfc-gh-dmatthews Dec 8, 2024
c2017c3
Bump next js version
sfc-gh-dmatthews Dec 8, 2024
ce610bc
Bump next to 15.0.4
sfc-gh-dmatthews Dec 8, 2024
727e91f
Bump plugin-nextjs to 5.8.1
sfc-gh-dmatthews Dec 8, 2024
71984fc
Run npx update-browserslist-db@latest
sfc-gh-dmatthews Dec 8, 2024
75e432b
Clean up version data imports
sfc-gh-dmatthews Dec 8, 2024
17369b2
Only pass the docstrings needed for the current page
sfc-gh-dmatthews Dec 9, 2024
1ee2588
Handle missing docstrings
sfc-gh-dmatthews Dec 9, 2024
2c9a674
Route back to latest version from warning
sfc-gh-dmatthews Dec 10, 2024
575b92d
Update version warnings for "not latest, not oss"
sfc-gh-dmatthews Dec 10, 2024
f5758ed
Use runtime values in version context and selector
sfc-gh-dmatthews Dec 11, 2024
ec1e2ee
Test rendering of cookies page
sfc-gh-dmatthews Dec 11, 2024
b2f2df1
Make sure currMenuItem isn't null
sfc-gh-dmatthews Dec 11, 2024
31cfa8a
Use tabs for platform selection
sfc-gh-dmatthews Dec 11, 2024
fcbe805
Tabs cleanup
sfc-gh-dmatthews Dec 11, 2024
0a0ceae
Merge branch 'main' into test-sis
sfc-gh-dmatthews Jan 2, 2025
dcbbd03
Update package-lock.json
sfc-gh-dmatthews Jan 3, 2025
009098f
Update platform label
sfc-gh-dmatthews Jan 10, 2025
001fa72
Merge branch 'main' into test-sis
sfc-gh-dmatthews Jan 10, 2025
bcde733
Remove initialize() from VersionContext and just init in the Context …
sfc-gh-tteixeira Jan 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
167 changes: 72 additions & 95 deletions components/blocks/autofunction.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import React, { useEffect, useState, useRef } from "react";
import ReactDOMServer from "react-dom/server";
import Markdown from "react-markdown";
import reverse from "lodash/reverse";
import classNames from "classnames";
import Table from "./table";
import { H2, H3 } from "./headers";
import Warning from "./warning";
import Deprecation from "./deprecation";
import { withRouter, useRouter } from "next/router";
import Prism from "prismjs";
import "prismjs/components/prism-python";
Expand All @@ -15,31 +12,34 @@ import "prismjs/plugins/toolbar/prism-toolbar";
import "prismjs/plugins/copy-to-clipboard/prism-copy-to-clipboard";
import "prismjs/plugins/normalize-whitespace/prism-normalize-whitespace";

import styles from "./autofunction.module.css";
import { name } from "file-loader";
import Table from "./table";
import { H2, H3 } from "./headers";
import Note from "./note";
import Warning from "./warning";
import Deprecation from "./deprecation";
import { functionNameToAnchorName } from "../../lib/utils";
import VersionSelector from "../utilities/versionSelector";
import { useVersion } from "../../context/VersionContext";

const cleanHref = (name) => {
return String(name).replace(/\./g, "").replace(/\s+/g, "-");
};
import styles from "./autofunction.module.css";

const Autofunction = ({
version,
versions,
snowflakeVersions,
streamlitFunction,
streamlit,
exceptions,
slug,
hideHeader,
deprecated,
deprecatedText,
oldStreamlitFunction,
}) => {
const blockRef = useRef();
const router = useRouter();
const maxVersion = versions[versions.length - 1];
const [isHighlighted, setIsHighlighted] = useState(false);
const [currentVersion, setCurrentVersion] = useState(
version ? version : versions[versions.length - 1],
);

const { version: currentVersion } = useVersion();

useEffect(() => {
highlightWithPrism();
Expand Down Expand Up @@ -97,75 +97,13 @@ const Autofunction = ({
setIsHighlighted(true);
};

const VersionSelector = ({
versionList,
currentVersion,
handleSelectVersion,
}) => {
const isSiS = currentVersion.startsWith("SiS") ? true : false;
const selectClass = isSiS
? "version-select sis-version"
: currentVersion !== versionList[0]
? "version-select old-version"
: "version-select";

return (
<form className={classNames(selectClass, styles.Form)}>
<label>
<span className="sr-only">Streamlit Version</span>
<select
value={currentVersion}
onChange={handleSelectVersion}
className={styles.Select}
>
{versionList.map((version, index) => (
<option value={version} key={version}>
{version == "SiS"
? "Streamlit in Snowflake"
: version.startsWith("SiS.")
? version.replace("SiS.", "Streamlit in Snowflake ")
: "Version " + version}
</option>
))}
</select>
</label>
</form>
);
};

const handleSelectVersion = (event) => {
const functionObject =
streamlit[streamlitFunction] ?? streamlit[oldStreamlitFunction];
const slicedSlug = slug.slice();

if (event.target.value !== currentVersion) {
setCurrentVersion(event.target.value);
if (event.target.value !== maxVersion) {
let isnum = /^[\d\.]+$/.test(slicedSlug[0]);
let isSiS = /^SiS[\d\.]*$/.test(slicedSlug[0]);
if (isnum || isSiS) {
slicedSlug[0] = event.target.value;
} else {
slicedSlug.unshift(event.target.value);
}
slug.unshift(event.target.value);
}
}

if (!functionObject) {
router.push(`/${slicedSlug.join("/")}`);
} else {
const name = cleanHref(`st.${functionObject.name}`);
router.push(`/${slicedSlug.join("/")}#${name} `);
}
};

const footers = [];
const args = [];
const returns = [];
const versionList = reverse(versions.slice());
let functionObject;
let functionException;
let functionDescription;
let functionDescriptionPrefix = "";
let header;
let headerTitle;
let body;
Expand All @@ -177,8 +115,17 @@ const Autofunction = ({
if (streamlitFunction in streamlit || oldStreamlitFunction in streamlit) {
functionObject =
streamlit[streamlitFunction] ?? streamlit[oldStreamlitFunction];
functionException =
streamlitFunction in streamlit
? exceptions[streamlitFunction] ?? {}
: oldStreamlitFunction in streamlit
? exceptions[oldStreamlitFunction] ?? {}
: {};
isClass = functionObject.is_class;
isAttributeDict = functionObject.is_attribute_dict ?? false;
if ("_" in functionException && "content" in functionException["_"]) {
functionDescriptionPrefix = functionException["_"]["content"];
}
if (
functionObject.description !== undefined &&
functionObject.description
Expand All @@ -198,20 +145,14 @@ const Autofunction = ({
<a
aria-hidden="true"
tabIndex="-1"
href={`#${cleanHref(
streamlitFunction.replace("streamlit", "st"),
)}`.toLowerCase()}
href={`#${functionNameToAnchorName(streamlitFunction)}`}
className="absolute"
>
<span className="icon icon-link"></span>
</a>
{streamlitFunction.replace("streamlit", "st")}
</H2>
<VersionSelector
versionList={versionList}
currentVersion={currentVersion}
handleSelectVersion={handleSelectVersion}
/>
<VersionSelector functionObject={functionObject} slug={slug} />
</div>
<Warning>
{version && version.startsWith("SiS") ? (
Expand Down Expand Up @@ -246,7 +187,7 @@ const Autofunction = ({
<a
aria-hidden="true"
tabIndex="-1"
href={`#${cleanHref(name)}`.toLowerCase()}
href={`#${functionNameToAnchorName(name)}`}
className="absolute"
>
<span className="icon icon-link"></span>
Expand All @@ -258,7 +199,7 @@ const Autofunction = ({
<a
aria-hidden="true"
tabIndex="-1"
href={`#${cleanHref(name)}`.toLowerCase()}
href={`#${functionNameToAnchorName(name)}`}
className="absolute"
>
<span className="icon icon-link"></span>
Expand All @@ -275,11 +216,7 @@ const Autofunction = ({
`}
>
{headerTitle}
<VersionSelector
versionList={versionList}
currentVersion={currentVersion}
handleSelectVersion={handleSelectVersion}
/>
<VersionSelector functionObject={functionObject} slug={slug} />
</div>
{deprecated === true ? (
<Deprecation>
Expand All @@ -288,6 +225,13 @@ const Autofunction = ({
) : (
""
)}
{functionDescriptionPrefix ? (
<Note label="Streamlit in Snowflake Note" compact>
<Markdown children={functionDescriptionPrefix} />
</Note>
) : (
""
)}
<div
className="code-desc"
dangerouslySetInnerHTML={functionDescription}
Expand Down Expand Up @@ -315,7 +259,7 @@ const Autofunction = ({
// propertiesRows is initialized early to allow Attributes (recorded as args)
// in any class docstring to be diverted to the properties section.
let propertiesRows = [];
let docstringProperties = []; // Used to avoid duplicates with @property
let docstringProperties = []; // Internal use to avoid duplicates with @property

for (const index in functionObject.args) {
const row = {};
Expand All @@ -332,6 +276,9 @@ const Autofunction = ({
${param.deprecated.deprecatedText}
</div>`
: "";
const paramPrefix = functionException[param.name]
? functionException[param.name]["content"]
: "";
const description = param.description
? param.description
: `<p>No description</p> `;
Expand All @@ -348,6 +295,15 @@ const Autofunction = ({
`;
row["body"] = `
${deprecatedMarkup}
${
paramPrefix
? ReactDOMServer.renderToString(
<Note label="Streamlit in Snowflake Note" compact>
<Markdown children={paramPrefix} />
</Note>,
)
: ""
}
${description}
`;
} else {
Expand All @@ -362,6 +318,15 @@ const Autofunction = ({
`;
row["body"] = `
${deprecatedMarkup}
${
paramPrefix
? ReactDOMServer.renderToString(
<Note label="Streamlit in Snowflake Note" compact>
<Markdown children={paramPrefix} />
</Note>,
)
: ""
}
${description}
`;
}
Expand Down Expand Up @@ -440,6 +405,9 @@ const Autofunction = ({
${property.deprecated.deprecatedText}
</div>`
: "";
const propertyPrefix = functionException[property.name]
? functionException[property.name]["content"]
: "";
const description = property.description
? property.description
: `<p>No description</p> `;
Expand All @@ -452,6 +420,15 @@ const Autofunction = ({
</p>`;
row["body"] = `
${deprecatedMarkup}
${
propertyPrefix
? ReactDOMServer.renderToString(
<Note label="Streamlit in Snowflake Note" compact>
<Markdown children={propertyPrefix} />
</Note>,
)
: ""
}
${description}
`;
propertiesRows.push(row);
Expand Down
6 changes: 5 additions & 1 deletion components/blocks/autofunction.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
}

.Title {
@apply mt-6 mb-2;
@apply grow mt-6 mb-2;
}

.Form {
Expand Down Expand Up @@ -175,3 +175,7 @@
:global(.dark) .Keyword::after {
@apply bg-gray-80 text-gray-30;
}

.Snowflake::after {
content: "SiS";
}
22 changes: 13 additions & 9 deletions components/blocks/iconHeader.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@ import classNames from "classnames";

import styles from "./iconHeader.module.css";

const IconHeader = ({ icon, rotate, title, background, color }) => {
const IconHeader = ({ icon, rotate, title, background, color, compact }) => {
return (
<section className={classNames(styles.Container)}>
<i
className={classNames(styles.Icon, BG_CLASS[background])}
style={{
transform: `rotate(${rotate}deg)`,
}}
>
{icon}
</i>
{compact ? (
""
) : (
<i
className={classNames(styles.Icon, BG_CLASS[background])}
style={{
transform: `rotate(${rotate}deg)`,
}}
>
{icon}
</i>
)}
<h4 className={classNames(styles.Title, FG_CLASS[background])}>
{title}
</h4>
Expand Down
15 changes: 11 additions & 4 deletions components/blocks/note.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ import NoteStyles from "./note.module.css";

import IconHeader from "./iconHeader";

const Note = ({ children }) => {
const Note = ({ children, label, compact }) => {
return (
<section className={classNames(CalloutStyles.Container, NoteStyles.Note)}>
<section
className={classNames(
CalloutStyles.Container,
NoteStyles.Note,
compact ? NoteStyles.Compact : "",
)}
>
<IconHeader
icon="push_pin"
icon={"push_pin"}
rotate="45"
title="Note"
title={label ?? "Note"}
background="lightBlue-70"
color="white"
compact={compact}
/>
{children}
</section>
Expand Down
4 changes: 4 additions & 0 deletions components/blocks/note.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@
:global(.dark) .Note {
background-color: #062633;
}

.Compact {
@apply p-4;
}
Loading