frontend_nyla/src/components/Automation2FlowEditor/nodes/shared/utils.ts

25 lines
811 B
TypeScript

/**
* Automation2 Flow Editor - Utility functions
*/
import type React from 'react';
import { CATEGORY_ICONS, DEFAULT_CATEGORY_ICON } from './categoryIcons';
/** Resolve localized label from string or { de, en, fr } object */
export function getLabel(
text: string | Record<string, string> | undefined,
lang = 'de'
): string {
if (!text) return '';
if (typeof text === 'string') return text;
const rec = text as Record<string, string>;
return rec[lang] ?? rec.en ?? '';
}
/** Get icon for a category */
export function getCategoryIcon(categoryId: string): React.ReactNode {
return CATEGORY_ICONS[categoryId] ?? DEFAULT_CATEGORY_ICON;
}
/** Function type for resolving localized labels */
export type GetLabelFn = (text: string | Record<string, string> | undefined, lang?: string) => string;