import { useState } from 'react' import { useTranslation } from 'react-i18next' import { Badge, Tabs, type TabItem } from '@/ui' import { generateEventPreviews } from './eventPreview' import type { DataScope, JsonSchema } from '@/api/client' type Props = { dictionaryName: string dataScope: DataScope bundle: string schema: JsonSchema businessKeyField?: string } /** * Preview tab inside DictionaryEditorDialog. Показывает sample JSON envelope * для каждого event type, который Kafka получит после save'а dict / records. * *

Помогает integrators (Альтум, Геопортал, etc) понять shape события до * того как dict published. Без этого они вынуждены ждать live event'а * чтобы посмотреть payload. * *

Pure client-side preview — не отправляет ничего в Kafka. Sample data * генерится из schema properties (string → "sample", integer → 42, и т.д.). */ export const EventsPreviewTab = ({ dictionaryName, dataScope, bundle, schema, businessKeyField, }: Props) => { const { t } = useTranslation() const previews = generateEventPreviews( dictionaryName || 'sample_dict', dataScope, bundle || 'cuod', schema, businessKeyField, ) const [active, setActive] = useState(previews[0]?.eventType ?? 'RecordCreated') const current = previews.find((p) => p.eventType === active) ?? previews[0] const tabs: TabItem[] = previews.map((p) => ({ id: p.eventType, label: p.label, })) return (

{t('schema.events.intro')}

{current && (
{current.eventType} {t('schema.events.topic')}: {current.topic}

{current.description}

            {JSON.stringify(current.envelope, null, 2)}
          

{t('schema.events.disclaimer')}

)}
) }