-
Notifications
You must be signed in to change notification settings - Fork 2
Export resolveI18nLabel and fix i18n label type errors in plugin-designer #901
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ import { | |
| } from 'lucide-react'; | ||
| import { clsx } from 'clsx'; | ||
| import { twMerge } from 'tailwind-merge'; | ||
| import { resolveI18nLabel } from '@object-ui/react'; | ||
| import { useDesignerTranslation } from './hooks/useDesignerTranslation'; | ||
|
|
||
| function cn(...inputs: (string | undefined | false)[]) { | ||
|
|
@@ -139,7 +140,7 @@ function NavItemRow({ | |
| t, | ||
| }: NavItemRowProps) { | ||
| const [editingLabel, setEditingLabel] = useState(false); | ||
| const [labelDraft, setLabelDraft] = useState(item.label); | ||
| const [labelDraft, setLabelDraft] = useState(resolveI18nLabel(item.label) ?? ''); | ||
| const [editingIcon, setEditingIcon] = useState(false); | ||
|
Comment on lines
142
to
144
|
||
| const [iconDraft, setIconDraft] = useState(item.icon || ''); | ||
| const meta = NAV_TYPE_META[item.type]; | ||
|
|
@@ -151,7 +152,7 @@ function NavItemRow({ | |
| if (labelDraft.trim()) { | ||
| onUpdateLabel(item.id, labelDraft.trim()); | ||
| } else { | ||
| setLabelDraft(item.label); | ||
| setLabelDraft(resolveI18nLabel(item.label) ?? ''); | ||
| } | ||
| setEditingLabel(false); | ||
| }; | ||
|
|
@@ -243,7 +244,7 @@ function NavItemRow({ | |
| onKeyDown={(e) => { | ||
| if (e.key === 'Enter') handleLabelCommit(); | ||
| if (e.key === 'Escape') { | ||
| setLabelDraft(item.label); | ||
| setLabelDraft(resolveI18nLabel(item.label) ?? ''); | ||
| setEditingLabel(false); | ||
| } | ||
| }} | ||
|
|
@@ -258,12 +259,12 @@ function NavItemRow({ | |
| )} | ||
| onDoubleClick={() => { | ||
| if (!readOnly && item.type !== 'separator') { | ||
| setLabelDraft(item.label); | ||
| setLabelDraft(resolveI18nLabel(item.label) ?? ''); | ||
| setEditingLabel(true); | ||
| } | ||
| }} | ||
| > | ||
| {item.label} | ||
| {resolveI18nLabel(item.label)} | ||
| </span> | ||
| )} | ||
|
|
||
|
|
@@ -410,7 +411,7 @@ function PreviewItem({ item, depth }: { item: NavigationItem; depth: number }) { | |
| style={{ marginLeft: depth * 12 }} | ||
| > | ||
| <meta.Icon className="h-3 w-3 text-gray-400" /> | ||
| <span className="truncate">{item.label}</span> | ||
| <span className="truncate">{resolveI18nLabel(item.label)}</span> | ||
| </li> | ||
| {item.type === 'group' && item.children?.map((child) => ( | ||
| <PreviewItem key={child.id} item={child} depth={depth + 1} /> | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,6 +13,9 @@ export * from './components/form'; | |||||||||||||||||||||||||||||||||||||||||
| export * from './LazyPluginLoader'; | ||||||||||||||||||||||||||||||||||||||||||
| export * from './spec-bridge'; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
| // i18n utilities | ||||||||||||||||||||||||||||||||||||||||||
| export { resolveI18nLabel } from './utils/i18n'; | ||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+17
to
+18
|
||||||||||||||||||||||||||||||||||||||||||
| export { resolveI18nLabel } from './utils/i18n'; | |
| import { resolveI18nLabel as baseResolveI18nLabel } from './utils/i18n'; | |
| export function resolveI18nLabel( | |
| ...args: Parameters<typeof baseResolveI18nLabel> | |
| ): ReturnType<typeof baseResolveI18nLabel> { | |
| const [label] = args; | |
| if ( | |
| label && | |
| typeof label === 'object' && | |
| 'defaultValue' in label && | |
| (label as { defaultValue?: unknown }).defaultValue === '' | |
| ) { | |
| // Preserve intentionally empty-string default values instead of falling back to the key | |
| return '' as ReturnType<typeof baseResolveI18nLabel>; | |
| } | |
| return baseResolveI18nLabel(...args); | |
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Test coverage: since the navigation preview now resolves
item.labelviaresolveI18nLabel, add a test case inAppCreationWizard.test.tsxwith an i18n-object label to ensure the preview renders the expected fallback string (and doesn’t regress back to TS/ReactNode issues).