Skip to content

Commit 4623f8d

Browse files
authored
[FE] Update display of key/value serdes in messages (#3543)
* added key format and value format * comented some test cases * comented some test cases * changed test cases * changed test cases * swapped key Serde and Value Serde
1 parent 20cc1e4 commit 4623f8d

File tree

3 files changed

+40
-28
lines changed

3 files changed

+40
-28
lines changed

kafka-ui-react-app/src/components/Topics/Topic/Messages/Message.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@ const Message: React.FC<Props> = ({
4242
key,
4343
partition,
4444
content,
45-
valueFormat,
46-
keyFormat,
4745
headers,
4846
},
4947
keyFilters,
@@ -140,9 +138,7 @@ const Message: React.FC<Props> = ({
140138
{isOpen && (
141139
<MessageContent
142140
messageKey={key}
143-
messageKeyFormat={keyFormat}
144141
messageContent={content}
145-
messageContentFormat={valueFormat}
146142
headers={headers}
147143
timestamp={timestamp}
148144
timestampType={timestampType}

kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/MessageContent.tsx

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,31 @@ import EditorViewer from 'components/common/EditorViewer/EditorViewer';
33
import BytesFormatted from 'components/common/BytesFormatted/BytesFormatted';
44
import { SchemaType, TopicMessageTimestampTypeEnum } from 'generated-sources';
55
import { formatTimestamp } from 'lib/dateTimeHelpers';
6+
import { useSearchParams } from 'react-router-dom';
67

78
import * as S from './MessageContent.styled';
89

910
type Tab = 'key' | 'content' | 'headers';
1011

1112
export interface MessageContentProps {
1213
messageKey?: string;
13-
messageKeyFormat?: string;
1414
messageContent?: string;
15-
messageContentFormat?: string;
1615
headers?: { [key: string]: string | undefined };
1716
timestamp?: Date;
1817
timestampType?: TopicMessageTimestampTypeEnum;
1918
}
2019

2120
const MessageContent: React.FC<MessageContentProps> = ({
2221
messageKey,
23-
messageKeyFormat,
2422
messageContent,
25-
messageContentFormat,
2623
headers,
2724
timestamp,
2825
timestampType,
2926
}) => {
3027
const [activeTab, setActiveTab] = React.useState<Tab>('content');
28+
const [searchParams] = useSearchParams();
29+
const keyFormat = searchParams.get('keySerde') || '';
30+
const valueFormat = searchParams.get('valueSerde') || '';
3131

3232
const activeTabContent = () => {
3333
switch (activeTab) {
@@ -54,7 +54,6 @@ const MessageContent: React.FC<MessageContentProps> = ({
5454
e.preventDefault();
5555
setActiveTab('headers');
5656
};
57-
5857
const keySize = new TextEncoder().encode(messageKey).length;
5958
const contentSize = new TextEncoder().encode(messageContent).length;
6059
const contentType =
@@ -106,21 +105,21 @@ const MessageContent: React.FC<MessageContentProps> = ({
106105
</S.Metadata>
107106

108107
<S.Metadata>
109-
<S.MetadataLabel>Value</S.MetadataLabel>
108+
<S.MetadataLabel>Key Serde</S.MetadataLabel>
110109
<span>
111-
<S.MetadataValue>{messageContentFormat}</S.MetadataValue>
110+
<S.MetadataValue>{keyFormat}</S.MetadataValue>
112111
<S.MetadataMeta>
113-
Size: <BytesFormatted value={contentSize} />
112+
Size: <BytesFormatted value={keySize} />
114113
</S.MetadataMeta>
115114
</span>
116115
</S.Metadata>
117116

118117
<S.Metadata>
119-
<S.MetadataLabel>Key</S.MetadataLabel>
118+
<S.MetadataLabel>Value Serde</S.MetadataLabel>
120119
<span>
121-
<S.MetadataValue>{messageKeyFormat}</S.MetadataValue>
120+
<S.MetadataValue>{valueFormat}</S.MetadataValue>
122121
<S.MetadataMeta>
123-
Size: <BytesFormatted value={keySize} />
122+
Size: <BytesFormatted value={contentSize} />
124123
</S.MetadataMeta>
125124
</span>
126125
</S.Metadata>

kafka-ui-react-app/src/components/Topics/Topic/Messages/MessageContent/__tests__/MessageContent.spec.tsx

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,7 @@ const setupWrapper = (props?: Partial<MessageContentProps>) => {
1616
<tbody>
1717
<MessageContent
1818
messageKey='"test-key"'
19-
messageKeyFormat="JSON"
2019
messageContent='{"data": "test"}'
21-
messageContentFormat="AVRO"
2220
headers={{ header: 'test' }}
2321
timestamp={new Date(0)}
2422
timestampType={TopicMessageTimestampTypeEnum.CREATE_TIME}
@@ -34,14 +32,33 @@ const proto =
3432

3533
global.TextEncoder = TextEncoder;
3634

35+
const searchParamsContentAVRO = new URLSearchParams({
36+
keySerde: 'SchemaRegistry',
37+
valueSerde: 'AVRO',
38+
limit: '100',
39+
});
40+
41+
const searchParamsContentJSON = new URLSearchParams({
42+
keySerde: 'SchemaRegistry',
43+
valueSerde: 'JSON',
44+
limit: '100',
45+
});
46+
47+
const searchParamsContentPROTOBUF = new URLSearchParams({
48+
keySerde: 'SchemaRegistry',
49+
valueSerde: 'PROTOBUF',
50+
limit: '100',
51+
});
3752
describe('MessageContent screen', () => {
3853
beforeEach(() => {
39-
render(setupWrapper());
54+
render(setupWrapper(), {
55+
initialEntries: [`/messages?${searchParamsContentAVRO}`],
56+
});
4057
});
4158

4259
describe('renders', () => {
4360
it('key format in document', () => {
44-
expect(screen.getByText('JSON')).toBeInTheDocument();
61+
expect(screen.getByText('SchemaRegistry')).toBeInTheDocument();
4562
});
4663

4764
it('content format in document', () => {
@@ -86,36 +103,36 @@ describe('checking content type depend on message type', () => {
86103
it('renders component with message having JSON type', () => {
87104
render(
88105
setupWrapper({
89-
messageContentFormat: 'JSON',
90106
messageContent: '{"data": "test"}',
91-
})
107+
}),
108+
{ initialEntries: [`/messages?${searchParamsContentJSON}`] }
92109
);
93-
expect(screen.getAllByText('JSON')[1]).toBeInTheDocument();
110+
expect(screen.getByText('JSON')).toBeInTheDocument();
94111
});
95112
it('renders component with message having AVRO type', () => {
96113
render(
97114
setupWrapper({
98-
messageContentFormat: 'AVRO',
99115
messageContent: '{"data": "test"}',
100-
})
116+
}),
117+
{ initialEntries: [`/messages?${searchParamsContentAVRO}`] }
101118
);
102119
expect(screen.getByText('AVRO')).toBeInTheDocument();
103120
});
104121
it('renders component with message having PROTOBUF type', () => {
105122
render(
106123
setupWrapper({
107-
messageContentFormat: 'PROTOBUF',
108124
messageContent: proto,
109-
})
125+
}),
126+
{ initialEntries: [`/messages?${searchParamsContentPROTOBUF}`] }
110127
);
111128
expect(screen.getByText('PROTOBUF')).toBeInTheDocument();
112129
});
113130
it('renders component with message having no type which is equal to having PROTOBUF type', () => {
114131
render(
115132
setupWrapper({
116-
messageContentFormat: 'PROTOBUF',
117133
messageContent: '',
118-
})
134+
}),
135+
{ initialEntries: [`/messages?${searchParamsContentPROTOBUF}`] }
119136
);
120137
expect(screen.getByText('PROTOBUF')).toBeInTheDocument();
121138
});

0 commit comments

Comments
 (0)