Skip to content

Commit 6c5baf9

Browse files
authored
annotated code component (#4953)
* annotated code * refactor annotatedcode to keep in mdx and update colors * add it on more pages * build-it-component * add to components.md
1 parent a8d5b04 commit 6c5baf9

11 files changed

Lines changed: 950 additions & 56 deletions

File tree

COMPONENTS.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Whether you’re using core components or experimenting with new ones, this guid
2525
- [Using RelatedRead](#using-relatedread)
2626
- [Using ToolTipTerm](#using-tooltipterm)
2727
- [Using SdkGuideLinks](#using-sdkguidelinks)
28+
- [Using AnnotatedCode](#using-annotatedcode)
2829
- [Using ReleaseNoteHeader](#using-release-note-header)
2930

3031
## Finding Components
@@ -482,6 +483,78 @@ Valid `name` values for the block icons: `goLangBlock`, `javaBlock`, `dotnetBloc
482483

483484
- `/temporal-client` — links to the Temporal Client feature guide for each SDK
484485

486+
## Using AnnotatedCode
487+
488+
Role: Let readers click concept pills to highlight matching lines in a code sample and show a short description.
489+
490+
Put a normal Markdown fence as children so the sample stays in the MDX. Put `annotations` inline on the page next to that fence.
491+
492+
How to import:
493+
494+
```
495+
import { AnnotatedCode } from '@site/src/components';
496+
```
497+
498+
### Usage
499+
500+
Example from the Worker performance page (poller autoscaling):
501+
502+
```
503+
<AnnotatedCode
504+
annotations={[
505+
{
506+
label: 'Workflow Task poller',
507+
description: 'Autoscales the number of pollers for Workflow Tasks based on load.',
508+
lines: [2],
509+
},
510+
{
511+
label: 'Activity Task poller',
512+
description: 'Autoscales the number of pollers for Activity Tasks based on load.',
513+
lines: [3],
514+
},
515+
{
516+
label: 'Nexus Task poller',
517+
description: 'Autoscales the number of pollers for Nexus Tasks based on load.',
518+
lines: [4],
519+
},
520+
]}
521+
>
522+
```go
523+
w := worker.New(c, "my-task-queue", worker.Options{
524+
WorkflowTaskPollerBehavior: worker.NewPollerBehaviorAutoscaling(worker.PollerBehaviorAutoscalingOptions{}),
525+
ActivityTaskPollerBehavior: worker.NewPollerBehaviorAutoscaling(worker.PollerBehaviorAutoscalingOptions{}),
526+
NexusTaskPollerBehavior: worker.NewPollerBehaviorAutoscaling(worker.PollerBehaviorAutoscalingOptions{}),
527+
})
528+
```
529+
</AnnotatedCode>
530+
```
531+
532+
`lines` are 1-based line numbers within the fence. Use an empty array when a concept has no lines to highlight in that sample.
533+
534+
Optional `color` on an annotation: `indigo`, `magenta`, `blue`, or `amber`. If omitted, tones rotate in that order.
535+
536+
Optional `hint` prop overrides the default “Highlight a concept” text above the pills.
537+
538+
### Props
539+
540+
| Prop | Type | Required | Description |
541+
| --- | --- | --- | --- |
542+
| `annotations` | `object[]` | No | Each item needs `label`, `description`, and `lines`. Optional `color`. |
543+
| `hint` | `string` | No | Text above the pills. Defaults to `Highlight a concept`. |
544+
| `children` | Markdown fence | Yes | The code sample to display and highlight. |
545+
546+
### LLM markdown
547+
548+
Registered as `strip-tag` in the MDX → Markdown pipeline: wrapper tags are removed and the fence content is kept. Keep annotation copy in the MDX `annotations` prop so authors edit it on the page.
549+
550+
### Where the component is used
551+
552+
- Worker Versioning — Worker options concepts
553+
- Worker performance — poller autoscaling options
554+
- Environment configuration — TOML Cloud profile fields
555+
- Task Queue Priority and Fairness — priority / fairness options
556+
- Child Workflows design pattern — async start concepts
557+
485558
## Using ReleaseNoteHeader
486559
487560
Role: To provide a consistent component for adding, updating, and removing release stages on different features.

MARKDOWN_PIPELINE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Each component maps to a strategy in `COMPONENT_REGISTRY` (in `scripts/mdx-to-md
124124
| `QuickstartCards`, `PatternCards` | `cards` | Markdown link list parsed from the inline `items={[{href,title,description}]}` prop |
125125
| `ZoomPanPinch` | `transparent` | Wrapper stripped; inner content passed through |
126126
| `DocCardList`, `CardList`, `LandingCard`, `ThemedImage`, `SdkSvg`, `CloudRegionCount`, `RetrySimulator`, `ServerlessWorkerDemo`, `OperationsTable`, `InvitationContent` | `strip-block` | Removed entirely (visual/dynamic, no extractable text) |
127-
| `DL`, `DT`, `DD`, `DefinitionList` | `strip-tag` | Tags stripped, text content kept |
127+
| `DL`, `DT`, `DD`, `DefinitionList`, `AnnotatedCode` | `strip-tag` | Tags stripped, text content kept |
128128
| `details` / `summary` | `details` / `summary` | `<summary>` becomes a heading; body expanded inline |
129129

130130
**Transclusion.** Components imported from a Markdown file

docs/design-patterns/child-workflows.mdx

Lines changed: 95 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ description: "Decomposes complex Workflows into smaller, reusable units. Each ch
77

88
import Tabs from '@theme/Tabs';
99
import TabItem from '@theme/TabItem';
10+
import { AnnotatedCode } from '@site/src/components';
1011

1112
## Overview
1213

@@ -167,13 +168,33 @@ In Go, `workflow.ExecuteChildWorkflow()` returns a `ChildWorkflowFuture`, and ca
167168
### Asynchronous Child Workflow
168169

169170
The following example starts a Child Workflow asynchronously with an ABANDON policy.
170-
The parent receives the child's execution info without waiting for completion:
171+
The parent receives the child's execution info without waiting for completion. Select a concept to highlight the matching lines:
171172

172173
<Tabs groupId="language" queryString>
173174
<TabItem value="python" label="Python">
174-
175+
<AnnotatedCode
176+
annotations={[
177+
{
178+
label: 'Parent Close Policy',
179+
description:
180+
'Controls what happens to the Child Workflow when the parent closes. ABANDON lets the child keep running after the parent completes.',
181+
lines: [14],
182+
},
183+
{
184+
label: 'Workflow Id',
185+
description:
186+
'Gives the Child Workflow a stable identity for tracking, querying, and deduplication in the UI.',
187+
lines: [13],
188+
},
189+
{
190+
label: 'Async start',
191+
description:
192+
'Starts the Child Workflow without waiting for it to finish. The parent continues after the child has started.',
193+
lines: [10, 11, 12, 13, 14, 15],
194+
},
195+
]}
196+
>
175197
```python
176-
# workflows.py
177198
from temporalio import workflow
178199
from temporalio.workflow import ParentClosePolicy
179200

@@ -183,28 +204,41 @@ from child_workflows import ChildWorkflow
183204
class ParentWorkflow:
184205
@workflow.run
185206
async def run(self, input: str) -> str:
186-
# Async call - returns handle once child starts
187207
handle = await workflow.start_child_workflow(
188208
ChildWorkflow.run,
189209
input,
190210
id=f"child-{workflow.uuid4()}",
191211
parent_close_policy=ParentClosePolicy.ABANDON,
192212
)
193213

194-
# Parent continues without waiting for child completion
195214
return handle.id
196215
```
197-
216+
</AnnotatedCode>
198217
</TabItem>
199218
<TabItem value="go" label="Go">
200-
219+
<AnnotatedCode
220+
annotations={[
221+
{
222+
label: 'Parent Close Policy',
223+
description:
224+
'Controls what happens to the Child Workflow when the parent closes. ABANDON lets the child keep running after the parent completes.',
225+
lines: [3],
226+
},
227+
{
228+
label: 'Workflow Id',
229+
description:
230+
'Gives the Child Workflow a stable identity for tracking, querying, and deduplication in the UI.',
231+
lines: [14],
232+
},
233+
{
234+
label: 'Async start',
235+
description:
236+
'Starts the Child Workflow without waiting for it to finish. The parent continues after the child has started.',
237+
lines: [7],
238+
},
239+
]}
240+
>
201241
```go
202-
// parent_workflow.go
203-
import (
204-
enumspb "go.temporal.io/api/enums/v1"
205-
"go.temporal.io/sdk/workflow"
206-
)
207-
208242
func ParentWorkflow(ctx workflow.Context, input string) (string, error) {
209243
cwo := workflow.ChildWorkflowOptions{
210244
ParentClosePolicy: enumspb.PARENT_CLOSE_POLICY_ABANDON,
@@ -213,22 +247,40 @@ func ParentWorkflow(ctx workflow.Context, input string) (string, error) {
213247

214248
childFuture := workflow.ExecuteChildWorkflow(ctx, ChildWorkflow, input)
215249

216-
// Wait for child to start, not complete
217250
var childWE workflow.Execution
218251
if err := childFuture.GetChildWorkflowExecution().Get(ctx, &childWE); err != nil {
219252
return "", err
220253
}
221254

222-
// Parent continues without waiting for child completion
223255
return childWE.ID, nil
224256
}
225257
```
226-
258+
</AnnotatedCode>
227259
</TabItem>
228260
<TabItem value="java" label="Java">
229-
261+
<AnnotatedCode
262+
annotations={[
263+
{
264+
label: 'Parent Close Policy',
265+
description:
266+
'Controls what happens to the Child Workflow when the parent closes. ABANDON lets the child keep running after the parent completes.',
267+
lines: [6],
268+
},
269+
{
270+
label: 'Workflow Id',
271+
description:
272+
'Gives the Child Workflow a stable identity for tracking, querying, and deduplication in the UI.',
273+
lines: [5],
274+
},
275+
{
276+
label: 'Async start',
277+
description:
278+
'Starts the Child Workflow without waiting for it to finish. The parent continues after the child has started.',
279+
lines: [11],
280+
},
281+
]}
282+
>
230283
```java
231-
// ParentWorkflowImpl.java
232284
public class ParentWorkflowImpl implements ParentWorkflow {
233285
@Override
234286
public WorkflowExecution execute(String input) {
@@ -239,21 +291,39 @@ public class ParentWorkflowImpl implements ParentWorkflow {
239291

240292
ChildWorkflow child = Workflow.newChildWorkflowStub(ChildWorkflow.class, options);
241293

242-
// Async call - returns immediately
243294
Async.function(child::processData, input);
244295

245-
// Get child execution info without waiting for completion
246296
Promise<WorkflowExecution> childExecution = Workflow.getWorkflowExecution(child);
247-
return childExecution.get(); // Blocks only until child starts
297+
return childExecution.get();
248298
}
249299
}
250300
```
251-
301+
</AnnotatedCode>
252302
</TabItem>
253303
<TabItem value="typescript" label="TypeScript">
254-
304+
<AnnotatedCode
305+
annotations={[
306+
{
307+
label: 'Parent Close Policy',
308+
description:
309+
'Controls what happens to the Child Workflow when the parent closes. ABANDON lets the child keep running after the parent completes.',
310+
lines: [7],
311+
},
312+
{
313+
label: 'Workflow Id',
314+
description:
315+
'Gives the Child Workflow a stable identity for tracking, querying, and deduplication in the UI.',
316+
lines: [10],
317+
},
318+
{
319+
label: 'Async start',
320+
description:
321+
'Starts the Child Workflow without waiting for it to finish. The parent continues after the child has started.',
322+
lines: [5, 6, 7, 8],
323+
},
324+
]}
325+
>
255326
```typescript
256-
// workflows.ts
257327
import { startChild, ParentClosePolicy } from '@temporalio/workflow';
258328
import { childWorkflow } from './child-workflows';
259329

@@ -263,12 +333,10 @@ export async function parentWorkflow(input: string): Promise<string> {
263333
parentClosePolicy: ParentClosePolicy.PARENT_CLOSE_POLICY_ABANDON,
264334
});
265335

266-
// Parent continues without waiting for child completion
267-
// childHandle.workflowId and childHandle.firstExecutionRunId are available
268336
return childHandle.workflowId;
269337
}
270338
```
271-
339+
</AnnotatedCode>
272340
</TabItem>
273341
</Tabs>
274342

docs/develop/environment-configuration.mdx

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ tags:
1010
- TOML
1111
---
1212

13-
import { SdkTabs } from '@site/src/components';
13+
import { SdkTabs, AnnotatedCode } from '@site/src/components';
1414
import Tabs from '@theme/Tabs';
1515
import TabItem from '@theme/TabItem';
1616

@@ -92,6 +92,48 @@ MIIPrivateKeyDataHere...
9292
-----END PRIVATE KEY-----"""
9393
```
9494

95+
Select a concept to highlight the matching connection settings in a Cloud profile:
96+
97+
<AnnotatedCode
98+
annotations={[
99+
{
100+
label: 'Address',
101+
description:
102+
'Temporal Service host and port. For Temporal Cloud, use your Namespace endpoint (for example your-namespace.account.tmprl.cloud:7233).',
103+
lines: [2],
104+
},
105+
{
106+
label: 'Namespace',
107+
description:
108+
'Namespace this Client connects to. On Temporal Cloud, include the account suffix when your tooling expects it.',
109+
lines: [3],
110+
},
111+
{
112+
label: 'API key',
113+
description:
114+
'Authenticates the Client to Temporal Cloud. Prefer environment variables for secrets in real deployments; TOML is fine for local profiles.',
115+
lines: [4],
116+
},
117+
{
118+
label: 'TLS',
119+
description:
120+
'Optional mTLS settings. TLS is often auto-enabled when an API key or TLS block is present; set certificate paths for mutual TLS.',
121+
lines: [6, 7, 8],
122+
},
123+
]}
124+
>
125+
```toml
126+
[profile.prod]
127+
address = "your-namespace.a1b2c.tmprl.cloud:7233"
128+
namespace = "your-namespace"
129+
api_key = "your-api-key-here"
130+
131+
[profile.prod.tls]
132+
client_cert_path = "/etc/temporal/certs/client.pem"
133+
client_key_path = "/etc/temporal/certs/client.key"
134+
```
135+
</AnnotatedCode>
136+
95137
The [`temporal cloud login`](/cli/cloud#interactive-login) command also writes to this file. When you run `temporal cloud login --profile prod`, the OAuth token is stored in the specified profile automatically. Subsequent commands that use that profile read the token from the TOML file to authenticate with Temporal Cloud.
96138

97139
## CLI integration

0 commit comments

Comments
 (0)