Skip to content

Commit b55f507

Browse files
chore(apollo-react): add temp locale selector to Flow Default story
Adds a temporary Storybook control on `Flow > Default` that drives the StickyNote formatting toolbar's locale via `ApI18nProvider`. Intended purely as a dev-harness to verify the canvas i18n pipeline end-to-end until a real ambient locale context exists. - New optional `locale?: SupportedLocale` prop on `StickyNoteNode`, threaded into the internal `ApI18nProvider`. Marked as storybook-only in the JSDoc. - New `stickyNoteLocale` storybook arg (select control, 5 translated locales: en/es/fr/ja/de). - `DefaultStory` rebuilds its `stickyNote` node type entry on locale change so xyflow remounts the notes with the new prop — xyflow keys its node type map by component identity, so a stable wrapper would close over the initial value. Remove the arg, the prop, and this commit once a real locale context lands. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 429b7e2 commit b55f507

2 files changed

Lines changed: 53 additions & 7 deletions

File tree

packages/apollo-react/src/canvas/components/Flow.stories.tsx

Lines changed: 44 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,17 @@ import type { Meta, StoryObj } from '@storybook/react-vite';
33
import type { Edge, Node, NodeProps } from '@uipath/apollo-react/canvas/xyflow/react';
44
import { Handle, Panel, Position, useReactFlow } from '@uipath/apollo-react/canvas/xyflow/react';
55
import { Download, Plus, StickyNote } from 'lucide-react';
6-
import { type FC, memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
6+
import {
7+
type ComponentProps,
8+
type FC,
9+
memo,
10+
useCallback,
11+
useEffect,
12+
useMemo,
13+
useRef,
14+
useState,
15+
} from 'react';
16+
import type { SupportedLocale } from '../../i18n';
717
import { useCanvasEvent, useExportCanvas } from '../hooks';
818
import {
919
createNode,
@@ -28,8 +38,19 @@ import type { ListItem } from './Toolbox';
2838

2939
interface FlowStoryArgs {
3040
useSmartHandles: boolean;
41+
/**
42+
* TEMPORARY dev harness — drives the StickyNote formatting toolbar's locale
43+
* via the `ApI18nProvider`. Remove once a real ambient locale context lands.
44+
* Only `en / es / fr / ja / de` have non-empty translations today; other
45+
* locales fall back to the source `message` default.
46+
*/
47+
stickyNoteLocale: SupportedLocale;
3148
}
3249

50+
// Locales that actually have translations in src/canvas/locales/*.json (others
51+
// are shipped with empty strings and fall back to the English `message`).
52+
const STICKY_NOTE_LOCALE_OPTIONS: SupportedLocale[] = ['en', 'es', 'fr', 'ja', 'de'];
53+
3354
const meta: Meta<FlowStoryArgs> = {
3455
title: 'Flow',
3556
parameters: {
@@ -45,9 +66,19 @@ const meta: Meta<FlowStoryArgs> = {
4566
defaultValue: { summary: 'false' },
4667
},
4768
},
69+
stickyNoteLocale: {
70+
control: 'select',
71+
options: STICKY_NOTE_LOCALE_OPTIONS,
72+
description:
73+
'[TEMP] Locale applied to the StickyNote formatting toolbar tooltips. Remove once a real locale context lands.',
74+
table: {
75+
defaultValue: { summary: 'en' },
76+
},
77+
},
4878
},
4979
args: {
5080
useSmartHandles: false,
81+
stickyNoteLocale: 'en',
5182
},
5283
};
5384

@@ -159,11 +190,19 @@ const ExportMessage = styled.div`
159190

160191
const DELETE_KEY_CODES = ['Backspace', 'Delete'];
161192

162-
const additionalNodeTypes = {
163-
stickyNote: StickyNoteNode,
164-
};
193+
function DefaultStory({ useSmartHandles, stickyNoteLocale }: FlowStoryArgs) {
194+
// Re-create the node type whenever the locale changes so xyflow remounts the
195+
// sticky notes with the new `locale` prop. (xyflow keys its node type map by
196+
// component identity; a stable wrapper would close over the initial value.)
197+
const additionalNodeTypes = useMemo(
198+
() => ({
199+
stickyNote: (props: ComponentProps<typeof StickyNoteNode>) => (
200+
<StickyNoteNode {...props} locale={stickyNoteLocale} />
201+
),
202+
}),
203+
[stickyNoteLocale]
204+
);
165205

166-
function DefaultStory({ useSmartHandles }: FlowStoryArgs) {
167206
const initialNodes = useMemo(() => createInitialNodes(useSmartHandles), [useSmartHandles]);
168207
const initialEdges = useMemo(() => createInitialEdges(), []);
169208
const [stickyNoteCounter, setStickyNoteCounter] = useState(0);

packages/apollo-react/src/canvas/components/StickyNoteNode/StickyNoteNode.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { NodeResizeControl, useReactFlow } from '@uipath/apollo-react/canvas/xyf
55
import type { ResizeDragEvent, ResizeParams } from '@uipath/apollo-react/canvas/xyflow/system';
66
import { AnimatePresence } from 'motion/react';
77
import { memo, useCallback, useEffect, useMemo, useRef, useState } from 'react';
8-
import { ApI18nProvider } from '../../../i18n';
8+
import { ApI18nProvider, type SupportedLocale } from '../../../i18n';
99
import ReactMarkdown from 'react-markdown';
1010
import remarkBreaks from 'remark-breaks';
1111
import remarkGfm from 'remark-gfm';
@@ -42,6 +42,12 @@ export interface StickyNoteNodeProps extends NodeProps {
4242
data: StickyNoteData;
4343
placeholder?: string;
4444
renderPlaceholderOnSelect?: boolean;
45+
/**
46+
* Locale for the formatting toolbar tooltips. Defaults to `'en'`. Currently
47+
* only consumed by the storybook harness — production callers should rely on
48+
* an ambient locale context once one is wired up.
49+
*/
50+
locale?: SupportedLocale;
4551
onContentChange?: (content: string) => void;
4652
onColorChange?: (color: StickyNoteColor) => void;
4753
onResize?: (width: number, height: number) => void;
@@ -57,6 +63,7 @@ const StickyNoteNodeComponent = ({
5763
dragging,
5864
placeholder = 'Add text',
5965
renderPlaceholderOnSelect = false,
66+
locale,
6067
onContentChange,
6168
onColorChange,
6269
onResize,
@@ -349,7 +356,7 @@ const StickyNoteNodeComponent = ({
349356
<TopCornerIndicators selected={selected} />
350357
<BottomCornerIndicators selected={selected} />
351358
{isEditing ? (
352-
<ApI18nProvider component="canvas">
359+
<ApI18nProvider component="canvas" locale={locale}>
353360
<FormattingToolbar
354361
textAreaRef={textAreaRef}
355362
borderColor={color}

0 commit comments

Comments
 (0)