From 32c89abe67d913977775e1973144862bd1c7427e Mon Sep 17 00:00:00 2001 From: Shahed Nasser Date: Wed, 21 May 2025 19:34:55 +0300 Subject: [PATCH] docs: show when condition in workflows reference (#12566) --- .../components/CodeBlock/Actions/index.tsx | 6 ++- .../src/components/CodeBlock/index.tsx | 5 ++- .../WorkflowDiagram/Common/Node/index.tsx | 41 +++++++++++++++---- 3 files changed, 43 insertions(+), 9 deletions(-) diff --git a/www/packages/docs-ui/src/components/CodeBlock/Actions/index.tsx b/www/packages/docs-ui/src/components/CodeBlock/Actions/index.tsx index f040cf96ff..6a05c91a91 100644 --- a/www/packages/docs-ui/src/components/CodeBlock/Actions/index.tsx +++ b/www/packages/docs-ui/src/components/CodeBlock/Actions/index.tsx @@ -19,6 +19,7 @@ export type CodeBlockActionsProps = { onApiTesting?: React.Dispatch> noReport?: boolean noCopy?: boolean + noAskAi?: boolean } export const CodeBlockActions = ({ @@ -32,6 +33,7 @@ export const CodeBlockActions = ({ onApiTesting, noReport = false, noCopy = false, + noAskAi = false, }: CodeBlockActionsProps) => { const iconClassName = [ "text-medusa-contrast-fg-secondary", @@ -75,7 +77,9 @@ export const CodeBlockActions = ({ ] )} > - + {!noAskAi && ( + + )} {canShowApiTesting && ( { if (!source && typeof children === "string") { @@ -306,6 +307,7 @@ export const CodeBlock = ({ isCollapsed: collapsibleType !== undefined && collapsibleResult.collapsed, inInnerCode: hasInnerCodeBlock, showGradientBg: scrollable, + noAskAi, }), [ source, @@ -317,6 +319,7 @@ export const CodeBlock = ({ collapsibleResult, hasInnerCodeBlock, scrollable, + noAskAi, ] ) @@ -457,7 +460,7 @@ export const CodeBlock = ({ {!hasInnerCodeBlock && - (!noCopy || !noReport || canShowApiTesting) && ( + (!noCopy || !noReport || canShowApiTesting || !noAskAi) && ( { } }, [ref.current]) + const unindentLines = (str: string) => { + let minIndent = 4 + return str + .split("\n") + .reverse() + .map((line, index) => { + const trimmedStartLine = line.trimStart() + const numberOfSpaces = line.length - trimmedStartLine.length + if (index === 0) { + minIndent = numberOfSpaces || minIndent + } + if (numberOfSpaces >= minIndent) { + return " ".repeat(numberOfSpaces - 4) + trimmedStartLine + } + + return line + }) + .reverse() + .join("\n") + } + return (

{step.name}

- {step.when && ( - - Runs only if a when condition is - satisfied. - - )} {description && ( { {description} )} + {step.when?.condition && ( + + )} } clickable={true}