diff --git a/kafka-ui-react-app/src/components/App.scss b/kafka-ui-react-app/src/components/App.scss index e66343f9dd..98dde95019 100644 --- a/kafka-ui-react-app/src/components/App.scss +++ b/kafka-ui-react-app/src/components/App.scss @@ -36,3 +36,26 @@ $navbar-width: 250px; .react-datepicker-popper { z-index: 30 !important; } + +.topic-message-button { + &::after { + content: attr(data-title); + position: absolute; + top: -140%; + z-index: 1; + background: #F5F5F5; + color: rgb(89, 89, 89); + border-radius: 5px; + font-size: 15px; + padding: 5px 10px; + opacity: 0; + pointer-events: none; + transition: .2s opacity; + transition-delay: 0s; + } + + &:hover::after { + opacity: 1; + transition-delay: .5s; + } +} diff --git a/kafka-ui-react-app/src/components/Topics/Details/Messages/MessageItem.tsx b/kafka-ui-react-app/src/components/Topics/Details/Messages/MessageItem.tsx index 0f7b13de23..d08c09bb49 100644 --- a/kafka-ui-react-app/src/components/Topics/Details/Messages/MessageItem.tsx +++ b/kafka-ui-react-app/src/components/Topics/Details/Messages/MessageItem.tsx @@ -15,15 +15,72 @@ const MessageItem: React.FC = ({ offset, timestamp, content, -}) => ( - - {format(timestamp, 'yyyy-MM-dd HH:mm:ss')} - {offset} - {partition} - - {content && } - - -); +}) => { + const copyData = () => { + if (navigator.clipboard) + navigator.clipboard.writeText(JSON.stringify(content || {})); + }; + const saveFile = () => { + let extension = 'json'; + if (typeof content === 'string') { + try { + JSON.parse(content); + } catch (e) { + extension = 'txt'; + } + } + const dataStr = `data:text/json;charset=utf-8,${encodeURIComponent( + JSON.stringify(content || {}) + )}`; + const downloadAnchorNode = document.createElement('a'); + downloadAnchorNode.setAttribute('href', dataStr); + downloadAnchorNode.setAttribute( + 'download', + `topic-message[${timestamp}].${extension}` + ); + document.body.appendChild(downloadAnchorNode); + downloadAnchorNode.click(); + downloadAnchorNode.remove(); + }; + + const buttonStyle = { + height: '30px', + }; + const buttonClasses = 'button is-link is-outlined topic-message-button'; + return ( + + {format(timestamp, 'yyyy-MM-dd HH:mm:ss')} + {offset} + {partition} + + {content && ( +
+
+ + +
+ +
+ )} + + + ); +}; export default MessageItem; diff --git a/kafka-ui-react-app/src/components/Topics/Details/Messages/__test__/__snapshots__/MessageItem.spec.tsx.snap b/kafka-ui-react-app/src/components/Topics/Details/Messages/__test__/__snapshots__/MessageItem.spec.tsx.snap index b3dc6ebf01..8038e1d230 100644 --- a/kafka-ui-react-app/src/components/Topics/Details/Messages/__test__/__snapshots__/MessageItem.spec.tsx.snap +++ b/kafka-ui-react-app/src/components/Topics/Details/Messages/__test__/__snapshots__/MessageItem.spec.tsx.snap @@ -36,14 +36,56 @@ exports[`MessageItem when content is defined matches snapshot 1`] = ` } } > - +
+ > + + +
+ + `;