docs: show when condition in workflows reference (#12566)
This commit is contained in:
@@ -19,6 +19,7 @@ export type CodeBlockActionsProps = {
|
|||||||
onApiTesting?: React.Dispatch<React.SetStateAction<boolean>>
|
onApiTesting?: React.Dispatch<React.SetStateAction<boolean>>
|
||||||
noReport?: boolean
|
noReport?: boolean
|
||||||
noCopy?: boolean
|
noCopy?: boolean
|
||||||
|
noAskAi?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CodeBlockActions = ({
|
export const CodeBlockActions = ({
|
||||||
@@ -32,6 +33,7 @@ export const CodeBlockActions = ({
|
|||||||
onApiTesting,
|
onApiTesting,
|
||||||
noReport = false,
|
noReport = false,
|
||||||
noCopy = false,
|
noCopy = false,
|
||||||
|
noAskAi = false,
|
||||||
}: CodeBlockActionsProps) => {
|
}: CodeBlockActionsProps) => {
|
||||||
const iconClassName = [
|
const iconClassName = [
|
||||||
"text-medusa-contrast-fg-secondary",
|
"text-medusa-contrast-fg-secondary",
|
||||||
@@ -75,7 +77,9 @@ export const CodeBlockActions = ({
|
|||||||
]
|
]
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
|
{!noAskAi && (
|
||||||
<CodeBlockAskAiAction source={source} inHeader={inHeader} />
|
<CodeBlockAskAiAction source={source} inHeader={inHeader} />
|
||||||
|
)}
|
||||||
{canShowApiTesting && (
|
{canShowApiTesting && (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
text="Test API"
|
text="Test API"
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ export const CodeBlock = ({
|
|||||||
style,
|
style,
|
||||||
forceNoTitle = false,
|
forceNoTitle = false,
|
||||||
animateTokenHighlights,
|
animateTokenHighlights,
|
||||||
|
noAskAi = false,
|
||||||
...rest
|
...rest
|
||||||
}: CodeBlockProps) => {
|
}: CodeBlockProps) => {
|
||||||
if (!source && typeof children === "string") {
|
if (!source && typeof children === "string") {
|
||||||
@@ -306,6 +307,7 @@ export const CodeBlock = ({
|
|||||||
isCollapsed: collapsibleType !== undefined && collapsibleResult.collapsed,
|
isCollapsed: collapsibleType !== undefined && collapsibleResult.collapsed,
|
||||||
inInnerCode: hasInnerCodeBlock,
|
inInnerCode: hasInnerCodeBlock,
|
||||||
showGradientBg: scrollable,
|
showGradientBg: scrollable,
|
||||||
|
noAskAi,
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
source,
|
source,
|
||||||
@@ -317,6 +319,7 @@ export const CodeBlock = ({
|
|||||||
collapsibleResult,
|
collapsibleResult,
|
||||||
hasInnerCodeBlock,
|
hasInnerCodeBlock,
|
||||||
scrollable,
|
scrollable,
|
||||||
|
noAskAi,
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -457,7 +460,7 @@ export const CodeBlock = ({
|
|||||||
</code>
|
</code>
|
||||||
</pre>
|
</pre>
|
||||||
{!hasInnerCodeBlock &&
|
{!hasInnerCodeBlock &&
|
||||||
(!noCopy || !noReport || canShowApiTesting) && (
|
(!noCopy || !noReport || canShowApiTesting || !noAskAi) && (
|
||||||
<CodeBlockActions
|
<CodeBlockActions
|
||||||
{...actionsProps}
|
{...actionsProps}
|
||||||
inHeader={false}
|
inHeader={false}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import clsx from "clsx"
|
|||||||
import Link from "next/link"
|
import Link from "next/link"
|
||||||
import React, { useEffect, useMemo, useRef, useState } from "react"
|
import React, { useEffect, useMemo, useRef, useState } from "react"
|
||||||
import { WorkflowStepUi } from "types"
|
import { WorkflowStepUi } from "types"
|
||||||
import { InlineCode, MarkdownContent, Tooltip } from "../../.."
|
import { CodeBlock, MarkdownContent, Tooltip } from "../../.."
|
||||||
import { Bolt, InformationCircle } from "@medusajs/icons"
|
import { Bolt, InformationCircle } from "@medusajs/icons"
|
||||||
import { getBrowser } from "../../../../utils"
|
import { getBrowser } from "../../../../utils"
|
||||||
|
|
||||||
@@ -53,18 +53,33 @@ export const WorkflowDiagramStepNode = ({ step }: WorkflowDiagramNodeProps) => {
|
|||||||
}
|
}
|
||||||
}, [ref.current])
|
}, [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 (
|
return (
|
||||||
<Tooltip
|
<Tooltip
|
||||||
tooltipClassName="!text-left max-w-[300px] text-pretty overflow-scroll"
|
tooltipClassName="!text-left max-w-[300px] text-pretty overflow-scroll"
|
||||||
tooltipChildren={
|
tooltipChildren={
|
||||||
<>
|
<>
|
||||||
<h4 className="text-compact-x-small-plus">{step.name}</h4>
|
<h4 className="text-compact-x-small-plus">{step.name}</h4>
|
||||||
{step.when && (
|
|
||||||
<span className="block py-docs_0.25">
|
|
||||||
Runs only if a <InlineCode>when</InlineCode> condition is
|
|
||||||
satisfied.
|
|
||||||
</span>
|
|
||||||
)}
|
|
||||||
{description && (
|
{description && (
|
||||||
<MarkdownContent
|
<MarkdownContent
|
||||||
allowedElements={["a", "strong", "code"]}
|
allowedElements={["a", "strong", "code"]}
|
||||||
@@ -73,6 +88,18 @@ export const WorkflowDiagramStepNode = ({ step }: WorkflowDiagramNodeProps) => {
|
|||||||
{description}
|
{description}
|
||||||
</MarkdownContent>
|
</MarkdownContent>
|
||||||
)}
|
)}
|
||||||
|
{step.when?.condition && (
|
||||||
|
<CodeBlock
|
||||||
|
lang="typescript"
|
||||||
|
source={unindentLines(step.when.condition)}
|
||||||
|
noReport
|
||||||
|
noCopy
|
||||||
|
noAskAi
|
||||||
|
noLineNumbers
|
||||||
|
title="when Condition"
|
||||||
|
wrapperClassName="mt-docs_0.5"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
}
|
}
|
||||||
clickable={true}
|
clickable={true}
|
||||||
|
|||||||
Reference in New Issue
Block a user