Skip to content

Commit

Permalink
message-card-tools-restyling (#307)
Browse files Browse the repository at this point in the history
* message-card-tools-restyling

* message-card-tools--restyling-release_6.1-based
 * change requests
  • Loading branch information
VitalyMashanov authored Dec 29, 2021
1 parent 8a30582 commit 26c8782
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 98 deletions.
14 changes: 7 additions & 7 deletions resources/icons/ascii.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions resources/icons/binar.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions resources/icons/json.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions resources/icons/messages-beautify.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions src/components/message/message-card/MessageCardBase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,6 @@ export function MessageCardBase({

const messageCardToolsConfig: MessageCardToolsConfig = {
message,
messageId,
messageType,
messageViewType: viewType,
toggleViewType,
isBookmarked: isBookmarked || false,
Expand Down
93 changes: 30 additions & 63 deletions src/components/message/message-card/MessageCardTools.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ const COPY_NOTIFICATION_TEXT = 'Text copied to the clipboard!';

export type MessageCardToolsConfig = {
message: EventMessage;
messageId: string;
messageType: string;
messageViewType: MessageViewType;
toggleViewType: (viewType: MessageViewType) => void;
isBookmarked: boolean;
Expand All @@ -43,15 +41,15 @@ export type MessageCardToolsConfig = {

const MessageCardTools = ({
message,
messageId,
messageType,
messageViewType,
toggleViewType,
isBookmarked,
toggleMessagePin,
isScreenshotMsg,
isEmbedded,
}: MessageCardToolsConfig) => {
const { messageId, messageType } = message;

const [isViewMenuOpen, setIsViewMenuOpen] = useState(false);
const rootRef = useRef<HTMLDivElement>(null);
const appViewMode = useViewMode();
Expand All @@ -66,20 +64,15 @@ const MessageCardTools = ({
? [
MessageViewType.JSON,
MessageViewType.FORMATTED,
MessageViewType.BINARY,
MessageViewType.ASCII,
MessageViewType.BINARY,
]
: [MessageViewType.BINARY, MessageViewType.ASCII];

function onCopy(jsonObjectToCopy: 'body' | 'fields' = 'body') {
function onCopy() {
let content: string;

const jsonToCopy =
jsonObjectToCopy === 'fields'
? message.body?.fields
? normalizeFields(message.body.fields)
: null
: message.body;
const jsonToCopy = message.body;

switch (messageViewType) {
case MessageViewType.ASCII:
Expand Down Expand Up @@ -119,11 +112,10 @@ const MessageCardTools = ({
</div>
<MessagePopup isOpen={isViewMenuOpen}>
{!isEmbedded && (
<div className='message-card-tools__controls-group'>
<div
className='message-card-tools__controls-group'
title={isBookmarked ? 'Remove bookmark' : 'Bookmark'}>
<div className='message-card-tools__item' onClick={() => toggleMessagePin()}>
<span className='message-card-tools__item-title'>
{isBookmarked ? 'Remove bookmark' : 'Bookmark'}
</span>
<div
className={createBemElement(
'message-card-tools',
Expand All @@ -132,75 +124,50 @@ const MessageCardTools = ({
isBookmarked ? 'pinned' : null,
)}
/>

<div
className={createBemElement(
'message-card-tools',
'indicator',
'bookmark',
isBookmarked ? 'active' : null,
)}
/>
</div>
</div>
)}
{!isScreenshotMsg && (
<div className='message-card-tools__controls-group'>
{viewTypes.map(viewType => {
const iconClassName = createBemElement('message-card-tools', 'icon', viewType);
const indicatorClassName = createBemElement(
const itemClassName = createBemElement(
'message-card-tools',
'indicator',
'item',
viewType === messageViewType ? 'active' : null,
);
const iconClassName = createBemElement('message-card-tools', 'icon', viewType);

return (
<div
title={viewType}
className='message-card-tools__item'
className={itemClassName}
key={viewType}
onClick={() => toggleViewType(viewType)}>
<span className='message-card-tools__item-title'>{viewType}</span>
<div className={iconClassName} />
<div className={indicatorClassName} />
</div>
);
})}
</div>
)}
{!isScreenshotMsg &&
(messageViewType === MessageViewType.JSON ||
messageViewType === MessageViewType.FORMATTED) && (
<div className='message-card-tools__controls-group'>
{['body', 'fields'].map(copyOption => (
<div
key={copyOption}
title='Copy content to clipboard'
className='message-card-tools__item'
onClick={() => {
onCopy(copyOption as 'body' | 'fields');
setIsViewMenuOpen(false);
}}>
<span className='message-card-tools__item-title'>
{copyOption === 'body' ? 'Copy full' : 'Copy simplified'}
</span>
<div className='message-card-tools__copy-icon' />
<div
className={createBemElement('message-card-tools', 'indicator', 'bookmark')}
/>
</div>
))}
</div>
)}
{isScreenshotMsg && (
<>
<a
{!isScreenshotMsg ? (
<div className='message-card-tools__controls-group'>
<div
title='Copy to clipboard'
className='message-card-tools__item'
download={`${messageId}.${messageType.replace('image/', '')}`}
href={`data:${message.messageType};base64,${message.bodyBase64 || ''}`}>
<div className='message-card-tools__icon download' />
</a>
</>
onClick={() => {
onCopy();
setIsViewMenuOpen(false);
}}>
<div className='message-card-tools__copy-icon' />
</div>
</div>
) : (
<a
className='message-card-tools__item'
download={`${messageId}.${messageType.replace('image/', '')}`}
href={`data:${message.messageType};base64,${message.bodyBase64 || ''}`}>
<div className='message-card-tools__icon download' />
</a>
)}
{appViewMode === ViewMode.EmbeddedMessages && (
<div className='message-card-tools__controls-group'>
Expand Down
24 changes: 12 additions & 12 deletions src/styles/messages.scss
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@
}

.message-card-tools {
position: relative;
margin: 1px 4px 0 4px;
align-self: stretch;
display: flex;
Expand Down Expand Up @@ -126,35 +127,34 @@

&__controls {
position: absolute;
right: 11px;
right: -7px;
background-color: white;
box-shadow: 0 0 1px 0 rgba(0, 0, 0, 0.5);
display: flex;
padding: 4px 0;
gap: 4px;
flex-direction: column;
padding: 4px 8px;
border-radius: 2px;
z-index: 2;

&-group {
display: flex;
flex-direction: column;
&:nth-child(2) {
margin: 0 24px;
}
}
}

&__item {
display: flex;
justify-content: flex-end;
align-items: center;
gap: 4px;
padding: 2px 4px 2px 10px;
cursor: pointer;
font-size: 11px;
color: $primaryTextColor;
&:not(:last-child) {
margin-right: 12px;
}

&-title {
text-transform: capitalize;
}

&.active,
&:hover {
background-color: rgba(0, 0, 0, 0.07);
}
Expand Down Expand Up @@ -431,9 +431,9 @@

.mc-raw {
display: flex;
gap: 10px;
align-items: center;
position: relative;
min-height: 26px;

&__header {
display: flex;
Expand Down

0 comments on commit 26c8782

Please sign in to comment.