Skip to content

Commit

Permalink
[FE] Update display of key/value serdes in messages (#3543)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
David-DB88 authored Mar 28, 2023
1 parent 20cc1e4 commit 4623f8d
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ const Message: React.FC<Props> = ({
key,
partition,
content,
valueFormat,
keyFormat,
headers,
},
keyFilters,
Expand Down Expand Up @@ -140,9 +138,7 @@ const Message: React.FC<Props> = ({
{isOpen && (
<MessageContent
messageKey={key}
messageKeyFormat={keyFormat}
messageContent={content}
messageContentFormat={valueFormat}
headers={headers}
timestamp={timestamp}
timestampType={timestampType}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,31 @@ 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 { useSearchParams } from 'react-router-dom';

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

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

export interface MessageContentProps {
messageKey?: string;
messageKeyFormat?: string;
messageContent?: string;
messageContentFormat?: string;
headers?: { [key: string]: string | undefined };
timestamp?: Date;
timestampType?: TopicMessageTimestampTypeEnum;
}

const MessageContent: React.FC<MessageContentProps> = ({
messageKey,
messageKeyFormat,
messageContent,
messageContentFormat,
headers,
timestamp,
timestampType,
}) => {
const [activeTab, setActiveTab] = React.useState<Tab>('content');
const [searchParams] = useSearchParams();
const keyFormat = searchParams.get('keySerde') || '';
const valueFormat = searchParams.get('valueSerde') || '';

const activeTabContent = () => {
switch (activeTab) {
Expand All @@ -54,7 +54,6 @@ const MessageContent: React.FC<MessageContentProps> = ({
e.preventDefault();
setActiveTab('headers');
};

const keySize = new TextEncoder().encode(messageKey).length;
const contentSize = new TextEncoder().encode(messageContent).length;
const contentType =
Expand Down Expand Up @@ -106,21 +105,21 @@ const MessageContent: React.FC<MessageContentProps> = ({
</S.Metadata>

<S.Metadata>
<S.MetadataLabel>Value</S.MetadataLabel>
<S.MetadataLabel>Key Serde</S.MetadataLabel>
<span>
<S.MetadataValue>{messageContentFormat}</S.MetadataValue>
<S.MetadataValue>{keyFormat}</S.MetadataValue>
<S.MetadataMeta>
Size: <BytesFormatted value={contentSize} />
Size: <BytesFormatted value={keySize} />
</S.MetadataMeta>
</span>
</S.Metadata>

<S.Metadata>
<S.MetadataLabel>Key</S.MetadataLabel>
<S.MetadataLabel>Value Serde</S.MetadataLabel>
<span>
<S.MetadataValue>{messageKeyFormat}</S.MetadataValue>
<S.MetadataValue>{valueFormat}</S.MetadataValue>
<S.MetadataMeta>
Size: <BytesFormatted value={keySize} />
Size: <BytesFormatted value={contentSize} />
</S.MetadataMeta>
</span>
</S.Metadata>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ const setupWrapper = (props?: Partial<MessageContentProps>) => {
<tbody>
<MessageContent
messageKey='"test-key"'
messageKeyFormat="JSON"
messageContent='{"data": "test"}'
messageContentFormat="AVRO"
headers={{ header: 'test' }}
timestamp={new Date(0)}
timestampType={TopicMessageTimestampTypeEnum.CREATE_TIME}
Expand All @@ -34,14 +32,33 @@ const proto =

global.TextEncoder = TextEncoder;

const searchParamsContentAVRO = new URLSearchParams({
keySerde: 'SchemaRegistry',
valueSerde: 'AVRO',
limit: '100',
});

const searchParamsContentJSON = new URLSearchParams({
keySerde: 'SchemaRegistry',
valueSerde: 'JSON',
limit: '100',
});

const searchParamsContentPROTOBUF = new URLSearchParams({
keySerde: 'SchemaRegistry',
valueSerde: 'PROTOBUF',
limit: '100',
});
describe('MessageContent screen', () => {
beforeEach(() => {
render(setupWrapper());
render(setupWrapper(), {
initialEntries: [`/messages?${searchParamsContentAVRO}`],
});
});

describe('renders', () => {
it('key format in document', () => {
expect(screen.getByText('JSON')).toBeInTheDocument();
expect(screen.getByText('SchemaRegistry')).toBeInTheDocument();
});

it('content format in document', () => {
Expand Down Expand Up @@ -86,36 +103,36 @@ describe('checking content type depend on message type', () => {
it('renders component with message having JSON type', () => {
render(
setupWrapper({
messageContentFormat: 'JSON',
messageContent: '{"data": "test"}',
})
}),
{ initialEntries: [`/messages?${searchParamsContentJSON}`] }
);
expect(screen.getAllByText('JSON')[1]).toBeInTheDocument();
expect(screen.getByText('JSON')).toBeInTheDocument();
});
it('renders component with message having AVRO type', () => {
render(
setupWrapper({
messageContentFormat: 'AVRO',
messageContent: '{"data": "test"}',
})
}),
{ initialEntries: [`/messages?${searchParamsContentAVRO}`] }
);
expect(screen.getByText('AVRO')).toBeInTheDocument();
});
it('renders component with message having PROTOBUF type', () => {
render(
setupWrapper({
messageContentFormat: 'PROTOBUF',
messageContent: proto,
})
}),
{ initialEntries: [`/messages?${searchParamsContentPROTOBUF}`] }
);
expect(screen.getByText('PROTOBUF')).toBeInTheDocument();
});
it('renders component with message having no type which is equal to having PROTOBUF type', () => {
render(
setupWrapper({
messageContentFormat: 'PROTOBUF',
messageContent: '',
})
}),
{ initialEntries: [`/messages?${searchParamsContentPROTOBUF}`] }
);
expect(screen.getByText('PROTOBUF')).toBeInTheDocument();
});
Expand Down

0 comments on commit 4623f8d

Please sign in to comment.