-
-
Notifications
You must be signed in to change notification settings - Fork 136
/
Copy pathMessageContent.tsx
146 lines (132 loc) · 4.12 KB
/
MessageContent.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import React from 'react';
import EditorViewer from 'components/common/EditorViewer/EditorViewer';
import BytesFormatted from 'components/common/BytesFormatted/BytesFormatted';
import { SchemaType, TopicMessageTimestampTypeEnum } from 'generated-sources';
import { formatTimestamp } from 'lib/dateTimeHelpers';
import AvroMetadata from './AvroMetadata';
import * as S from './MessageContent.styled';
type Tab = 'key' | 'content' | 'headers';
export interface MessageContentProps {
messageKey?: string;
messageContent?: string;
headers?: { [key: string]: string | undefined };
timestamp?: Date;
timestampType?: TopicMessageTimestampTypeEnum;
keySize?: number;
contentSize?: number;
keySerde?: string;
valueSerde?: string;
keyDeserializeProperties?: { [key: string]: unknown | undefined };
valueDeserializeProperties?: { [key: string]: unknown | undefined };
}
const MessageContent: React.FC<MessageContentProps> = ({
messageKey,
messageContent,
headers,
timestamp,
timestampType,
keySize,
contentSize,
keySerde,
valueSerde,
keyDeserializeProperties,
valueDeserializeProperties,
}) => {
const [activeTab, setActiveTab] = React.useState<Tab>('content');
const activeTabContent = () => {
switch (activeTab) {
case 'content':
return messageContent;
case 'key':
return messageKey;
default:
return JSON.stringify(headers);
}
};
const handleKeyTabClick = (e: React.MouseEvent) => {
e.preventDefault();
setActiveTab('key');
};
const handleContentTabClick = (e: React.MouseEvent) => {
e.preventDefault();
setActiveTab('content');
};
const handleHeadersTabClick = (e: React.MouseEvent) => {
e.preventDefault();
setActiveTab('headers');
};
const contentType =
messageContent &&
(messageContent.trim().startsWith('{') ||
messageContent.trim().startsWith('['))
? SchemaType.JSON
: SchemaType.PROTOBUF;
return (
<S.Wrapper>
<td colSpan={10}>
<S.Section>
<S.ContentBox>
<S.Tabs>
<S.Tab
type="button"
$active={activeTab === 'key'}
onClick={handleKeyTabClick}
>
Key
</S.Tab>
<S.Tab
$active={activeTab === 'content'}
type="button"
onClick={handleContentTabClick}
>
Value
</S.Tab>
<S.Tab
$active={activeTab === 'headers'}
type="button"
onClick={handleHeadersTabClick}
>
Headers
</S.Tab>
</S.Tabs>
<EditorViewer
data={activeTabContent() || ''}
maxLines={28}
schemaType={contentType}
/>
</S.ContentBox>
<S.MetadataWrapper>
<S.Metadata>
<S.MetadataLabel>Timestamp</S.MetadataLabel>
<span>
<S.MetadataValue>{formatTimestamp(timestamp)}</S.MetadataValue>
<S.MetadataMeta>Timestamp type: {timestampType}</S.MetadataMeta>
</span>
</S.Metadata>
<S.Metadata>
<S.MetadataLabel>Key Serde</S.MetadataLabel>
<span>
<S.MetadataValue>{keySerde}</S.MetadataValue>
<S.MetadataMeta>
Size: <BytesFormatted value={keySize} />
</S.MetadataMeta>
</span>
</S.Metadata>
<AvroMetadata deserializeProperties={keyDeserializeProperties} />
<S.Metadata>
<S.MetadataLabel>Value Serde</S.MetadataLabel>
<span>
<S.MetadataValue>{valueSerde}</S.MetadataValue>
<S.MetadataMeta>
Size: <BytesFormatted value={contentSize} />
</S.MetadataMeta>
</span>
</S.Metadata>
<AvroMetadata deserializeProperties={valueDeserializeProperties} />
</S.MetadataWrapper>
</S.Section>
</td>
</S.Wrapper>
);
};
export default MessageContent;