From f152a6735adfaa7a6c18b62ef934020ce6ea17aa Mon Sep 17 00:00:00 2001 From: nithindavid <1277421+nithindavid@users.noreply.github.com> Date: Wed, 14 Dec 2022 22:31:08 +0530 Subject: [PATCH] Fix label overflow --- .../assets/scss/widgets/_buttons.scss | 4 + .../dashboard/components/ui/Label.vue | 9 +- .../widgets/conversation/ConversationCard.vue | 232 ++++++++++++++++-- .../i18n/locale/en/conversation.json | 11 + .../shared/assets/stylesheets/colors.scss | 4 +- 5 files changed, 229 insertions(+), 31 deletions(-) diff --git a/app/javascript/dashboard/assets/scss/widgets/_buttons.scss b/app/javascript/dashboard/assets/scss/widgets/_buttons.scss index 13fd0ce73..049f054f4 100644 --- a/app/javascript/dashboard/assets/scss/widgets/_buttons.scss +++ b/app/javascript/dashboard/assets/scss/widgets/_buttons.scss @@ -199,6 +199,10 @@ $default-button-height: 4.0rem; height: auto; margin: 0; padding: 0; + + &:hover { + text-decoration: underline; + } } } diff --git a/app/javascript/dashboard/components/ui/Label.vue b/app/javascript/dashboard/components/ui/Label.vue index cb1dd010d..a2e3cfcaf 100644 --- a/app/javascript/dashboard/components/ui/Label.vue +++ b/app/javascript/dashboard/components/ui/Label.vue @@ -4,7 +4,7 @@ @@ -125,6 +125,9 @@ export default { .label--icon { cursor: pointer; + } + + .label-color-dot { margin-right: var(--space-smaller); } @@ -230,11 +233,13 @@ export default { height: var(--space-one); border-radius: var(--border-radius-small); margin-right: var(--space-smaller); + box-shadow: var(--shadow-small); } .label.small .label-color-dot { width: var(--space-small); height: var(--space-small); border-radius: var(--border-radius-small); - margin-right: var(--space-smaller); + margin-right: var(--space-micro); + box-shadow: var(--shadow-small); } diff --git a/app/javascript/dashboard/components/widgets/conversation/ConversationCard.vue b/app/javascript/dashboard/components/widgets/conversation/ConversationCard.vue index ee474bdcb..4574c68d1 100644 --- a/app/javascript/dashboard/components/widgets/conversation/ConversationCard.vue +++ b/app/javascript/dashboard/components/widgets/conversation/ConversationCard.vue @@ -1,5 +1,6 @@ {{ currentContact.name }} + @@ -116,15 +124,28 @@ @@ -233,6 +254,8 @@ export default { return { hovered: false, showContextMenu: false, + showAllLabels: false, + showExpandLabelButton: false, contextMenu: { x: null, y: null, @@ -349,8 +372,124 @@ export default { }); return frontendURL(path); }, + badgeTooltipKey() { + return { + instagram_direct_message: 'INSTAGRAM_DM', + facebook: 'FB_DM', + 'twitter-tweet': 'TWITTER_TWEET', + 'twitter-dm': 'TWITTER_DM', + whatsapp: 'WHATSAPP', + sms: 'SMS', + 'Channel::Line': 'LINE', + 'Channel::Telegram': 'TELEGRAM', + 'Channel::WebWidget': 'WEB_WIDGET', + }[this.inboxBadge]; + }, + badgeSrc() { + return { + instagram_direct_message: 'instagram-dm', + facebook: 'messenger', + 'twitter-tweet': 'twitter-tweet', + 'twitter-dm': 'twitter-dm', + whatsapp: 'whatsapp', + sms: 'sms', + 'Channel::Line': 'line', + 'Channel::Telegram': 'telegram', + 'Channel::WebWidget': '', + }[this.inboxBadge]; + }, + badgeStyle() { + const size = 12; + const badgeSize = `${size + 2}px`; + const borderRadius = `${size / 2}px`; + return { width: badgeSize, height: badgeSize, borderRadius }; + }, + remainingLabel() { + const { label } = this.chat; + const { name } = this.activeLabel; + return label.filter(l => l.name !== name); + }, + }, + watch: { + activeLabels() { + const footer = this.$refs.conversationCard.querySelector('.footer'); + const labelsWrap = this.$refs.conversationCard.querySelector( + '.labels-wrap' + ); + const labels = this.$refs.conversationCard.querySelectorAll('.label'); + + if (!footer || !labelsWrap || this.activeLabels.length === 0) { + return; + } + + Array.from(labels).forEach(label => { + label.classList.remove('hidden'); + }); + + this.showExpandLabelButton = + footer.offsetWidth - 80 < labelsWrap.scrollWidth; + + const labelsWrapWidth = footer.scrollWidth; + let currentIndex = 0; + let labelsWidth = 0; + if (labels.length === 0) return; + + do { + if (labelsWidth + 80 < labelsWrapWidth) { + labelsWidth += Array.from(labels)[currentIndex].offsetWidth + 24; + currentIndex += 1; + } else { + break; + } + } while (currentIndex < labels.length); + + Array.from(labels).forEach((label, index) => { + if (index >= currentIndex) { + label.classList.add('hidden'); + } else { + label.classList.remove('hidden'); + } + }); + }, + }, + mounted() { + this.collapseLabels(); }, methods: { + collapseLabels() { + const footer = this.$refs.conversationCard.querySelector('.footer'); + const labelsWrap = this.$refs.conversationCard.querySelector( + '.labels-wrap' + ); + const labels = this.$refs.conversationCard.querySelectorAll('.label'); + + if (!footer || !labelsWrap || this.activeLabels.length === 0) { + return; + } + + const labelsWrapWidth = footer.scrollWidth; + let currentIndex = 0; + let labelsWidth = 0; + this.showExpandLabelButton = + footer.offsetWidth - 80 < labelsWrap.scrollWidth; + + do { + if (labelsWidth + 80 < labelsWrapWidth) { + labelsWidth += Array.from(labels)[currentIndex].offsetWidth + 24; + currentIndex += 1; + } else { + break; + } + } while (currentIndex < labels.length); + + Array.from(labels).forEach((label, index) => { + if (index >= currentIndex) { + label.classList.add('hidden'); + } else { + label.classList.remove('hidden'); + } + }); + }, cardClick(chat) { const { activeInbox } = this; const path = conversationUrl({ @@ -405,6 +544,10 @@ export default { snoozedUntil ); }, + onShowLabels(e) { + e.stopPropagation(); + this.showAllLabels = !this.showAllLabels; + }, async onAssignAgent(agent) { this.$emit('assign-agent', agent, [this.chat.id]); this.closeContextMenu(); @@ -537,11 +680,40 @@ export default { .footer { display: flex; align-items: center; - flex-flow: row wrap; .label { margin-bottom: var(--space-smaller); } + + .hidden { + display: none; + } + + .remaining-labels { + height: var(--space-two); + position: sticky; + flex-shrink: 0; + right: 0; + margin-bottom: var(--space-smaller); + margin-right: var(--space-medium); + } +} + +.labels-wrap { + display: flex; + align-items: center; + height: var(--space-medium); + overflow: hidden; + min-width: 0; + flex-shrink: 1; + &.expand { + height: auto; + overflow: visible; + flex-flow: row wrap; + .hidden { + display: inline-flex; + } + } } .checkbox-wrapper { @@ -577,22 +749,11 @@ export default { /* color: var(--s-800); */ } -.footer { - display: flex; - align-items: center; - flex-flow: row wrap; - margin-top: var(--space-smaller); - - .label { - margin-bottom: var(--space-smaller); - } -} - .conversation-meta { display: flex; } .conversation__id { - margin-left: var(--space-small); + margin-left: var(--space-smaller); } .message--attachment-icon { @@ -618,12 +779,29 @@ export default { } .badge { - min-width: var(--space-normal); - height: var(--space-normal); - line-height: var(--space-normal); - padding: 0 var(--space-micro); + min-width: 14px; + height: 14px; + line-height: 14px; + padding: 0; text-align: center; border-radius: var(--space-medium); font-weight: var(--font-weight-bold); } + +.source-badge { + margin-left: var(--space-smaller); + filter: grayscale(100%); + opacity: 0.7; + padding: var(--space-micro); + + &:hover { + filter: grayscale(0); + opacity: 1; + } +} + +.overflow-wrap { + display: flex; + width: 100%; +} diff --git a/app/javascript/dashboard/i18n/locale/en/conversation.json b/app/javascript/dashboard/i18n/locale/en/conversation.json index 4ad8a6e56..cf8cd42b2 100644 --- a/app/javascript/dashboard/i18n/locale/en/conversation.json +++ b/app/javascript/dashboard/i18n/locale/en/conversation.json @@ -157,6 +157,17 @@ "CARD": { "COPY_LINK": "Copy link", "GOTO_INBOX": "Goto inbox" + }, + "VIA_TOOLTIP": { + "INSTAGRAM_DM": "Via instagram DM", + "FB_DM": "Via facebook DM", + "TWITTER_TWEET": "Via tweet", + "TWITTER_DM": "Via twitter DM", + "WHATSAPP": "Via WhatsApp", + "SMS": "Via SMS", + "LINE": "Via Line", + "TELEGRAM": "Via telegram", + "WEB_WIDGET": "Via live chat" } }, "EMAIL_TRANSCRIPT": { diff --git a/app/javascript/shared/assets/stylesheets/colors.scss b/app/javascript/shared/assets/stylesheets/colors.scss index 64b7f3f94..dced82da1 100644 --- a/app/javascript/shared/assets/stylesheets/colors.scss +++ b/app/javascript/shared/assets/stylesheets/colors.scss @@ -86,8 +86,8 @@ // Common color aliases --color-woot: var(--w-500); - --color-heading: #1f2d3d; - --color-body: #3c4858; + --color-heading: var(--s-900); + --color-body: var(--s-700); --color-border: var(--s-75); --color-border-light: var(--s-50);