
* message * if tag contains -SNAPSHOT - display formatted timestamp * create Time format context * fix pull request commits * change pull request commits * add fetchTimeFormat function * add fetchTimeFormat function * chnage test run * fix testing error * covered global context with tests * removed unused import statement * fixed smell * pull master * fixed code smeils * covered Version component, hooks with tests, fixed code review comments * converted outdated to boolean * remove tag condition from return
112 lines
2.9 KiB
TypeScript
112 lines
2.9 KiB
TypeScript
import React from 'react';
|
|
import styled from 'styled-components';
|
|
import useDataSaver from 'lib/hooks/useDataSaver';
|
|
import { TopicMessage } from 'generated-sources';
|
|
import { useTimeFormat } from 'lib/hooks/useTimeFormat';
|
|
import MessageToggleIcon from 'components/common/Icons/MessageToggleIcon';
|
|
import IconButtonWrapper from 'components/common/Icons/IconButtonWrapper';
|
|
import { Dropdown, DropdownItem } from 'components/common/Dropdown';
|
|
|
|
import MessageContent from './MessageContent/MessageContent';
|
|
import * as S from './MessageContent/MessageContent.styled';
|
|
|
|
const StyledDataCell = styled.td`
|
|
overflow: hidden;
|
|
white-space: nowrap;
|
|
text-overflow: ellipsis;
|
|
max-width: 350px;
|
|
min-width: 350px;
|
|
`;
|
|
|
|
const ClickableRow = styled.tr`
|
|
cursor: pointer;
|
|
`;
|
|
|
|
export interface Props {
|
|
message: TopicMessage;
|
|
}
|
|
|
|
const Message: React.FC<Props> = ({
|
|
message: {
|
|
timestamp,
|
|
timestampType,
|
|
offset,
|
|
key,
|
|
partition,
|
|
content,
|
|
valueFormat,
|
|
keyFormat,
|
|
headers,
|
|
},
|
|
}) => {
|
|
const [isOpen, setIsOpen] = React.useState(false);
|
|
const savedMessageJson = {
|
|
Content: content,
|
|
Offset: offset,
|
|
Key: key,
|
|
Partition: partition,
|
|
Headers: headers,
|
|
Timestamp: timestamp,
|
|
};
|
|
const formatTimestamp = useTimeFormat();
|
|
|
|
const savedMessage = JSON.stringify(savedMessageJson, null, '\t');
|
|
const { copyToClipboard, saveFile } = useDataSaver(
|
|
'topic-message',
|
|
savedMessage || ''
|
|
);
|
|
|
|
const toggleIsOpen = () => setIsOpen(!isOpen);
|
|
|
|
const [vEllipsisOpen, setVEllipsisOpen] = React.useState(false);
|
|
|
|
return (
|
|
<>
|
|
<ClickableRow
|
|
onMouseEnter={() => setVEllipsisOpen(true)}
|
|
onMouseLeave={() => setVEllipsisOpen(false)}
|
|
onClick={toggleIsOpen}
|
|
>
|
|
<td>
|
|
<IconButtonWrapper aria-hidden>
|
|
<MessageToggleIcon isOpen={isOpen} />
|
|
</IconButtonWrapper>
|
|
</td>
|
|
<td>{offset}</td>
|
|
<td>{partition}</td>
|
|
<td>
|
|
<div>{formatTimestamp(timestamp)}</div>
|
|
</td>
|
|
<StyledDataCell title={key}>{key}</StyledDataCell>
|
|
<StyledDataCell>
|
|
<S.Metadata>
|
|
<S.MetadataValue>{content}</S.MetadataValue>
|
|
</S.Metadata>
|
|
</StyledDataCell>
|
|
<td style={{ width: '5%' }}>
|
|
{vEllipsisOpen && (
|
|
<Dropdown>
|
|
<DropdownItem onClick={copyToClipboard}>
|
|
Copy to clipboard
|
|
</DropdownItem>
|
|
<DropdownItem onClick={saveFile}>Save as a file</DropdownItem>
|
|
</Dropdown>
|
|
)}
|
|
</td>
|
|
</ClickableRow>
|
|
{isOpen && (
|
|
<MessageContent
|
|
messageKey={key}
|
|
messageKeyFormat={keyFormat}
|
|
messageContent={content}
|
|
messageContentFormat={valueFormat}
|
|
headers={headers}
|
|
timestamp={timestamp}
|
|
timestampType={timestampType}
|
|
/>
|
|
)}
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default Message;
|